Skip to content

Commit

Permalink
[OpenMP] Avoid calling isSPMDMode during RT initialization
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jhuber6 committed Oct 9, 2021
1 parent 222305d commit 85ad566
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions openmp/libomptarget/DeviceRTL/include/Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/DeviceRTL/src/Kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions openmp/libomptarget/DeviceRTL/src/Mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/DeviceRTL/src/Reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 85ad566

Please sign in to comment.