Commit 85ad5663 authored by Huber, Joseph's avatar Huber, Joseph
Browse files

[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
parent 222305d6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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.
+1 −1
Original line number Diff line number Diff line
@@ -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)
+6 −2
Original line number Diff line number Diff line
@@ -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();
+1 −1
Original line number Diff line number Diff line
@@ -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)