Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions openmp/runtime/src/kmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions openmp/runtime/src/kmp_affinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#if KMP_USE_HIER_SCHED
#include "kmp_dispatch_hier.h"
#endif
#if KMP_USE_HWLOC
#if KMP_INCLUDES_HWLOC
Copy link
Contributor

@mjklemm mjklemm Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several of these do not have the comment to indicate which #endif is closing off that compilation guards. It would be great if you could add them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// Copied from hwloc
#define HWLOC_GROUP_KIND_INTEL_MODULE 102
#define HWLOC_GROUP_KIND_INTEL_TILE 103
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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 ||
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions openmp/runtime/src/kmp_affinity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions openmp/runtime/src/kmp_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion openmp/runtime/src/kmp_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion openmp/runtime/src/kmp_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions openmp/runtime/src/kmp_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
Loading