@@ -41,6 +41,8 @@ static int mca_accelerator_rocm_import_ipc_handle(int dev_id, uint8_t ipc_handle
4141 opal_accelerator_ipc_handle_t * handle );
4242static int mca_accelerator_rocm_open_ipc_handle (int dev_id , opal_accelerator_ipc_handle_t * handle ,
4343 void * * dev_ptr );
44+ static int mca_accelerator_rocm_compare_ipc_handles (uint8_t handle_1 [IPC_MAX_HANDLE_SIZE ],
45+ uint8_t handle_2 [IPC_MAX_HANDLE_SIZE ]);
4446static int mca_accelerator_rocm_get_ipc_event_handle (opal_accelerator_event_t * event ,
4547 opal_accelerator_ipc_event_handle_t * handle );
4648static int mca_accelerator_rocm_import_ipc_event_handle (uint8_t ipc_handle [IPC_MAX_HANDLE_SIZE ],
@@ -82,6 +84,7 @@ opal_accelerator_base_module_t opal_accelerator_rocm_module =
8284 mca_accelerator_rocm_get_ipc_handle ,
8385 mca_accelerator_rocm_import_ipc_handle ,
8486 mca_accelerator_rocm_open_ipc_handle ,
87+ mca_accelerator_rocm_compare_ipc_handles ,
8588 mca_accelerator_rocm_get_ipc_event_handle ,
8689 mca_accelerator_rocm_import_ipc_event_handle ,
8790 mca_accelerator_rocm_open_ipc_event_handle ,
@@ -573,6 +576,27 @@ static int mca_accelerator_rocm_open_ipc_handle(int dev_id, opal_accelerator_ipc
573576 return OPAL_SUCCESS ;
574577}
575578
579+ static int mca_accelerator_rocm_compare_ipc_handles (uint8_t handle_1 [IPC_MAX_HANDLE_SIZE ],
580+ uint8_t handle_2 [IPC_MAX_HANDLE_SIZE ])
581+ {
582+ /*
583+ * The HIP IPC handles consists of multiple elements.
584+ * We will only use the ROCr IPC handle (32 bytes, starting at pos 0)
585+ * and the process ID for comparison.
586+ * We definitily need to exclude the offset component in the comparison.
587+ */
588+ static const int rocr_ipc_handle_size = 32 ;
589+ static const int pos = rocr_ipc_handle_size + 2 * sizeof (size_t );
590+ int * pid_1 = (int * )& handle_1 [pos ];
591+ int * pid_2 = (int * )& handle_2 [pos ];
592+
593+ if (* pid_1 != * pid_2 ) {
594+ return 1 ;
595+ }
596+
597+ return memcmp (handle_1 , handle_2 , rocr_ipc_handle_size );
598+ }
599+
576600static void mca_accelerator_rocm_ipc_event_handle_destruct (opal_accelerator_rocm_ipc_handle_t * handle )
577601{
578602 // Just a place holder, there is no hipIpcCloseEventHandle.
0 commit comments