Skip to content

Commit 7d7ab2f

Browse files
[SYCL] Remove unnamed lambda check from headers (#14614)
Currently the SYCL headers checks for unnamed lambdas in the case where they have been disabled. However, this falsely flags functor objects which should not be covered by the unnamed lambda restriction. Luckily, the compiler already issues diagnostics for illegal unnamed lambdas, so this patch removes the check from the headers and instead relies on the frontend for issuing diagnostics for the illegal cases. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 13c9d0e commit 7d7ab2f

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

sycl/include/sycl/kernel.hpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,16 @@ class auto_name {};
4848
/// the \c Name.
4949
template <typename Name, typename Type> struct get_kernel_name_t {
5050
using name = Name;
51-
static_assert(
52-
!std::is_same_v<Name, auto_name>,
53-
"No kernel name provided without -fsycl-unnamed-lambda enabled!");
5451
};
5552

56-
#ifdef __SYCL_UNNAMED_LAMBDA__
5753
/// Specialization for the case when \c Name is undefined.
58-
/// This is only legal with our compiler with the unnamed lambda
59-
/// extension, so make sure the specialiation isn't available in that case: the
60-
/// lack of specialization allows us to trigger static_assert from the primary
61-
/// definition.
54+
/// This is only legal with our compiler with the unnamed lambda extension or if
55+
/// the kernel is a functor object. For the case where \c Type is a lambda
56+
/// function and unnamed lambdas are disabled, the compiler will issue a
57+
/// diagnostic.
6258
template <typename Type> struct get_kernel_name_t<detail::auto_name, Type> {
6359
using name = Type;
6460
};
65-
#endif // __SYCL_UNNAMED_LAMBDA__
6661

6762
} // namespace detail
6863

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %clangxx -fsycl -fsycl-device-only -std=c++17 -fno-sycl-unnamed-lambda -isystem %sycl_include/sycl -Xclang -verify -fsyntax-only %s -Xclang -verify-ignore-unexpected=note
2+
// expected-no-diagnostics
3+
4+
// Tests that kernel functor objects are allowed through when unnamed lambdas
5+
// are disabled.
6+
7+
#include <sycl/sycl.hpp>
8+
9+
struct SingleTaskKernel {
10+
void operator()() const {}
11+
};
12+
13+
struct ParallelForKernel {
14+
void operator()(sycl::item<1> it) const {}
15+
};
16+
17+
struct ParallelForWorkGroupKernel {
18+
void operator()(sycl::item<1> it) const {}
19+
};
20+
21+
int main() {
22+
sycl::queue q;
23+
24+
q.single_task(SingleTaskKernel{});
25+
26+
q.parallel_for(sycl::range<1>{1}, ParallelForKernel{});
27+
28+
q.submit([&](sycl::handler &cgh) {
29+
cgh.single_task(SingleTaskKernel{});
30+
});
31+
32+
q.submit([&](sycl::handler &cgh) {
33+
cgh.parallel_for(sycl::range<1>{1}, ParallelForKernel{});
34+
});
35+
36+
q.submit([&](sycl::handler &cgh) {
37+
cgh.parallel_for_work_group(sycl::range<1>{1},
38+
ParallelForWorkGroupKernel{});
39+
});
40+
}

sycl/test/basic_tests/handler/unnamed-lambda-negative.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
// RUN: %clangxx -fsycl -fsycl-device-only -std=c++17 -fno-sycl-unnamed-lambda -isystem %sycl_include/sycl -Xclang -verify -fsyntax-only %s -Xclang -verify-ignore-unexpected=note
2+
3+
// NOTE: Due to rounded kernels, some parallel_for cases may issue two error
4+
// diagnostics.
5+
26
#include <sycl/sycl.hpp>
37

48
int main() {
59
sycl::queue q;
610

7-
// expected-error@sycl/kernel.hpp:* {{No kernel name provided without -fsycl-unnamed-lambda enabled!}}
11+
// expected-error-re@sycl/handler.hpp:* {{unnamed type '{{.*}}' is invalid; provide a kernel name, or use '-fsycl-unnamed-lambda' to enable unnamed kernel lambdas}}
812
// expected-note@+1 {{in instantiation of function template}}
913
q.single_task([=](){});
1014

11-
// expected-error@sycl/kernel.hpp:* {{No kernel name provided without -fsycl-unnamed-lambda enabled!}}
15+
// expected-error-re@sycl/handler.hpp:* {{unnamed type 'sycl::detail::RoundedRangeKernel<{{.*}}>' is invalid; provide a kernel name, or use '-fsycl-unnamed-lambda' to enable unnamed kernel lambdas}}
16+
// expected-error-re@sycl/handler.hpp:* {{unnamed type '{{.*}}' is invalid; provide a kernel name, or use '-fsycl-unnamed-lambda' to enable unnamed kernel lambdas}}
1217
// expected-note@+1 {{in instantiation of function template}}
1318
q.parallel_for(sycl::range<1>{1}, [=](sycl::item<1>) {});
1419

1520
q.submit([&](sycl::handler &cgh) {
16-
// expected-error@sycl/kernel.hpp:* {{No kernel name provided without -fsycl-unnamed-lambda enabled!}}
21+
// expected-error-re@sycl/handler.hpp:* {{unnamed type '{{.*}}' is invalid; provide a kernel name, or use '-fsycl-unnamed-lambda' to enable unnamed kernel lambdas}}
1722
// expected-note@+1 {{in instantiation of function template}}
1823
cgh.single_task([=](){});
1924

20-
// expected-error@sycl/kernel.hpp:* {{No kernel name provided without -fsycl-unnamed-lambda enabled!}}
25+
// expected-error-re@sycl/handler.hpp:* {{unnamed type 'sycl::detail::RoundedRangeKernel<{{.*}}>' is invalid; provide a kernel name, or use '-fsycl-unnamed-lambda' to enable unnamed kernel lambdas}}
26+
// expected-error-re@sycl/handler.hpp:* {{unnamed type '{{.*}}' is invalid; provide a kernel name, or use '-fsycl-unnamed-lambda' to enable unnamed kernel lambdas}}
2127
// expected-note@+1 {{in instantiation of function template}}
2228
cgh.parallel_for(sycl::range<1>{1}, [=](sycl::item<1>) {});
2329

24-
// expected-error@sycl/kernel.hpp:* {{No kernel name provided without -fsycl-unnamed-lambda enabled!}}
30+
// expected-error-re@sycl/handler.hpp:* {{unnamed type '{{.*}}' is invalid; provide a kernel name, or use '-fsycl-unnamed-lambda' to enable unnamed kernel lambdas}}
2531
// expected-note@+1 {{in instantiation of function template}}
2632
cgh.parallel_for_work_group(sycl::range<1>{1}, [=](sycl::group<1>) {});
2733
});

0 commit comments

Comments
 (0)