Skip to content

Commit a61b86e

Browse files
committed
[OpenMP] Fix preprocessor mismatches between include and usages of hwloc
1 parent 5a339b0 commit a61b86e

File tree

7 files changed

+34
-31
lines changed

7 files changed

+34
-31
lines changed

openmp/runtime/src/kmp.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ class kmp_stats_list;
9797
// OMPD_SKIP_HWLOC used in libompd/omp-icv.cpp to avoid OMPD depending on hwloc
9898
#if KMP_USE_HWLOC && KMP_AFFINITY_SUPPORTED && !defined(OMPD_SKIP_HWLOC)
9999
#include "hwloc.h"
100+
#define KMP_INCLUDES_HWLOC 1
100101
#ifndef HWLOC_OBJ_NUMANODE
101102
#define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE
102103
#endif
103104
#ifndef HWLOC_OBJ_PACKAGE
104105
#define HWLOC_OBJ_PACKAGE HWLOC_OBJ_SOCKET
105106
#endif
107+
#else
108+
#define KMP_INCLUDES_HWLOC 0
106109
#endif
107110

108111
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
@@ -672,7 +675,7 @@ typedef BOOL (*kmp_SetThreadGroupAffinity_t)(HANDLE, const GROUP_AFFINITY *,
672675
extern kmp_SetThreadGroupAffinity_t __kmp_SetThreadGroupAffinity;
673676
#endif /* KMP_OS_WINDOWS */
674677

675-
#if KMP_USE_HWLOC && !defined(OMPD_SKIP_HWLOC)
678+
#if KMP_INCLUDES_HWLOC
676679
extern hwloc_topology_t __kmp_hwloc_topology;
677680
extern int __kmp_hwloc_error;
678681
#endif
@@ -784,7 +787,7 @@ class KMPAffinity {
784787
static void destroy_api();
785788
enum api_type {
786789
NATIVE_OS
787-
#if KMP_USE_HWLOC
790+
#if KMP_INCLUDES_HWLOC
788791
,
789792
HWLOC
790793
#endif
@@ -856,7 +859,7 @@ enum affinity_top_method {
856859
affinity_top_method_group,
857860
#endif /* KMP_GROUP_AFFINITY */
858861
affinity_top_method_flat,
859-
#if KMP_USE_HWLOC
862+
#if KMP_INCLUDES_HWLOC
860863
affinity_top_method_hwloc,
861864
#endif
862865
affinity_top_method_default
@@ -1125,7 +1128,7 @@ typedef struct kmp_allocator_t {
11251128
omp_alloctrait_value_t target_access;
11261129
omp_alloctrait_value_t atomic_scope;
11271130
size_t part_size;
1128-
#if KMP_USE_HWLOC
1131+
#if KMP_INCLUDES_HWLOC
11291132
omp_alloctrait_value_t membind;
11301133
#endif
11311134
} kmp_allocator_t;
@@ -2087,7 +2090,7 @@ typedef struct dispatch_shared_info {
20872090
#if KMP_USE_HIER_SCHED
20882091
void *hier;
20892092
#endif
2090-
#if KMP_USE_HWLOC
2093+
#if KMP_INCLUDES_HWLOC
20912094
// When linking with libhwloc, the ORDERED EPCC test slows down on big
20922095
// machines (> 48 cores). Performance analysis showed that a cache thrash
20932096
// was occurring and this padding helps alleviate the problem.

openmp/runtime/src/kmp_affinity.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#if KMP_USE_HIER_SCHED
2020
#include "kmp_dispatch_hier.h"
2121
#endif
22-
#if KMP_USE_HWLOC
22+
#if KMP_INCLUDES_HWLOC
2323
// Copied from hwloc
2424
#define HWLOC_GROUP_KIND_INTEL_MODULE 102
2525
#define HWLOC_GROUP_KIND_INTEL_TILE 103
@@ -1440,7 +1440,7 @@ void KMPAffinity::pick_api() {
14401440
KMPAffinity *affinity_dispatch;
14411441
if (picked_api)
14421442
return;
1443-
#if KMP_USE_HWLOC
1443+
#if KMP_INCLUDES_HWLOC
14441444
// Only use Hwloc if affinity isn't explicitly disabled and
14451445
// user requests Hwloc topology method
14461446
if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
@@ -1699,7 +1699,7 @@ kmp_affin_mask_t *__kmp_affin_fullMask = NULL;
16991699
// Original mask is a subset of full mask in multiple processor groups topology
17001700
kmp_affin_mask_t *__kmp_affin_origMask = NULL;
17011701

1702-
#if KMP_USE_HWLOC
1702+
#if KMP_INCLUDES_HWLOC
17031703
static inline bool __kmp_hwloc_is_cache_type(hwloc_obj_t obj) {
17041704
#if HWLOC_API_VERSION >= 0x00020000
17051705
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) {
20072007
__kmp_topology->sort_ids();
20082008
return true;
20092009
}
2010-
#endif // KMP_USE_HWLOC
2010+
#endif // KMP_INCLUDES_HWLOC
20112011

20122012
// If we don't know how to retrieve the machine's processor topology, or
20132013
// 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) {
48544854
// In the default code path, errors are not fatal - we just try using
48554855
// another method. We only emit a warning message if affinity is on, or the
48564856
// verbose flag is set, an the nowarnings flag was not set.
4857-
#if KMP_USE_HWLOC
4857+
#if KMP_INCLUDES_HWLOC
48584858
if (!success &&
48594859
__kmp_affinity_dispatch->get_api_type() == KMPAffinity::HWLOC) {
48604860
if (!__kmp_hwloc_error) {
@@ -4914,7 +4914,7 @@ static bool __kmp_aux_affinity_initialize_topology(kmp_affinity_t &affinity) {
49144914
// If the user has specified that a paricular topology discovery method is to be
49154915
// used, then we abort if that method fails. The exception is group affinity,
49164916
// which might have been implicitly set.
4917-
#if KMP_USE_HWLOC
4917+
#if KMP_INCLUDES_HWLOC
49184918
else if (__kmp_affinity_top_method == affinity_top_method_hwloc) {
49194919
KMP_ASSERT(__kmp_affinity_dispatch->get_api_type() == KMPAffinity::HWLOC);
49204920
success = __kmp_affinity_create_hwloc_map(&msg_id);
@@ -4923,7 +4923,7 @@ static bool __kmp_aux_affinity_initialize_topology(kmp_affinity_t &affinity) {
49234923
KMP_FATAL(MsgExiting, __kmp_i18n_catgets(msg_id));
49244924
}
49254925
}
4926-
#endif // KMP_USE_HWLOC
4926+
#endif // KMP_INCLUDES_HWLOC
49274927

49284928
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
49294929
else if (__kmp_affinity_top_method == affinity_top_method_x2apicid ||
@@ -5322,7 +5322,7 @@ void __kmp_affinity_uninitialize(void) {
53225322
__kmp_free(__kmp_osid_to_hwthread_map);
53235323
__kmp_osid_to_hwthread_map = NULL;
53245324
}
5325-
#if KMP_USE_HWLOC
5325+
#if KMP_INCLUDES_HWLOC
53265326
if (__kmp_hwloc_topology != NULL) {
53275327
hwloc_topology_destroy(__kmp_hwloc_topology);
53285328
__kmp_hwloc_topology = NULL;

openmp/runtime/src/kmp_affinity.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <limits>
1919

2020
#if KMP_AFFINITY_SUPPORTED
21-
#if KMP_USE_HWLOC
21+
#if KMP_INCLUDES_HWLOC
2222
class KMPHwlocAffinity : public KMPAffinity {
2323
public:
2424
class Mask : public KMPAffinity::Mask {
@@ -191,7 +191,7 @@ class KMPHwlocAffinity : public KMPAffinity {
191191
}
192192
api_type get_api_type() const override { return HWLOC; }
193193
};
194-
#endif /* KMP_USE_HWLOC */
194+
#endif /* KMP_INCLUDES_HWLOC */
195195

196196
#if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY || \
197197
KMP_OS_AIX

openmp/runtime/src/kmp_alloc.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "kmp_io.h"
1515
#include "kmp_wrapper_malloc.h"
1616

17-
#if KMP_USE_HWLOC
17+
#if KMP_INCLUDES_HWLOC
1818
#if HWLOC_API_VERSION > 0x00020300
1919
#define KMP_HWLOC_LOCATION_TYPE_CPUSET HWLOC_LOCATION_TYPE_CPUSET
2020
#elif HWLOC_API_VERSION == 0x00020300
@@ -26,7 +26,7 @@ enum hwloc_memattr_id_e {
2626
HWLOC_MEMATTR_ID_CAPACITY
2727
};
2828
#endif
29-
#endif // KMP_USE_HWLOC
29+
#endif // KMP_INCLUDES_HWLOC
3030

3131
// Disable bget when it is not used
3232
#if KMP_USE_BGET
@@ -1545,7 +1545,7 @@ void __kmp_fini_memkind() {
15451545
#endif
15461546
}
15471547

1548-
#if KMP_USE_HWLOC
1548+
#if KMP_INCLUDES_HWLOC
15491549
static bool __kmp_is_hwloc_membind_supported(hwloc_membind_policy_t policy) {
15501550
#if HWLOC_API_VERSION >= 0x00020300
15511551
const hwloc_topology_support *support;
@@ -1611,7 +1611,7 @@ void *__kmp_hwloc_membind_policy(omp_memspace_handle_t ms, size_t size,
16111611
return NULL;
16121612
#endif
16131613
}
1614-
#endif // KMP_USE_HWLOC
1614+
#endif // KMP_INCLUDES_HWLOC
16151615

16161616
void __kmp_init_target_mem() {
16171617
*(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,
16801680
al->fb_data = RCAST(kmp_allocator_t *, traits[i].value);
16811681
break;
16821682
case omp_atk_partition:
1683-
#if KMP_USE_HWLOC
1683+
#if KMP_INCLUDES_HWLOC
16841684
al->membind = (omp_alloctrait_value_t)traits[i].value;
16851685
KMP_DEBUG_ASSERT(al->membind == omp_atv_environment ||
16861686
al->membind == omp_atv_nearest ||
@@ -1980,7 +1980,7 @@ void *__kmp_alloc(int gtid, size_t algn, size_t size,
19801980
}
19811981
}
19821982

1983-
#if KMP_USE_HWLOC
1983+
#if KMP_INCLUDES_HWLOC
19841984
if (__kmp_hwloc_available) {
19851985
if (__kmp_is_hwloc_membind_supported(HWLOC_MEMBIND_BIND)) {
19861986
if (allocator < kmp_max_mem_alloc) {
@@ -2201,7 +2201,7 @@ void *__kmp_alloc(int gtid, size_t algn, size_t size,
22012201
KMP_ASSERT(0); // abort fallback requested
22022202
} // no sense to look for another fallback because of same internal alloc
22032203
}
2204-
#if KMP_USE_HWLOC
2204+
#if KMP_INCLUDES_HWLOC
22052205
}
22062206
#endif
22072207
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) {
23392339
kmp_target_unlock_mem(desc.ptr_alloc, device);
23402340
}
23412341

2342-
#if KMP_USE_HWLOC
2342+
#if KMP_INCLUDES_HWLOC
23432343
if (__kmp_hwloc_available) {
23442344
if (oal > kmp_max_mem_alloc && al->pool_size > 0) {
23452345
kmp_uint64 used =
@@ -2378,7 +2378,7 @@ void ___kmpc_free(int gtid, void *ptr, omp_allocator_handle_t allocator) {
23782378
}
23792379
__kmp_thread_free(__kmp_thread_from_gtid(gtid), desc.ptr_alloc);
23802380
}
2381-
#if KMP_USE_HWLOC
2381+
#if KMP_INCLUDES_HWLOC
23822382
}
23832383
#endif
23842384
}

openmp/runtime/src/kmp_dispatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ template <typename T> struct dispatch_shared_info_template {
182182
#if KMP_USE_HIER_SCHED
183183
kmp_hier_t<T> *hier;
184184
#endif
185-
#if KMP_USE_HWLOC
185+
#if KMP_INCLUDES_HWLOC
186186
// When linking with libhwloc, the ORDERED EPCC test slowsdown on big
187187
// machines (> 48 cores). Performance analysis showed that a cache thrash
188188
// was occurring and this padding helps alleviate the problem.

openmp/runtime/src/kmp_global.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ enum mic_type __kmp_mic_type = non_mic;
248248

249249
KMPAffinity *__kmp_affinity_dispatch = NULL;
250250

251-
#if KMP_USE_HWLOC
251+
#if KMP_INCLUDES_HWLOC
252252
int __kmp_hwloc_error = FALSE;
253253
hwloc_topology_t __kmp_hwloc_topology = NULL;
254254
#endif

openmp/runtime/src/kmp_settings.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
10691069
static void __kmp_stg_parse_nesting_mode(char const *name, char const *value,
10701070
void *data) {
10711071
__kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_nesting_mode);
1072-
#if KMP_AFFINITY_SUPPORTED && KMP_USE_HWLOC
1072+
#if KMP_INCLUDES_HWLOC
10731073
if (__kmp_nesting_mode > 0)
10741074
__kmp_affinity_top_method = affinity_top_method_hwloc;
10751075
#endif
@@ -3301,7 +3301,7 @@ static void __kmp_stg_parse_topology_method(char const *name, char const *value,
33013301
if (__kmp_str_match("all", 1, value)) {
33023302
__kmp_affinity_top_method = affinity_top_method_all;
33033303
}
3304-
#if KMP_USE_HWLOC
3304+
#if KMP_INCLUDES_HWLOC
33053305
else if (__kmp_str_match("hwloc", 1, value)) {
33063306
__kmp_affinity_top_method = affinity_top_method_hwloc;
33073307
}
@@ -3409,7 +3409,7 @@ static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
34093409
break;
34103410
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
34113411

3412-
#if KMP_USE_HWLOC
3412+
#if KMP_INCLUDES_HWLOC
34133413
case affinity_top_method_hwloc:
34143414
value = "hwloc";
34153415
break;
@@ -6277,7 +6277,7 @@ void __kmp_env_initialize(char const *string) {
62776277
#if KMP_AFFINITY_SUPPORTED
62786278

62796279
if (!TCR_4(__kmp_init_middle)) {
6280-
#if KMP_USE_HWLOC
6280+
#if KMP_INCLUDES_HWLOC
62816281
// Force using hwloc when either tiles or numa nodes requested within
62826282
// KMP_HW_SUBSET or granularity setting and no other topology method
62836283
// is requested
@@ -6297,7 +6297,7 @@ void __kmp_env_initialize(char const *string) {
62976297
// affinity.
62986298
const char *var = "KMP_AFFINITY";
62996299
KMPAffinity::pick_api();
6300-
#if KMP_USE_HWLOC
6300+
#if KMP_INCLUDES_HWLOC
63016301
// If Hwloc topology discovery was requested but affinity was also disabled,
63026302
// then tell user that Hwloc request is being ignored and use default
63036303
// topology discovery method.

0 commit comments

Comments
 (0)