[Openmp-commits] [openmp] 85ad566 - [OpenMP] Avoid calling `isSPMDMode` during RT initialization
Joseph Huber via Openmp-commits
openmp-commits at lists.llvm.org
Fri Oct 8 19:00:51 PDT 2021
Author: Joseph Huber
Date: 2021-10-08T22:00:41-04:00
New Revision: 85ad56633593d011ab00f4eb431ffd879677bffc
URL: https://github.com/llvm/llvm-project/commit/85ad56633593d011ab00f4eb431ffd879677bffc
DIFF: https://github.com/llvm/llvm-project/commit/85ad56633593d011ab00f4eb431ffd879677bffc.diff
LOG: [OpenMP] Avoid calling `isSPMDMode` during RT initialization
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.
Reviewed By: tianshilei1992
Differential Revision: https://reviews.llvm.org/D111381
Added:
Modified:
openmp/libomptarget/DeviceRTL/include/Mapping.h
openmp/libomptarget/DeviceRTL/src/Kernel.cpp
openmp/libomptarget/DeviceRTL/src/Mapping.cpp
openmp/libomptarget/DeviceRTL/src/Reduction.cpp
Removed:
################################################################################
diff --git a/openmp/libomptarget/DeviceRTL/include/Mapping.h b/openmp/libomptarget/DeviceRTL/include/Mapping.h
index b34ecf4f7738..a3193f357564 100644
--- a/openmp/libomptarget/DeviceRTL/include/Mapping.h
+++ b/openmp/libomptarget/DeviceRTL/include/Mapping.h
@@ -35,6 +35,7 @@ bool isGenericMode();
/// 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.
diff --git a/openmp/libomptarget/DeviceRTL/src/Kernel.cpp b/openmp/libomptarget/DeviceRTL/src/Kernel.cpp
index ead6085ae373..f834754ccc56 100644
--- a/openmp/libomptarget/DeviceRTL/src/Kernel.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Kernel.cpp
@@ -81,7 +81,7 @@ int32_t __kmpc_target_init(IdentTy *Ident, int8_t Mode,
return -1;
}
- if (mapping::isMainThreadInGenericMode())
+ if (mapping::isMainThreadInGenericMode(IsSPMD))
return -1;
if (UseGenericStateMachine)
diff --git a/openmp/libomptarget/DeviceRTL/src/Mapping.cpp b/openmp/libomptarget/DeviceRTL/src/Mapping.cpp
index 96a612d5cf3f..66089eaa7496 100644
--- a/openmp/libomptarget/DeviceRTL/src/Mapping.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Mapping.cpp
@@ -165,8 +165,8 @@ uint32_t getWarpSize() { return getGridValue().GV_Warp_Size; }
} // namespace impl
} // namespace _OMP
-bool mapping::isMainThreadInGenericMode() {
- if (mapping::isSPMDMode() || icv::Level)
+bool mapping::isMainThreadInGenericMode(bool IsSPMD) {
+ if (IsSPMD || icv::Level)
return false;
// Check if this is the last warp in the block.
@@ -175,6 +175,10 @@ bool mapping::isMainThreadInGenericMode() {
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();
diff --git a/openmp/libomptarget/DeviceRTL/src/Reduction.cpp b/openmp/libomptarget/DeviceRTL/src/Reduction.cpp
index cd5658161a4d..a06ac23c4276 100644
--- a/openmp/libomptarget/DeviceRTL/src/Reduction.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Reduction.cpp
@@ -72,7 +72,7 @@ static int32_t nvptx_parallel_reduce_nowait(int32_t TId, int32_t num_vars,
InterWarpCopyFnTy cpyFct,
bool isSPMDExecutionMode, bool) {
uint32_t BlockThreadId = mapping::getThreadIdInBlock();
- if (mapping::isMainThreadInGenericMode())
+ if (mapping::isMainThreadInGenericMode(/* IsSPMD */ false))
BlockThreadId = 0;
uint32_t NumThreads = omp_get_num_threads();
if (NumThreads == 1)
More information about the Openmp-commits
mailing list