Skip to content

Commit bba3a82

Browse files
committed
[OpenMP] Use persistent memory for omp_large_cap_mem
This change enables volatile use of persistent memory for omp_large_cap_mem* on supported systems. It depends on libmemkind's support for persistent memory, and requirements/details can be found at the following url. https://pmem.io/2020/01/20/memkind-dax-kmem.html Differential Revision: https://reviews.llvm.org/D94353
1 parent 0066a09 commit bba3a82

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

openmp/runtime/src/kmp_alloc.cpp

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,9 @@ static void **mk_hbw_preferred;
12391239
static void **mk_hugetlb;
12401240
static void **mk_hbw_hugetlb;
12411241
static void **mk_hbw_preferred_hugetlb;
1242+
static void **mk_dax_kmem;
1243+
static void **mk_dax_kmem_all;
1244+
static void **mk_dax_kmem_preferred;
12421245

12431246
#if KMP_OS_UNIX && KMP_DYNAMIC_LIB
12441247
static inline void chk_kind(void ***pkind) {
@@ -1279,25 +1282,21 @@ void __kmp_init_memkind() {
12791282
mk_hbw_preferred_hugetlb =
12801283
(void **)dlsym(h_memkind, "MEMKIND_HBW_PREFERRED_HUGETLB");
12811284
chk_kind(&mk_hbw_preferred_hugetlb);
1285+
mk_dax_kmem = (void **)dlsym(h_memkind, "MEMKIND_DAX_KMEM");
1286+
chk_kind(&mk_dax_kmem);
1287+
mk_dax_kmem_all = (void **)dlsym(h_memkind, "MEMKIND_DAX_KMEM_ALL");
1288+
chk_kind(&mk_dax_kmem_all);
1289+
mk_dax_kmem_preferred =
1290+
(void **)dlsym(h_memkind, "MEMKIND_DAX_KMEM_PREFERRED");
1291+
chk_kind(&mk_dax_kmem_preferred);
12821292
KE_TRACE(25, ("__kmp_init_memkind: memkind library initialized\n"));
12831293
return; // success
12841294
}
12851295
dlclose(h_memkind); // failure
1286-
h_memkind = NULL;
12871296
}
1288-
kmp_mk_check = NULL;
1289-
kmp_mk_alloc = NULL;
1290-
kmp_mk_free = NULL;
1291-
mk_default = NULL;
1292-
mk_interleave = NULL;
1293-
mk_hbw = NULL;
1294-
mk_hbw_interleave = NULL;
1295-
mk_hbw_preferred = NULL;
1296-
mk_hugetlb = NULL;
1297-
mk_hbw_hugetlb = NULL;
1298-
mk_hbw_preferred_hugetlb = NULL;
1299-
#else
1297+
#else // !(KMP_OS_UNIX && KMP_DYNAMIC_LIB)
13001298
kmp_mk_lib_name = "";
1299+
#endif // !(KMP_OS_UNIX && KMP_DYNAMIC_LIB)
13011300
h_memkind = NULL;
13021301
kmp_mk_check = NULL;
13031302
kmp_mk_alloc = NULL;
@@ -1310,7 +1309,9 @@ void __kmp_init_memkind() {
13101309
mk_hugetlb = NULL;
13111310
mk_hbw_hugetlb = NULL;
13121311
mk_hbw_preferred_hugetlb = NULL;
1313-
#endif
1312+
mk_dax_kmem = NULL;
1313+
mk_dax_kmem_all = NULL;
1314+
mk_dax_kmem_preferred = NULL;
13141315
}
13151316

13161317
void __kmp_fini_memkind() {
@@ -1332,6 +1333,9 @@ void __kmp_fini_memkind() {
13321333
mk_hugetlb = NULL;
13331334
mk_hbw_hugetlb = NULL;
13341335
mk_hbw_preferred_hugetlb = NULL;
1336+
mk_dax_kmem = NULL;
1337+
mk_dax_kmem_all = NULL;
1338+
mk_dax_kmem_preferred = NULL;
13351339
#endif
13361340
}
13371341

@@ -1401,6 +1405,17 @@ omp_allocator_handle_t __kmpc_init_allocator(int gtid, omp_memspace_handle_t ms,
14011405
__kmp_free(al);
14021406
return omp_null_allocator;
14031407
}
1408+
} else if (ms == omp_large_cap_mem_space) {
1409+
if (mk_dax_kmem_all) {
1410+
// All pmem nodes are visited
1411+
al->memkind = mk_dax_kmem_all;
1412+
} else if (mk_dax_kmem) {
1413+
// Only closest pmem node is visited
1414+
al->memkind = mk_dax_kmem;
1415+
} else {
1416+
__kmp_free(al);
1417+
return omp_null_allocator;
1418+
}
14041419
} else {
14051420
if (al->memkind == (void *)omp_atv_interleaved && mk_interleave) {
14061421
al->memkind = mk_interleave;
@@ -1473,6 +1488,8 @@ void *__kmpc_alloc(int gtid, size_t size, omp_allocator_handle_t allocator) {
14731488
// pre-defined allocator
14741489
if (allocator == omp_high_bw_mem_alloc && mk_hbw_preferred) {
14751490
ptr = kmp_mk_alloc(*mk_hbw_preferred, desc.size_a);
1491+
} else if (allocator == omp_large_cap_mem_alloc && mk_dax_kmem_all) {
1492+
ptr = kmp_mk_alloc(*mk_dax_kmem_all, desc.size_a);
14761493
} else {
14771494
ptr = kmp_mk_alloc(*mk_default, desc.size_a);
14781495
}
@@ -1529,6 +1546,8 @@ void *__kmpc_alloc(int gtid, size_t size, omp_allocator_handle_t allocator) {
15291546
// pre-defined allocator
15301547
if (allocator == omp_high_bw_mem_alloc) {
15311548
// ptr = NULL;
1549+
} else if (allocator == omp_large_cap_mem_alloc) {
1550+
// warnings?
15321551
} else {
15331552
ptr = __kmp_thread_malloc(__kmp_thread_from_gtid(gtid), desc.size_a);
15341553
}
@@ -1684,6 +1703,8 @@ void __kmpc_free(int gtid, void *ptr, const omp_allocator_handle_t allocator) {
16841703
// pre-defined allocator
16851704
if (oal == omp_high_bw_mem_alloc && mk_hbw_preferred) {
16861705
kmp_mk_free(*mk_hbw_preferred, desc.ptr_alloc);
1706+
} else if (oal == omp_large_cap_mem_alloc && mk_dax_kmem_all) {
1707+
kmp_mk_free(*mk_dax_kmem_all, desc.ptr_alloc);
16871708
} else {
16881709
kmp_mk_free(*mk_default, desc.ptr_alloc);
16891710
}

0 commit comments

Comments
 (0)