Skip to content

Commit b06fc66

Browse files
MrSidimsbader
authored andcommitted
[SYCL] Make cl::reqd_work_group_size applicable to lambdas (#856)
Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 160684d commit b06fc66

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

clang/include/clang/Basic/AttributeCommonInfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ 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+
auto ParsedAttr = getParsedKind();
156+
if (ParsedAttr == AT_SYCLIntelKernelArgsRestrict ||
157+
(ParsedAttr == AT_ReqdWorkGroupSize && isCXX11Attribute()))
158+
return true;
159+
160+
return false;
156161
}
157162

158163
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: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,30 @@ void bar() {
7777
FunctorAttr fattr;
7878
kernel<class kernel_name4>(fattr);
7979

80+
kernel<class kernel_name5>([]() [[cl::reqd_work_group_size(32, 32, 32)]] {
81+
f32x32x32();
82+
});
83+
84+
8085
#ifdef TRIGGER_ERROR
8186
Functor8 f8;
82-
kernel<class kernel_name5>(f8);
87+
kernel<class kernel_name6>(f8);
8388

84-
kernel<class kernel_name6>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
89+
kernel<class kernel_name7>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
8590
f4x1x1();
8691
f32x1x1();
8792
});
8893

89-
kernel<class kernel_name7>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
94+
kernel<class kernel_name8>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
9095
f16x1x1();
9196
f16x16x1();
9297
});
9398

94-
kernel<class kernel_name8>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
99+
kernel<class kernel_name9>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
95100
f32x32x32();
96101
f32x32x1();
97102
});
98103

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):
108104
// expected-error@+1 {{expected variable name or 'this' in lambda capture list}}
109105
kernel<class kernel_name10>([[cl::reqd_work_group_size(32, 32, 32)]] []() {
110106
f32x32x32();
@@ -121,4 +117,6 @@ void bar() {
121117
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 16 16
122118
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name4
123119
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 128 128 128
120+
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5
121+
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 32 32 32
124122
#endif // __SYCL_DEVICE_ONLY__

0 commit comments

Comments
 (0)