[clang] [llvm] [offload][OpenMP] Improve cross-team reduction grid selection (PR #208253)
Dhruva Chakrabarti via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 12 14:01:25 PDT 2026
================
@@ -751,6 +764,15 @@ void CGOpenMPRuntimeGPU::emitKernelInit(const OMPExecutableDirective &D,
: llvm::omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC;
computeMinAndMaxThreadsAndTeams(D, CGF, Attrs);
+ // Set MaxThreads to twice the default workgroup size for SPMD cross-team
+ // reductions. For these reductions, we want to have fewer, larger teams to
+ // make better use of intra-team reduction and not over-emphasize the
+ // inter-team part. Note that this only buys us more freedom. The actual grid
+ // size for the launch is going to be chosen later by the offload plugin.
+ if (IsSPMD && Attrs.MaxThreads.front() < 0 && hasTeamsReduction(D))
+ Attrs.MaxThreads.front() =
+ 2 * CGM.getTarget().getGridValue().GV_Default_WG_Size;
----------------
dhruvachak wrote:
Clamp it to GV_Max_WG_Size.
A more general concern is whether it makes sense to tie the reduction kernel wg_size to the default wg_size. If you think that reduction kernels should default to a different wg_size, perhaps use a different wg_size independently. Otherwise, what happens if in the future, the default_wg_size is changed? Would reduction kernels still benefit from the doubling?
https://github.com/llvm/llvm-project/pull/208253
More information about the cfe-commits
mailing list