[Openmp-commits] [llvm] [openmp] [OpenMP][offload] Fix single-thread SPMD cross-team reductions (PR #228216)
Robert Imschweiler via Openmp-commits
openmp-commits at lists.llvm.org
Mon Oct 5 12:48:08 PDT 2026
================
@@ -235,14 +235,19 @@ int32_t __kmpc_gpu_xteam_reduce_nowait(IdentTy *Loc, void *reduce_data,
uint32_t ThreadId;
uint32_t NumThreads;
- if (mapping::isSPMDMode()) {
+ // In SPMD mode, we're dealing with full warps unless the kernel was SPMD-ized
+ // without parallel regions: then, only the main thread is alive (see
+ // OpenMPOpt).
+ bool AllThreads =
+ mapping::isSPMDMode() && utils::popc(mapping::activemask()) > 1;
----------------
ro-i wrote:
"fake" SPMD might be a bit of a loose term. The situation basically is what https://reviews.llvm.org/D133120 tried to fix: OpenMPOpt sees a generic target region and starts to SPMDize it because it might contain a parallel region, which OpenMPOpt doesn't know from the beginning. As a result, if there is no parallel region, the conversion to SPMD had already been done and now, this is rolled back. What https://reviews.llvm.org/D133120 fixed is the situation where something that is actually meant as a single-thread program is now executed by all threads in SPMD. That's bad because it means that a lot of synchronization/guarding has to be introduced. As a result, that other patch made the whole thing being executed by one thread again by letting the other threads exit early.
Does that clarify things?
https://github.com/llvm/llvm-project/pull/228216
More information about the Openmp-commits
mailing list