[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
Fri Oct 2 06:53:14 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:
I mean, OpenMPOpt *could* set MaxThreads to 1, I guess. But that would not necessary be a cleaner solution.
The fundamental issue is that OpenMPOpt knows some stuff only at the very end for sure.
Like, with the MaxThreads=1 approach, there would be a new problem (see llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll): __kmpc_get_hardware_num_threads_in_block() is folded by OpenMPOpt using the thread_limit attribute. I think that this would conflict with OpenMPOpt changing the maximum number of threads.
(Consider that OpenMPOpt can only do so once it knows at the end that no parallel region has been reached.)
https://github.com/llvm/llvm-project/pull/228216
More information about the Openmp-commits
mailing list