@@ -240,6 +240,7 @@ int mca_spml_ucx_ctx_mkey_add(mca_spml_ucx_ctx_t *ucx_ctx, int pe, uint32_t segn
240240{
241241 int rc ;
242242 ucs_status_t err ;
243+ ucp_rkey_h rkey ;
243244
244245 rc = mca_spml_ucx_ctx_mkey_new (ucx_ctx , pe , segno , ucx_mkey );
245246 if (OSHMEM_SUCCESS != rc ) {
@@ -248,11 +249,18 @@ int mca_spml_ucx_ctx_mkey_add(mca_spml_ucx_ctx_t *ucx_ctx, int pe, uint32_t segn
248249 }
249250
250251 if (mkey -> u .data ) {
251- err = ucp_ep_rkey_unpack (ucx_ctx -> ucp_peers [pe ].ucp_conn , mkey -> u .data , & (( * ucx_mkey ) -> rkey ) );
252+ err = ucp_ep_rkey_unpack (ucx_ctx -> ucp_peers [pe ].ucp_conn , mkey -> u .data , & rkey );
252253 if (UCS_OK != err ) {
253254 SPML_UCX_ERROR ("failed to unpack rkey: %s" , ucs_status_string (err ));
254255 return OSHMEM_ERROR ;
255256 }
257+
258+ if (!oshmem_proc_on_local_node (pe )) {
259+ rkey = mca_spml_ucx_rkey_store_get (& mca_spml_ucx .rkey_store , rkey );
260+ }
261+
262+ (* ucx_mkey )-> rkey = rkey ;
263+
256264 rc = mca_spml_ucx_ctx_mkey_cache (ucx_ctx , mkey , segno , pe );
257265 if (OSHMEM_SUCCESS != rc ) {
258266 SPML_UCX_ERROR ("mca_spml_ucx_ctx_mkey_cache failed" );
@@ -267,7 +275,11 @@ int mca_spml_ucx_ctx_mkey_del(mca_spml_ucx_ctx_t *ucx_ctx, int pe, uint32_t segn
267275 ucp_peer_t * ucp_peer ;
268276 int rc ;
269277 ucp_peer = & (ucx_ctx -> ucp_peers [pe ]);
270- ucp_rkey_destroy (ucx_mkey -> rkey );
278+ if (!oshmem_proc_on_local_node (pe )) {
279+ mca_spml_ucx_rkey_store_put (& mca_spml_ucx .rkey_store , ucx_mkey -> rkey );
280+ } else {
281+ ucp_rkey_destroy (ucx_mkey -> rkey );
282+ }
271283 ucx_mkey -> rkey = NULL ;
272284 rc = mca_spml_ucx_peer_mkey_cache_del (ucp_peer , segno );
273285 if (OSHMEM_SUCCESS != rc ){
0 commit comments