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
Цей коміт міститься в:
Ioannis Assiouras
2024-12-04 22:47:44 +00:00
джерело 78f62d3230
коміт e80442fdbf
+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;
}