Skip to content

Commit ab184bb

Browse files
committed
fix: coalesced_threads size-1 fallback so warp-aggregated patterns work on SPIR-V
1 parent 60c7520 commit ab184bb

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

include/hip/spirv_hip_cooperative_groups.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ class coalesced_group : public thread_group {
434434
template <class T> __CG_QUALIFIER__ T shfl(T var, int srcRank) const {
435435
static_assert(is_valid_type<T>::value, "Neither an integer or float type.");
436436

437+
// Singleton coalesced group (chipStar SPIR-V fallback when the active-
438+
// lane mask is unavailable): the only valid source rank is 0 and the
439+
// result is the caller's own value.
440+
if (size() == 1)
441+
return var;
442+
437443
srcRank = srcRank % static_cast<int>(size());
438444

439445
int lane = (size() == __AMDGCN_WAVEFRONT_SIZE) ? srcRank
@@ -508,7 +514,12 @@ class coalesced_group : public thread_group {
508514
*/
509515

510516
__CG_QUALIFIER__ coalesced_group coalesced_threads() {
511-
return cooperative_groups::coalesced_group(__builtin_amdgcn_read_exec());
517+
// chipStar's SPIR-V backend has no way to query the active-lane mask
518+
// (the AMDGCN exec register), so we conservatively model each thread
519+
// as its own coalesced group of size 1. This keeps semantics correct
520+
// for common patterns such as warp-aggregated atomics (atomicAggInc)
521+
// at the cost of the warp-level optimisation.
522+
return cooperative_groups::coalesced_group(static_cast<lane_mask>(1));
512523
}
513524

514525
/**

0 commit comments

Comments
 (0)