Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
42 changes: 31 additions & 11 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2898,21 +2898,33 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr,
/*ReverseAttrs=*/ true);

if (const auto *A = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
if (!(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() &&
WGSize[2] <= A->getZDim())) {
if (S.getLangOpts().SYCLIsDevice && !(WGSize[2] <= A->getXDim() && WGSize[1] <= A->getYDim() &&
WGSize[0] <= A->getZDim())) {
S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< Attr << A->getSpelling();
Result &= false;
}
}
if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
if (!(WGSize[0] >= A->getXDim() && WGSize[1] >= A->getYDim() &&
WGSize[2] >= A->getZDim())) {
if (!S.getLangOpts().SYCLIsDevice && !(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() &&
WGSize[2] <= A->getZDim())) {
S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< Attr << A->getSpelling();
Result &= false;
}
}
if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
if (S.getLangOpts().SYCLIsDevice && !(WGSize[2] >= A->getXDim() && WGSize[1] >= A->getYDim() &&
WGSize[0] >= A->getZDim())) {
S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< Attr << A->getSpelling();
Result &= false;
}
if (!S.getLangOpts().SYCLIsDevice && !(WGSize[0] >= A->getXDim() && WGSize[1] >= A->getYDim() &&
WGSize[2] >= A->getZDim())) {
S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< Attr << A->getSpelling();
Result &= false;
}
}
return Result;
}

Expand All @@ -2939,13 +2951,21 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
return;

WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>();
if (Existing && !(Existing->getXDim() == WGSize[0] &&
Existing->getYDim() == WGSize[1] &&
Existing->getZDim() == WGSize[2]))
if (S.getLangOpts().SYCLIsDevice && Existing && !(Existing->getXDim() == WGSize[2] &&
Existing->getYDim() == WGSize[1] &&
Existing->getZDim() == WGSize[0]))
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
if (!S.getLangOpts().SYCLIsDevice && Existing && !(Existing->getXDim() == WGSize[0] &&
Existing->getYDim() == WGSize[1] &&
Existing->getZDim() == WGSize[2]))
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;

D->addAttr(::new (S.Context)
WorkGroupAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2]));
if (S.getLangOpts().SYCLIsDevice)
D->addAttr(::new (S.Context) WorkGroupAttr(S.Context, AL, WGSize[2],
WGSize[1], WGSize[0]));
else
D->addAttr(::new (S.Context) WorkGroupAttr(S.Context, AL, WGSize[0],
WGSize[1], WGSize[2]));
}

// Handles intel_reqd_sub_group_size.
Expand Down
7 changes: 3 additions & 4 deletions clang/test/CodeGenSYCL/reqd-work-group-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ void bar() {
kernel<class kernel_name2>(f);

kernel<class kernel_name3>(
[]() [[cl::reqd_work_group_size(8, 8, 8)]] {});
[]() [[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: ![[WGSIZE32]] = !{i32 16, i32 16, i32 32}
// CHECK: ![[WGSIZE8]] = !{i32 1, i32 1, i32 8}
// CHECK: ![[WGSIZE88]] = !{i32 8, i32 8, i32 8}

2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/sycl-multi-kernel-attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ void bar() {
}

// CHECK: define spir_kernel void @{{.*}}kernel_name() {{.*}} !reqd_work_group_size ![[WGSIZE:[0-9]+]] !intel_reqd_sub_group_size ![[SGSIZE:[0-9]+]]
// CHECK: ![[WGSIZE]] = !{i32 32, i32 16, i32 16}
// CHECK: ![[WGSIZE]] = !{i32 16, i32 16, i32 32}
// CHECK: ![[SGSIZE]] = !{i32 4}
4 changes: 2 additions & 2 deletions clang/test/SemaSYCL/intel-max-global-work-dim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ int main() {
kernel<class test_kernel5>(
TRIFuncObjGood2());
// CHECK-LABEL: FunctionDecl {{.*}} _ZTSZ4mainE12test_kernel5
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 4 1 1
// CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} 8 1 1
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 4
// CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} 1 1 8
// CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}} 3

#ifdef TRIGGER_ERROR
Expand Down
10 changes: 5 additions & 5 deletions clang/test/SemaSYCL/reqd-work-group-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void bar() {

class Functor16 {
public:
[[cl::reqd_work_group_size(16, 1, 1)]] void operator()() {}
[[cl::reqd_work_group_size(16, 1, 1)]] [[cl::reqd_work_group_size(16, 1, 1)]] void operator()() {}
Comment on lines -35 to +34
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new one.

};

class Functor16x16x16 {
Expand All @@ -42,7 +42,7 @@ class Functor16x16x16 {

class Functor8 { // expected-error {{conflicting attributes applied to a SYCL kernel}}
public:
[[cl::reqd_work_group_size(8, 1, 1)]] void operator()() { // expected-note {{conflicting attribute is here}}
[[cl::reqd_work_group_size(1, 1, 8)]] void operator()() { // expected-note {{conflicting attribute is here}}
f4x1x1();
}
};
Expand Down Expand Up @@ -77,7 +77,7 @@ void bar() {
FunctorAttr fattr;
kernel<class kernel_name4>(fattr);

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

Expand Down Expand Up @@ -110,9 +110,9 @@ void bar() {
}

// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 1 1
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 16
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 4 1 1
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 4
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name3
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 16 16
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name4
Expand Down