SWDEV-529449 - Bug fix when retrieving a memobj from the IPC mem handle

This commit is contained in:
Assiouras, Ioannis
2025-05-13 19:18:22 +01:00
committed by GitHub
parent 5606debd8e
commit f7482ef0a6
7 changed files with 55 additions and 53 deletions
-10
View File
@@ -48,9 +48,6 @@
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
/*! IHIP IPC MEMORY Structure */
#define IHIP_IPC_MEM_HANDLE_SIZE 32
#define IHIP_IPC_MEM_RESERVED_SIZE LP64_SWITCH(20,12)
namespace hip{
extern std::once_flag g_ihipInitialized;
}
@@ -89,13 +86,6 @@ struct GraphNode;
struct GraphExec;
struct UserObject;
class Stream;
typedef struct ihipIpcMemHandle_st {
char ipc_handle[IHIP_IPC_MEM_HANDLE_SIZE]; ///< ipc memory handle on ROCr
size_t psize;
size_t poffset;
int owners_process_id;
char reserved[IHIP_IPC_MEM_RESERVED_SIZE];
} ihipIpcMemHandle_t;
#define IHIP_IPC_EVENT_HANDLE_SIZE 32
#define IHIP_IPC_EVENT_RESERVED_SIZE LP64_SWITCH(28,24)
+11 -20
View File
@@ -3236,16 +3236,16 @@ hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* dev_ptr) {
HIP_INIT_API(hipIpcGetMemHandle, handle, dev_ptr);
amd::Device* device = nullptr;
ihipIpcMemHandle_t* ihandle = nullptr;
amd::MemObjMap::IpcMemHandle* ihandle = nullptr;
if ((handle == nullptr) || (dev_ptr == nullptr)) {
HIP_RETURN(hipErrorInvalidValue);
}
device = hip::getCurrentDevice()->devices()[0];
ihandle = reinterpret_cast<ihipIpcMemHandle_t *>(handle);
ihandle = reinterpret_cast<amd::MemObjMap::IpcMemHandle*>(handle);
if(!device->IpcCreate(dev_ptr, &(ihandle->psize), &(ihandle->ipc_handle), &(ihandle->poffset))) {
if (!device->IpcCreate(dev_ptr, &(ihandle->psize), ihandle->ipc_handle, &(ihandle->poffset))) {
LogPrintfError("IPC memory creation failed for memory: 0x%x", dev_ptr);
HIP_RETURN(hipErrorInvalidValue);
}
@@ -3256,10 +3256,9 @@ hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* dev_ptr) {
hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigned int flags) {
HIP_INIT_API(hipIpcOpenMemHandle, dev_ptr, &handle, flags);
amd::Memory* amd_mem_obj = nullptr;
amd::Device* device = nullptr;
ihipIpcMemHandle_t* ihandle = nullptr;
amd::MemObjMap::IpcMemHandle* ihandle = nullptr;
size_t offset = 0;
if (dev_ptr == nullptr || flags != hipIpcMemLazyEnablePeerAccess) {
@@ -3268,7 +3267,7 @@ hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigne
/* Call the IPC Attach from Device class */
device = hip::getCurrentDevice()->devices()[0];
ihandle = reinterpret_cast<ihipIpcMemHandle_t *>(&handle);
ihandle = reinterpret_cast<amd::MemObjMap::IpcMemHandle*>(&handle);
if (ihandle->psize == 0) {
HIP_RETURN(hipErrorInvalidValue);
@@ -3278,9 +3277,9 @@ hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigne
HIP_RETURN(hipErrorInvalidContext);
}
amd_mem_obj = amd::MemObjMap::FindIpcHandleMemObj(ihandle);
amd_mem_obj = amd::MemObjMap::FindIpcHandleMemObj(*ihandle);
if (amd_mem_obj == nullptr) {
if (!device->IpcAttach(&(ihandle->ipc_handle), ihandle->psize, ihandle->poffset, flags,
if (!device->IpcAttach(ihandle->ipc_handle, ihandle->psize, ihandle->poffset, flags,
dev_ptr)) {
LogPrintfError(
"Cannot attach ipc_handle: with ipc_size: %u"
@@ -3289,7 +3288,7 @@ hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigne
HIP_RETURN(hipErrorInvalidDevicePointer);
}
amd_mem_obj = getMemoryObject(*dev_ptr, offset);
amd::MemObjMap::AddIpcHandleMemObj(ihandle, amd_mem_obj);
amd::MemObjMap::AddIpcHandleMemObj(*ihandle, amd_mem_obj);
} else {
// Handle was already opened by the same process
*dev_ptr = amd_mem_obj->getSvmPtr();
@@ -3330,18 +3329,10 @@ hipError_t hipIpcCloseMemHandle(void* dev_ptr) {
HIP_RETURN(hipErrorInvalidValue);
}
// If handle is opened more than once, do detach on last release call
if (amd_mem_obj->referenceCount() == 1) {
auto device_id = amd_mem_obj->getUserData().deviceId;
g_devices[device_id]->SyncAllStreams();
auto device_id = amd_mem_obj->getUserData().deviceId;
g_devices[device_id]->SyncAllStreams();
// Remove entry from the map
amd::MemObjMap::RemoveIpcHandleMemObj(amd_mem_obj);
/* detach the memory */
device->IpcDetach(dev_ptr);
} else {
amd_mem_obj->release();
}
amd_mem_obj->release();
HIP_RETURN(hipSuccess);
}
+1 -1
View File
@@ -35,7 +35,7 @@ class Stream;
struct SharedMemPointer {
size_t offset_;
size_t size_;
char handle_[IHIP_IPC_MEM_HANDLE_SIZE];
char handle_[AMD_IPC_MEM_HANDLE_SIZE];
};
struct MemoryTimestamp {