Skip to content

Commit 48033ac

Browse files
xinzhao3Tomislav Janjusic
authored andcommitted
ompi/oshmem: add spml_context back to sshmem_type in memheap, to keep track of ucx_ctx_default's rkeys
Signed-off-by: Tomislav Janjusic <tomislavj@mellanox.com>
1 parent 9a06000 commit 48033ac

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

oshmem/mca/spml/ucx/spml_ucx.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int mca_spml_ucx_enable(bool enable)
103103
int mca_spml_ucx_del_procs(ompi_proc_t** procs, size_t nprocs)
104104
{
105105
opal_common_ucx_del_proc_t *del_procs;
106-
size_t i, j;
106+
size_t i;
107107
int ret;
108108

109109
oshmem_shmem_barrier();
@@ -118,12 +118,6 @@ int mca_spml_ucx_del_procs(ompi_proc_t** procs, size_t nprocs)
118118
}
119119

120120
for (i = 0; i < nprocs; ++i) {
121-
for (j = 0; j < MCA_MEMHEAP_SEG_COUNT; j++) {
122-
if (mca_spml_ucx_ctx_default.ucp_peers[i].mkeys[j].key.rkey != NULL) {
123-
ucp_rkey_destroy(mca_spml_ucx_ctx_default.ucp_peers[i].mkeys[j].key.rkey);
124-
}
125-
}
126-
127121
del_procs[i].ep = mca_spml_ucx_ctx_default.ucp_peers[i].ucp_conn;
128122
del_procs[i].vpid = i;
129123

@@ -349,16 +343,21 @@ spml_ucx_mkey_t * mca_spml_ucx_get_mkey_slow(shmem_ctx_t ctx, int pe, void *va,
349343

350344
void mca_spml_ucx_rmkey_free(sshmem_mkey_t *mkey)
351345
{
346+
spml_ucx_mkey_t *ucx_mkey;
347+
348+
if (!mkey->spml_context) {
349+
return;
350+
}
351+
ucx_mkey = (spml_ucx_mkey_t *)(mkey->spml_context);
352+
ucp_rkey_destroy(ucx_mkey->rkey);
352353
}
353354

354-
void *mca_spml_ucx_rmkey_ptr(const void *dst_addr, sshmem_mkey_t *key, int pe)
355+
void *mca_spml_ucx_rmkey_ptr(const void *dst_addr, sshmem_mkey_t *mkey, int pe)
355356
{
356357
#if (((UCP_API_MAJOR >= 1) && (UCP_API_MINOR >= 3)) || (UCP_API_MAJOR >= 2))
357358
void *rva;
358359
ucs_status_t err;
359-
mca_spml_ucx_ctx_t *ucx_ctx = (mca_spml_ucx_ctx_t *)&mca_spml_ucx_ctx_default;
360-
uint32_t segno = memheap_find_segnum((void*)dst_addr);
361-
spml_ucx_mkey_t *ucx_mkey = &ucx_ctx->ucp_peers[pe].mkeys[segno].key;
360+
spml_ucx_mkey_t *ucx_mkey = (spml_ucx_mkey_t *)(mkey->spml_context);
362361

363362
err = ucp_rkey_ptr(ucx_mkey->rkey, (uint64_t)dst_addr, &rva);
364363
if (UCS_OK != err) {
@@ -386,6 +385,9 @@ void mca_spml_ucx_rmkey_unpack(shmem_ctx_t ctx, sshmem_mkey_t *mkey, uint32_t se
386385
goto error_fatal;
387386
}
388387

388+
if (ucx_ctx == &mca_spml_ucx_ctx_default) {
389+
mkey->spml_context = ucx_mkey;
390+
}
389391
mca_spml_ucx_cache_mkey(ucx_ctx, mkey, segno, pe);
390392
return;
391393

@@ -448,6 +450,7 @@ sshmem_mkey_t *mca_spml_ucx_register(void* addr,
448450
mem_seg = memheap_find_seg(segno);
449451

450452
ucx_mkey = &mca_spml_ucx_ctx_default.ucp_peers[my_pe].mkeys[segno].key;
453+
mkeys[0].spml_context = ucx_mkey;
451454

452455
/* if possible use mem handle already created by ucx allocator */
453456
if (MAP_SEGMENT_ALLOC_UCX != mem_seg->type) {
@@ -514,12 +517,14 @@ int mca_spml_ucx_deregister(sshmem_mkey_t *mkeys)
514517
int my_pe = oshmem_my_proc_id();
515518

516519
MCA_SPML_CALL(quiet(oshmem_ctx_default));
517-
if (!mkeys || !mkeys[0].va_base)
520+
if (!mkeys)
521+
return OSHMEM_SUCCESS;
522+
523+
if (!mkeys[0].spml_context)
518524
return OSHMEM_SUCCESS;
519525

520526
mem_seg = memheap_find_va(mkeys[0].va_base);
521-
segno = memheap_find_segnum(mkeys[0].va_base);
522-
ucx_mkey = &mca_spml_ucx_ctx_default.ucp_peers[my_pe].mkeys[segno].key;
527+
ucx_mkey = (spml_ucx_mkey_t*)mkeys[0].spml_context;
523528

524529
if (OPAL_UNLIKELY(NULL == mem_seg)) {
525530
return OSHMEM_ERROR;

oshmem/mca/sshmem/sshmem_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ typedef struct sshmem_mkey {
9494
void *data;
9595
uint64_t key;
9696
} u;
97+
void *spml_context; /* spml module can attach internal structures here */
9798
} sshmem_mkey_t;
9899

99100
typedef struct map_base_segment {

0 commit comments

Comments
 (0)