[Openmp-commits] [PATCH] D84065: [OpenMP] libomp cleanup: check presence of hwloc objects CORE, PACKAGE

Andrey Churbanov via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Jul 17 11:29:45 PDT 2020


AndreyChurbanov created this revision.
AndreyChurbanov added reviewers: hbae, jlpeyton.
AndreyChurbanov added a project: OpenMP.
Herald added subscribers: openmp-commits, sstefan1, guansong, yaxunl.
Herald added a reviewer: jdoerfert.

hwloc documentation guarantees the only object that is always present
in topology is PU. We can check the presence of other objects in the topology
just in case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84065

Files:
  openmp/runtime/src/kmp_affinity.cpp


Index: openmp/runtime/src/kmp_affinity.cpp
===================================================================
--- openmp/runtime/src/kmp_affinity.cpp
+++ openmp/runtime/src/kmp_affinity.cpp
@@ -577,11 +577,17 @@
     // Hack to try and infer the machine topology using only the data
     // available from cpuid on the current thread, and __kmp_xproc.
     KMP_ASSERT(__kmp_affinity_type == affinity_none);
-
-    nCoresPerPkg = __kmp_hwloc_get_nobjs_under_obj(
-        hwloc_get_obj_by_type(tp, HWLOC_OBJ_PACKAGE, 0), HWLOC_OBJ_CORE);
-    __kmp_nThreadsPerCore = __kmp_hwloc_get_nobjs_under_obj(
-        hwloc_get_obj_by_type(tp, HWLOC_OBJ_CORE, 0), HWLOC_OBJ_PU);
+    // hwloc only guarantees existance of PU object, so check PACKAGE and CORE
+    hwloc_obj_t o = hwloc_get_obj_by_type(tp, HWLOC_OBJ_PACKAGE, 0);
+    if (o != NULL)
+      nCoresPerPkg = __kmp_hwloc_get_nobjs_under_obj(o, HWLOC_OBJ_CORE);
+    else
+      nCoresPerPkg = 1; // no PACKAGE found
+    o = hwloc_get_obj_by_type(tp, HWLOC_OBJ_CORE, 0);
+    if (o != NULL)
+      __kmp_nThreadsPerCore = __kmp_hwloc_get_nobjs_under_obj(o, HWLOC_OBJ_PU);
+    else
+      __kmp_nThreadsPerCore = 1; // no CORE found
     __kmp_ncores = __kmp_xproc / __kmp_nThreadsPerCore;
     nPackages = (__kmp_xproc + nCoresPerPkg - 1) / nCoresPerPkg;
     if (__kmp_affinity_verbose) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84065.278861.patch
Type: text/x-patch
Size: 1344 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200717/4d789d5d/attachment-0001.bin>


More information about the Openmp-commits mailing list