[Openmp-commits] [openmp] [OpenMP] Fix preprocessor mismatches between include and usages of hwloc (PR #158349)
Peter Arzt via Openmp-commits
openmp-commits at lists.llvm.org
Mon Oct 6 03:01:07 PDT 2025
https://github.com/pearzt updated https://github.com/llvm/llvm-project/pull/158349
>From a61b86e2a7c6d855680919f4ae807969a89e764b Mon Sep 17 00:00:00 2001
From: Peter Arzt <peter.arzt at tu-darmstadt.de>
Date: Fri, 12 Sep 2025 20:58:19 +0200
Subject: [PATCH 1/2] [OpenMP] Fix preprocessor mismatches between include and
usages of hwloc
---
openmp/runtime/src/kmp.h | 13 ++++++++-----
openmp/runtime/src/kmp_affinity.cpp | 16 ++++++++--------
openmp/runtime/src/kmp_affinity.h | 4 ++--
openmp/runtime/src/kmp_alloc.cpp | 18 +++++++++---------
openmp/runtime/src/kmp_dispatch.h | 2 +-
openmp/runtime/src/kmp_global.cpp | 2 +-
openmp/runtime/src/kmp_settings.cpp | 10 +++++-----
7 files changed, 34 insertions(+), 31 deletions(-)
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index 83afc0e83f231..54a1408f05dc7 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -97,12 +97,15 @@ class kmp_stats_list;
// OMPD_SKIP_HWLOC used in libompd/omp-icv.cpp to avoid OMPD depending on hwloc
#if KMP_USE_HWLOC && KMP_AFFINITY_SUPPORTED && !defined(OMPD_SKIP_HWLOC)
#include "hwloc.h"
+#define KMP_INCLUDES_HWLOC 1
#ifndef HWLOC_OBJ_NUMANODE
#define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE
#endif
#ifndef HWLOC_OBJ_PACKAGE
#define HWLOC_OBJ_PACKAGE HWLOC_OBJ_SOCKET
#endif
+#else
+#define KMP_INCLUDES_HWLOC 0
#endif
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
@@ -672,7 +675,7 @@ typedef BOOL (*kmp_SetThreadGroupAffinity_t)(HANDLE, const GROUP_AFFINITY *,
extern kmp_SetThreadGroupAffinity_t __kmp_SetThreadGroupAffinity;
#endif /* KMP_OS_WINDOWS */
-#if KMP_USE_HWLOC && !defined(OMPD_SKIP_HWLOC)
+#if KMP_INCLUDES_HWLOC
extern hwloc_topology_t __kmp_hwloc_topology;
extern int __kmp_hwloc_error;
#endif
@@ -784,7 +787,7 @@ class KMPAffinity {
static void destroy_api();
enum api_type {
NATIVE_OS
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
,
HWLOC
#endif
@@ -856,7 +859,7 @@ enum affinity_top_method {
affinity_top_method_group,
#endif /* KMP_GROUP_AFFINITY */
affinity_top_method_flat,
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
affinity_top_method_hwloc,
#endif
affinity_top_method_default
@@ -1125,7 +1128,7 @@ typedef struct kmp_allocator_t {
omp_alloctrait_value_t target_access;
omp_alloctrait_value_t atomic_scope;
size_t part_size;
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
omp_alloctrait_value_t membind;
#endif
} kmp_allocator_t;
@@ -2087,7 +2090,7 @@ typedef struct dispatch_shared_info {
#if KMP_USE_HIER_SCHED
void *hier;
#endif
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
// When linking with libhwloc, the ORDERED EPCC test slows down on big
// machines (> 48 cores). Performance analysis showed that a cache thrash
// was occurring and this padding helps alleviate the problem.
diff --git a/openmp/runtime/src/kmp_affinity.cpp b/openmp/runtime/src/kmp_affinity.cpp
index 6bfdfbf2d3cdc..bd755c8fb0fab 100644
--- a/openmp/runtime/src/kmp_affinity.cpp
+++ b/openmp/runtime/src/kmp_affinity.cpp
@@ -19,7 +19,7 @@
#if KMP_USE_HIER_SCHED
#include "kmp_dispatch_hier.h"
#endif
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
// Copied from hwloc
#define HWLOC_GROUP_KIND_INTEL_MODULE 102
#define HWLOC_GROUP_KIND_INTEL_TILE 103
@@ -1440,7 +1440,7 @@ void KMPAffinity::pick_api() {
KMPAffinity *affinity_dispatch;
if (picked_api)
return;
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
// Only use Hwloc if affinity isn't explicitly disabled and
// user requests Hwloc topology method
if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
@@ -1699,7 +1699,7 @@ kmp_affin_mask_t *__kmp_affin_fullMask = NULL;
// Original mask is a subset of full mask in multiple processor groups topology
kmp_affin_mask_t *__kmp_affin_origMask = NULL;
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
static inline bool __kmp_hwloc_is_cache_type(hwloc_obj_t obj) {
#if HWLOC_API_VERSION >= 0x00020000
return hwloc_obj_type_is_cache(obj->type);
@@ -2007,7 +2007,7 @@ static bool __kmp_affinity_create_hwloc_map(kmp_i18n_id_t *const msg_id) {
__kmp_topology->sort_ids();
return true;
}
-#endif // KMP_USE_HWLOC
+#endif // KMP_INCLUDES_HWLOC
// If we don't know how to retrieve the machine's processor topology, or
// encounter an error in doing so, this routine is called to form a "flat"
@@ -4854,7 +4854,7 @@ static bool __kmp_aux_affinity_initialize_topology(kmp_affinity_t &affinity) {
// In the default code path, errors are not fatal - we just try using
// another method. We only emit a warning message if affinity is on, or the
// verbose flag is set, an the nowarnings flag was not set.
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
if (!success &&
__kmp_affinity_dispatch->get_api_type() == KMPAffinity::HWLOC) {
if (!__kmp_hwloc_error) {
@@ -4914,7 +4914,7 @@ static bool __kmp_aux_affinity_initialize_topology(kmp_affinity_t &affinity) {
// If the user has specified that a paricular topology discovery method is to be
// used, then we abort if that method fails. The exception is group affinity,
// which might have been implicitly set.
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
else if (__kmp_affinity_top_method == affinity_top_method_hwloc) {
KMP_ASSERT(__kmp_affinity_dispatch->get_api_type() == KMPAffinity::HWLOC);
success = __kmp_affinity_create_hwloc_map(&msg_id);
@@ -4923,7 +4923,7 @@ static bool __kmp_aux_affinity_initialize_topology(kmp_affinity_t &affinity) {
KMP_FATAL(MsgExiting, __kmp_i18n_catgets(msg_id));
}
}
-#endif // KMP_USE_HWLOC
+#endif // KMP_INCLUDES_HWLOC
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
else if (__kmp_affinity_top_method == affinity_top_method_x2apicid ||
@@ -5322,7 +5322,7 @@ void __kmp_affinity_uninitialize(void) {
__kmp_free(__kmp_osid_to_hwthread_map);
__kmp_osid_to_hwthread_map = NULL;
}
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
if (__kmp_hwloc_topology != NULL) {
hwloc_topology_destroy(__kmp_hwloc_topology);
__kmp_hwloc_topology = NULL;
diff --git a/openmp/runtime/src/kmp_affinity.h b/openmp/runtime/src/kmp_affinity.h
index dc3191caae634..599939fc0837e 100644
--- a/openmp/runtime/src/kmp_affinity.h
+++ b/openmp/runtime/src/kmp_affinity.h
@@ -18,7 +18,7 @@
#include <limits>
#if KMP_AFFINITY_SUPPORTED
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
class KMPHwlocAffinity : public KMPAffinity {
public:
class Mask : public KMPAffinity::Mask {
@@ -191,7 +191,7 @@ class KMPHwlocAffinity : public KMPAffinity {
}
api_type get_api_type() const override { return HWLOC; }
};
-#endif /* KMP_USE_HWLOC */
+#endif /* KMP_INCLUDES_HWLOC */
#if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY || \
KMP_OS_AIX
diff --git a/openmp/runtime/src/kmp_alloc.cpp b/openmp/runtime/src/kmp_alloc.cpp
index 051f88c5a0996..63733fa64b093 100644
--- a/openmp/runtime/src/kmp_alloc.cpp
+++ b/openmp/runtime/src/kmp_alloc.cpp
@@ -14,7 +14,7 @@
#include "kmp_io.h"
#include "kmp_wrapper_malloc.h"
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
#if HWLOC_API_VERSION > 0x00020300
#define KMP_HWLOC_LOCATION_TYPE_CPUSET HWLOC_LOCATION_TYPE_CPUSET
#elif HWLOC_API_VERSION == 0x00020300
@@ -26,7 +26,7 @@ enum hwloc_memattr_id_e {
HWLOC_MEMATTR_ID_CAPACITY
};
#endif
-#endif // KMP_USE_HWLOC
+#endif // KMP_INCLUDES_HWLOC
// Disable bget when it is not used
#if KMP_USE_BGET
@@ -1545,7 +1545,7 @@ void __kmp_fini_memkind() {
#endif
}
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
static bool __kmp_is_hwloc_membind_supported(hwloc_membind_policy_t policy) {
#if HWLOC_API_VERSION >= 0x00020300
const hwloc_topology_support *support;
@@ -1611,7 +1611,7 @@ void *__kmp_hwloc_membind_policy(omp_memspace_handle_t ms, size_t size,
return NULL;
#endif
}
-#endif // KMP_USE_HWLOC
+#endif // KMP_INCLUDES_HWLOC
void __kmp_init_target_mem() {
*(void **)(&kmp_target_alloc_host) = KMP_DLSYM("llvm_omp_target_alloc_host");
@@ -1680,7 +1680,7 @@ omp_allocator_handle_t __kmpc_init_allocator(int gtid, omp_memspace_handle_t ms,
al->fb_data = RCAST(kmp_allocator_t *, traits[i].value);
break;
case omp_atk_partition:
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
al->membind = (omp_alloctrait_value_t)traits[i].value;
KMP_DEBUG_ASSERT(al->membind == omp_atv_environment ||
al->membind == omp_atv_nearest ||
@@ -1980,7 +1980,7 @@ void *__kmp_alloc(int gtid, size_t algn, size_t size,
}
}
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
if (__kmp_hwloc_available) {
if (__kmp_is_hwloc_membind_supported(HWLOC_MEMBIND_BIND)) {
if (allocator < kmp_max_mem_alloc) {
@@ -2201,7 +2201,7 @@ void *__kmp_alloc(int gtid, size_t algn, size_t size,
KMP_ASSERT(0); // abort fallback requested
} // no sense to look for another fallback because of same internal alloc
}
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
}
#endif
KE_TRACE(10, ("__kmp_alloc: T#%d %p=alloc(%d)\n", gtid, ptr, desc.size_a));
@@ -2339,7 +2339,7 @@ void ___kmpc_free(int gtid, void *ptr, omp_allocator_handle_t allocator) {
kmp_target_unlock_mem(desc.ptr_alloc, device);
}
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
if (__kmp_hwloc_available) {
if (oal > kmp_max_mem_alloc && al->pool_size > 0) {
kmp_uint64 used =
@@ -2378,7 +2378,7 @@ void ___kmpc_free(int gtid, void *ptr, omp_allocator_handle_t allocator) {
}
__kmp_thread_free(__kmp_thread_from_gtid(gtid), desc.ptr_alloc);
}
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
}
#endif
}
diff --git a/openmp/runtime/src/kmp_dispatch.h b/openmp/runtime/src/kmp_dispatch.h
index cf19eb52662ce..61a9cd8a4d424 100644
--- a/openmp/runtime/src/kmp_dispatch.h
+++ b/openmp/runtime/src/kmp_dispatch.h
@@ -182,7 +182,7 @@ template <typename T> struct dispatch_shared_info_template {
#if KMP_USE_HIER_SCHED
kmp_hier_t<T> *hier;
#endif
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
// When linking with libhwloc, the ORDERED EPCC test slowsdown on big
// machines (> 48 cores). Performance analysis showed that a cache thrash
// was occurring and this padding helps alleviate the problem.
diff --git a/openmp/runtime/src/kmp_global.cpp b/openmp/runtime/src/kmp_global.cpp
index 323d13e948b42..b596b381f387e 100644
--- a/openmp/runtime/src/kmp_global.cpp
+++ b/openmp/runtime/src/kmp_global.cpp
@@ -248,7 +248,7 @@ enum mic_type __kmp_mic_type = non_mic;
KMPAffinity *__kmp_affinity_dispatch = NULL;
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
int __kmp_hwloc_error = FALSE;
hwloc_topology_t __kmp_hwloc_topology = NULL;
#endif
diff --git a/openmp/runtime/src/kmp_settings.cpp b/openmp/runtime/src/kmp_settings.cpp
index b9d615f43b570..a38a2f6d733eb 100644
--- a/openmp/runtime/src/kmp_settings.cpp
+++ b/openmp/runtime/src/kmp_settings.cpp
@@ -1069,7 +1069,7 @@ static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
static void __kmp_stg_parse_nesting_mode(char const *name, char const *value,
void *data) {
__kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_nesting_mode);
-#if KMP_AFFINITY_SUPPORTED && KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
if (__kmp_nesting_mode > 0)
__kmp_affinity_top_method = affinity_top_method_hwloc;
#endif
@@ -3301,7 +3301,7 @@ static void __kmp_stg_parse_topology_method(char const *name, char const *value,
if (__kmp_str_match("all", 1, value)) {
__kmp_affinity_top_method = affinity_top_method_all;
}
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
else if (__kmp_str_match("hwloc", 1, value)) {
__kmp_affinity_top_method = affinity_top_method_hwloc;
}
@@ -3409,7 +3409,7 @@ static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
break;
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
case affinity_top_method_hwloc:
value = "hwloc";
break;
@@ -6277,7 +6277,7 @@ void __kmp_env_initialize(char const *string) {
#if KMP_AFFINITY_SUPPORTED
if (!TCR_4(__kmp_init_middle)) {
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
// Force using hwloc when either tiles or numa nodes requested within
// KMP_HW_SUBSET or granularity setting and no other topology method
// is requested
@@ -6297,7 +6297,7 @@ void __kmp_env_initialize(char const *string) {
// affinity.
const char *var = "KMP_AFFINITY";
KMPAffinity::pick_api();
-#if KMP_USE_HWLOC
+#if KMP_INCLUDES_HWLOC
// If Hwloc topology discovery was requested but affinity was also disabled,
// then tell user that Hwloc request is being ignored and use default
// topology discovery method.
>From 39177a7b00c45f1de7f9274e250184a20220c478 Mon Sep 17 00:00:00 2001
From: Peter Arzt <peter.arzt at tu-darmstadt.de>
Date: Mon, 6 Oct 2025 11:59:36 +0200
Subject: [PATCH 2/2] [OpenMP] Use KMP_HWLOC_ENABLED and fix #endif comments
KMP_HWLOC_ENABLED expresses whether hwloc is included *and*
hwloc-based affinity is enabled.
---
openmp/runtime/src/kmp.h | 24 +++++++++++------------
openmp/runtime/src/kmp_affinity.cpp | 24 +++++++++++------------
openmp/runtime/src/kmp_affinity.h | 6 +++---
openmp/runtime/src/kmp_alloc.cpp | 30 ++++++++++++++---------------
openmp/runtime/src/kmp_dispatch.h | 4 ++--
openmp/runtime/src/kmp_global.cpp | 4 ++--
openmp/runtime/src/kmp_settings.cpp | 20 +++++++++----------
7 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index 54a1408f05dc7..3ffec41a7f679 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -97,7 +97,7 @@ class kmp_stats_list;
// OMPD_SKIP_HWLOC used in libompd/omp-icv.cpp to avoid OMPD depending on hwloc
#if KMP_USE_HWLOC && KMP_AFFINITY_SUPPORTED && !defined(OMPD_SKIP_HWLOC)
#include "hwloc.h"
-#define KMP_INCLUDES_HWLOC 1
+#define KMP_HWLOC_ENABLED 1
#ifndef HWLOC_OBJ_NUMANODE
#define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE
#endif
@@ -105,7 +105,7 @@ class kmp_stats_list;
#define HWLOC_OBJ_PACKAGE HWLOC_OBJ_SOCKET
#endif
#else
-#define KMP_INCLUDES_HWLOC 0
+#define KMP_HWLOC_ENABLED 0
#endif
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
@@ -675,10 +675,10 @@ typedef BOOL (*kmp_SetThreadGroupAffinity_t)(HANDLE, const GROUP_AFFINITY *,
extern kmp_SetThreadGroupAffinity_t __kmp_SetThreadGroupAffinity;
#endif /* KMP_OS_WINDOWS */
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
extern hwloc_topology_t __kmp_hwloc_topology;
extern int __kmp_hwloc_error;
-#endif
+#endif // KMP_HWLOC_ENABLED
extern size_t __kmp_affin_mask_size;
#define KMP_AFFINITY_CAPABLE() (__kmp_affin_mask_size > 0)
@@ -787,10 +787,10 @@ class KMPAffinity {
static void destroy_api();
enum api_type {
NATIVE_OS
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
,
HWLOC
-#endif
+#endif // KMP_HWLOC_ENABLED
};
virtual api_type get_api_type() const {
KMP_ASSERT(0);
@@ -859,9 +859,9 @@ enum affinity_top_method {
affinity_top_method_group,
#endif /* KMP_GROUP_AFFINITY */
affinity_top_method_flat,
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
affinity_top_method_hwloc,
-#endif
+#endif // KMP_HWLOC_ENABLED
affinity_top_method_default
};
@@ -1128,9 +1128,9 @@ typedef struct kmp_allocator_t {
omp_alloctrait_value_t target_access;
omp_alloctrait_value_t atomic_scope;
size_t part_size;
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
omp_alloctrait_value_t membind;
-#endif
+#endif // KMP_HWLOC_ENABLED
} kmp_allocator_t;
extern omp_allocator_handle_t __kmpc_init_allocator(int gtid,
@@ -2090,12 +2090,12 @@ typedef struct dispatch_shared_info {
#if KMP_USE_HIER_SCHED
void *hier;
#endif
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
// When linking with libhwloc, the ORDERED EPCC test slows down on big
// machines (> 48 cores). Performance analysis showed that a cache thrash
// was occurring and this padding helps alleviate the problem.
char padding[64];
-#endif
+#endif // KMP_HWLOC_ENABLED
} dispatch_shared_info_t;
typedef struct kmp_disp {
diff --git a/openmp/runtime/src/kmp_affinity.cpp b/openmp/runtime/src/kmp_affinity.cpp
index bd755c8fb0fab..6a0e2910db8e0 100644
--- a/openmp/runtime/src/kmp_affinity.cpp
+++ b/openmp/runtime/src/kmp_affinity.cpp
@@ -19,13 +19,13 @@
#if KMP_USE_HIER_SCHED
#include "kmp_dispatch_hier.h"
#endif
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
// Copied from hwloc
#define HWLOC_GROUP_KIND_INTEL_MODULE 102
#define HWLOC_GROUP_KIND_INTEL_TILE 103
#define HWLOC_GROUP_KIND_INTEL_DIE 104
#define HWLOC_GROUP_KIND_WINDOWS_PROCESSOR_GROUP 220
-#endif
+#endif // KMP_HWLOC_ENABLED
#include <ctype.h>
// The machine topology
@@ -1440,7 +1440,7 @@ void KMPAffinity::pick_api() {
KMPAffinity *affinity_dispatch;
if (picked_api)
return;
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
// Only use Hwloc if affinity isn't explicitly disabled and
// user requests Hwloc topology method
if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
@@ -1448,7 +1448,7 @@ void KMPAffinity::pick_api() {
affinity_dispatch = new KMPHwlocAffinity();
__kmp_hwloc_available = true;
} else
-#endif
+#endif // KMP_HWLOC_ENABLED
{
affinity_dispatch = new KMPNativeAffinity();
}
@@ -1699,7 +1699,7 @@ kmp_affin_mask_t *__kmp_affin_fullMask = NULL;
// Original mask is a subset of full mask in multiple processor groups topology
kmp_affin_mask_t *__kmp_affin_origMask = NULL;
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
static inline bool __kmp_hwloc_is_cache_type(hwloc_obj_t obj) {
#if HWLOC_API_VERSION >= 0x00020000
return hwloc_obj_type_is_cache(obj->type);
@@ -2007,7 +2007,7 @@ static bool __kmp_affinity_create_hwloc_map(kmp_i18n_id_t *const msg_id) {
__kmp_topology->sort_ids();
return true;
}
-#endif // KMP_INCLUDES_HWLOC
+#endif // KMP_HWLOC_ENABLED
// If we don't know how to retrieve the machine's processor topology, or
// encounter an error in doing so, this routine is called to form a "flat"
@@ -4854,7 +4854,7 @@ static bool __kmp_aux_affinity_initialize_topology(kmp_affinity_t &affinity) {
// In the default code path, errors are not fatal - we just try using
// another method. We only emit a warning message if affinity is on, or the
// verbose flag is set, an the nowarnings flag was not set.
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
if (!success &&
__kmp_affinity_dispatch->get_api_type() == KMPAffinity::HWLOC) {
if (!__kmp_hwloc_error) {
@@ -4866,7 +4866,7 @@ static bool __kmp_aux_affinity_initialize_topology(kmp_affinity_t &affinity) {
KMP_INFORM(AffIgnoringHwloc, env_var);
}
}
-#endif
+#endif // KMP_HWLOC_ENABLED
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
if (!success) {
@@ -4914,7 +4914,7 @@ static bool __kmp_aux_affinity_initialize_topology(kmp_affinity_t &affinity) {
// If the user has specified that a paricular topology discovery method is to be
// used, then we abort if that method fails. The exception is group affinity,
// which might have been implicitly set.
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
else if (__kmp_affinity_top_method == affinity_top_method_hwloc) {
KMP_ASSERT(__kmp_affinity_dispatch->get_api_type() == KMPAffinity::HWLOC);
success = __kmp_affinity_create_hwloc_map(&msg_id);
@@ -4923,7 +4923,7 @@ static bool __kmp_aux_affinity_initialize_topology(kmp_affinity_t &affinity) {
KMP_FATAL(MsgExiting, __kmp_i18n_catgets(msg_id));
}
}
-#endif // KMP_INCLUDES_HWLOC
+#endif // KMP_HWLOC_ENABLED
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
else if (__kmp_affinity_top_method == affinity_top_method_x2apicid ||
@@ -5322,12 +5322,12 @@ void __kmp_affinity_uninitialize(void) {
__kmp_free(__kmp_osid_to_hwthread_map);
__kmp_osid_to_hwthread_map = NULL;
}
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
if (__kmp_hwloc_topology != NULL) {
hwloc_topology_destroy(__kmp_hwloc_topology);
__kmp_hwloc_topology = NULL;
}
-#endif
+#endif // KMP_HWLOC_ENABLED
if (__kmp_hw_subset) {
kmp_hw_subset_t::deallocate(__kmp_hw_subset);
__kmp_hw_subset = nullptr;
diff --git a/openmp/runtime/src/kmp_affinity.h b/openmp/runtime/src/kmp_affinity.h
index 599939fc0837e..fa69585f7e2d5 100644
--- a/openmp/runtime/src/kmp_affinity.h
+++ b/openmp/runtime/src/kmp_affinity.h
@@ -18,7 +18,7 @@
#include <limits>
#if KMP_AFFINITY_SUPPORTED
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
class KMPHwlocAffinity : public KMPAffinity {
public:
class Mask : public KMPAffinity::Mask {
@@ -109,7 +109,7 @@ class KMPHwlocAffinity : public KMPAffinity {
}
return error;
}
-#endif
+#endif // KMP_OS_WINDOWS
int get_proc_group() const override {
int group = -1;
#if KMP_OS_WINDOWS
@@ -191,7 +191,7 @@ class KMPHwlocAffinity : public KMPAffinity {
}
api_type get_api_type() const override { return HWLOC; }
};
-#endif /* KMP_INCLUDES_HWLOC */
+#endif /* KMP_HWLOC_ENABLED */
#if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY || \
KMP_OS_AIX
diff --git a/openmp/runtime/src/kmp_alloc.cpp b/openmp/runtime/src/kmp_alloc.cpp
index 63733fa64b093..d43daefb6ef1e 100644
--- a/openmp/runtime/src/kmp_alloc.cpp
+++ b/openmp/runtime/src/kmp_alloc.cpp
@@ -14,7 +14,7 @@
#include "kmp_io.h"
#include "kmp_wrapper_malloc.h"
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
#if HWLOC_API_VERSION > 0x00020300
#define KMP_HWLOC_LOCATION_TYPE_CPUSET HWLOC_LOCATION_TYPE_CPUSET
#elif HWLOC_API_VERSION == 0x00020300
@@ -26,7 +26,7 @@ enum hwloc_memattr_id_e {
HWLOC_MEMATTR_ID_CAPACITY
};
#endif
-#endif // KMP_INCLUDES_HWLOC
+#endif // KMP_HWLOC_ENABLED
// Disable bget when it is not used
#if KMP_USE_BGET
@@ -1545,7 +1545,7 @@ void __kmp_fini_memkind() {
#endif
}
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
static bool __kmp_is_hwloc_membind_supported(hwloc_membind_policy_t policy) {
#if HWLOC_API_VERSION >= 0x00020300
const hwloc_topology_support *support;
@@ -1561,7 +1561,7 @@ static bool __kmp_is_hwloc_membind_supported(hwloc_membind_policy_t policy) {
return false;
#else
return false;
-#endif
+#endif // KMP_HWLOC_ENABLED
}
void *__kmp_hwloc_alloc_membind(hwloc_memattr_id_e attr, size_t size,
@@ -1611,7 +1611,7 @@ void *__kmp_hwloc_membind_policy(omp_memspace_handle_t ms, size_t size,
return NULL;
#endif
}
-#endif // KMP_INCLUDES_HWLOC
+#endif // KMP_HWLOC_ENABLED
void __kmp_init_target_mem() {
*(void **)(&kmp_target_alloc_host) = KMP_DLSYM("llvm_omp_target_alloc_host");
@@ -1680,13 +1680,13 @@ omp_allocator_handle_t __kmpc_init_allocator(int gtid, omp_memspace_handle_t ms,
al->fb_data = RCAST(kmp_allocator_t *, traits[i].value);
break;
case omp_atk_partition:
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
al->membind = (omp_alloctrait_value_t)traits[i].value;
KMP_DEBUG_ASSERT(al->membind == omp_atv_environment ||
al->membind == omp_atv_nearest ||
al->membind == omp_atv_blocked ||
al->membind == omp_atv_interleaved);
-#endif
+#endif // KMP_HWLOC_ENABLED
al->memkind = RCAST(void **, traits[i].value);
break;
case omp_atk_pin_device:
@@ -1980,7 +1980,7 @@ void *__kmp_alloc(int gtid, size_t algn, size_t size,
}
}
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
if (__kmp_hwloc_available) {
if (__kmp_is_hwloc_membind_supported(HWLOC_MEMBIND_BIND)) {
if (allocator < kmp_max_mem_alloc) {
@@ -2074,7 +2074,7 @@ void *__kmp_alloc(int gtid, size_t algn, size_t size,
ptr = hwloc_alloc(__kmp_hwloc_topology, desc.size_a);
}
} else {
-#endif
+#endif // KMP_HWLOC_ENABLED
if (__kmp_memkind_available) {
if (allocator < kmp_max_mem_alloc) {
// pre-defined allocator
@@ -2201,9 +2201,9 @@ void *__kmp_alloc(int gtid, size_t algn, size_t size,
KMP_ASSERT(0); // abort fallback requested
} // no sense to look for another fallback because of same internal alloc
}
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
}
-#endif
+#endif // KMP_HWLOC_ENABLED
KE_TRACE(10, ("__kmp_alloc: T#%d %p=alloc(%d)\n", gtid, ptr, desc.size_a));
if (ptr == NULL)
return NULL;
@@ -2339,7 +2339,7 @@ void ___kmpc_free(int gtid, void *ptr, omp_allocator_handle_t allocator) {
kmp_target_unlock_mem(desc.ptr_alloc, device);
}
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
if (__kmp_hwloc_available) {
if (oal > kmp_max_mem_alloc && al->pool_size > 0) {
kmp_uint64 used =
@@ -2349,7 +2349,7 @@ void ___kmpc_free(int gtid, void *ptr, omp_allocator_handle_t allocator) {
}
hwloc_free(__kmp_hwloc_topology, desc.ptr_alloc, desc.size_a);
} else {
-#endif
+#endif // KMP_HWLOC_ENABLED
if (__kmp_memkind_available) {
if (oal < kmp_max_mem_alloc) {
// pre-defined allocator
@@ -2378,9 +2378,9 @@ void ___kmpc_free(int gtid, void *ptr, omp_allocator_handle_t allocator) {
}
__kmp_thread_free(__kmp_thread_from_gtid(gtid), desc.ptr_alloc);
}
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
}
-#endif
+#endif // KMP_HWLOC_ENABLED
}
/* If LEAK_MEMORY is defined, __kmp_free() will *not* free memory. It causes
diff --git a/openmp/runtime/src/kmp_dispatch.h b/openmp/runtime/src/kmp_dispatch.h
index 61a9cd8a4d424..f161a801700f4 100644
--- a/openmp/runtime/src/kmp_dispatch.h
+++ b/openmp/runtime/src/kmp_dispatch.h
@@ -182,12 +182,12 @@ template <typename T> struct dispatch_shared_info_template {
#if KMP_USE_HIER_SCHED
kmp_hier_t<T> *hier;
#endif
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
// When linking with libhwloc, the ORDERED EPCC test slowsdown on big
// machines (> 48 cores). Performance analysis showed that a cache thrash
// was occurring and this padding helps alleviate the problem.
char padding[64];
-#endif
+#endif // KMP_HWLOC_ENABLED
};
/* ------------------------------------------------------------------------ */
diff --git a/openmp/runtime/src/kmp_global.cpp b/openmp/runtime/src/kmp_global.cpp
index b596b381f387e..6c3b576cab405 100644
--- a/openmp/runtime/src/kmp_global.cpp
+++ b/openmp/runtime/src/kmp_global.cpp
@@ -248,10 +248,10 @@ enum mic_type __kmp_mic_type = non_mic;
KMPAffinity *__kmp_affinity_dispatch = NULL;
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
int __kmp_hwloc_error = FALSE;
hwloc_topology_t __kmp_hwloc_topology = NULL;
-#endif
+#endif // KMP_HWLOC_ENABLED
#if KMP_OS_WINDOWS
#if KMP_GROUP_AFFINITY
diff --git a/openmp/runtime/src/kmp_settings.cpp b/openmp/runtime/src/kmp_settings.cpp
index a38a2f6d733eb..b6e7e9cadfe60 100644
--- a/openmp/runtime/src/kmp_settings.cpp
+++ b/openmp/runtime/src/kmp_settings.cpp
@@ -1069,10 +1069,10 @@ static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
static void __kmp_stg_parse_nesting_mode(char const *name, char const *value,
void *data) {
__kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_nesting_mode);
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
if (__kmp_nesting_mode > 0)
__kmp_affinity_top_method = affinity_top_method_hwloc;
-#endif
+#endif // KMP_HWLOC_ENABLED
} // __kmp_stg_parse_nesting_mode
static void __kmp_stg_print_nesting_mode(kmp_str_buf_t *buffer,
@@ -3301,11 +3301,11 @@ static void __kmp_stg_parse_topology_method(char const *name, char const *value,
if (__kmp_str_match("all", 1, value)) {
__kmp_affinity_top_method = affinity_top_method_all;
}
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
else if (__kmp_str_match("hwloc", 1, value)) {
__kmp_affinity_top_method = affinity_top_method_hwloc;
}
-#endif
+#endif // KMP_HWLOC_ENABLED
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
else if (__kmp_str_match("cpuid_leaf31", 12, value) ||
__kmp_str_match("cpuid 1f", 8, value) ||
@@ -3409,11 +3409,11 @@ static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
break;
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
case affinity_top_method_hwloc:
value = "hwloc";
break;
-#endif
+#endif // KMP_HWLOC_ENABLED
case affinity_top_method_cpuinfo:
value = "cpuinfo";
@@ -6277,7 +6277,7 @@ void __kmp_env_initialize(char const *string) {
#if KMP_AFFINITY_SUPPORTED
if (!TCR_4(__kmp_init_middle)) {
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
// Force using hwloc when either tiles or numa nodes requested within
// KMP_HW_SUBSET or granularity setting and no other topology method
// is requested
@@ -6292,12 +6292,12 @@ void __kmp_env_initialize(char const *string) {
if (__kmp_affinity.gran == KMP_HW_NUMA ||
__kmp_affinity.gran == KMP_HW_TILE)
__kmp_affinity_top_method = affinity_top_method_hwloc;
-#endif
+#endif // KMP_HWLOC_ENABLED
// Determine if the machine/OS is actually capable of supporting
// affinity.
const char *var = "KMP_AFFINITY";
KMPAffinity::pick_api();
-#if KMP_INCLUDES_HWLOC
+#if KMP_HWLOC_ENABLED
// If Hwloc topology discovery was requested but affinity was also disabled,
// then tell user that Hwloc request is being ignored and use default
// topology discovery method.
@@ -6306,7 +6306,7 @@ void __kmp_env_initialize(char const *string) {
KMP_WARNING(AffIgnoringHwloc, var);
__kmp_affinity_top_method = affinity_top_method_all;
}
-#endif
+#endif // KMP_HWLOC_ENABLED
if (__kmp_affinity.type == affinity_disabled) {
KMP_AFFINITY_DISABLE();
} else if (!KMP_AFFINITY_CAPABLE()) {
More information about the Openmp-commits
mailing list