Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 13 additions & 10 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_HWLOC_ENABLED 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_HWLOC_ENABLED 0
#endif

#if KMP_ARCH_X86 || KMP_ARCH_X86_64
Expand Down Expand Up @@ -672,10 +675,10 @@ 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_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)
Expand Down Expand Up @@ -784,10 +787,10 @@ class KMPAffinity {
static void destroy_api();
enum api_type {
NATIVE_OS
#if KMP_USE_HWLOC
#if KMP_HWLOC_ENABLED
,
HWLOC
#endif
#endif // KMP_HWLOC_ENABLED
};
virtual api_type get_api_type() const {
KMP_ASSERT(0);
Expand Down Expand Up @@ -856,9 +859,9 @@ enum affinity_top_method {
affinity_top_method_group,
#endif /* KMP_GROUP_AFFINITY */
affinity_top_method_flat,
#if KMP_USE_HWLOC
#if KMP_HWLOC_ENABLED
affinity_top_method_hwloc,
#endif
#endif // KMP_HWLOC_ENABLED
affinity_top_method_default
};

Expand Down Expand Up @@ -1125,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_USE_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,
Expand Down Expand Up @@ -2087,12 +2090,12 @@ typedef struct dispatch_shared_info {
#if KMP_USE_HIER_SCHED
void *hier;
#endif
#if KMP_USE_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 {
Expand Down
24 changes: 12 additions & 12 deletions openmp/runtime/src/kmp_affinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#if KMP_USE_HIER_SCHED
#include "kmp_dispatch_hier.h"
#endif
#if KMP_USE_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
Expand Down Expand Up @@ -1440,15 +1440,15 @@ void KMPAffinity::pick_api() {
KMPAffinity *affinity_dispatch;
if (picked_api)
return;
#if KMP_USE_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 &&
__kmp_affinity.type != affinity_disabled) {
affinity_dispatch = new KMPHwlocAffinity();
__kmp_hwloc_available = true;
} else
#endif
#endif // KMP_HWLOC_ENABLED
{
affinity_dispatch = new KMPNativeAffinity();
}
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_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);
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_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"
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_HWLOC_ENABLED
if (!success &&
__kmp_affinity_dispatch->get_api_type() == KMPAffinity::HWLOC) {
if (!__kmp_hwloc_error) {
Expand All @@ -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) {
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_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);
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_HWLOC_ENABLED

#if KMP_ARCH_X86 || KMP_ARCH_X86_64
else if (__kmp_affinity_top_method == affinity_top_method_x2apicid ||
Expand Down Expand Up @@ -5322,12 +5322,12 @@ void __kmp_affinity_uninitialize(void) {
__kmp_free(__kmp_osid_to_hwthread_map);
__kmp_osid_to_hwthread_map = NULL;
}
#if KMP_USE_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;
Expand Down
6 changes: 3 additions & 3 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_HWLOC_ENABLED
class KMPHwlocAffinity : public KMPAffinity {
public:
class Mask : public KMPAffinity::Mask {
Expand Down Expand Up @@ -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
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_HWLOC_ENABLED */

#if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY || \
KMP_OS_AIX
Expand Down
30 changes: 15 additions & 15 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_HWLOC_ENABLED
#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_HWLOC_ENABLED

// 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_HWLOC_ENABLED
static bool __kmp_is_hwloc_membind_supported(hwloc_membind_policy_t policy) {
#if HWLOC_API_VERSION >= 0x00020300
const hwloc_topology_support *support;
Expand All @@ -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,
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_HWLOC_ENABLED

void __kmp_init_target_mem() {
*(void **)(&kmp_target_alloc_host) = KMP_DLSYM("llvm_omp_target_alloc_host");
Expand Down Expand Up @@ -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_USE_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:
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_HWLOC_ENABLED
if (__kmp_hwloc_available) {
if (__kmp_is_hwloc_membind_supported(HWLOC_MEMBIND_BIND)) {
if (allocator < kmp_max_mem_alloc) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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_USE_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;
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_HWLOC_ENABLED
if (__kmp_hwloc_available) {
if (oal > kmp_max_mem_alloc && al->pool_size > 0) {
kmp_uint64 used =
Expand All @@ -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
Expand Down Expand Up @@ -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_USE_HWLOC
#if KMP_HWLOC_ENABLED
}
#endif
#endif // KMP_HWLOC_ENABLED
}

/* If LEAK_MEMORY is defined, __kmp_free() will *not* free memory. It causes
Expand Down
4 changes: 2 additions & 2 deletions openmp/runtime/src/kmp_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_USE_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
};

/* ------------------------------------------------------------------------ */
Expand Down
4 changes: 2 additions & 2 deletions openmp/runtime/src/kmp_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ enum mic_type __kmp_mic_type = non_mic;

KMPAffinity *__kmp_affinity_dispatch = NULL;

#if KMP_USE_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
Expand Down
Loading
Loading