[Openmp-commits] [openmp] [OpenMP][offload] Fix wave32 handling of xteam reductions (PR #233096)

Robert Imschweiler via Openmp-commits openmp-commits at lists.llvm.org
Sat Oct 17 07:56:31 PDT 2026


https://github.com/ro-i created https://github.com/llvm/llvm-project/pull/233096

None

>From 5b782e91083068605922a90b60f2511333625951 Mon Sep 17 00:00:00 2001
From: Robert Imschweiler <robert.imschweiler at amd.com>
Date: Sat, 17 Oct 2026 09:54:05 -0500
Subject: [PATCH] [OpenMP][offload] Fix wave32 handling of xteam reductions

---
 openmp/device/src/Reduction.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/openmp/device/src/Reduction.cpp b/openmp/device/src/Reduction.cpp
index 0b7f687d6a83e4..c0655501a92010 100644
--- a/openmp/device/src/Reduction.cpp
+++ b/openmp/device/src/Reduction.cpp
@@ -101,11 +101,14 @@ static uint32_t gpu_block_reduce(void *reduce_data, ShuffleReductFnTy shflFct,
   if constexpr (checkLiveness) {
     __kmpc_impl_lanemask_t Liveness = mapping::activemask();
     // Check for partial warp with non-contiguous lanes.
-    if (Liveness == lanes::All) {
+    // Consider that Liveness::ALL is a 64-bit value, so compare the actual
+    // number of set bits to handle 32bit waves correctly.
+    uint32_t NumLive = static_cast<uint32_t>(utils::popc(Liveness));
+    if (NumLive == mapping::getWarpSize()) {
       gpu_regular_warp_reduce(reduce_data, shflFct);
     } else if (!(Liveness & (Liveness + 1))) {
       // Partial warp but contiguous lanes.
-      gpu_irregular_warp_reduce(reduce_data, shflFct, utils::popc(Liveness),
+      gpu_irregular_warp_reduce(reduce_data, shflFct, NumLive,
                                 BlockThreadId % mapping::getWarpSize());
     } else {
       // Dispersed lanes. Only threads in L2 parallel region may enter here.



More information about the Openmp-commits mailing list