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
2022-06-06 11:08:52 -07:00
committed by Christophe Paquot
vanhempi 9e7b44511a
commit faa7ee48ba
2 muutettua tiedostoa jossa 20 lisäystä ja 3 poistoa
+18 -2
Näytä tiedosto
@@ -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);
}
+2 -1
Näytä tiedosto
@@ -38,7 +38,8 @@ public:
const hipMemAllocationProp& GetProperties() const { return properties_; }
hipMemGenericAllocationHandle_t asMemGenericAllocationHandle() { return reinterpret_cast<hipMemGenericAllocationHandle_t>(this); }
amd::Memory& asAmdMemory() { return *amd::MemObjMap::FindMemObj(ptr_); }
amd::Memory& asAmdMemory() { return *amd::MemObjMap::FindMemObj(genericAddress()); }
void* genericAddress() const { return ptr_; }
};
};