Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions projects/rocr-runtime/libhsakmt/include/impl/wddm/gpu_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include <cstddef>
#include <cstdint>
#include <vector>
#include "util/utils.h"
#include "impl/wddm/types.h"
#include "impl/wddm/thunks.h"
Expand Down Expand Up @@ -259,6 +260,14 @@ class GpuMemory {

ErrorCode MapGpuVirtualAddress(const gpusize map_addr, const gpusize size, gpusize offset = 0);
ErrorCode UnmapGpuVirtualAddress(const gpusize map_addr, const gpusize size, gpusize offset = 0);

// This allocation's view on dev. System and user memory can create a peer view
// at the owner's VA; the owner keeps that reservation. *created is set when a
// new peer view was added.
GpuMemory* ViewOn(WDDMDevice* dev, bool create, bool* created);
void DropPeer(GpuMemory* peer);
void ReleasePeers();
GpuMemory* Owner() const { return owner_; }
ErrorCode MapMemoryToVirtualAddress(bool create_phys_mem = true);
ErrorCode MakeResident();
ErrorCode Evict();
Expand Down Expand Up @@ -286,11 +295,12 @@ class GpuMemory {

protected:
explicit GpuMemory(WDDMDevice *device);
private:
uint64_t AdjustSize(gpusize size) const;
private:
friend class WDDMDevice;

uint64_t AdjustSize(gpusize size) const;
ErrorCode MapFromPeer(GpuMemory* owner);

WDDMDevice *const device_;

GpuMemoryDesc desc_;
Expand All @@ -303,6 +313,9 @@ class GpuMemory {

int mem_fd_; // IPC sigal's sys mem fd

GpuMemory* owner_ = nullptr; // set when this object is a peer view
std::vector<GpuMemory*> peers_; // peer views; only the owner has entries

bool is_phymem_created = false; // status of physical memory allocation
bool is_sysmem_locked_ = false; // kSystem allocation pinned via D3DKMTLock2

Expand Down
3 changes: 2 additions & 1 deletion projects/rocr-runtime/libhsakmt/src/dxg/libdrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ HSAKMTAPI int amdgpu_bo_import(amdgpu_device_handle dev,
}

wsl::thunk::WDDMDevice *pDevice = reinterpret_cast<wsl::thunk::WDDMDevice *>(dev);
HSAuint32 node_id = static_cast<HSAuint32>(pDevice->NodeId());
wsl::thunk::GpuMemoryHandle mem_handle;
bool is_ipc_memfd = is_ipc_sysmemfd(shared_handle);
bool alloc_va = is_ipc_memfd;

// kmt handle importer is false for dma_buf_fd
HSAKMT_STATUS ret = import_dmabuf_fd(shared_handle, pDevice->NodeId(), alloc_va, is_ipc_memfd,
HSAKMT_STATUS ret = import_dmabuf_fd(shared_handle, 1, &node_id, alloc_va, is_ipc_memfd,
&mem_handle, false);
if (ret == HSAKMT_STATUS_SUCCESS) {
//use GpuMemory object handle as drm buf handle
Expand Down
10 changes: 6 additions & 4 deletions projects/rocr-runtime/libhsakmt/src/dxg/librocdxg.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#endif
#include <stdint.h>
#include <limits.h>
#include <vector>
#include "hsakmt/hsakmt.h"
#if defined(__linux__)
#include "hsakmt/hsakmt_drm.h"
Expand Down Expand Up @@ -70,8 +71,7 @@ struct hsakmtRuntime {
system_heap_space_start_(0),
system_heap_space_size_(0),
handle_aperture_start_(0),
handle_aperture_size_(0),
default_node(1) {}
handle_aperture_size_(0) {}

void HeapInit();
void HeapFini();
Expand Down Expand Up @@ -113,7 +113,8 @@ struct hsakmtRuntime {
unsigned long dxg_open_count;

size_t max_single_alloc_size;
uint32_t default_node;
/* GPU HSA nodes used when the caller does not name a node. */
std::vector<uint32_t> default_node;
D3DKMT_DRIVERVERSION wddm_version = static_cast<D3DKMT_DRIVERVERSION>(0);

/* local heap means bo's backend is vram of all GPUs */
Expand Down Expand Up @@ -305,7 +306,8 @@ uint32_t get_vgpr_size_per_cu(HSA_ENGINE_ID id);

bool is_ipc_sysmemfd(uint64_t fd);

HSAKMT_STATUS import_dmabuf_fd(uint64_t DMABufFd, uint32_t NodeId, bool alloc_va, bool is_ipc_memfd,
HSAKMT_STATUS import_dmabuf_fd(uint64_t DMABufFd, HSAuint64 NumberOfNodes, HSAuint32* NodeArray,
bool alloc_va, bool is_ipc_memfd,
wsl::thunk::GpuMemoryHandle* GpuMemHandle, bool is_kmt_handle,
uint64_t size_hint = 0);

Expand Down
Loading
Loading