summaryrefslogtreecommitdiff
path: root/runtime/src/kmp_affinity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/kmp_affinity.cpp')
-rw-r--r--runtime/src/kmp_affinity.cpp77
1 files changed, 20 insertions, 57 deletions
diff --git a/runtime/src/kmp_affinity.cpp b/runtime/src/kmp_affinity.cpp
index f14cdf68c0864..372c300d44ebb 100644
--- a/runtime/src/kmp_affinity.cpp
+++ b/runtime/src/kmp_affinity.cpp
@@ -4,10 +4,9 @@
//===----------------------------------------------------------------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.txt for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -458,7 +457,8 @@ static int __kmp_hwloc_get_nobjs_under_obj(hwloc_obj_t obj,
}
static int __kmp_hwloc_count_children_by_depth(hwloc_topology_t t,
- hwloc_obj_t o, unsigned depth,
+ hwloc_obj_t o,
+ kmp_hwloc_depth_t depth,
hwloc_obj_t *f) {
if (o->depth == depth) {
if (*f == NULL)
@@ -531,7 +531,7 @@ static int __kmp_hwloc_process_obj_core_pu(AddrUnsPair *addrPair,
static int __kmp_hwloc_check_numa() {
hwloc_topology_t &tp = __kmp_hwloc_topology;
hwloc_obj_t hT, hC, hL, hN, hS; // hwloc objects (pointers to)
- int depth;
+ int depth, l2cache_depth, package_depth;
// Get some PU
hT = hwloc_get_obj_by_type(tp, HWLOC_OBJ_PU, 0);
@@ -545,12 +545,14 @@ static int __kmp_hwloc_check_numa() {
if (hN != NULL && hN->depth > hS->depth) {
__kmp_numa_detected = TRUE; // socket includes node(s)
if (__kmp_affinity_gran == affinity_gran_node) {
- __kmp_affinity_gran == affinity_gran_numa;
+ __kmp_affinity_gran = affinity_gran_numa;
}
}
+ package_depth = hwloc_get_type_depth(tp, HWLOC_OBJ_PACKAGE);
+ l2cache_depth = hwloc_get_cache_type_depth(tp, 2, HWLOC_OBJ_CACHE_UNIFIED);
// check tile, get object by depth because of multiple caches possible
- depth = hwloc_get_cache_type_depth(tp, 2, HWLOC_OBJ_CACHE_UNIFIED);
+ depth = (l2cache_depth < package_depth) ? package_depth : l2cache_depth;
hL = hwloc_get_ancestor_obj_by_depth(tp, depth, hT);
hC = NULL; // not used, but reset it here just in case
if (hL != NULL &&
@@ -3017,8 +3019,6 @@ static void __kmp_affinity_process_proclist(kmp_affin_mask_t **out_masks,
KMP_CPU_FREE(sumMask);
}
-#if OMP_40_ENABLED
-
/*-----------------------------------------------------------------------------
Re-parse the OMP_PLACES proc id list, forming the newMasks for the different
places. Again, Here is the grammar:
@@ -3039,7 +3039,6 @@ signed := num
signed := + signed
signed := - signed
-----------------------------------------------------------------------------*/
-
static void __kmp_process_subplace_list(const char **scan,
kmp_affin_mask_t *osId2Mask,
int maxOsId, kmp_affin_mask_t *tempMask,
@@ -3358,8 +3357,6 @@ void __kmp_affinity_process_placelist(kmp_affin_mask_t **out_masks,
KMP_CPU_INTERNAL_FREE_ARRAY(newMasks, numNewMasks);
}
-#endif /* OMP_40_ENABLED */
-
#undef ADD_MASK
#undef ADD_MASK_OSID
@@ -4484,21 +4481,15 @@ static void __kmp_aux_affinity_initialize(void) {
case affinity_explicit:
KMP_DEBUG_ASSERT(__kmp_affinity_proclist != NULL);
-#if OMP_40_ENABLED
- if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_intel)
-#endif
- {
+ if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_intel) {
__kmp_affinity_process_proclist(
&__kmp_affinity_masks, &__kmp_affinity_num_masks,
__kmp_affinity_proclist, osId2Mask, maxIndex);
- }
-#if OMP_40_ENABLED
- else {
+ } else {
__kmp_affinity_process_placelist(
&__kmp_affinity_masks, &__kmp_affinity_num_masks,
__kmp_affinity_proclist, osId2Mask, maxIndex);
}
-#endif
if (__kmp_affinity_num_masks == 0) {
if (__kmp_affinity_verbose ||
(__kmp_affinity_warnings && (__kmp_affinity_type != affinity_none))) {
@@ -4614,13 +4605,11 @@ static void __kmp_aux_affinity_initialize(void) {
__kmp_affinity_num_masks = numUnique;
}
-#if OMP_40_ENABLED
if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
(__kmp_affinity_num_places > 0) &&
((unsigned)__kmp_affinity_num_places < __kmp_affinity_num_masks)) {
__kmp_affinity_num_masks = __kmp_affinity_num_places;
}
-#endif
KMP_CPU_ALLOC_ARRAY(__kmp_affinity_masks, __kmp_affinity_num_masks);
@@ -4690,9 +4679,7 @@ void __kmp_affinity_uninitialize(void) {
}
__kmp_affinity_num_masks = 0;
__kmp_affinity_type = affinity_default;
-#if OMP_40_ENABLED
__kmp_affinity_num_places = 0;
-#endif
if (__kmp_affinity_proclist != NULL) {
__kmp_free(__kmp_affinity_proclist);
__kmp_affinity_proclist = NULL;
@@ -4733,10 +4720,7 @@ void __kmp_affinity_set_init_mask(int gtid, int isa_root) {
kmp_affin_mask_t *mask;
int i;
-#if OMP_40_ENABLED
- if (KMP_AFFINITY_NON_PROC_BIND)
-#endif
- {
+ if (KMP_AFFINITY_NON_PROC_BIND) {
if ((__kmp_affinity_type == affinity_none) ||
(__kmp_affinity_type == affinity_balanced)) {
#if KMP_GROUP_AFFINITY
@@ -4752,9 +4736,7 @@ void __kmp_affinity_set_init_mask(int gtid, int isa_root) {
i = (gtid + __kmp_affinity_offset) % __kmp_affinity_num_masks;
mask = KMP_CPU_INDEX(__kmp_affinity_masks, i);
}
- }
-#if OMP_40_ENABLED
- else {
+ } else {
if ((!isa_root) ||
(__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
#if KMP_GROUP_AFFINITY
@@ -4773,9 +4755,7 @@ void __kmp_affinity_set_init_mask(int gtid, int isa_root) {
mask = KMP_CPU_INDEX(__kmp_affinity_masks, i);
}
}
-#endif
-#if OMP_40_ENABLED
th->th.th_current_place = i;
if (isa_root) {
th->th.th_new_place = i;
@@ -4795,17 +4775,6 @@ void __kmp_affinity_set_init_mask(int gtid, int isa_root) {
KA_TRACE(100, ("__kmp_affinity_set_init_mask: binding T#%d to place %d\n",
gtid, i));
}
-#else
- if (i == -1) {
- KA_TRACE(
- 100,
- ("__kmp_affinity_set_init_mask: binding T#%d to __kmp_affin_fullMask\n",
- gtid));
- } else {
- KA_TRACE(100, ("__kmp_affinity_set_init_mask: binding T#%d to mask %d\n",
- gtid, i));
- }
-#endif /* OMP_40_ENABLED */
KMP_CPU_COPY(th->th.th_affin_mask, mask);
@@ -4831,8 +4800,6 @@ void __kmp_affinity_set_init_mask(int gtid, int isa_root) {
__kmp_set_system_affinity(th->th.th_affin_mask, TRUE);
}
-#if OMP_40_ENABLED
-
void __kmp_affinity_set_place(int gtid) {
if (!KMP_AFFINITY_CAPABLE()) {
return;
@@ -4873,8 +4840,6 @@ void __kmp_affinity_set_place(int gtid) {
__kmp_set_system_affinity(th->th.th_affin_mask, TRUE);
}
-#endif /* OMP_40_ENABLED */
-
int __kmp_aux_set_affinity(void **mask) {
int gtid;
kmp_info_t *th;
@@ -4885,7 +4850,7 @@ int __kmp_aux_set_affinity(void **mask) {
}
gtid = __kmp_entry_gtid();
- KA_TRACE(1000, ; {
+ KA_TRACE(1000, (""); {
char buf[KMP_AFFIN_MASK_PRINT_LEN];
__kmp_affinity_print_mask(buf, KMP_AFFIN_MASK_PRINT_LEN,
(kmp_affin_mask_t *)(*mask));
@@ -4929,7 +4894,6 @@ int __kmp_aux_set_affinity(void **mask) {
KMP_CPU_COPY(th->th.th_affin_mask, (kmp_affin_mask_t *)(*mask));
}
-#if OMP_40_ENABLED
th->th.th_current_place = KMP_PLACE_UNDEFINED;
th->th.th_new_place = KMP_PLACE_UNDEFINED;
th->th.th_first_place = 0;
@@ -4937,7 +4901,6 @@ int __kmp_aux_set_affinity(void **mask) {
// Turn off 4.0 affinity for the current tread at this parallel level.
th->th.th_current_task->td_icvs.proc_bind = proc_bind_false;
-#endif
return retval;
}
@@ -4955,7 +4918,7 @@ int __kmp_aux_get_affinity(void **mask) {
th = __kmp_threads[gtid];
KMP_DEBUG_ASSERT(th->th.th_affin_mask != NULL);
- KA_TRACE(1000, ; {
+ KA_TRACE(1000, (""); {
char buf[KMP_AFFIN_MASK_PRINT_LEN];
__kmp_affinity_print_mask(buf, KMP_AFFIN_MASK_PRINT_LEN,
th->th.th_affin_mask);
@@ -4972,7 +4935,7 @@ int __kmp_aux_get_affinity(void **mask) {
#if !KMP_OS_WINDOWS
retval = __kmp_get_system_affinity((kmp_affin_mask_t *)(*mask), FALSE);
- KA_TRACE(1000, ; {
+ KA_TRACE(1000, (""); {
char buf[KMP_AFFIN_MASK_PRINT_LEN];
__kmp_affinity_print_mask(buf, KMP_AFFIN_MASK_PRINT_LEN,
(kmp_affin_mask_t *)(*mask));
@@ -5006,7 +4969,7 @@ int __kmp_aux_set_affinity_mask_proc(int proc, void **mask) {
return -1;
}
- KA_TRACE(1000, ; {
+ KA_TRACE(1000, (""); {
int gtid = __kmp_entry_gtid();
char buf[KMP_AFFIN_MASK_PRINT_LEN];
__kmp_affinity_print_mask(buf, KMP_AFFIN_MASK_PRINT_LEN,
@@ -5038,7 +5001,7 @@ int __kmp_aux_unset_affinity_mask_proc(int proc, void **mask) {
return -1;
}
- KA_TRACE(1000, ; {
+ KA_TRACE(1000, (""); {
int gtid = __kmp_entry_gtid();
char buf[KMP_AFFIN_MASK_PRINT_LEN];
__kmp_affinity_print_mask(buf, KMP_AFFIN_MASK_PRINT_LEN,
@@ -5070,7 +5033,7 @@ int __kmp_aux_get_affinity_mask_proc(int proc, void **mask) {
return -1;
}
- KA_TRACE(1000, ; {
+ KA_TRACE(1000, (""); {
int gtid = __kmp_entry_gtid();
char buf[KMP_AFFIN_MASK_PRINT_LEN];
__kmp_affinity_print_mask(buf, KMP_AFFIN_MASK_PRINT_LEN,