Skip to content

Commit 06d0887

Browse files
committed
osc/sm: add support for mpi_minimum_memory_alignment info key
Signed-off-by: Joseph Schuchart <schuchart@hlrs.de>
1 parent d524fa4 commit 06d0887

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

ompi/mca/osc/sm/osc_sm_component.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
1414
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
1515
* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
16+
* Copyright (c) 2020 High Performance Computing Center Stuttgart,
17+
* University of Stuttgart. All rights reserved.
1618
* $COPYRIGHT$
1719
*
1820
* Additional copyrights may follow
@@ -30,6 +32,7 @@
3032
#include "opal/include/opal/align.h"
3133
#include "opal/util/info_subscriber.h"
3234
#include "opal/util/printf.h"
35+
#include "opal/mca/mpool/base/base.h"
3336

3437
#include "osc_sm.h"
3538

@@ -193,6 +196,8 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
193196
int comm_size = ompi_comm_size (comm);
194197
bool unlink_needed = false;
195198
int ret = OMPI_ERROR;
199+
int flag;
200+
size_t memory_alignment = OPAL_ALIGN_MIN;
196201

197202
if (OMPI_SUCCESS != (ret = check_win_ok(comm, flavor))) {
198203
return ret;
@@ -208,9 +213,20 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
208213
OBJ_CONSTRUCT(&module->lock, opal_mutex_t);
209214

210215
ret = opal_infosubscribe_subscribe(&(win->super), "alloc_shared_noncontig", "false", component_set_alloc_shared_noncontig_info);
211-
212216
if (OPAL_SUCCESS != ret) goto error;
213217

218+
if (NULL != info) {
219+
opal_cstring_t *align_info_str;
220+
ret = opal_info_get(info, "mpi_minimum_memory_alignment", &align_info_str, &flag);
221+
if (flag) {
222+
ssize_t tmp_align = atoll(align_info_str->string);
223+
OBJ_RELEASE(align_info_str);
224+
if (OPAL_ALIGN_MIN < tmp_align) {
225+
memory_alignment = tmp_align;
226+
}
227+
}
228+
}
229+
214230
/* fill in the function pointer part */
215231
memcpy(module, &ompi_osc_sm_module_template,
216232
sizeof(ompi_osc_base_module_t));
@@ -230,7 +246,8 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
230246
if (NULL == module->bases) return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
231247

232248
module->sizes[0] = size;
233-
module->bases[0] = malloc(size);
249+
module->bases[0] = mca_mpool_base_default_module->mpool_alloc(mca_mpool_base_default_module, size,
250+
memory_alignment, 0);
234251
if (NULL == module->bases[0]) return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
235252

236253
module->global_state = malloc(sizeof(ompi_osc_sm_global_state_t));
@@ -246,6 +263,7 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
246263
size_t pagesize;
247264
size_t state_size;
248265
size_t posts_size, post_size = (comm_size + OSC_SM_POST_MASK) / (OSC_SM_POST_MASK + 1);
266+
size_t data_base_size;
249267

250268
OPAL_OUTPUT_VERBOSE((1, ompi_osc_base_framework.framework_output,
251269
"allocating shared memory region of size %ld\n", (long) size));
@@ -283,6 +301,8 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
283301
state_size += OPAL_ALIGN_PAD_AMOUNT(state_size, 64);
284302
posts_size = comm_size * post_size * sizeof (module->posts[0][0]);
285303
posts_size += OPAL_ALIGN_PAD_AMOUNT(posts_size, 64);
304+
data_base_size = state_size + posts_size;
305+
data_base_size += OPAL_ALIGN_PAD_AMOUNT(data_base_size, pagesize);
286306
if (0 == ompi_comm_rank (module->comm)) {
287307
char *data_file;
288308
ret = opal_asprintf (&data_file, "%s" OPAL_PATH_SEP "osc_sm.%s.%x.%d.%d",
@@ -293,7 +313,7 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
293313
return OMPI_ERR_OUT_OF_RESOURCE;
294314
}
295315

296-
ret = opal_shmem_segment_create (&module->seg_ds, data_file, total + pagesize + state_size + posts_size);
316+
ret = opal_shmem_segment_create (&module->seg_ds, data_file, total + data_base_size);
297317
free(data_file);
298318
if (OPAL_SUCCESS != ret) {
299319
free(rbuf);
@@ -340,7 +360,7 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
340360
module->global_state = (ompi_osc_sm_global_state_t *) (module->posts[0] + comm_size * post_size);
341361
module->node_states = (ompi_osc_sm_node_state_t *) (module->global_state + 1);
342362

343-
for (i = 0, total = state_size + posts_size ; i < comm_size ; ++i) {
363+
for (i = 0, total = data_base_size ; i < comm_size ; ++i) {
344364
if (i > 0) {
345365
module->posts[i] = module->posts[i - 1] + post_size;
346366
}
@@ -523,12 +543,13 @@ ompi_osc_sm_free(struct ompi_win_t *win)
523543
module->comm->c_coll->coll_barrier(module->comm,
524544
module->comm->c_coll->coll_barrier_module);
525545

526-
opal_shmem_segment_detach (&module->seg_ds);
546+
opal_shmem_segment_detach (&module->seg_ds);
527547
} else {
528548
free(module->node_states);
529549
free(module->global_state);
530550
if (NULL != module->bases) {
531-
free(module->bases[0]);
551+
mca_mpool_base_default_module->mpool_free(mca_mpool_base_default_module,
552+
module->bases[0]);
532553
}
533554
}
534555
free(module->disp_units);
@@ -565,9 +586,9 @@ static const char*
565586
component_set_blocking_fence_info(opal_infosubscriber_t *obj, const char *key, const char *val)
566587
{
567588
ompi_osc_sm_module_t *module = (ompi_osc_sm_module_t*) ((struct ompi_win_t*) obj)->w_osc_module;
568-
/*
569-
* Assuming that you can't change the default.
570-
*/
589+
/*
590+
* Assuming that you can't change the default.
591+
*/
571592
return module->global_state->use_barrier_for_fence ? "true" : "false";
572593
}
573594

@@ -577,9 +598,9 @@ component_set_alloc_shared_noncontig_info(opal_infosubscriber_t *obj, const char
577598
{
578599

579600
ompi_osc_sm_module_t *module = (ompi_osc_sm_module_t*) ((struct ompi_win_t*) obj)->w_osc_module;
580-
/*
581-
* Assuming that you can't change the default.
582-
*/
601+
/*
602+
* Assuming that you can't change the default.
603+
*/
583604
return module->noncontig ? "true" : "false";
584605
}
585606

0 commit comments

Comments
 (0)