Skip to content

[SYCL] Fix work-group size selection in reductions #2693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions sycl/source/detail/reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,23 @@ __SYCL_EXPORT size_t reduComputeWGSize(size_t NWorkItems, size_t MaxWGSize,
NWorkGroups = NWorkItems / WGSize;
size_t Rem = NWorkItems % WGSize;
if (Rem != 0) {
// Let's say MaxWGSize = 128 and NWorkItems is (128+32).
// Let's suppose MaxWGSize = 128 and NWorkItems = (128+32).
// It seems better to have 5 groups 32 work-items each than 2 groups with
// 128 work-items in the 1st group and 32 work-items in the 2nd group.
size_t NWorkGroupsAlt = NWorkItems / Rem;
size_t RemAlt = NWorkItems % Rem;
if (RemAlt == 0 && NWorkGroupsAlt <= MaxWGSize) {
// Choose smaller uniform work-groups.
// The condition 'NWorkGroupsAlt <= MaxWGSize' was checked to ensure
// that choosing smaller groups will not cause the need in additional
// invocations of the kernel.
NWorkGroups = NWorkGroupsAlt;
WGSize = Rem;
} else {
// Add 1 more group to process the remaining elements and proceed
// with bigger non-uniform work-groups
NWorkGroups++;
}
} else {
NWorkGroups++;
}
}
return WGSize;
Expand Down
2 changes: 1 addition & 1 deletion sycl/test/reduction/reduction_nd_lambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void test(T Identity, BinaryOperation BOp, size_t WGSize, size_t NWItems) {

int main() {
test<class AddTestName, int>(
0, [](auto x, auto y) { return (x + y); }, 8, 32);
0, [](auto x, auto y) { return (x + y); }, 1, 1024);
test<class MulTestName, int>(
0, [](auto x, auto y) { return (x * y); }, 8, 32);

Expand Down