[Openmp-commits] [openmp] 343b9e8 - [OpenMP][host runtime] Introduce kmp_cpuinfo_flags_t to replace integer flags
via Openmp-commits
openmp-commits at lists.llvm.org
Fri Oct 1 09:08:56 PDT 2021
Author: Peyton, Jonathan L
Date: 2021-10-01T11:08:39-05:00
New Revision: 343b9e8590db6bc815df3a3fec5bb25c23261476
URL: https://github.com/llvm/llvm-project/commit/343b9e8590db6bc815df3a3fec5bb25c23261476
DIFF: https://github.com/llvm/llvm-project/commit/343b9e8590db6bc815df3a3fec5bb25c23261476.diff
LOG: [OpenMP][host runtime] Introduce kmp_cpuinfo_flags_t to replace integer flags
Store CPUID support flags as bits instead of using entire integers.
Differential Revision: https://reviews.llvm.org/D110091
Added:
Modified:
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_csupport.cpp
openmp/runtime/src/kmp_lock.cpp
openmp/runtime/src/kmp_os.h
openmp/runtime/src/kmp_settings.cpp
openmp/runtime/src/kmp_utility.cpp
Removed:
################################################################################
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index 90973d0667ea0..ae27fe44419e1 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -1206,6 +1206,12 @@ typedef struct kmp_cpuid {
kmp_uint32 edx;
} kmp_cpuid_t;
+typedef struct kmp_cpuinfo_flags_t {
+ unsigned sse2 : 1; // 0 if SSE2 instructions are not supported, 1 otherwise.
+ unsigned rtm : 1; // 0 if RTM instructions are not supported, 1 otherwise.
+ unsigned reserved : 30; // Ensure size of 32 bits
+} kmp_cpuinfo_flags_t;
+
typedef struct kmp_cpuinfo {
int initialized; // If 0, other fields are not initialized.
int signature; // CPUID(1).EAX
@@ -1213,8 +1219,7 @@ typedef struct kmp_cpuinfo {
int model; // ( CPUID(1).EAX[19:16] << 4 ) + CPUID(1).EAX[7:4] ( ( Extended
// Model << 4 ) + Model)
int stepping; // CPUID(1).EAX[3:0] ( Stepping )
- int sse2; // 0 if SSE2 instructions are not supported, 1 otherwise.
- int rtm; // 0 if RTM instructions are not supported, 1 otherwise.
+ kmp_cpuinfo_flags_t flags;
int apic_id;
int physical_id;
int logical_id;
diff --git a/openmp/runtime/src/kmp_csupport.cpp b/openmp/runtime/src/kmp_csupport.cpp
index 0d333576467fa..29fbc6273215f 100644
--- a/openmp/runtime/src/kmp_csupport.cpp
+++ b/openmp/runtime/src/kmp_csupport.cpp
@@ -683,7 +683,7 @@ void __kmpc_flush(ident_t *loc) {
if (!__kmp_cpuinfo.initialized) {
__kmp_query_cpuid(&__kmp_cpuinfo);
}
- if (!__kmp_cpuinfo.sse2) {
+ if (!__kmp_cpuinfo.flags.sse2) {
// CPU cannot execute SSE2 instructions.
} else {
#if KMP_COMPILER_ICC
@@ -1356,7 +1356,7 @@ static __forceinline kmp_dyna_lockseq_t __kmp_map_hint_to_lock(uintptr_t hint) {
#endif
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
-#define KMP_CPUINFO_RTM (__kmp_cpuinfo.rtm)
+#define KMP_CPUINFO_RTM (__kmp_cpuinfo.flags.rtm)
#else
#define KMP_CPUINFO_RTM 0
#endif
diff --git a/openmp/runtime/src/kmp_lock.cpp b/openmp/runtime/src/kmp_lock.cpp
index 13bb7ace86826..f3bdb03663a61 100644
--- a/openmp/runtime/src/kmp_lock.cpp
+++ b/openmp/runtime/src/kmp_lock.cpp
@@ -3202,13 +3202,13 @@ __kmp_lookup_indirect_lock(void **user_lock, const char *func) {
static void __kmp_init_indirect_lock(kmp_dyna_lock_t *lock,
kmp_dyna_lockseq_t seq) {
#if KMP_USE_ADAPTIVE_LOCKS
- if (seq == lockseq_adaptive && !__kmp_cpuinfo.rtm) {
+ if (seq == lockseq_adaptive && !__kmp_cpuinfo.flags.rtm) {
KMP_WARNING(AdaptiveNotSupported, "kmp_lockseq_t", "adaptive");
seq = lockseq_queuing;
}
#endif
#if KMP_USE_TSX
- if (seq == lockseq_rtm_queuing && !__kmp_cpuinfo.rtm) {
+ if (seq == lockseq_rtm_queuing && !__kmp_cpuinfo.flags.rtm) {
seq = lockseq_queuing;
}
#endif
diff --git a/openmp/runtime/src/kmp_os.h b/openmp/runtime/src/kmp_os.h
index 519f8fe7e0d45..d71e9aecb3f69 100644
--- a/openmp/runtime/src/kmp_os.h
+++ b/openmp/runtime/src/kmp_os.h
@@ -1040,7 +1040,7 @@ extern kmp_real64 __kmp_xchg_real64(volatile kmp_real64 *p, kmp_real64 v);
if (UNLIKELY(!__kmp_cpuinfo.initialized)) { \
__kmp_query_cpuid(&__kmp_cpuinfo); \
} \
- if (__kmp_cpuinfo.sse2) { \
+ if (__kmp_cpuinfo.flags.sse2) { \
KMP_MFENCE_(); \
}
#define KMP_SFENCE() KMP_SFENCE_()
diff --git a/openmp/runtime/src/kmp_settings.cpp b/openmp/runtime/src/kmp_settings.cpp
index b0a045dc4eb97..8a3bd4cd60ce6 100644
--- a/openmp/runtime/src/kmp_settings.cpp
+++ b/openmp/runtime/src/kmp_settings.cpp
@@ -4467,7 +4467,7 @@ static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
}
#if KMP_USE_ADAPTIVE_LOCKS
else if (__kmp_str_match("adaptive", 1, value)) {
- if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
+ if (__kmp_cpuinfo.flags.rtm) { // ??? Is cpuinfo available here?
__kmp_user_lock_kind = lk_adaptive;
KMP_STORE_LOCK_SEQ(adaptive);
} else {
@@ -4479,7 +4479,7 @@ static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
#endif // KMP_USE_ADAPTIVE_LOCKS
#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
else if (__kmp_str_match("rtm_queuing", 1, value)) {
- if (__kmp_cpuinfo.rtm) {
+ if (__kmp_cpuinfo.flags.rtm) {
__kmp_user_lock_kind = lk_rtm_queuing;
KMP_STORE_LOCK_SEQ(rtm_queuing);
} else {
@@ -4488,7 +4488,7 @@ static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
KMP_STORE_LOCK_SEQ(queuing);
}
} else if (__kmp_str_match("rtm_spin", 1, value)) {
- if (__kmp_cpuinfo.rtm) {
+ if (__kmp_cpuinfo.flags.rtm) {
__kmp_user_lock_kind = lk_rtm_spin;
KMP_STORE_LOCK_SEQ(rtm_spin);
} else {
diff --git a/openmp/runtime/src/kmp_utility.cpp b/openmp/runtime/src/kmp_utility.cpp
index c4bfead9d0d6f..bf3e6114e0c20 100644
--- a/openmp/runtime/src/kmp_utility.cpp
+++ b/openmp/runtime/src/kmp_utility.cpp
@@ -129,7 +129,7 @@ void __kmp_query_cpuid(kmp_cpuinfo_t *p) {
p->initialized = 1;
- p->sse2 = 1; // Assume SSE2 by default.
+ p->flags.sse2 = 1; // Assume SSE2 by default.
__kmp_x86_cpuid(0, 0, &buf);
@@ -169,7 +169,7 @@ void __kmp_query_cpuid(kmp_cpuinfo_t *p) {
data[i] = (t & 0xff);
}
- p->sse2 = (buf.edx >> 26) & 1;
+ p->flags.sse2 = (buf.edx >> 26) & 1;
#ifdef KMP_DEBUG
@@ -248,11 +248,11 @@ void __kmp_query_cpuid(kmp_cpuinfo_t *p) {
}
#endif
#if KMP_USE_ADAPTIVE_LOCKS
- p->rtm = 0;
+ p->flags.rtm = 0;
if (max_arg > 7) {
/* RTM bit CPUID.07:EBX, bit 11 */
__kmp_x86_cpuid(7, 0, &buf);
- p->rtm = (buf.ebx >> 11) & 1;
+ p->flags.rtm = (buf.ebx >> 11) & 1;
KA_TRACE(trace_level, (" RTM"));
}
#endif
More information about the Openmp-commits
mailing list