Skip to content

Commit 4109213

Browse files
authored
[SYCL] Update tests with new test cases for FPGA function attributes (#3089)
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 <soumi.manna@intel.com>
1 parent 7f1a540 commit 4109213

9 files changed

+173
-3
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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
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 2{{'max_global_work_dim' attribute requires an integer constant}}
9+
[[intel::max_global_work_dim(Ty{})]] void func() {}
10+
11+
struct S {};
12+
void test() {
13+
//expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
14+
func<S>();
15+
//expected-note@+1{{in instantiation of function template specialization 'func<float>' requested here}}
16+
func<float>();
17+
// no error expected
18+
func<int>(); // OK
19+
}
20+
21+
// Test that checks expression is not a constant expression.
22+
int foo();
23+
// expected-error@+1{{'max_global_work_dim' attribute requires an integer constant}}
24+
[[intel::max_global_work_dim(foo() + 1)]] void func1();
25+
26+
// Test that checks expression is a constant expression.
27+
constexpr int bar() { return 0; }
28+
[[intel::max_global_work_dim(bar() + 2)]] void func2(); // OK
29+
30+
// Test that checks template parameter support on member function of class template.
531
template <int SIZE>
632
class KernelFunctor {
733
public:
@@ -23,3 +49,24 @@ int main() {
2349
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
2450
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
2551
// CHECK-NEXT: IntegerLiteral{{.*}}2{{$}}
52+
53+
// Test that checks template parameter support on function.
54+
template <int N>
55+
// expected-error@+1{{'max_global_work_dim' attribute requires a non-negative integral compile time constant expression}}
56+
[[intel::max_global_work_dim(N)]] void func3() {}
57+
58+
int check() {
59+
// no error expected
60+
func3<2>();
61+
//expected-note@+1{{in instantiation of function template specialization 'func3<-1>' requested here}}
62+
func3<-1>();
63+
return 0;
64+
}
65+
66+
// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3
67+
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N
68+
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()'
69+
// CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}}
70+
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
71+
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
72+
// CHECK-NEXT: IntegerLiteral{{.*}}2{{$}}

clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int foo();
2424
constexpr int bar() { return 0; }
2525
[[intel::max_work_group_size(bar() + 12, bar() + 12, bar() + 12)]] void func2(); // OK
2626

27-
// Test that checks template parameter suppport on member function of class template.
27+
// Test that checks template parameter support on member function of class template.
2828
template <int SIZE, int SIZE1, int SIZE2>
2929
class KernelFunctor {
3030
public:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int foo();
2424
constexpr int bar() { return 0; }
2525
[[intel::reqd_work_group_size(bar() + 12, bar() + 12, bar() + 12)]] void func2(); // OK
2626

27-
// Test that checks template parameter suppport on member function of class template.
27+
// Test that checks template parameter support on member function of class template.
2828
template <int SIZE, int SIZE1, int SIZE2>
2929
class KernelFunctor {
3030
public:

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
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@+2{{'num_simd_work_items' attribute requires a positive integral compile time constant expression}}
9+
// expected-error@+1 2{{'num_simd_work_items' attribute requires an integer constant}}
10+
[[intel::num_simd_work_items(Ty{})]] void func() {}
11+
12+
struct S {};
13+
void test() {
14+
//expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
15+
func<S>();
16+
//expected-note@+1{{in instantiation of function template specialization 'func<float>' requested here}}
17+
func<float>();
18+
//expected-note@+1{{in instantiation of function template specialization 'func<int>' requested here}}
19+
func<int>();
20+
}
21+
22+
// Test that checks expression is not a constant expression.
23+
int foo();
24+
// expected-error@+1{{'num_simd_work_items' attribute requires an integer constant}}
25+
[[intel::num_simd_work_items(foo() + 12)]] void func1();
26+
27+
// Test that checks expression is a constant expression.
28+
constexpr int bar() { return 0; }
29+
[[intel::num_simd_work_items(bar() + 12)]] void func2(); // OK
30+
31+
// Test that checks template parameter support on member function of class template.
532
template <int SIZE>
633
class KernelFunctor {
734
public:
@@ -14,6 +41,7 @@ int main() {
1441
KernelFunctor<-1>();
1542
// no error expected
1643
KernelFunctor<10>();
44+
return 0;
1745
}
1846

1947
// CHECK: ClassTemplateDecl {{.*}} {{.*}} KernelFunctor
@@ -23,3 +51,24 @@ int main() {
2351
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
2452
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
2553
// CHECK-NEXT: IntegerLiteral{{.*}}10{{$}}
54+
55+
// Test that checks template parameter support on function.
56+
template <int N>
57+
// expected-error@+1{{'num_simd_work_items' attribute requires a positive integral compile time constant expression}}
58+
[[intel::num_simd_work_items(N)]] void func3() {}
59+
60+
int check() {
61+
// no error expected
62+
func3<8>();
63+
//expected-note@+1{{in instantiation of function template specialization 'func3<-1>' requested here}}
64+
func3<-1>();
65+
return 0;
66+
}
67+
68+
// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3
69+
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N
70+
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()'
71+
// CHECK: SYCLIntelNumSimdWorkItemsAttr {{.*}}
72+
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
73+
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
74+
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
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@+2{{'reqd_sub_group_size' attribute requires a positive integral compile time constant expression}}
9+
// expected-error@+1 2{{'reqd_sub_group_size' attribute requires an integer constant}}
10+
[[intel::reqd_sub_group_size(Ty{})]] void func() {}
11+
12+
struct S {};
13+
void test() {
14+
//expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
15+
func<S>();
16+
//expected-note@+1{{in instantiation of function template specialization 'func<float>' requested here}}
17+
func<float>();
18+
//expected-note@+1{{in instantiation of function template specialization 'func<int>' requested here}}
19+
func<int>();
20+
}
21+
22+
// Test that checks expression is not a constant expression.
23+
int foo();
24+
// expected-error@+1{{'reqd_sub_group_size' attribute requires an integer constant}}
25+
[[intel::reqd_sub_group_size(foo() + 12)]] void func1();
26+
27+
// Test that checks expression is a constant expression.
28+
constexpr int bar() { return 0; }
29+
[[intel::reqd_sub_group_size(bar() + 12)]] void func2(); // OK
30+
31+
// Test that checks template parameter support on member function of class template.
532
template <int SIZE>
633
class KernelFunctor {
734
public:
@@ -14,6 +41,7 @@ int main() {
1441
KernelFunctor<-1>();
1542
// no error expected
1643
KernelFunctor<10>();
44+
return 0;
1745
}
1846

1947
// CHECK: ClassTemplateDecl {{.*}} {{.*}} KernelFunctor
@@ -23,3 +51,24 @@ int main() {
2351
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
2452
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
2553
// CHECK-NEXT: IntegerLiteral{{.*}}10{{$}}
54+
55+
// Test that checks template parameter support on function.
56+
template <int N>
57+
// expected-error@+1{{'reqd_sub_group_size' attribute requires a positive integral compile time constant expression}}
58+
[[intel::reqd_sub_group_size(N)]] void func3() {}
59+
60+
int check() {
61+
// no error expected
62+
func3<12>();
63+
//expected-note@+1{{in instantiation of function template specialization 'func3<-1>' requested here}}
64+
func3<-1>();
65+
return 0;
66+
}
67+
68+
// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3
69+
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N
70+
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()'
71+
// CHECK: IntelReqdSubGroupSizeAttr {{.*}}
72+
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
73+
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
74+
// CHECK-NEXT: IntegerLiteral{{.*}}12{{$}}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int foo();
2424
constexpr int bar() { return 0; }
2525
[[cl::reqd_work_group_size(bar() + 12, bar() + 12, bar() + 12)]] void func2(); // OK
2626

27-
// Test that checks template parameter suppport on member function of class template.
27+
// Test that checks template parameter support on member function of class template.
2828
template <int SIZE, int SIZE1, int SIZE2>
2929
class KernelFunctor {
3030
public:

0 commit comments

Comments
 (0)