Skip to content

[SYCL] Make cl::reqd_work_group_size applicable to lambdas #856

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 2 commits into from
Nov 29, 2019
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
7 changes: 6 additions & 1 deletion clang/include/clang/Basic/AttributeCommonInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ class AttributeCommonInfo {
// FIXME: Eventually we want to do a list here populated via tablegen. But
// we want C++ attributes to be permissible on Lambdas, and get propagated
// to the call operator declaration.
return getParsedKind() == AT_SYCLIntelKernelArgsRestrict;
auto ParsedAttr = getParsedKind();
if (ParsedAttr == AT_SYCLIntelKernelArgsRestrict ||
(ParsedAttr == AT_ReqdWorkGroupSize && isCXX11Attribute()))
return true;

return false;
}

bool isC2xAttribute() const { return SyntaxUsed == AS_C2x; }
Expand Down
5 changes: 5 additions & 0 deletions clang/test/CodeGenSYCL/reqd-work-group-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ void bar() {

Functor f;
kernel<class kernel_name2>(f);

kernel<class kernel_name3>(
[]() [[cl::reqd_work_group_size(8, 8, 8)]] {});
}

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

24 changes: 11 additions & 13 deletions clang/test/SemaSYCL/reqd-work-group-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,30 @@ void bar() {
FunctorAttr fattr;
kernel<class kernel_name4>(fattr);

kernel<class kernel_name5>([]() [[cl::reqd_work_group_size(32, 32, 32)]] {
f32x32x32();
});


#ifdef TRIGGER_ERROR
Functor8 f8;
kernel<class kernel_name5>(f8);
kernel<class kernel_name6>(f8);

kernel<class kernel_name6>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
kernel<class kernel_name7>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
f4x1x1();
f32x1x1();
});

kernel<class kernel_name7>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
kernel<class kernel_name8>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
f16x1x1();
f16x16x1();
});

kernel<class kernel_name8>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
kernel<class kernel_name9>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
f32x32x32();
f32x32x1();
});

// Support for reqd_work_group_size (and other SYCL attributes) that apply to
// lambda expressions is not implemented in clang yet.
// When it lands, the following code is expected to compile successfully.
//
// expected-error@+1 {{'reqd_work_group_size' attribute cannot be applied to types}}
kernel<class kernel_name9>([]() [[cl::reqd_work_group_size(32, 32, 32)]] {
f32x32x32();
});
// While this case is not going to work (wrong syntax):
// expected-error@+1 {{expected variable name or 'this' in lambda capture list}}
kernel<class kernel_name10>([[cl::reqd_work_group_size(32, 32, 32)]] []() {
f32x32x32();
Expand All @@ -121,4 +117,6 @@ void bar() {
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 16 16
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name4
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 128 128 128
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 32 32 32
#endif // __SYCL_DEVICE_ONLY__