Skip to content

Commit 1b5df76

Browse files
committed
oshmem: shmem_ptr() implementation
Signed-off-by: Alex Mikheev <[email protected]>
1 parent fca68b0 commit 1b5df76

File tree

8 files changed

+86
-7
lines changed

8 files changed

+86
-7
lines changed

oshmem/mca/memheap/memheap.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,18 @@ typedef struct mca_memheap_base_module_t mca_memheap_base_module_t;
138138

139139
OSHMEM_DECLSPEC extern mca_memheap_base_module_t mca_memheap;
140140

141+
static inline int mca_memheap_base_mkey_is_shm(sshmem_mkey_t *mkey)
142+
{
143+
return (0 == mkey->len) && (MAP_SEGMENT_SHM_INVALID != (int)mkey->u.key);
144+
}
145+
141146
/**
142147
* check if memcpy() can be used to copy data to dst_addr
143148
* must be memheap address and segment must be mapped
144149
*/
145150
static inline int mca_memheap_base_can_local_copy(sshmem_mkey_t *mkey, void *dst_addr) {
146151
return mca_memheap.memheap_is_symmetric_addr(dst_addr) &&
147-
(0 == mkey->len) && (MAP_SEGMENT_SHM_INVALID != (int)mkey->u.key);
152+
mca_memheap_base_mkey_is_shm(mkey);
148153
}
149154

150155

oshmem/mca/spml/base/base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ OSHMEM_DECLSPEC int mca_spml_base_oob_get_mkeys(int pe,
7373

7474
OSHMEM_DECLSPEC void mca_spml_base_rmkey_unpack(sshmem_mkey_t *mkey, uint32_t seg, int pe, int tr_id);
7575
OSHMEM_DECLSPEC void mca_spml_base_rmkey_free(sshmem_mkey_t *mkey);
76+
OSHMEM_DECLSPEC void *mca_spml_base_rmkey_ptr(const void *dst_addr, sshmem_mkey_t *mkey, int pe);
77+
7678
OSHMEM_DECLSPEC int mca_spml_base_put_nb(void *dst_addr,
7779
size_t size,
7880
void *src_addr,

oshmem/mca/spml/base/spml_base.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ void mca_spml_base_rmkey_free(sshmem_mkey_t *mkey)
175175
{
176176
}
177177

178+
void *mca_spml_base_rmkey_ptr(const void *dst_addr, sshmem_mkey_t *mkey, int pe)
179+
{
180+
return NULL;
181+
}
182+
178183
int mca_spml_base_put_nb(void *dst_addr, size_t size,
179184
void *src_addr, int dst, void **handle)
180185
{

oshmem/mca/spml/ikrit/spml_ikrit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ mca_spml_ikrit_t mca_spml_ikrit = {
171171
mca_spml_ikrit_fence,
172172
mca_spml_ikrit_cache_mkeys,
173173
mca_spml_base_rmkey_free,
174+
mca_spml_base_rmkey_ptr,
174175
mca_spml_base_memuse_hook,
175176

176177
(void*)&mca_spml_ikrit

oshmem/mca/spml/spml.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ typedef int (*mca_spml_base_module_wait_fn_t)(void* addr,
120120
*/
121121
typedef void (*mca_spml_base_module_mkey_unpack_fn_t)(sshmem_mkey_t *, uint32_t segno, int remote_pe, int tr_id);
122122

123+
/**
124+
* If possible, get a pointer to the remote memory described by the mkey
125+
*
126+
* @param dst_addr address of the symmetric variable
127+
* @param mkey remote memory key
128+
* @param pe remote PE
129+
*
130+
* @return pointer to remote memory or NULL
131+
*/
132+
typedef void * (*mca_spml_base_module_mkey_ptr_fn_t)(const void *dst_addr, sshmem_mkey_t *mkey, int pe);
133+
123134
/**
124135
* free resources used by deserialized remote mkey
125136
*
@@ -313,6 +324,7 @@ struct mca_spml_base_module_1_0_0_t {
313324

314325
mca_spml_base_module_mkey_unpack_fn_t spml_rmkey_unpack;
315326
mca_spml_base_module_mkey_free_fn_t spml_rmkey_free;
327+
mca_spml_base_module_mkey_ptr_fn_t spml_rmkey_ptr;
316328

317329
mca_spml_base_module_memuse_hook_fn_t spml_memuse_hook;
318330
void *self;

oshmem/mca/spml/ucx/spml_ucx.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ mca_spml_ucx_t mca_spml_ucx = {
6464
every spml */
6565
mca_spml_ucx_rmkey_unpack,
6666
mca_spml_ucx_rmkey_free,
67+
mca_spml_ucx_rmkey_ptr,
6768
mca_spml_ucx_memuse_hook,
6869
(void*)&mca_spml_ucx
6970
},
@@ -353,6 +354,23 @@ void mca_spml_ucx_rmkey_free(sshmem_mkey_t *mkey)
353354
ucp_rkey_destroy(ucx_mkey->rkey);
354355
}
355356

357+
void *mca_spml_ucx_rmkey_ptr(const void *dst_addr, sshmem_mkey_t *mkey, int pe)
358+
{
359+
#if (((UCP_API_MAJOR >= 1) && (UCP_API_MINOR >= 3)) || (UCP_API_MAJOR >= 2))
360+
void *rva;
361+
ucs_status_t err;
362+
spml_ucx_mkey_t *ucx_mkey = (spml_ucx_mkey_t *)(mkey->spml_context);
363+
364+
err = ucp_rkey_ptr(ucx_mkey->rkey, (uint64_t)dst_addr, &rva);
365+
if (UCS_OK != err) {
366+
return NULL;
367+
}
368+
return rva;
369+
#else
370+
return NULL;
371+
#endif
372+
}
373+
356374
static void mca_spml_ucx_cache_mkey(sshmem_mkey_t *mkey, uint32_t segno, int dst_pe)
357375
{
358376
ucp_peer_t *peer;

oshmem/mca/spml/ucx/spml_ucx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ extern void mca_spml_ucx_memuse_hook(void *addr, size_t length);
112112

113113
extern void mca_spml_ucx_rmkey_unpack(sshmem_mkey_t *mkey, uint32_t segno, int pe, int tr_id);
114114
extern void mca_spml_ucx_rmkey_free(sshmem_mkey_t *mkey);
115+
extern void *mca_spml_ucx_rmkey_ptr(const void *dst_addr, sshmem_mkey_t *, int pe);
115116

116117
extern int mca_spml_ucx_add_procs(ompi_proc_t** procs, size_t nprocs);
117118
extern int mca_spml_ucx_del_procs(ompi_proc_t** procs, size_t nprocs);

oshmem/shmem/c/shmem_ptr.c

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,53 @@
1919
#include "oshmem/shmem/shmem_api_logger.h"
2020

2121
#include "oshmem/runtime/runtime.h"
22+
#include "oshmem/mca/memheap/memheap.h"
23+
#include "oshmem/mca/memheap/base/base.h"
24+
2225

2326
#if OSHMEM_PROFILING
2427
#include "oshmem/include/pshmem.h"
2528
#pragma weak shmem_ptr = pshmem_ptr
2629
#include "oshmem/shmem/c/profile/defines.h"
2730
#endif
2831

29-
void *shmem_ptr(const void *ptr, int pe)
32+
void *shmem_ptr(const void *dst_addr, int pe)
3033
{
31-
SHMEM_API_VERBOSE(10,
32-
"*************** WARNING!!! NOT SUPPORTED FUNCTION **********************\n"
33-
"shmem_ptr() function is available only on systems where ordinary memory loads\n"
34-
"and stores are used to implement OpenSHMEM put and get operations.");
35-
return 0;
34+
ompi_proc_t *proc;
35+
sshmem_mkey_t *mkey;
36+
int i;
37+
void *rva;
38+
39+
RUNTIME_CHECK_INIT();
40+
RUNTIME_CHECK_PE(pe);
41+
RUNTIME_CHECK_ADDR(dst_addr);
42+
43+
/* process can access its own memory */
44+
if (pe == oshmem_my_proc_id()) {
45+
return (void *)dst_addr;
46+
}
47+
48+
/* The memory must be on the local node */
49+
proc = oshmem_proc_group_find(oshmem_group_all, pe);
50+
if (!OPAL_PROC_ON_LOCAL_NODE(proc->super.proc_flags)) {
51+
return NULL;
52+
}
53+
54+
for (i = 0; i < mca_memheap_base_num_transports(); i++) {
55+
mkey = mca_memheap_base_get_cached_mkey(pe, (void *)dst_addr, i, &rva);
56+
if (!mkey) {
57+
continue;
58+
}
59+
60+
if (mca_memheap_base_mkey_is_shm(mkey)) {
61+
return rva;
62+
}
63+
64+
rva = MCA_SPML_CALL(rmkey_ptr(dst_addr, mkey, pe));
65+
if (rva != NULL) {
66+
return rva;
67+
}
68+
}
69+
70+
return NULL;
3671
}

0 commit comments

Comments
 (0)