Skip to content

Commit 7882c71

Browse files
committed
[SYCL] Make cl::reqd_work_group_size applicable to lambdas
Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 16ae15a commit 7882c71

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

clang/include/clang/Basic/AttributeCommonInfo.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ class AttributeCommonInfo {
152152
// FIXME: Eventually we want to do a list here populated via tablegen. But
153153
// we want C++ attributes to be permissible on Lambdas, and get propagated
154154
// to the call operator declaration.
155-
return getParsedKind() == AT_SYCLIntelKernelArgsRestrict;
155+
// FIXME: Attribute lambda capturing is not a part of SYCL 1.2.1. We shall
156+
// check if a program is being compiled with -sycl-ext option.
157+
auto ParsedAttr = getParsedKind();
158+
if (ParsedAttr == AT_SYCLIntelKernelArgsRestrict ||
159+
(ParsedAttr == AT_ReqdWorkGroupSize && isCXX11Attribute()))
160+
return true;
161+
162+
return false;
156163
}
157164

158165
bool isC2xAttribute() const { return SyntaxUsed == AS_C2x; }

clang/test/CodeGenSYCL/reqd-work-group-size.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ void bar() {
2525

2626
Functor f;
2727
kernel<class kernel_name2>(f);
28+
29+
kernel<class kernel_name3>(
30+
[]() [[cl::reqd_work_group_size(8, 8, 8)]] {});
2831
}
2932

3033
// CHECK: define spir_kernel void @{{.*}}kernel_name1() {{.*}} !reqd_work_group_size ![[WGSIZE32:[0-9]+]]
3134
// CHECK: define spir_kernel void @{{.*}}kernel_name2() {{.*}} !reqd_work_group_size ![[WGSIZE8:[0-9]+]]
35+
// CHECK: define spir_kernel void @{{.*}}kernel_name3() {{.*}} !reqd_work_group_size ![[WGSIZE88:[0-9]+]]
3236
// CHECK: ![[WGSIZE32]] = !{i32 32, i32 16, i32 16}
3337
// CHECK: ![[WGSIZE8]] = !{i32 8, i32 1, i32 1}
38+
// CHECK: ![[WGSIZE88]] = !{i32 8, i32 8, i32 8}
3439

clang/test/SemaSYCL/reqd-work-group-size.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,8 @@ void bar() {
9696
f32x32x1();
9797
});
9898

99-
// Support for reqd_work_group_size (and other SYCL attributes) that apply to
100-
// lambda expressions is not implemented in clang yet.
101-
// When it lands, the following code is expected to compile successfully.
102-
//
103-
// expected-error@+1 {{'reqd_work_group_size' attribute cannot be applied to types}}
104-
kernel<class kernel_name9>([]() [[cl::reqd_work_group_size(32, 32, 32)]] {
105-
f32x32x32();
106-
});
107-
// While this case is not going to work (wrong syntax):
10899
// expected-error@+1 {{expected variable name or 'this' in lambda capture list}}
109-
kernel<class kernel_name10>([[cl::reqd_work_group_size(32, 32, 32)]] []() {
100+
kernel<class kernel_name9>([[cl::reqd_work_group_size(32, 32, 32)]] []() {
110101
f32x32x32();
111102
});
112103

0 commit comments

Comments
 (0)