Skip to content

Commit 436dc40

Browse files
committed
[SYCL][NFC] Fix num_simd_work_items and reqd_work_group_size argument check
This patch fixes #3252. According to https://www.intel.com/content/www/us/en/programmable/documentation/mwh1391807965224.html#mwh1391807939093 (section : 5.2.13. Specifying Number of SIMD Work-Items): Important: Introduce the num_simd_work_items attribute in conjunction with the reqd_work_group_size attribute. The num_simd_work_items attribute you specify must evenly divide the work-group size you specify for the reqd_work_group_size attribute. Based on discussion, the requirement applies only for X argument of reqd_work_group_size attribute. Signed-off-by: Soumi Manna <[email protected]>
1 parent 51f22c4 commit 436dc40

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11213,7 +11213,7 @@ def err_sycl_invalid_accessor_property_list_template_param : Error<
1121311213
"template parameter must be a "
1121411214
"%select{parameter pack|type|non-negative integer}1">;
1121511215
def err_sycl_num_kernel_wrong_reqd_wg_size : Error<
11216-
"%0 attribute must evenly divide the work-group size for the %1 attribute">;
11216+
"%0 attribute must evenly divide X argument of %1 attribute">;
1121711217

1121811218
def warn_sycl_pass_by_value_deprecated
1121911219
: Warning<"Passing kernel functions by value is deprecated in SYCL 2020">,

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,9 +3155,7 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
31553155
int64_t NumSimdWorkItems =
31563156
A->getValue()->getIntegerConstantExpr(Ctx)->getSExtValue();
31573157

3158-
if (!(XDimVal.getZExtValue() % NumSimdWorkItems == 0 ||
3159-
YDimVal.getZExtValue() % NumSimdWorkItems == 0 ||
3160-
ZDimVal.getZExtValue() % NumSimdWorkItems == 0)) {
3158+
if (XDimVal.getZExtValue() % NumSimdWorkItems != 0) {
31613159
S.Diag(A->getLocation(), diag::err_sycl_num_kernel_wrong_reqd_wg_size)
31623160
<< A << AL;
31633161
S.Diag(AL.getLoc(), diag::note_conflicting_attribute);
@@ -3305,14 +3303,12 @@ void Sema::AddSYCLIntelNumSimdWorkItemsAttr(Decl *D,
33053303
}
33063304

33073305
// If the declaration has an [[intel::reqd_work_group_size]] attribute,
3308-
// check to see if can be evenly divided by the num_simd_work_items attr.
3306+
// check to see X argument can be evenly divided by the num_simd_work_items
3307+
// attribute.
33093308
if (const auto *DeclAttr = D->getAttr<ReqdWorkGroupSizeAttr>()) {
33103309
Optional<llvm::APSInt> XDimVal = DeclAttr->getXDimVal(Context);
3311-
Optional<llvm::APSInt> YDimVal = DeclAttr->getYDimVal(Context);
3312-
Optional<llvm::APSInt> ZDimVal = DeclAttr->getZDimVal(Context);
33133310

3314-
if (!(*XDimVal % ArgVal == 0 || *YDimVal % ArgVal == 0 ||
3315-
*ZDimVal % ArgVal == 0)) {
3311+
if (*XDimVal % ArgVal != 0) {
33163312
Diag(CI.getLoc(), diag::err_sycl_num_kernel_wrong_reqd_wg_size)
33173313
<< CI << DeclAttr;
33183314
Diag(DeclAttr->getLocation(), diag::note_conflicting_attribute);

clang/test/SemaSYCL/num_simd_work_items_device.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,29 @@ struct FuncObj {
4141

4242
#ifdef TRIGGER_ERROR
4343
struct TRIFuncObjBad1 {
44-
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide the work-group size for the 'reqd_work_group_size' attribute}}
44+
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide X argument of 'reqd_work_group_size' attribute}}
4545
[[intel::reqd_work_group_size(5, 5, 5)]] //expected-note{{conflicting attribute is here}}
4646
void
4747
operator()() const {}
4848
};
4949

5050
struct TRIFuncObjBad2 {
5151
[[intel::reqd_work_group_size(5, 5, 5)]] // expected-note{{conflicting attribute is here}}
52-
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide the work-group size for the 'reqd_work_group_size' attribute}}
52+
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide X argument of 'reqd_work_group_size' attribute}}
5353
void
5454
operator()() const {}
5555
};
5656

5757
struct TRIFuncObjBad3 {
58-
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide the work-group size for the 'reqd_work_group_size' attribute}}
59-
[[cl::reqd_work_group_size(5, 5, 5)]] //expected-note{{conflicting attribute is here}}
58+
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide X argument of 'reqd_work_group_size' attribute}}
59+
[[cl::reqd_work_group_size(5, 5, 5)]] // expected-note{{conflicting attribute is here}}
6060
void
6161
operator()() const {}
6262
};
6363

6464
struct TRIFuncObjBad4 {
6565
[[cl::reqd_work_group_size(5, 5, 5)]] // expected-note{{conflicting attribute is here}}
66-
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide the work-group size for the 'reqd_work_group_size' attribute}}
66+
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide X argument of 'reqd_work_group_size' attribute}}
6767
void
6868
operator()() const {}
6969
};
@@ -75,29 +75,29 @@ struct TRIFuncObjBad5 {
7575
};
7676

7777
struct TRIFuncObjBad6 {
78-
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide the work-group size for the 'reqd_work_group_size' attribute}}
78+
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide X argument of 'reqd_work_group_size' attribute}}
7979
[[intel::reqd_work_group_size(5)]] //expected-note{{conflicting attribute is here}}
8080
void
8181
operator()() const {}
8282
};
8383

8484
struct TRIFuncObjBad7 {
8585
[[intel::reqd_work_group_size(5)]] // expected-note{{conflicting attribute is here}}
86-
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide the work-group size for the 'reqd_work_group_size' attribute}}
86+
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide X argument of 'reqd_work_group_size' attribute}}
8787
void
8888
operator()() const {}
8989
};
9090

9191
struct TRIFuncObjBad8 {
92-
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide the work-group size for the 'reqd_work_group_size' attribute}}
93-
[[intel::reqd_work_group_size(5, 5)]] // expected-note{{conflicting attribute is here}}
92+
[[intel::num_simd_work_items(4)]] // expected-error{{'num_simd_work_items' attribute must evenly divide X argument of 'reqd_work_group_size' attribute}}
93+
[[intel::reqd_work_group_size(3, 64)]] // expected-note{{conflicting attribute is here}}
9494
void
9595
operator()() const {}
9696
};
9797

9898
struct TRIFuncObjBad9 {
99-
[[intel::reqd_work_group_size(5, 5)]] // expected-note{{conflicting attribute is here}}
100-
[[intel::num_simd_work_items(3)]] // expected-error{{'num_simd_work_items' attribute must evenly divide the work-group size for the 'reqd_work_group_size' attribute}}
99+
[[intel::reqd_work_group_size(3, 64)]] // expected-note{{conflicting attribute is here}}
100+
[[intel::num_simd_work_items(4)]] // expected-error{{'num_simd_work_items' attribute must evenly divide X argument of 'reqd_work_group_size' attribute}}
101101
void
102102
operator()() const {}
103103
};
@@ -155,6 +155,13 @@ struct TRIFuncObjBad18 {
155155
[[intel::reqd_work_group_size(-1)]] // expected-warning{{implicit conversion changes signedness: 'int' to 'unsigned long long'}}
156156
void operator()() const {}
157157
};
158+
159+
struct TRIFuncObjBad19 {
160+
[[intel::reqd_work_group_size(5, 64, 64)]] // expected-note{{conflicting attribute is here}}
161+
[[intel::num_simd_work_items(4)]] // expected-error{{'num_simd_work_items' attribute must evenly divide X argument of 'reqd_work_group_size' attribute}}
162+
void operator()() const {}
163+
};
164+
158165
#endif // TRIGGER_ERROR
159166

160167
struct TRIFuncObjGood1 {
@@ -413,7 +420,9 @@ int main() {
413420

414421
h.single_task<class test_kernel31>(TRIFuncObjBad18());
415422

416-
h.single_task<class test_kernel32>(
423+
h.single_task<class test_kernel32>(TRIFuncObjBad19());
424+
425+
h.single_task<class test_kernel33>(
417426
[]() [[intel::num_simd_work_items(1), intel::num_simd_work_items(2)]]{}); // expected-warning{{attribute 'num_simd_work_items' is already applied with different parameters}} \
418427
// expected-note {{previous attribute is here}}
419428
#endif // TRIGGER_ERROR

0 commit comments

Comments
 (0)