Skip to content

Commit 86fb2db

Browse files
[OpenMP] libomp cleanup: check presence of hwloc objects CORE, PACKAGE
hwloc documentation guarantees the only object that is always present in the topology is PU. We can check the presence of other objects in the topology, just in case. Differential Revision: https://reviews.llvm.org/D84065
1 parent 7fcc1bb commit 86fb2db

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

openmp/runtime/src/kmp_affinity.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,17 @@ static int __kmp_affinity_create_hwloc_map(AddrUnsPair **address2os,
577577
// Hack to try and infer the machine topology using only the data
578578
// available from cpuid on the current thread, and __kmp_xproc.
579579
KMP_ASSERT(__kmp_affinity_type == affinity_none);
580-
581-
nCoresPerPkg = __kmp_hwloc_get_nobjs_under_obj(
582-
hwloc_get_obj_by_type(tp, HWLOC_OBJ_PACKAGE, 0), HWLOC_OBJ_CORE);
583-
__kmp_nThreadsPerCore = __kmp_hwloc_get_nobjs_under_obj(
584-
hwloc_get_obj_by_type(tp, HWLOC_OBJ_CORE, 0), HWLOC_OBJ_PU);
580+
// hwloc only guarantees existance of PU object, so check PACKAGE and CORE
581+
hwloc_obj_t o = hwloc_get_obj_by_type(tp, HWLOC_OBJ_PACKAGE, 0);
582+
if (o != NULL)
583+
nCoresPerPkg = __kmp_hwloc_get_nobjs_under_obj(o, HWLOC_OBJ_CORE);
584+
else
585+
nCoresPerPkg = 1; // no PACKAGE found
586+
o = hwloc_get_obj_by_type(tp, HWLOC_OBJ_CORE, 0);
587+
if (o != NULL)
588+
__kmp_nThreadsPerCore = __kmp_hwloc_get_nobjs_under_obj(o, HWLOC_OBJ_PU);
589+
else
590+
__kmp_nThreadsPerCore = 1; // no CORE found
585591
__kmp_ncores = __kmp_xproc / __kmp_nThreadsPerCore;
586592
nPackages = (__kmp_xproc + nCoresPerPkg - 1) / nCoresPerPkg;
587593
if (__kmp_affinity_verbose) {

0 commit comments

Comments
 (0)