From c398c75512f099227244a3d13e32d79be18fdce3 Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Mon, 20 Nov 2023 13:40:18 +0000 Subject: [PATCH] SWDEV-432977 - Set the correct device id in hipIpcOpenMemHandle hipIpcOpenMemHandle can be used to open memory handle and fetch a device pointer on a different device than the actual device where the memory was allocated. The device Id must be set to the current device in such cases and not the original device. Change-Id: Ie1c7eada928d02124a41125876876f96015552e5 --- hipamd/src/hip_memory.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hipamd/src/hip_memory.cpp b/hipamd/src/hip_memory.cpp index ec32019033..64ed22985c 100644 --- a/hipamd/src/hip_memory.cpp +++ b/hipamd/src/hip_memory.cpp @@ -3492,6 +3492,7 @@ hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigne amd::Memory* amd_mem_obj = nullptr; amd::Device* device = nullptr; ihipIpcMemHandle_t* ihandle = nullptr; + size_t offset = 0; if (dev_ptr == nullptr || flags != hipIpcMemLazyEnablePeerAccess) { HIP_RETURN(hipErrorInvalidValue); @@ -3516,6 +3517,9 @@ hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigne HIP_RETURN(hipErrorInvalidDevicePointer); } + amd_mem_obj = getMemoryObject(*dev_ptr, offset); + amd_mem_obj->getUserData().deviceId = hip::getCurrentDevice()->deviceId(); + HIP_RETURN(hipSuccess); }