[Openmp-commits] [PATCH] D111381: [OpenMP] Avoid calling `isSPMDMode` during RT initialization

Johannes Doerfert via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Oct 7 20:27:22 PDT 2021


jdoerfert created this revision.
jdoerfert added reviewers: jhuber6, tianshilei1992, ye-luo.
Herald added subscribers: guansong, bollu, yaxunl.
jdoerfert requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: OpenMP.

Until we hit the first barrier we should not call `mapping::isSPMDMode`
with all threads. Instead, we now have (and use during initialization) a
`mapping::isMainThreadInGenericMode` overload that takes the known
SPMD-mode state and one that queries it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111381

Files:
  openmp/libomptarget/DeviceRTL/include/Mapping.h
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/DeviceRTL/src/Mapping.cpp
  openmp/libomptarget/DeviceRTL/src/Reduction.cpp


Index: openmp/libomptarget/DeviceRTL/src/Reduction.cpp
===================================================================
--- openmp/libomptarget/DeviceRTL/src/Reduction.cpp
+++ openmp/libomptarget/DeviceRTL/src/Reduction.cpp
@@ -195,7 +195,7 @@
   uint32_t NumTeams = mapping::getNumberOfBlocks();
   uint32_t NumThreads = mapping::getBlockSize();
   if (mapping::isGenericMode()) {
-    if (!mapping::isMainThreadInGenericMode())
+    if (!mapping::isMainThreadInGenericMode(/* IsSPMD */ false))
       return 0;
     ThreadId = 0;
     NumThreads = /* main thread only */ 1;
Index: openmp/libomptarget/DeviceRTL/src/Mapping.cpp
===================================================================
--- openmp/libomptarget/DeviceRTL/src/Mapping.cpp
+++ openmp/libomptarget/DeviceRTL/src/Mapping.cpp
@@ -167,8 +167,8 @@
 /// below to avoid repeating assumptions or including irrelevant ones.
 ///{
 
-bool mapping::isMainThreadInGenericMode() {
-  if (mapping::isSPMDMode())
+bool mapping::isMainThreadInGenericMode(bool IsSPMD) {
+  if (IsSPMD)
     return false;
 
   // Check if this is the last warp in the block.
@@ -177,6 +177,10 @@
   return mapping::getThreadIdInBlock() == MainTId;
 }
 
+bool mapping::isMainThreadInGenericMode() {
+  return mapping::isMainThreadInGenericMode(mapping::isSPMDMode());
+}
+
 bool mapping::isLeaderInWarp() {
   __kmpc_impl_lanemask_t Active = mapping::activemask();
   __kmpc_impl_lanemask_t LaneMaskLT = mapping::lanemaskLT();
Index: openmp/libomptarget/DeviceRTL/src/Kernel.cpp
===================================================================
--- openmp/libomptarget/DeviceRTL/src/Kernel.cpp
+++ openmp/libomptarget/DeviceRTL/src/Kernel.cpp
@@ -81,7 +81,7 @@
     return -1;
   }
 
-  if (mapping::isMainThreadInGenericMode())
+  if (mapping::isMainThreadInGenericMode(IsSPMD))
     return -1;
 
   if (UseGenericStateMachine)
Index: openmp/libomptarget/DeviceRTL/include/Mapping.h
===================================================================
--- openmp/libomptarget/DeviceRTL/include/Mapping.h
+++ openmp/libomptarget/DeviceRTL/include/Mapping.h
@@ -35,6 +35,7 @@
 
 /// Return true if the executing thread is the main thread in generic mode.
 bool isMainThreadInGenericMode();
+bool isMainThreadInGenericMode(bool IsSPMD);
 
 /// Return true if the executing thread has the lowest Id of the active threads
 /// in the warp.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111381.378080.patch
Type: text/x-patch
Size: 2379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20211008/035bf055/attachment.bin>


More information about the Openmp-commits mailing list