Skip to content

Commit 8b16747

Browse files
authored
Merge pull request #2872 from alex-mikheev/topic/oshmem_mem_prefetch_v2.x
Topic/oshmem mem prefetch v2.x
2 parents dc4ec12 + a422154 commit 8b16747

File tree

9 files changed

+58
-6
lines changed

9 files changed

+58
-6
lines changed

oshmem/mca/memheap/buddy/memheap_buddy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static int _do_alloc(uint32_t order,
469469
}
470470

471471
*p_buff = (void*) addr;
472-
/* no barrier because it is not required by spec! */
472+
MCA_SPML_CALL(memuse_hook(*p_buff, 1ULL<<order));
473473
return OSHMEM_SUCCESS;
474474

475475
alloc_error: _buddy_free(&memheap_buddy, offset, order, heap);

oshmem/mca/memheap/ptmalloc/memheap_ptmalloc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ int mca_memheap_ptmalloc_alloc(size_t size, void** p_buff)
8585
if (NULL == *p_buff)
8686
return OSHMEM_ERROR;
8787

88+
MCA_SPML_CALL(memuse_hook(*p_buff, size));
8889
return OSHMEM_SUCCESS;
8990
}
9091

@@ -113,6 +114,7 @@ int mca_memheap_ptmalloc_align(size_t align, size_t size, void **p_buff)
113114
if (NULL == *p_buff)
114115
return OSHMEM_ERROR;
115116

117+
MCA_SPML_CALL(memuse_hook(*p_buff, size));
116118
return OSHMEM_SUCCESS;
117119
}
118120

@@ -132,6 +134,7 @@ int mca_memheap_ptmalloc_realloc(size_t new_size,
132134
if (!*p_new_buff)
133135
return OSHMEM_ERR_OUT_OF_RESOURCE;
134136

137+
MCA_SPML_CALL(memuse_hook(*p_new_buff, new_size));
135138
return OSHMEM_SUCCESS;
136139
}
137140

oshmem/mca/spml/base/base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ OSHMEM_DECLSPEC int mca_spml_base_get_nb(void *dst_addr,
8484
int src,
8585
void **handle);
8686

87+
OSHMEM_DECLSPEC void mca_spml_base_memuse_hook(void *addr, size_t length);
8788
/*
8889
* MCA framework
8990
*/

oshmem/mca/spml/base/spml_base.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,7 @@ int mca_spml_base_get_nb(void *dst_addr, size_t size,
177177
{
178178
return OSHMEM_ERROR;
179179
}
180+
181+
void mca_spml_base_memuse_hook(void *addr, size_t length)
182+
{
183+
}

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_memuse_hook,
174175

175176
(void*)&mca_spml_ikrit
176177
}

oshmem/mca/spml/spml.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@ typedef int (*mca_spml_base_module_fence_fn_t)(void);
277277
*/
278278
typedef int (*mca_spml_base_module_wait_nb_fn_t)(void *);
279279

280+
/**
281+
* Called by memheap when memory is allocated by shmalloc(),
282+
* shcalloc(), shmemalign() or shrealloc()
283+
*
284+
* @param addr base address of the registered buffer.
285+
* @param size the size of the buffer to be registered.
286+
*/
287+
typedef void (*mca_spml_base_module_memuse_hook_fn_t)(void *, size_t);
288+
280289
/**
281290
* SPML instance.
282291
*/
@@ -304,6 +313,8 @@ struct mca_spml_base_module_1_0_0_t {
304313

305314
mca_spml_base_module_mkey_unpack_fn_t spml_rmkey_unpack;
306315
mca_spml_base_module_mkey_free_fn_t spml_rmkey_free;
316+
317+
mca_spml_base_module_memuse_hook_fn_t spml_memuse_hook;
307318
void *self;
308319
};
309320

oshmem/mca/spml/ucx/spml_ucx.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#define SPML_UCX_PUT_DEBUG 0
4444
#endif
4545

46-
4746
mca_spml_ucx_t mca_spml_ucx = {
4847
{
4948
/* Init mca_spml_base_module_t */
@@ -65,6 +64,7 @@ mca_spml_ucx_t mca_spml_ucx = {
6564
every spml */
6665
mca_spml_ucx_rmkey_unpack,
6766
mca_spml_ucx_rmkey_free,
67+
mca_spml_ucx_memuse_hook,
6868
(void*)&mca_spml_ucx
6969
},
7070

@@ -288,7 +288,7 @@ int mca_spml_ucx_add_procs(ompi_proc_t **procs, size_t nprocs)
288288
&ep_params,
289289
&mca_spml_ucx.ucp_peers[i].ucp_conn);
290290
if (UCS_OK != err) {
291-
SPML_ERROR("ucp_ep_create failed!!!\n");
291+
SPML_ERROR("ucp_ep_create failed: %s", ucs_status_string(err));
292292
goto error2;
293293
}
294294
OSHMEM_PROC_DATA(procs[i])->num_transports = 1;
@@ -371,7 +371,7 @@ void mca_spml_ucx_rmkey_unpack(sshmem_mkey_t *mkey, uint32_t segno, int pe, int
371371
mkey->u.data,
372372
&ucx_mkey->rkey);
373373
if (UCS_OK != err) {
374-
SPML_ERROR("failed to unpack rkey");
374+
SPML_ERROR("failed to unpack rkey: %s", ucs_status_string(err));
375375
goto error_fatal;
376376
}
377377

@@ -384,6 +384,35 @@ void mca_spml_ucx_rmkey_unpack(sshmem_mkey_t *mkey, uint32_t segno, int pe, int
384384
return;
385385
}
386386

387+
void mca_spml_ucx_memuse_hook(void *addr, size_t length)
388+
{
389+
int my_pe;
390+
spml_ucx_mkey_t *ucx_mkey;
391+
ucp_mem_advise_params_t params;
392+
ucs_status_t status;
393+
394+
if (!(mca_spml_ucx.heap_reg_nb && memheap_is_va_in_segment(addr, HEAP_SEG_INDEX))) {
395+
return;
396+
}
397+
398+
my_pe = oshmem_my_proc_id();
399+
ucx_mkey = &mca_spml_ucx.ucp_peers[my_pe].mkeys[HEAP_SEG_INDEX].key;
400+
401+
params.field_mask = UCP_MEM_ADVISE_PARAM_FIELD_ADDRESS |
402+
UCP_MEM_ADVISE_PARAM_FIELD_LENGTH |
403+
UCP_MEM_ADVISE_PARAM_FIELD_ADVICE;
404+
405+
params.address = addr;
406+
params.length = length;
407+
params.advice = UCP_MADV_WILLNEED;
408+
409+
status = ucp_mem_advise(mca_spml_ucx.ucp_context, ucx_mkey->mem_h, &params);
410+
if (UCS_OK != status) {
411+
SPML_ERROR("ucp_mem_advise failed addr %p len %llu : %s",
412+
addr, (unsigned long long)length, ucs_status_string(status));
413+
}
414+
}
415+
387416
sshmem_mkey_t *mca_spml_ucx_register(void* addr,
388417
size_t size,
389418
uint64_t shmid,
@@ -539,7 +568,7 @@ int mca_spml_ucx_fence(void)
539568

540569
err = ucp_worker_flush(mca_spml_ucx.ucp_worker);
541570
if (UCS_OK != err) {
542-
SPML_ERROR("fence failed");
571+
SPML_ERROR("fence failed: %s", ucs_status_string(err));
543572
oshmem_shmem_abort(-1);
544573
return OSHMEM_ERROR;
545574
}
@@ -552,7 +581,7 @@ int mca_spml_ucx_quiet(void)
552581

553582
err = ucp_worker_flush(mca_spml_ucx.ucp_worker);
554583
if (UCS_OK != err) {
555-
SPML_ERROR("fence failed");
584+
SPML_ERROR("fence failed: %s", ucs_status_string(err));
556585
oshmem_shmem_abort(-1);
557586
return OSHMEM_ERROR;
558587
}

oshmem/mca/spml/ucx/spml_ucx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ extern sshmem_mkey_t *mca_spml_ucx_register(void* addr,
108108
int *count);
109109
extern int mca_spml_ucx_deregister(sshmem_mkey_t *mkeys);
110110

111+
extern void mca_spml_ucx_memuse_hook(void *addr, size_t length);
112+
111113
extern void mca_spml_ucx_rmkey_unpack(sshmem_mkey_t *mkey, uint32_t segno, int pe, int tr_id);
112114
extern void mca_spml_ucx_rmkey_free(sshmem_mkey_t *mkey);
113115

oshmem/mca/spml/yoda/spml_yoda.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ mca_spml_yoda_module_t mca_spml_yoda = {
6565
mca_spml_yoda_fence,
6666
mca_spml_base_rmkey_unpack,
6767
mca_spml_base_rmkey_free,
68+
mca_spml_base_memuse_hook,
6869

6970
(void *)&mca_spml_yoda
7071
}

0 commit comments

Comments
 (0)