Skip to content

Commit b17edec

Browse files
jacek-galazkaigcbot
authored andcommitted
Reimplement generic case of subroups reduce
1 parent 6a6b39c commit b17edec

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

IGC/BiFModule/Implementation/group.cl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,23 +1956,19 @@ type __builtin_IB_SubGroupReduce_##func##_##type_abbr(type X)
19561956
else \
19571957
{ \
19581958
uint sglid = SPIRV_BUILTIN_NO_OP(BuiltInSubgroupLocalInvocationId, , )(); \
1959-
uint mask = 1 << ( ((8 * sizeof(uint)) - __builtin_spirv_OpenCL_clz_i32(sgsize - 1)) - 1 ); \
1960-
while( mask > 0 ) \
1961-
{ \
1962-
uint c = sglid ^ mask; \
1963-
type other = ( c < sgsize ) ? \
1964-
intel_sub_group_shuffle( X, c ): \
1965-
identity; \
1966-
X = op( other, X ); \
1967-
mask >>= 1; \
1959+
uint sgMaxSize = SPIRV_BUILTIN_NO_OP(BuiltInSubgroupMaxSize, , )(); \
1960+
\
1961+
for (uint i = 1; i < sgMaxSize; i <<= 1) { \
1962+
type contribution = (sglid < i) ? identity : \
1963+
intel_sub_group_shuffle_up((type)identity, X, i); \
1964+
X = op(X, contribution); \
19681965
} \
19691966
} \
19701967
int3 vec3; \
19711968
vec3.s0 = 0; \
19721969
return SPIRV_BUILTIN(GroupBroadcast, _i32_##type_abbr##_v3i32, )(Subgroup, signed_cast(X), vec3 ); \
19731970
}
19741971

1975-
19761972
#define DEFN_SUB_GROUP_SCAN_INCL(func, type_abbr, type, op, identity) \
19771973
type __builtin_IB_SubGroupScanInclusive_##func##_##type_abbr(type X) \
19781974
{ \

0 commit comments

Comments
 (0)