Skip to content

Commit b2da2c8

Browse files
authored
[SYCL] Add support for [[intel::reqd_sub_group_size()]] attribute (#2137)
This patch adds new spelling of IntelReqdSubGroupSize attribute and generates a diagnostic which will tell that previous spelling of the attribute is deprecated. Signed-off-by: Soumi Manna <[email protected]>
1 parent 4cc1da1 commit b2da2c8

File tree

7 files changed

+66
-18
lines changed

7 files changed

+66
-18
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,9 @@ def LoopUnrollHint : InheritableAttr {
12881288
}
12891289

12901290
def IntelReqdSubGroupSize: InheritableAttr {
1291-
let Spellings = [GNU<"intel_reqd_sub_group_size">, CXX11<"cl", "intel_reqd_sub_group_size">];
1291+
let Spellings = [GNU<"intel_reqd_sub_group_size">,
1292+
CXX11<"cl", "intel_reqd_sub_group_size">,
1293+
CXX11<"intel", "reqd_sub_group_size">];
12921294
let Args = [ExprArgument<"SubGroupSize">];
12931295
let Subjects = SubjectList<[Function, CXXMethod], ErrorDiag>;
12941296
let Documentation = [IntelReqdSubGroupSizeDocs];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3472,9 +3472,10 @@ code. See `cl_intel_required_subgroup_size
34723472
for details.
34733473

34743474
SYCL documentation:
3475-
The [[cl::intel_reqd_sub_group_size(n)]] attribute indicates that the kernel
3476-
must be compiled and executed with a sub-group of size n. The value of n must be
3477-
set to a sub-group size supported by the device, or device compilation will fail.
3475+
The [[cl::intel_reqd_sub_group_size(n)]] and [[intel::reqd_sub_group_size(n)]]
3476+
attribute indicates that the kernel must be compiled and executed with a
3477+
sub-group of size n. The value of n must be set to a sub-group size supported
3478+
by the device, or device compilation will fail.
34783479

34793480
In addition to device functions, the required sub-group size attribute may also
34803481
be specified in the definition of a named functor object and lambda functions,
@@ -3495,6 +3496,19 @@ as in the examples below:
34953496
/* kernel code */
34963497
});
34973498

3499+
class Functor
3500+
{
3501+
[[intel::reqd_sub_group_size(16)]] void operator()(item<1> item)
3502+
{
3503+
/* kernel code */
3504+
}
3505+
}
3506+
3507+
kernel<class kernel_name>(
3508+
[]() [[intel::reqd_sub_group_size(n)]] {
3509+
/* kernel code */
3510+
});
3511+
34983512
See Sub-groups for NDRange Parallelism proposal in sycl/doc/extensions/sub_group_ndrange/sub_group_ndrange.md
34993513
}];
35003514
}

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10990,6 +10990,11 @@ def err_ivdep_declrefexpr_arg : Error<
1099010990
def warn_ivdep_redundant : Warning <"ignoring redundant Intel FPGA loop "
1099110991
"attribute 'ivdep': safelen %select{INF|%1}0 >= safelen %select{INF|%3}2">,
1099210992
InGroup<IgnoredAttributes>;
10993+
def warn_attribute_spelling_deprecated : Warning<
10994+
"attribute %0 is deprecated">,
10995+
InGroup<DeprecatedAttributes>;
10996+
def note_spelling_suggestion : Note<
10997+
"did you mean to use %0 instead?">;
1099310998

1099410999
// errors of expect.with.probability
1099511000
def err_probability_not_constant_float : Error<

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,6 +3014,13 @@ static void handleSubGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
30143014
if (D->getAttr<IntelReqdSubGroupSizeAttr>())
30153015
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
30163016

3017+
if (AL.getAttributeSpellingListIndex() ==
3018+
IntelReqdSubGroupSizeAttr::CXX11_cl_intel_reqd_sub_group_size) {
3019+
S.Diag(AL.getLoc(), diag::warn_attribute_spelling_deprecated) << AL;
3020+
S.Diag(AL.getLoc(), diag::note_spelling_suggestion)
3021+
<< "'intel::reqd_sub_group_size'";
3022+
}
3023+
30173024
S.addIntelReqdSubGroupSizeAttr(D, AL, E);
30183025
}
30193026

clang/test/SemaSYCL/reqd-sub-group-size-device.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -verify -DTRIGGER_ERROR %s
22
// RUN: %clang_cc1 -fsycl -fsycl-is-device -ast-dump %s | FileCheck %s
33

4-
[[cl::intel_reqd_sub_group_size(4)]] void foo() {} // expected-note {{conflicting attribute is here}}
4+
[[intel::reqd_sub_group_size(4)]] void foo() {} // expected-note {{conflicting attribute is here}}
55
// expected-note@-1 {{conflicting attribute is here}}
6-
[[cl::intel_reqd_sub_group_size(32)]] void baz() {} // expected-note {{conflicting attribute is here}}
6+
[[intel::reqd_sub_group_size(32)]] void baz() {} // expected-note {{conflicting attribute is here}}
77

88
class Functor16 {
99
public:
10+
// expected-warning@+2 {{attribute 'intel_reqd_sub_group_size' is deprecated}}
11+
// expected-note@+1 {{did you mean to use 'intel::reqd_sub_group_size' instead?}}
1012
[[cl::intel_reqd_sub_group_size(16)]] void operator()() {}
1113
};
1214

1315
class Functor8 { // expected-error {{conflicting attributes applied to a SYCL kernel}}
1416
public:
15-
[[cl::intel_reqd_sub_group_size(8)]] void operator()() { // expected-note {{conflicting attribute is here}}
17+
[[intel::reqd_sub_group_size(8)]] void operator()() { // expected-note {{conflicting attribute is here}}
1618
foo();
1719
}
1820
};
1921

22+
class Functor4 {
23+
public:
24+
[[intel::reqd_sub_group_size(12)]] void operator()() {}
25+
};
26+
2027
class Functor {
2128
public:
2229
void operator()() {
@@ -46,24 +53,31 @@ void bar() {
4653
});
4754
#endif
4855

49-
kernel<class kernel_name5>([]() [[cl::intel_reqd_sub_group_size(2)]] { });
50-
kernel<class kernel_name6>([]() [[cl::intel_reqd_sub_group_size(4)]] { foo(); });
56+
kernel<class kernel_name5>([]() [[intel::reqd_sub_group_size(2)]]{});
57+
kernel<class kernel_name6>([]() [[intel::reqd_sub_group_size(4)]] { foo(); });
58+
// expected-warning@+2 {{attribute 'intel_reqd_sub_group_size' is deprecated}}
59+
// expected-note@+1 {{did you mean to use 'intel::reqd_sub_group_size' instead?}}
60+
kernel<class kernel_name7>([]() [[cl::intel_reqd_sub_group_size(6)]]{});
61+
62+
Functor4 f4;
63+
kernel<class kernel_name8>(f4);
5164
}
5265

53-
[[cl::intel_reqd_sub_group_size(16)]] SYCL_EXTERNAL void B();
54-
[[cl::intel_reqd_sub_group_size(16)]] void A() {
66+
[[intel::reqd_sub_group_size(16)]] SYCL_EXTERNAL void B();
67+
[[intel::reqd_sub_group_size(16)]] void A() {
5568
}
56-
[[cl::intel_reqd_sub_group_size(16)]] SYCL_EXTERNAL void B() {
69+
70+
[[intel::reqd_sub_group_size(16)]] SYCL_EXTERNAL void B() {
5771
A();
5872
}
5973

6074
#ifdef TRIGGER_ERROR
6175
// expected-note@+1 {{conflicting attribute is here}}
62-
[[cl::intel_reqd_sub_group_size(2)]] void sg_size2() {}
76+
[[intel::reqd_sub_group_size(2)]] void sg_size2() {}
6377

6478
// expected-note@+2 {{conflicting attribute is here}}
6579
// expected-error@+1 {{conflicting attributes applied to a SYCL kernel}}
66-
[[cl::intel_reqd_sub_group_size(4)]] __attribute__((sycl_device)) void sg_size4() {
80+
[[intel::reqd_sub_group_size(4)]] __attribute__((sycl_device)) void sg_size4() {
6781
sg_size2();
6882
}
6983
#endif
@@ -77,3 +91,9 @@ void bar() {
7791
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5
7892
// CHECK: IntelReqdSubGroupSizeAttr {{.*}}
7993
// CHECK-NEXT: IntegerLiteral{{.*}}2{{$}}
94+
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name7
95+
// CHECK: IntelReqdSubGroupSizeAttr {{.*}}
96+
// CHECK-NEXT: IntegerLiteral{{.*}}6{{$}}
97+
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name8
98+
// CHECK: IntelReqdSubGroupSizeAttr {{.*}}
99+
// CHECK-NEXT: IntegerLiteral{{.*}}12{{$}}

clang/test/SemaSYCL/sycl-device-reqd-sub-group-size-template.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -ast-dump -verify -pedantic %s | FileCheck %s
22

3-
// Test that checkes template parameter support for 'intel_reqd_sub_group_size' attribute on sycl device.
3+
// Test that checkes template parameter support for 'reqd_sub_group_size' attribute on sycl device.
44

55
template <int SIZE>
66
class KernelFunctor {
77
public:
8-
//expected-error@+1{{'intel_reqd_sub_group_size' attribute requires a positive integral compile time constant expression}}
9-
[[cl::intel_reqd_sub_group_size(SIZE)]] void operator()() {}
8+
// expected-error@+1{{'reqd_sub_group_size' attribute requires a positive integral compile time constant expression}}
9+
[[intel::reqd_sub_group_size(SIZE)]] void operator()() {}
1010
};
1111

1212
int main() {

clang/test/SemaSYCL/sycl-esimd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void kernel0(F f) __attribute__((sycl_kernel)) {
1717
}
1818

1919
// expected-note@+1{{conflicting attribute is here}}
20-
[[cl::intel_reqd_sub_group_size(2)]] void g0() {}
20+
[[intel::reqd_sub_group_size(2)]] void g0() {}
2121

2222
void test0() {
2323
// expected-error@+2{{conflicting attributes applied to a SYCL kernel}}

0 commit comments

Comments
 (0)