SWDEV-322620 - Virtual Memory Management

Implements hipMemRetainAllocationHandle
HIP layer updates the svmPtr of the amd::memory
ROCCLR just manages the MemObjMap
This is because HIP knows the orignal (generic) address of the
physical memory whereas ROCCLR doesn't keep track of that

Change-Id: Ied26d7f814bc468f5cf586c967020737b9aa9e9f
This commit is contained in:
Christophe Paquot authored and Christophe Paquot committed 2022-06-10 17:48:07 -04:00
1 parent 9e7b44511a
commit faa7ee48ba
2 files changed
+20 -3

No files matched your search

+18 -2
View File
@@ -202,8 +202,8 @@ hipError_t hipMemMap(void* ptr, size_t size, size_t offset, hipMemGenericAllocat
cmd->awaitCompletion();
cmd->release();
amd::Memory* va = amd::MemObjMap::FindMemObj(ptr);
va->getUserData().deviceId = ga->GetProperties().location.id;
// update the internal svm address to ptr
ga->asAmdMemory().setSvmPtr(ptr);
HIP_RETURN(hipSuccess);
}
@@ -235,6 +235,18 @@ hipError_t hipMemRetainAllocationHandle(hipMemGenericAllocationHandle_t* handle,
if (handle == nullptr || addr == nullptr) HIP_RETURN(hipErrorInvalidValue);
amd::Memory* mem = amd::MemObjMap::FindMemObj(addr);
if (mem == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
*handle = reinterpret_cast<hipMemGenericAllocationHandle_t>(mem->getUserData().data);
if (*handle == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
HIP_RETURN(hipSuccess);
}
@@ -265,6 +277,10 @@ hipError_t hipMemUnmap(void* ptr, size_t size) {
cmd->awaitCompletion();
cmd->release();
// restore the original va of the generic allocation
hip::GenericAllocation* ga = reinterpret_cast<hip::GenericAllocation*>(va->getUserData().data);
va->setSvmPtr(ga->genericAddress());
HIP_RETURN(hipSuccess);
}