Skip to content

Commit bef85bd

Browse files
committed
[SYCL] Add new test cases for FPGA attributes
Template parameter support was added for 1. [[intel::max_global_work_dim)]] attribute on #2816 2. [[intel::num_simd_work_items()]] attribute on #2510 3. [[intel::reqd_sub_group_size()]] attribute on #1807 This patch adds the following new test cases that were not there before to improve the support: 1. Test that checks wrong function template instantiation and ensures that the type is checked properly when instantiating from the template definition. 2. Test that checks expression is not a constant expression. 3. Test that checks expression is a constant expression. 4. Test that checks template parameter support on function. NOTE: No change in compiler. All new test cases have already been supported. Signed-off-by: Soumi Manna <[email protected]>
1 parent c90b361 commit bef85bd

6 files changed

+142
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class Functor {
1616
[[intel::max_global_work_dim(SIZE)]] void operator()() const {}
1717
};
1818

19+
template <int N>
20+
[[intel::max_global_work_dim(N)]] void func() {}
21+
1922
int main() {
2023
q.submit([&](handler &h) {
2124
Foo boo;
@@ -26,12 +29,17 @@ int main() {
2629

2730
Functor<2> f;
2831
h.single_task<class kernel_name3>(f);
32+
33+
h.single_task<class kernel_name4>([]() {
34+
func<2>();
35+
});
2936
});
3037
return 0;
3138
}
3239

3340
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !max_global_work_dim ![[NUM1:[0-9]+]]
3441
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !max_global_work_dim ![[NUM2:[0-9]+]]
3542
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !max_global_work_dim ![[NUM2]]
43+
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !max_global_work_dim ![[NUM2]]
3644
// CHECK: ![[NUM1]] = !{i32 1}
3745
// CHECK: ![[NUM2]] = !{i32 2}

clang/test/CodeGenSYCL/num-simd-work-items.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class Functor {
1616
[[intel::num_simd_work_items(SIZE)]] void operator()() const {}
1717
};
1818

19+
template <int N>
20+
[[intel::num_simd_work_items(N)]] void func() {}
21+
1922
int main() {
2023
q.submit([&](handler &h) {
2124
Foo boo;
@@ -26,13 +29,19 @@ int main() {
2629

2730
Functor<2> f;
2831
h.single_task<class kernel_name3>(f);
32+
33+
h.single_task<class kernel_name4>([]() {
34+
func<4>();
35+
});
2936
});
3037
return 0;
3138
}
3239

3340
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !num_simd_work_items ![[NUM1:[0-9]+]]
3441
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !num_simd_work_items ![[NUM42:[0-9]+]]
3542
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !num_simd_work_items ![[NUM2:[0-9]+]]
43+
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !num_simd_work_items ![[NUM4:[0-9]+]]
3644
// CHECK: ![[NUM1]] = !{i32 1}
3745
// CHECK: ![[NUM42]] = !{i32 42}
3846
// CHECK: ![[NUM2]] = !{i32 2}
47+
// CHECK: ![[NUM4]] = !{i32 4}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Functor2 {
2525
[[intel::reqd_sub_group_size(SIZE)]] void operator()() const {}
2626
};
2727

28+
template <int N>
29+
[[intel::reqd_sub_group_size(N)]] void func() {}
30+
2831
int main() {
2932
q.submit([&](handler &h) {
3033
Functor16 f16;
@@ -38,6 +41,10 @@ int main() {
3841

3942
Functor2<2> f2;
4043
h.single_task<class kernel_name4>(f2);
44+
45+
h.single_task<class kernel_name5>([]() {
46+
func<2>();
47+
});
4148
});
4249
return 0;
4350
}
@@ -46,6 +53,7 @@ int main() {
4653
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE8:[0-9]+]]
4754
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE4:[0-9]+]]
4855
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE2:[0-9]+]]
56+
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name5"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE2]]
4957
// CHECK: ![[SGSIZE16]] = !{i32 16}
5058
// CHECK: ![[SGSIZE8]] = !{i32 8}
5159
// CHECK: ![[SGSIZE4]] = !{i32 4}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
// Test that checkes template parameter support for 'max_global_work_dim' attribute on sycl device.
44

5+
// Test that checks wrong function template instantiation and ensures that the type
6+
// is checked properly when instantiating from the template definition.
7+
template <typename Ty>
8+
// expected-error@+1{{'max_global_work_dim' attribute requires an integer constant}}
9+
[[intel::max_global_work_dim(Ty{})]] void func() {}
10+
11+
struct S {};
12+
void var() {
13+
//expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
14+
func<S>();
15+
}
16+
17+
// Test that checks expression is not a constant expression.
18+
int foo();
19+
// expected-error@+1{{'max_global_work_dim' attribute requires an integer constant}}
20+
[[intel::max_global_work_dim(foo() + 1)]] void func1();
21+
22+
// Test that checks expression is a constant expression.
23+
constexpr int bar() { return 0; }
24+
[[intel::max_global_work_dim(bar() + 2)]] void func2(); // OK
25+
26+
// Test that checks template parameter suppport on member function of class template.
527
template <int SIZE>
628
class KernelFunctor {
729
public:
@@ -23,3 +45,20 @@ int main() {
2345
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
2446
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
2547
// CHECK-NEXT: IntegerLiteral{{.*}}2{{$}}
48+
49+
// Test that checks template parameter support on function.
50+
template <int N>
51+
[[intel::max_global_work_dim(N)]] void func3() {}
52+
53+
int check() {
54+
func3<2>();
55+
return 0;
56+
}
57+
58+
// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3
59+
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N
60+
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()'
61+
// CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}}
62+
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
63+
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
64+
// CHECK-NEXT: IntegerLiteral{{.*}}2{{$}}

clang/test/SemaSYCL/sycl-device-num_simd_work_items-template.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
// Test that checkes template parameter support for 'num_simd_work_items' attribute on sycl device.
44

5+
// Test that checks wrong function template instantiation and ensures that the type
6+
// is checked properly when instantiating from the template definition.
7+
template <typename Ty>
8+
// expected-error@+1{{'num_simd_work_items' attribute requires an integer constant}}
9+
[[intel::num_simd_work_items(Ty{})]] void func() {}
10+
11+
struct S {};
12+
void var() {
13+
//expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
14+
func<S>();
15+
}
16+
17+
// Test that checks expression is not a constant expression.
18+
int foo();
19+
// expected-error@+1{{'num_simd_work_items' attribute requires an integer constant}}
20+
[[intel::num_simd_work_items(foo() + 12)]] void func1();
21+
22+
// Test that checks expression is a constant expression.
23+
constexpr int bar() { return 0; }
24+
[[intel::num_simd_work_items(bar() + 12)]] void func2(); // OK
25+
26+
// Test that checks template parameter suppport on member function of class template.
527
template <int SIZE>
628
class KernelFunctor {
729
public:
@@ -23,3 +45,20 @@ int main() {
2345
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
2446
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
2547
// CHECK-NEXT: IntegerLiteral{{.*}}10{{$}}
48+
49+
// Test that checks template parameter support on function.
50+
template <int N>
51+
[[intel::num_simd_work_items(N)]] void func3() {}
52+
53+
int check() {
54+
func3<8>();
55+
return 0;
56+
}
57+
58+
// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3
59+
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N
60+
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()'
61+
// CHECK: SYCLIntelNumSimdWorkItemsAttr {{.*}}
62+
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
63+
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
64+
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
// Test that checkes template parameter support for 'reqd_sub_group_size' attribute on sycl device.
44

5+
// Test that checks wrong function template instantiation and ensures that the type
6+
// is checked properly when instantiating from the template definition.
7+
template <typename Ty>
8+
// expected-error@+1{{'reqd_sub_group_size' attribute requires an integer constant}}
9+
[[intel::reqd_sub_group_size(Ty{})]] void func() {}
10+
11+
struct S {};
12+
void var() {
13+
//expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
14+
func<S>();
15+
}
16+
17+
// Test that checks expression is not a constant expression.
18+
int foo();
19+
// expected-error@+1{{'reqd_sub_group_size' attribute requires an integer constant}}
20+
[[intel::reqd_sub_group_size(foo() + 12)]] void func1();
21+
22+
// Test that checks expression is a constant expression.
23+
constexpr int bar() { return 0; }
24+
[[intel::reqd_sub_group_size(bar() + 12)]] void func2(); // OK
25+
26+
// Test that checks template parameter suppport on member function of class template.
527
template <int SIZE>
628
class KernelFunctor {
729
public:
@@ -23,3 +45,20 @@ int main() {
2345
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
2446
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
2547
// CHECK-NEXT: IntegerLiteral{{.*}}10{{$}}
48+
49+
// Test that checks template parameter support on function.
50+
template <int N>
51+
[[intel::reqd_sub_group_size(N)]] void func3() {}
52+
53+
int check() {
54+
func3<12>();
55+
return 0;
56+
}
57+
58+
// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3
59+
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N
60+
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()'
61+
// CHECK: IntelReqdSubGroupSizeAttr {{.*}}
62+
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
63+
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
64+
// CHECK-NEXT: IntegerLiteral{{.*}}12{{$}}

0 commit comments

Comments
 (0)