Skip to content

Commit 1da6fbe

Browse files
authored
[SYCL] Reverse reqd_work_group_size attribute (#1234)
Reverse reqd_work_group_size attribute to match SYCL behavior Signed-off-by: Aleksander Fadeev <aleksander.fadeev@intel.com>
1 parent 7a2e75e commit 1da6fbe

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,7 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr,
28952895
if (const auto *A = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>())
28962896
if (A->getNumber() == 0)
28972897
Result &= checkZeroDim(A, WGSize[0], WGSize[1], WGSize[2],
2898-
/*ReverseAttrs=*/ true);
2898+
/*ReverseAttrs=*/true);
28992899

29002900
if (const auto *A = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
29012901
if (!(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() &&
@@ -2935,14 +2935,17 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
29352935
}
29362936
}
29372937

2938-
if (!checkWorkGroupSizeValues(S, D, AL, WGSize))
2939-
return;
2940-
2938+
// For a SYCLDevice WorkGroupAttr arguments are reversed
2939+
if (S.getLangOpts().SYCLIsDevice) {
2940+
std::swap(WGSize[0], WGSize[2]);
2941+
}
29412942
WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>();
2942-
if (Existing && !(Existing->getXDim() == WGSize[0] &&
2943-
Existing->getYDim() == WGSize[1] &&
2944-
Existing->getZDim() == WGSize[2]))
2943+
if (Existing &&
2944+
!(Existing->getXDim() == WGSize[0] && Existing->getYDim() == WGSize[1] &&
2945+
Existing->getZDim() == WGSize[2]))
29452946
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2947+
if (!checkWorkGroupSizeValues(S, D, AL, WGSize))
2948+
return;
29462949

29472950
D->addAttr(::new (S.Context)
29482951
WorkGroupAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2]));

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ void bar() {
2727
kernel<class kernel_name2>(f);
2828

2929
kernel<class kernel_name3>(
30-
[]() [[cl::reqd_work_group_size(8, 8, 8)]] {});
30+
[]() [[cl::reqd_work_group_size(8, 8, 8)]]{});
3131
}
3232

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

clang/test/CodeGenSYCL/sycl-multi-kernel-attr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ void bar() {
1717
}
1818

1919
// CHECK: define spir_kernel void @{{.*}}kernel_name() {{.*}} !reqd_work_group_size ![[WGSIZE:[0-9]+]] !intel_reqd_sub_group_size ![[SGSIZE:[0-9]+]]
20-
// CHECK: ![[WGSIZE]] = !{i32 32, i32 16, i32 16}
20+
// CHECK: ![[WGSIZE]] = !{i32 16, i32 16, i32 32}
2121
// CHECK: ![[SGSIZE]] = !{i32 4}

clang/test/SemaSYCL/intel-max-global-work-dim.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ int main() {
8282
kernel<class test_kernel5>(
8383
TRIFuncObjGood2());
8484
// CHECK-LABEL: FunctionDecl {{.*}} _ZTSZ4mainE12test_kernel5
85-
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 4 1 1
86-
// CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} 8 1 1
85+
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 4
86+
// CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} 1 1 8
8787
// CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}} 3
8888

8989
#ifdef TRIGGER_ERROR

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
class Functor {
88
public:
99
[[cl::reqd_work_group_size(4, 1, 1)]] void operator()() {}
10-
1110
};
1211

1312
template <typename name, typename Func>
@@ -24,25 +23,33 @@ void bar() {
2423
// expected-note@-1 {{conflicting attribute is here}}
2524
[[cl::reqd_work_group_size(32, 1, 1)]] void f32x1x1() {} // expected-note {{conflicting attribute is here}}
2625

27-
[[cl::reqd_work_group_size(16, 1, 1)]] void f16x1x1() {} // expected-note {{conflicting attribute is here}}
26+
[[cl::reqd_work_group_size(16, 1, 1)]] void f16x1x1() {} // expected-note {{conflicting attribute is here}}
2827
[[cl::reqd_work_group_size(16, 16, 1)]] void f16x16x1() {} // expected-note {{conflicting attribute is here}}
2928

30-
[[cl::reqd_work_group_size(32, 32, 1)]] void f32x32x1() {} // expected-note {{conflicting attribute is here}}
29+
[[cl::reqd_work_group_size(32, 32, 1)]] void f32x32x1() {} // expected-note {{conflicting attribute is here}}
3130
[[cl::reqd_work_group_size(32, 32, 32)]] void f32x32x32() {} // expected-note {{conflicting attribute is here}}
3231

3332
class Functor16 {
3433
public:
35-
[[cl::reqd_work_group_size(16, 1, 1)]] void operator()() {}
34+
[[cl::reqd_work_group_size(16, 1, 1)]] [[cl::reqd_work_group_size(16, 1, 1)]] void operator()() {}
3635
};
3736

37+
#ifdef TRIGGER_ERROR
38+
class Functor32 {
39+
public:
40+
//expected-warning@+2{{attribute 'reqd_work_group_size' is already applied with different parameters}}
41+
// expected-error@+1{{'reqd_work_group_size' attribute conflicts with 'reqd_work_group_size' attribute}}
42+
[[cl::reqd_work_group_size(32, 1, 1)]] [[cl::reqd_work_group_size(1, 1, 32)]] void operator()() {}
43+
};
44+
#endif
3845
class Functor16x16x16 {
3946
public:
4047
[[cl::reqd_work_group_size(16, 16, 16)]] void operator()() {}
4148
};
4249

4350
class Functor8 { // expected-error {{conflicting attributes applied to a SYCL kernel}}
4451
public:
45-
[[cl::reqd_work_group_size(8, 1, 1)]] void operator()() { // expected-note {{conflicting attribute is here}}
52+
[[cl::reqd_work_group_size(1, 1, 8)]] void operator()() { // expected-note {{conflicting attribute is here}}
4653
f4x1x1();
4754
}
4855
};
@@ -77,15 +84,17 @@ void bar() {
7784
FunctorAttr fattr;
7885
kernel<class kernel_name4>(fattr);
7986

80-
kernel<class kernel_name5>([]() [[cl::reqd_work_group_size(32, 32, 32)]] {
81-
f32x32x32();
87+
kernel<class kernel_name5>([]() [[cl::reqd_work_group_size(32, 32, 32), cl::reqd_work_group_size(32, 32, 32)]] {
88+
f32x32x32();
8289
});
8390

84-
8591
#ifdef TRIGGER_ERROR
8692
Functor8 f8;
8793
kernel<class kernel_name6>(f8);
8894

95+
Functor32 f32;
96+
kernel<class kernel_name1>(f32);
97+
8998
kernel<class kernel_name7>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}}
9099
f4x1x1();
91100
f32x1x1();
@@ -102,17 +111,17 @@ void bar() {
102111
});
103112

104113
// expected-error@+1 {{expected variable name or 'this' in lambda capture list}}
105-
kernel<class kernel_name10>([[cl::reqd_work_group_size(32, 32, 32)]] []() {
114+
kernel<class kernel_name10>([[cl::reqd_work_group_size(32, 32, 32)]][]() {
106115
f32x32x32();
107116
});
108117

109118
#endif
110119
}
111120

112121
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1
113-
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 1 1
122+
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 16
114123
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2
115-
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 4 1 1
124+
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 4
116125
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name3
117126
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 16 16
118127
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name4

0 commit comments

Comments
 (0)