SWDEV-497759 - Fix memObj offset computation for hipHostRegister on Windows mgpu

On Windows, hipHostRegister may add a single object in the MemObjMap
that maps to memory that is allocated on different devices.
This change ensures that the offset that is returned from
getMemoryObject() is computed relative to the memory that is allocated
on the current device.

Change-Id: I5fd3af200bf6f4926fdeaea12dcb9d0154d3a843


[ROCm/clr commit: e80442fdbf]
이 커밋은 다음에 포함됨:
Ioannis Assiouras
2024-12-04 22:47:44 +00:00
부모 12dc02b4f8
커밋 dc3ca8aab7
+14
파일 보기
@@ -40,6 +40,20 @@ amd::Memory* getMemoryObject(const void* ptr, size_t& offset, size_t size) {
memObj = (hip::getCurrentDevice()->asContext()->svmDevices()[0])->GetArenaMemObj(
ptr, offset, size);
}
// On Windows, when using hipHostRegister, the map may contain a single memory object for
// multiple devices. This is because device addresses can overlap.
// The offset needs to be calculated relative to the memory of the current device.
if (IS_WINDOWS && (memObj != nullptr) && (memObj->getMemFlags() & CL_MEM_USE_HOST_PTR)) {
device::Memory* currentDevMem =
memObj->getDeviceMemory(*hip::getCurrentDevice()->devices()[0], false);
if (currentDevMem != nullptr) {
size_t currentDevOffset = reinterpret_cast<uint64_t>(ptr) - currentDevMem->virtualAddress();
if (currentDevOffset < memObj->getSize()) {
offset = currentDevOffset;
}
}
}
return memObj;
}