diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 45244291ec..85fec00987 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -3323,6 +3323,7 @@ hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* dev_ptr) { device = hip::getCurrentDevice()->devices()[0]; ihandle = reinterpret_cast(handle); + ihandle->owners_device_id = hip::getCurrentDevice()->deviceId(); if (!device->IpcCreate(dev_ptr, &(ihandle->psize), ihandle->ipc_handle, &(ihandle->poffset))) { LogPrintfError("IPC memory creation failed for memory: 0x%x", dev_ptr); @@ -3356,6 +3357,13 @@ hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigne HIP_RETURN(hipErrorInvalidContext); } + if (ihandle->owners_device_id >= g_devices.size()) { + HIP_RETURN(hipErrorInvalidValue); + } + + amd::Device* peer_device = g_devices[ihandle->owners_device_id]->asContext()->devices()[0]; + device->enableP2P(peer_device); + amd_mem_obj = amd::MemObjMap::FindIpcHandleMemObj(*ihandle); if (amd_mem_obj == nullptr) { if (!device->IpcAttach(ihandle->ipc_handle, ihandle->psize, ihandle->poffset, flags, dev_ptr)) { diff --git a/projects/clr/rocclr/device/device.hpp b/projects/clr/rocclr/device/device.hpp index 25d7ea9825..6cc562556f 100644 --- a/projects/clr/rocclr/device/device.hpp +++ b/projects/clr/rocclr/device/device.hpp @@ -1397,7 +1397,8 @@ class MemObjMap : public AllStatic { size_t psize; ///< Total size of the device memory allocation size_t poffset; ///< Offset within the allocation int owners_process_id; ///< ID of the process that owns the allocation - char reserved[LP64_SWITCH(20, 12)]; ///< Reserved for future extensions + int owners_device_id; ///< ID of the device that owns the allocation + char reserved[LP64_SWITCH(16, 8)]; ///< Reserved for future extensions bool operator<(const IpcMemHandle& h) const { int cmp = std::memcmp(ipc_handle, h.ipc_handle, AMD_IPC_MEM_HANDLE_SIZE);