[Openmp-commits] [PATCH] D126510: [OpenMP][libomp] avoid spin wait and yield on arm64 macOS
Daniel (Doug) Douglas via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Thu May 26 17:07:30 PDT 2022
danieljdouglas-deco created this revision.
danieljdouglas-deco added reviewers: jlpeyton, tlwilmar, hbae, AndreyChurbanov, jdoerfert.
danieljdouglas-deco added a project: OpenMP.
Herald added subscribers: guansong, kristof.beyls, yaxunl.
Herald added a project: All.
danieljdouglas-deco requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
This patch changes some of the default behavior of OpenMP to avoid behaviors that are not performant on Apple silicon: spin waiting and yielding. (See “Don’t Keep Threads Active And Idle” section here: https://developer.apple.com/documentation/apple-silicon/tuning-your-code-s-performance-for-apple-silicon)
We verified using instruments traces that the changes improve scheduling behavior on macOS.
We also collected results using EPCC schedbench (https://github.com/LangdalP/EPCC-OpenMP-micro-benchmarks) that are attached here that show a reduction in standard deviation and max test run time across all scheduling types. Static scheduling sees dramatic improvements with these changes, we see a 2-4x average runtime improvement in the benchmark.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D126510
Files:
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_global.cpp
openmp/runtime/src/kmp_runtime.cpp
Index: openmp/runtime/src/kmp_runtime.cpp
===================================================================
--- openmp/runtime/src/kmp_runtime.cpp
+++ openmp/runtime/src/kmp_runtime.cpp
@@ -8286,7 +8286,7 @@
break;
case library_throughput:
if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME)
- __kmp_dflt_blocktime = 200;
+ __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
break;
default:
KMP_FATAL(UnknownLibraryType, arg);
Index: openmp/runtime/src/kmp_global.cpp
===================================================================
--- openmp/runtime/src/kmp_global.cpp
+++ openmp/runtime/src/kmp_global.cpp
@@ -425,7 +425,13 @@
// 0 = never yield;
// 1 = always yield (default);
// 2 = yield only if oversubscribed
+#if KMP_OS_DARWIN && KMP_ARCH_AARCH64
+// Blocking is more performant then yielding on Apple Silicon
+kmp_int32 __kmp_use_yield = 0;
+#else
kmp_int32 __kmp_use_yield = 1;
+#endif
+
// This will be 1 if KMP_USE_YIELD environment variable was set explicitly
kmp_int32 __kmp_use_yield_exp_set = 0;
Index: openmp/runtime/src/kmp.h
===================================================================
--- openmp/runtime/src/kmp.h
+++ openmp/runtime/src/kmp.h
@@ -3046,6 +3046,8 @@
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
extern kmp_cpuinfo_t __kmp_cpuinfo;
static inline bool __kmp_is_hybrid_cpu() { return __kmp_cpuinfo.flags.hybrid; }
+#elif KMP_OS_DARWIN && KMP_ARCH_AARCH64
+static inline bool __kmp_is_hybrid_cpu() { return true; }
#else
static inline bool __kmp_is_hybrid_cpu() { return false; }
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126510.432421.patch
Type: text/x-patch
Size: 1562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220527/61b33118/attachment.bin>
More information about the Openmp-commits
mailing list