Skip to content

Commit 85ad566

Browse files
committed
[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
1 parent 222305d commit 85ad566

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

openmp/libomptarget/DeviceRTL/include/Mapping.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ bool isGenericMode();
3535

3636
/// Return true if the executing thread is the main thread in generic mode.
3737
bool isMainThreadInGenericMode();
38+
bool isMainThreadInGenericMode(bool IsSPMD);
3839

3940
/// Return true if the executing thread has the lowest Id of the active threads
4041
/// in the warp.

openmp/libomptarget/DeviceRTL/src/Kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int32_t __kmpc_target_init(IdentTy *Ident, int8_t Mode,
8181
return -1;
8282
}
8383

84-
if (mapping::isMainThreadInGenericMode())
84+
if (mapping::isMainThreadInGenericMode(IsSPMD))
8585
return -1;
8686

8787
if (UseGenericStateMachine)

openmp/libomptarget/DeviceRTL/src/Mapping.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ uint32_t getWarpSize() { return getGridValue().GV_Warp_Size; }
165165
} // namespace impl
166166
} // namespace _OMP
167167

168-
bool mapping::isMainThreadInGenericMode() {
169-
if (mapping::isSPMDMode() || icv::Level)
168+
bool mapping::isMainThreadInGenericMode(bool IsSPMD) {
169+
if (IsSPMD || icv::Level)
170170
return false;
171171

172172
// Check if this is the last warp in the block.
@@ -175,6 +175,10 @@ bool mapping::isMainThreadInGenericMode() {
175175
return mapping::getThreadIdInBlock() == MainTId;
176176
}
177177

178+
bool mapping::isMainThreadInGenericMode() {
179+
return mapping::isMainThreadInGenericMode(mapping::isSPMDMode());
180+
}
181+
178182
bool mapping::isLeaderInWarp() {
179183
__kmpc_impl_lanemask_t Active = mapping::activemask();
180184
__kmpc_impl_lanemask_t LaneMaskLT = mapping::lanemaskLT();

openmp/libomptarget/DeviceRTL/src/Reduction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static int32_t nvptx_parallel_reduce_nowait(int32_t TId, int32_t num_vars,
7272
InterWarpCopyFnTy cpyFct,
7373
bool isSPMDExecutionMode, bool) {
7474
uint32_t BlockThreadId = mapping::getThreadIdInBlock();
75-
if (mapping::isMainThreadInGenericMode())
75+
if (mapping::isMainThreadInGenericMode(/* IsSPMD */ false))
7676
BlockThreadId = 0;
7777
uint32_t NumThreads = omp_get_num_threads();
7878
if (NumThreads == 1)

0 commit comments

Comments
 (0)