diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 5cde1a41ca..c297724217 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -3604,7 +3604,8 @@ hipError_t ihipPointerGetAttributes(void* data, hipPointer_attribute attribute, } case HIP_POINTER_ATTRIBUTE_DEVICE_POINTER: { if (memObj) { - device::Memory* devMem = memObj->getDeviceMemory(*hip::getCurrentDevice()->devices()[0]); + amd::Device* currentDevice = hip::getCurrentDevice()->devices()[0]; + device::Memory* devMem = memObj->getDeviceMemory(*currentDevice); // getDeviceMemory can fail, hence validate the sanity of the mem obtained if (nullptr == devMem) { @@ -3612,6 +3613,16 @@ hipError_t ihipPointerGetAttributes(void* data, hipPointer_attribute attribute, "getDeviceMemory for ptr failed : %p", ptr); return hipErrorMemoryAllocation; } + + // Check if this is a cross-device access without peer access enabled + const std::vector& memDevices = memObj->getContext().devices(); + if (memDevices.size() == 1 && memDevices[0] != currentDevice) { + device::Memory* origDevMem = memObj->getDeviceMemory(*memDevices[0]); + if (origDevMem != nullptr && !origDevMem->getAllowedPeerAccess()) { + return hipErrorInvalidValue; + } + } + *reinterpret_cast(data) = reinterpret_cast(devMem->virtualAddress() + offset); } else {