[subgroups][non_uniform_broadcast] Fix broadcasting index generation

The subgroup size may not be greater than `NR_OF_ACTIVE_WORK_ITEMS`.
Broadcasting index needs to be reduced in that case.

Otherwise, if subgroup size == `NR_OF_ACTIVE_WORK_ITEMS` == 4, then we
will encounter "divide-by-zero" error when evaluating `bcast_index %
(n - NR_OF_ACTIVE_WORK_ITEMS)`.
This commit is contained in:
Yilong Guo
2023-03-23 13:55:43 +08:00
parent c3d36bf9fb
commit 9bbab539de

View File

@@ -82,7 +82,7 @@ template <typename Ty, SubgroupsBroadcastOp operation> struct BC
// broadcasted (one the same value for whole subgroup)
if (operation != SubgroupsBroadcastOp::broadcast)
{
// reduce brodcasting index in case of non_uniform and
// reduce broadcasting index in case of non_uniform and
// last workgroup last subgroup
if (last_subgroup_size && j == nj - 1
&& last_subgroup_size < NR_OF_ACTIVE_WORK_ITEMS)
@@ -90,6 +90,13 @@ template <typename Ty, SubgroupsBroadcastOp operation> struct BC
bcast_if = bcast_index % last_subgroup_size;
bcast_elseif = bcast_if;
}
// reduce broadcasting index in case subgroup size <=
// NR_OF_ACTIVE_WORK_ITEMS (i.e. all items are active)
else if (n <= NR_OF_ACTIVE_WORK_ITEMS)
{
bcast_if = bcast_index % n;
bcast_elseif = bcast_if;
}
else
{
bcast_if = bcast_index % NR_OF_ACTIVE_WORK_ITEMS;