Skip to content

Commit 4f87c6b

Browse files
authored
Merge pull request #13055 from edgargabriel/topic/memkind-support
ompi/info: introduce support for the mpi_memory_alloc_kinds info object (II)
2 parents 59d968e + e901e6a commit 4f87c6b

15 files changed

+752
-16
lines changed

ompi/communicator/comm.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
2727
* Copyright (c) 2018-2024 Triad National Security, LLC. All rights
2828
* reserved.
29-
* Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
29+
* Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
3030
* $COPYRIGHT$
3131
*
3232
* Additional copyrights may follow
@@ -56,6 +56,7 @@
5656
#include "ompi/communicator/communicator.h"
5757
#include "ompi/mca/pml/pml.h"
5858
#include "ompi/request/request.h"
59+
#include "ompi/info/info_memkind.h"
5960

6061
#include "ompi/runtime/params.h"
6162

@@ -447,6 +448,7 @@ int ompi_comm_create_w_info (ompi_communicator_t *comm, ompi_group_t *group, opa
447448
if (info) {
448449
opal_info_dup(info, &(newcomp->super.s_info));
449450
}
451+
ompi_info_memkind_copy_or_set (&comm->instance->super, &newcomp->super, info);
450452

451453
/* Set name for debugging purposes */
452454
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMMUNICATOR %s CREATE FROM %s",
@@ -699,10 +701,11 @@ int ompi_comm_split_with_info( ompi_communicator_t* comm, int color, int key,
699701
ompi_comm_print_cid (newcomp), ompi_comm_print_cid (comm));
700702

701703
/* Copy info if there is one */
704+
newcomp->super.s_info = OBJ_NEW(opal_info_t);
702705
if (info) {
703-
newcomp->super.s_info = OBJ_NEW(opal_info_t);
704706
opal_info_dup(info, &(newcomp->super.s_info));
705707
}
708+
ompi_info_memkind_copy_or_set (&comm->instance->super, &newcomp->super, info);
706709

707710
/* Activate the communicator and init coll-component */
708711
rc = ompi_comm_activate (&newcomp, comm, NULL, NULL, NULL, false, mode);
@@ -994,6 +997,7 @@ static int ompi_comm_split_type_core(ompi_communicator_t *comm,
994997
if (info) {
995998
opal_infosubscribe_change_info(&newcomp->super, info);
996999
}
1000+
ompi_info_memkind_copy_or_set (&comm->instance->super, &newcomp->super, info);
9971001

9981002
/* Activate the communicator and init coll-component */
9991003
rc = ompi_comm_activate (&newcomp, comm, NULL, NULL, NULL, false, mode);
@@ -1347,6 +1351,7 @@ int ompi_comm_dup_with_info ( ompi_communicator_t * comm, opal_info_t *info, omp
13471351
if (info) {
13481352
opal_infosubscribe_change_info(&newcomp->super, info);
13491353
}
1354+
ompi_info_memkind_copy_or_set (&comm->instance->super, &newcomp->super, info);
13501355

13511356
/* activate communicator and init coll-module */
13521357
rc = ompi_comm_activate (&newcomp, comm, NULL, NULL, NULL, false, mode);
@@ -1437,6 +1442,7 @@ static int ompi_comm_idup_internal (ompi_communicator_t *comm, ompi_group_t *gro
14371442
if (info) {
14381443
opal_info_dup(info, &(newcomp->super.s_info));
14391444
}
1445+
ompi_info_memkind_copy_or_set (&comm->super, &newcomp->super, info);
14401446
}
14411447

14421448
ompi_comm_request_schedule_append (request, ompi_comm_idup_getcid, subreq, subreq[0] ? 1 : 0);
@@ -1588,6 +1594,7 @@ int ompi_comm_create_from_group (ompi_group_t *group, const char *tag, opal_info
15881594
if (NULL == newcomp->super.s_info) {
15891595
return OMPI_ERR_OUT_OF_RESOURCE;
15901596
}
1597+
ompi_info_memkind_copy_or_set (&group->grp_instance->super, &newcomp->super, info);
15911598

15921599
/* activate communicator and init coll-module. use the group allreduce implementation as
15931600
* no collective module has yet been selected. the tag does not matter as any tag will
@@ -1727,6 +1734,10 @@ int ompi_intercomm_create (ompi_communicator_t *local_comm, int local_leader, om
17271734
return rc;
17281735
}
17291736

1737+
// Copy info if there is one.
1738+
newcomp->super.s_info = OBJ_NEW(opal_info_t);
1739+
ompi_info_memkind_copy_or_set (&local_comm->instance->super, &newcomp->super, &ompi_mpi_info_null.info.super);
1740+
17301741
*newintercomm = newcomp;
17311742

17321743
return OMPI_SUCCESS;
@@ -1791,6 +1802,7 @@ int ompi_intercomm_create_from_groups (ompi_group_t *local_group, int local_lead
17911802
ompi_comm_free (&local_comm);
17921803
return OMPI_ERR_OUT_OF_RESOURCE;
17931804
}
1805+
leader_group->grp_instance = local_group->grp_instance;
17941806

17951807
/* create a unique tag for allocating the leader communicator. we can eliminate this step
17961808
* if we take a CID from the newly allocated block belonging to local_comm. this is
@@ -1888,6 +1900,7 @@ int ompi_intercomm_create_from_groups (ompi_group_t *local_group, int local_lead
18881900
if (info) {
18891901
opal_info_dup(info, &(newcomp->super.s_info));
18901902
}
1903+
ompi_info_memkind_copy_or_set (&local_group->grp_instance->super, &newcomp->super, info);
18911904

18921905
/* activate communicator and init coll-module */
18931906
rc = ompi_comm_activate (&newcomp, local_comm, leader_comm, &local_leader, &leader_comm_remote_leader,

ompi/communicator/comm_init.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
2626
* Copyright (c) 2018-2024 Triad National Security, LLC. All rights
2727
* reserved.
28-
* Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
28+
* Copyright (c) 2023-2024 Advanced Micro Devices, Inc. All rights reserved.
2929
* Copyright (c) 2023 NVIDIA Corporation. All rights reserved.
3030
* $COPYRIGHT$
3131
*
@@ -53,6 +53,7 @@
5353
#include "ompi/dpm/dpm.h"
5454
#include "ompi/memchecker.h"
5555
#include "ompi/instance/instance.h"
56+
#include "ompi/info/info_memkind.h"
5657

5758
/*
5859
** Table for Fortran <-> C communicator handle conversion
@@ -266,6 +267,7 @@ int ompi_comm_init_mpi3 (void)
266267
free(str);
267268
}
268269
}
270+
269271
/* Setup MPI_COMM_SELF */
270272
OBJ_CONSTRUCT(&ompi_mpi_comm_self, ompi_communicator_t);
271273
assert(ompi_mpi_comm_self.comm.c_f_to_c_index == 1);
@@ -300,6 +302,17 @@ int ompi_comm_init_mpi3 (void)
300302
MPI_COMM_SELF, the keyhash will automatically be created. */
301303
ompi_mpi_comm_self.comm.c_keyhash = NULL;
302304

305+
char *memkind_requested = getenv ("OMPI_MCA_mpi_memory_alloc_kinds");
306+
if (NULL != memkind_requested) {
307+
char *memkind_provided;
308+
309+
ompi_info_memkind_process (memkind_requested, &memkind_provided);
310+
opal_infosubscribe_subscribe (&ompi_mpi_comm_world.comm.super, "mpi_memory_alloc_kinds", memkind_provided, ompi_info_memkind_cb);
311+
opal_infosubscribe_subscribe (&ompi_mpi_comm_self.comm.super, "mpi_memory_alloc_kinds", memkind_provided, ompi_info_memkind_cb);
312+
opal_infosubscribe_subscribe (&ompi_mpi_comm_world.comm.instance->super, "mpi_memory_alloc_kinds", memkind_provided, ompi_info_memkind_cb);
313+
free (memkind_provided);
314+
}
315+
303316
/*
304317
* finally here we set the predefined attribute keyvals
305318
*/

ompi/file/file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
1919
* Copyright (c) 2024 Triad National Security, LLC. All rights
2020
* reserved.
21+
* Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
2122
* $COPYRIGHT$
2223
*
2324
* Additional copyrights may follow
@@ -34,7 +35,7 @@
3435
#include "ompi/runtime/params.h"
3536
#include "ompi/mca/io/base/base.h"
3637
#include "ompi/info/info.h"
37-
38+
#include "ompi/info/info_memkind.h"
3839

3940
opal_mutex_t ompi_mpi_file_bootstrap_mutex = OPAL_MUTEX_STATIC_INIT;
4041

@@ -123,6 +124,7 @@ int ompi_file_open(struct ompi_communicator_t *comm, const char *filename,
123124
if (info) {
124125
opal_info_dup(info, &(file->super.s_info));
125126
}
127+
ompi_info_memkind_copy_or_set (&comm->instance->super, &file->super, info);
126128

127129
file->f_amode = amode;
128130
file->f_filename = strdup(filename);

ompi/info/Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
# This makefile.am does not stand on its own - it is included from ompi/Makefile.am
2222

2323
headers += \
24-
info/info.h
24+
info/info.h \
25+
info/info_memkind.h
2526

2627
lib@OMPI_LIBMPI_NAME@_la_SOURCES += \
27-
info/info.c
28+
info/info.c \
29+
info/info_memkind.c

ompi/info/info.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "opal/util/info.h"
5252

5353
#include "ompi/info/info.h"
54+
#include "ompi/info/info_memkind.h"
5455
#include "ompi/runtime/mpiruntime.h"
5556
#include "ompi/runtime/params.h"
5657
#include "ompi/runtime/ompi_rte.h"
@@ -351,6 +352,9 @@ int ompi_mpiinfo_finalize(void)
351352
}
352353
}
353354

355+
/* Release the array of available memkind objects */
356+
ompi_info_memkind_free_available();
357+
354358
/* All done -- destroy the table */
355359

356360
OBJ_DESTRUCT(&ompi_info_f_to_c_table);

0 commit comments

Comments
 (0)