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
Этот коммит содержится в:
Christophe Paquot
2022-06-06 11:08:52 -07:00
коммит произвёл Christophe Paquot
родитель 9e7b44511a
Коммит faa7ee48ba
2 изменённых файлов: 20 добавлений и 3 удалений
+18 -2
Просмотреть файл
@@ -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);
}