@@ -106,7 +106,7 @@ int mca_spml_ucx_enable(bool enable)
106106int  mca_spml_ucx_del_procs (ompi_proc_t * *  procs , size_t  nprocs )
107107{
108108    opal_common_ucx_del_proc_t  * del_procs ;
109-     size_t  i ,  j ;
109+     size_t  i ;
110110    int  ret ;
111111
112112    oshmem_shmem_barrier ();
@@ -121,12 +121,6 @@ int mca_spml_ucx_del_procs(ompi_proc_t** procs, size_t nprocs)
121121    }
122122
123123    for  (i  =  0 ; i  <  nprocs ; ++ i ) {
124-         for  (j  =  0 ; j  <  MCA_MEMHEAP_SEG_COUNT ; j ++ ) {
125-             if  (mca_spml_ucx_ctx_default .ucp_peers [i ].mkeys [j ].key .rkey  !=  NULL ) {
126-                 ucp_rkey_destroy (mca_spml_ucx_ctx_default .ucp_peers [i ].mkeys [j ].key .rkey );
127-             }
128-         }
129- 
130124        del_procs [i ].ep    =  mca_spml_ucx_ctx_default .ucp_peers [i ].ucp_conn ;
131125        del_procs [i ].vpid  =  i ;
132126
@@ -352,16 +346,21 @@ spml_ucx_mkey_t * mca_spml_ucx_get_mkey_slow(shmem_ctx_t ctx, int pe, void *va,
352346
353347void  mca_spml_ucx_rmkey_free (sshmem_mkey_t  * mkey )
354348{
349+     spml_ucx_mkey_t    * ucx_mkey ;
350+ 
351+     if  (!mkey -> spml_context ) {
352+         return ;
353+     }
354+     ucx_mkey  =  (spml_ucx_mkey_t  * )(mkey -> spml_context );
355+     ucp_rkey_destroy (ucx_mkey -> rkey );
355356}
356357
357- void  * mca_spml_ucx_rmkey_ptr (const  void  * dst_addr , sshmem_mkey_t  * key , int  pe )
358+ void  * mca_spml_ucx_rmkey_ptr (const  void  * dst_addr , sshmem_mkey_t  * mkey , int  pe )
358359{
359360#if  (((UCP_API_MAJOR  >= 1 ) &&  (UCP_API_MINOR  >= 3 )) ||  (UCP_API_MAJOR  >= 2 ))
360361    void  * rva ;
361362    ucs_status_t  err ;
362-     mca_spml_ucx_ctx_t  * ucx_ctx  =  (mca_spml_ucx_ctx_t  * )& mca_spml_ucx_ctx_default ;
363-     uint32_t  segno  =  memheap_find_segnum ((void * )dst_addr );
364-     spml_ucx_mkey_t  * ucx_mkey  =  & ucx_ctx -> ucp_peers [pe ].mkeys [segno ].key ;
363+     spml_ucx_mkey_t  * ucx_mkey  =  (spml_ucx_mkey_t  * )(mkey -> spml_context );
365364
366365    err  =  ucp_rkey_ptr (ucx_mkey -> rkey , (uint64_t )dst_addr , & rva );
367366    if  (UCS_OK  !=  err ) {
@@ -389,6 +388,9 @@ void mca_spml_ucx_rmkey_unpack(shmem_ctx_t ctx, sshmem_mkey_t *mkey, uint32_t se
389388        goto error_fatal ;
390389    }
391390
391+     if  (ucx_ctx  ==  & mca_spml_ucx_ctx_default ) {
392+         mkey -> spml_context  =  ucx_mkey ;
393+     }
392394    mca_spml_ucx_cache_mkey (ucx_ctx , mkey , segno , pe );
393395    return ;
394396
@@ -451,6 +453,7 @@ sshmem_mkey_t *mca_spml_ucx_register(void* addr,
451453    mem_seg  =  memheap_find_seg (segno );
452454
453455    ucx_mkey  =  & mca_spml_ucx_ctx_default .ucp_peers [my_pe ].mkeys [segno ].key ;
456+     mkeys [0 ].spml_context  =  ucx_mkey ;
454457
455458    /* if possible use mem handle already created by ucx allocator */ 
456459    if  (MAP_SEGMENT_ALLOC_UCX  !=  mem_seg -> type ) {
@@ -517,12 +520,14 @@ int mca_spml_ucx_deregister(sshmem_mkey_t *mkeys)
517520    int  my_pe  =  oshmem_my_proc_id ();
518521
519522    MCA_SPML_CALL (quiet (oshmem_ctx_default ));
520-     if  (!mkeys  ||  !mkeys [0 ].va_base )
523+     if  (!mkeys )
524+         return  OSHMEM_SUCCESS ;
525+ 
526+     if  (!mkeys [0 ].spml_context )
521527        return  OSHMEM_SUCCESS ;
522528
523529    mem_seg   =  memheap_find_va (mkeys [0 ].va_base );
524-     segno  =  memheap_find_segnum (mkeys [0 ].va_base );
525-     ucx_mkey  =  & mca_spml_ucx_ctx_default .ucp_peers [my_pe ].mkeys [segno ].key ;
530+     ucx_mkey  =  (spml_ucx_mkey_t * )mkeys [0 ].spml_context ;
526531
527532    if  (OPAL_UNLIKELY (NULL  ==  mem_seg )) {
528533        return  OSHMEM_ERROR ;
0 commit comments