From c2b3dd7dc5e6bf584f14012ee3e8b57fca1d6791 Mon Sep 17 00:00:00 2001 From: Christophe Paquot Date: Mon, 25 Apr 2022 16:30:37 -0700 Subject: [PATCH] SWDEV-322620 - Virtual Memory Management Implemented hipMemMap and hipMemUnmap Change-Id: Idc75e3964d88e375e445733557cfa8e421688f1f [ROCm/clr commit: 6d73282f25c429c94b8260ae2567c068d42a3245] --- projects/clr/hipamd/src/hip_vm.cpp | 21 +++++++++++++++++++++ projects/clr/hipamd/src/hip_vm.hpp | 1 + 2 files changed, 22 insertions(+) diff --git a/projects/clr/hipamd/src/hip_vm.cpp b/projects/clr/hipamd/src/hip_vm.cpp index 0f9c55a3fc..31eb381a76 100644 --- a/projects/clr/hipamd/src/hip_vm.cpp +++ b/projects/clr/hipamd/src/hip_vm.cpp @@ -193,6 +193,18 @@ hipError_t hipMemMap(void* ptr, size_t size, size_t offset, hipMemGenericAllocat HIP_RETURN(hipErrorInvalidValue); } + hip::GenericAllocation* ga = reinterpret_cast(handle); + + auto& queue = *g_devices[ga->GetProperties().location.id]->NullStream(); + + amd::Command* cmd = new amd::VirtualMapCommand(queue, amd::Command::EventWaitList{}, ptr, size, &ga->asAmdMemory()); + cmd->enqueue(); + cmd->awaitCompletion(); + cmd->release(); + + amd::Memory* va = amd::MemObjMap::FindMemObj(ptr); + va->getUserData().deviceId = ga->GetProperties().location.id; + HIP_RETURN(hipSuccess); } @@ -244,6 +256,15 @@ hipError_t hipMemUnmap(void* ptr, size_t size) { if (ptr == nullptr) HIP_RETURN(hipErrorInvalidValue); + amd::Memory* va = amd::MemObjMap::FindMemObj(ptr); + + auto& queue = *g_devices[va->getUserData().deviceId]->NullStream(); + + amd::Command* cmd = new amd::VirtualMapCommand(queue, amd::Command::EventWaitList{}, ptr, size, nullptr); + cmd->enqueue(); + cmd->awaitCompletion(); + cmd->release(); + HIP_RETURN(hipSuccess); } diff --git a/projects/clr/hipamd/src/hip_vm.hpp b/projects/clr/hipamd/src/hip_vm.hpp index dfe3240e4c..a6b8f7ed7d 100644 --- a/projects/clr/hipamd/src/hip_vm.hpp +++ b/projects/clr/hipamd/src/hip_vm.hpp @@ -38,6 +38,7 @@ public: const hipMemAllocationProp& GetProperties() const { return properties_; } hipMemGenericAllocationHandle_t asMemGenericAllocationHandle() { return reinterpret_cast(this); } + amd::Memory& asAmdMemory() { return *amd::MemObjMap::FindMemObj(ptr_); } }; };