Skip to content

Commit 848be18

Browse files
[SYCL] Fix two reduction bugs (#7347)
The one in NDRangeReduction<reduction::strategy::basic> was introduced during most recent reduction refactoring and most likely could only be triggered through internal API calls. Code path for public APIs is such that this strategy isn't auto-selected under conditions leading to the bug. I think another one (strategy::group_reduce_and_last_wg_detection) was introduced earlier (a couple of months maybe) and probably was user-visible. Both bugs were caused by some extra erroneous conditions resulting in taking the wrong branch target.
1 parent 6bd5f9c commit 848be18

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

sycl/include/sycl/reduction.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ struct NDRangeReduction<
917917
auto &PartialSumsBuf = Redu.getTempBuffer(NWorkGroups * NElements, CGH);
918918
accessor PartialSums(PartialSumsBuf, CGH, sycl::read_write, sycl::no_init);
919919

920-
bool IsUpdateOfUserVar = !Reduction::is_usm && !Redu.initializeToIdentity();
920+
bool IsUpdateOfUserVar = !Redu.initializeToIdentity();
921921
auto Rest = [&](auto NWorkGroupsFinished) {
922922
local_accessor<int, 1> DoReducePartialSumsInLastWG{1, CGH};
923923

@@ -1485,8 +1485,6 @@ template <> struct NDRangeReduction<reduction::strategy::basic> {
14851485
// group size may be not power of two. Those two cases considered
14861486
// inefficient as they require additional code and checks in the kernel.
14871487
bool HasUniformWG = NWorkGroups * WGSize == NWorkItems;
1488-
if (!Reduction::has_fast_reduce)
1489-
HasUniformWG = HasUniformWG && (WGSize & (WGSize - 1)) == 0;
14901488

14911489
// Get read accessor to the buffer that was used as output
14921490
// in the previous kernel.
@@ -1498,7 +1496,7 @@ template <> struct NDRangeReduction<reduction::strategy::basic> {
14981496
!Redu.initializeToIdentity() &&
14991497
NWorkGroups == 1;
15001498

1501-
bool UniformPow2WG = HasUniformWG;
1499+
bool UniformPow2WG = HasUniformWG && (WGSize & (WGSize - 1)) == 0;
15021500
// Use local memory to reduce elements in work-groups into 0-th element.
15031501
// If WGSize is not power of two, then WGSize+1 elements are allocated.
15041502
// The additional last element is used to catch elements that could

0 commit comments

Comments
 (0)