From c308cf0951e16b30ce729c0b6ee7d4ab6d08a8d2 Mon Sep 17 00:00:00 2001 From: sdashmiz Date: Fri, 18 Mar 2022 15:52:19 -0400 Subject: [PATCH] SWDEV-303187: find the device pointer is for - the pointer attribute is fetched for might not be the current device Signed-off-by: sdashmiz Change-Id: Ibcea92b52da31adba5f62baae25b55671704c005 [ROCm/clr commit: ae506b40c02683a1292646d9c1506e78cbd47af6] --- projects/clr/hipamd/src/hip_memory.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index f07977772b..a4cc73f31d 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -2624,6 +2624,7 @@ hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void size_t offset = 0; amd::Memory* memObj = getMemoryObject(ptr, offset); int device = 0; + device::Memory* devMem = nullptr; memset(attributes, 0, sizeof(hipPointerAttribute_t)); if (memObj != nullptr) { @@ -2637,8 +2638,13 @@ hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void attributes->hostPointer = static_cast(memObj->getSvmPtr()) + offset; } } - - device::Memory* devMem = memObj->getDeviceMemory(*hip::getCurrentDevice()->devices()[0]); + // the pointer that attribute is retrieved for might not be on the current device + for (const auto& device : g_devices) { + if(device->deviceId() == memObj->getUserData().deviceId) { + devMem = memObj->getDeviceMemory(*device->devices()[0]); + break; + } + } //getDeviceMemory can fail, hence validate the sanity of the mem obtained if (nullptr == devMem) { DevLogPrintfError("getDeviceMemory for ptr failed : %p \n", ptr);