Skip to content

[SYCL] Enable range rounding for unnamed lambdas #10736

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: 3 additions & 9 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,8 @@ class __SYCL_EXPORT handler {

// Disable the rounding-up optimizations under these conditions:
// 1. The env var SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING is set.
// 2. The kernel is provided via an interoperability method.
// 2. The kernel is provided via an interoperability method (this uses a
// different code path).
// 3. The range is already a multiple of the rounding factor.
//
// Cases 2 and 3 could be supported with extra effort.
Expand All @@ -1052,17 +1053,10 @@ class __SYCL_EXPORT handler {
// call-graph to make this_item calls kernel-specific but this is
// not considered worthwhile.

// Get the kernel name to check condition 2.
std::string KName = typeid(NameT *).name();
using KI = detail::KernelInfo<KernelName>;
bool DisableRounding =
this->DisableRangeRounding() ||
(KI::getName() == nullptr || KI::getName()[0] == '\0');

// Perform range rounding if rounding-up is enabled
// and there are sufficient work-items to need rounding
// and the user-specified range is not a multiple of a "good" value.
if (!DisableRounding && (NumWorkItems[0] >= MinRangeX) &&
if (!this->DisableRangeRounding() && (NumWorkItems[0] >= MinRangeX) &&
(NumWorkItems[0] % MinFactorX != 0)) {
// It is sufficient to round up just the first dimension.
// Multiplying the rounded-up value of the first dimension
Expand Down
26 changes: 26 additions & 0 deletions sycl/test-e2e/Basic/parallel_for_range_roundup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ void try_id3(size_t size) {
check("Counter = ", Counter, size * 10 * 10);
}

void try_unnamed_lambda(size_t size) {
range<3> Size{size, 10, 10};
int Counter = 0;
{
buffer<range<3>, 1> BufRange(&Range3, 1);
buffer<int, 1> BufCounter(&Counter, 1);
queue myQueue;

myQueue.submit([&](handler &cgh) {
auto AccRange = BufRange.get_access<access::mode::read_write>(cgh);
auto AccCounter = BufCounter.get_access<access::mode::atomic>(cgh);
cgh.parallel_for(Size, [=](id<3> ID) {
AccCounter[0].fetch_add(1);
AccRange[0][0] = ID[0];
});
});
myQueue.wait();
}
check("Counter = ", Counter, size * 10 * 10);
}

int main() {
int x;

Expand All @@ -155,6 +176,7 @@ int main() {
try_id1(x);
try_id2(x);
try_id3(x);
try_unnamed_lambda(x);

x = 256;
try_item1(x);
Expand All @@ -163,6 +185,7 @@ int main() {
try_id1(x);
try_id2(x);
try_id3(x);
try_unnamed_lambda(x);

return 0;
}
Expand All @@ -182,6 +205,8 @@ int main() {
// CHECK-NEXT: Counter = 15000
// CHECK-NEXT: parallel_for range adjusted from 1500 to 1504
// CHECK-NEXT: Counter = 150000
// CHECK-NEXT: parallel_for range adjusted from 1500 to 1504
// CHECK-NEXT: Counter = 150000
// CHECK-NEXT: Size seen by user = 256
// CHECK-NEXT: Counter = 256
// CHECK-NEXT: Size seen by user = 256
Expand All @@ -191,3 +216,4 @@ int main() {
// CHECK-NEXT: Counter = 256
// CHECK-NEXT: Counter = 2560
// CHECK-NEXT: Counter = 25600
// CHECK-NEXT: Counter = 25600