Skip to content

[SYCL] Update tests with new test cases for FPGA function attributes #3089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/test/CodeGenSYCL/intel-max-global-work-dim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Functor {
[[intel::max_global_work_dim(SIZE)]] void operator()() const {}
};

template <int N>
[[intel::max_global_work_dim(N)]] void func() {}

int main() {
q.submit([&](handler &h) {
Foo boo;
Expand All @@ -26,12 +29,17 @@ int main() {

Functor<2> f;
h.single_task<class kernel_name3>(f);

h.single_task<class kernel_name4>([]() {
func<2>();
});
});
return 0;
}

// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !max_global_work_dim ![[NUM1:[0-9]+]]
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !max_global_work_dim ![[NUM2:[0-9]+]]
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !max_global_work_dim ![[NUM2]]
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !max_global_work_dim ![[NUM2]]
// CHECK: ![[NUM1]] = !{i32 1}
// CHECK: ![[NUM2]] = !{i32 2}
9 changes: 9 additions & 0 deletions clang/test/CodeGenSYCL/num-simd-work-items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Functor {
[[intel::num_simd_work_items(SIZE)]] void operator()() const {}
};

template <int N>
[[intel::num_simd_work_items(N)]] void func() {}

int main() {
q.submit([&](handler &h) {
Foo boo;
Expand All @@ -26,13 +29,19 @@ int main() {

Functor<2> f;
h.single_task<class kernel_name3>(f);

h.single_task<class kernel_name4>([]() {
func<4>();
});
});
return 0;
}

// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !num_simd_work_items ![[NUM1:[0-9]+]]
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !num_simd_work_items ![[NUM42:[0-9]+]]
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !num_simd_work_items ![[NUM2:[0-9]+]]
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !num_simd_work_items ![[NUM4:[0-9]+]]
// CHECK: ![[NUM1]] = !{i32 1}
// CHECK: ![[NUM42]] = !{i32 42}
// CHECK: ![[NUM2]] = !{i32 2}
// CHECK: ![[NUM4]] = !{i32 4}
8 changes: 8 additions & 0 deletions clang/test/CodeGenSYCL/reqd-sub-group-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Functor2 {
[[intel::reqd_sub_group_size(SIZE)]] void operator()() const {}
};

template <int N>
[[intel::reqd_sub_group_size(N)]] void func() {}

int main() {
q.submit([&](handler &h) {
Functor16 f16;
Expand All @@ -38,6 +41,10 @@ int main() {

Functor2<2> f2;
h.single_task<class kernel_name4>(f2);

h.single_task<class kernel_name5>([]() {
func<2>();
});
});
return 0;
}
Expand All @@ -46,6 +53,7 @@ int main() {
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE8:[0-9]+]]
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE4:[0-9]+]]
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE2:[0-9]+]]
// CHECK: define {{.*}}spir_kernel void @{{.*}}kernel_name5"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE2]]
// CHECK: ![[SGSIZE16]] = !{i32 16}
// CHECK: ![[SGSIZE8]] = !{i32 8}
// CHECK: ![[SGSIZE4]] = !{i32 4}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@

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

// Test that checks wrong function template instantiation and ensures that the type
// is checked properly when instantiating from the template definition.
template <typename Ty>
// expected-error@+1 2{{'max_global_work_dim' attribute requires an integer constant}}
[[intel::max_global_work_dim(Ty{})]] void func() {}

struct S {};
void test() {
//expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
func<S>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another interesting test would be: func<float>(); to see if we get an exciting implicit conversion to int there or not. Also, a test like func<int>();, which should be accepted.

Copy link
Contributor Author

@smanna12 smanna12 Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another interesting test would be: func(); to see if we get an exciting implicit conversion to int there or not.

Test is added. We get an implicit conversion to int for all attributes here.

Also, a test like func();, which should be accepted.

Test is added.
[intel::max_global_work_dim)]] -- accepts this test
[[intel::num_simd_work_items()]] -- does not accept this test
[[intel::reqd_sub_group_size()]] -- does not accept this test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it expected that we get an implicit conversion for func<float>() or was that a surprise (if a surprise, maybe open an issue for it)?

Also, is the inconsistency between the other attributes with func<int>() expected? I would assume we'd want all of these or none of these to behave the same way. If it's unexpected, maybe open another issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created #3100 for this issue and assigned to me. I will investigate this behavior for all of these in a separate PR. Thanks @AaronBallman for suggesting about this tests.

//expected-note@+1{{in instantiation of function template specialization 'func<float>' requested here}}
func<float>();
// no error expected
func<int>(); // OK
}

// Test that checks expression is not a constant expression.
int foo();
// expected-error@+1{{'max_global_work_dim' attribute requires an integer constant}}
[[intel::max_global_work_dim(foo() + 1)]] void func1();

// Test that checks expression is a constant expression.
constexpr int bar() { return 0; }
[[intel::max_global_work_dim(bar() + 2)]] void func2(); // OK

// Test that checks template parameter support on member function of class template.
template <int SIZE>
class KernelFunctor {
public:
Expand All @@ -23,3 +49,24 @@ int main() {
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}2{{$}}

// Test that checks template parameter support on function.
template <int N>
// expected-error@+1{{'max_global_work_dim' attribute requires a non-negative integral compile time constant expression}}
[[intel::max_global_work_dim(N)]] void func3() {}

int check() {
// no error expected
func3<2>();
//expected-note@+1{{in instantiation of function template specialization 'func3<-1>' requested here}}
func3<-1>();
return 0;
}

// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()'
// CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}}
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}2{{$}}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int foo();
constexpr int bar() { return 0; }
[[intel::max_work_group_size(bar() + 12, bar() + 12, bar() + 12)]] void func2(); // OK

// Test that checks template parameter suppport on member function of class template.
// Test that checks template parameter support on member function of class template.
template <int SIZE, int SIZE1, int SIZE2>
class KernelFunctor {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int foo();
constexpr int bar() { return 0; }
[[intel::reqd_work_group_size(bar() + 12, bar() + 12, bar() + 12)]] void func2(); // OK

// Test that checks template parameter suppport on member function of class template.
// Test that checks template parameter support on member function of class template.
template <int SIZE, int SIZE1, int SIZE2>
class KernelFunctor {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

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

// Test that checks wrong function template instantiation and ensures that the type
// is checked properly when instantiating from the template definition.
template <typename Ty>
// expected-error@+2{{'num_simd_work_items' attribute requires a positive integral compile time constant expression}}
// expected-error@+1 2{{'num_simd_work_items' attribute requires an integer constant}}
[[intel::num_simd_work_items(Ty{})]] void func() {}

struct S {};
void test() {
//expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
func<S>();
//expected-note@+1{{in instantiation of function template specialization 'func<float>' requested here}}
func<float>();
//expected-note@+1{{in instantiation of function template specialization 'func<int>' requested here}}
func<int>();
}

// Test that checks expression is not a constant expression.
int foo();
// expected-error@+1{{'num_simd_work_items' attribute requires an integer constant}}
[[intel::num_simd_work_items(foo() + 12)]] void func1();

// Test that checks expression is a constant expression.
constexpr int bar() { return 0; }
[[intel::num_simd_work_items(bar() + 12)]] void func2(); // OK

// Test that checks template parameter support on member function of class template.
template <int SIZE>
class KernelFunctor {
public:
Expand All @@ -14,6 +41,7 @@ int main() {
KernelFunctor<-1>();
// no error expected
KernelFunctor<10>();
return 0;
}

// CHECK: ClassTemplateDecl {{.*}} {{.*}} KernelFunctor
Expand All @@ -23,3 +51,24 @@ int main() {
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}10{{$}}

// Test that checks template parameter support on function.
template <int N>
// expected-error@+1{{'num_simd_work_items' attribute requires a positive integral compile time constant expression}}
[[intel::num_simd_work_items(N)]] void func3() {}

int check() {
// no error expected
func3<8>();
//expected-note@+1{{in instantiation of function template specialization 'func3<-1>' requested here}}
func3<-1>();
return 0;
}

// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()'
// CHECK: SYCLIntelNumSimdWorkItemsAttr {{.*}}
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

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

// Test that checks wrong function template instantiation and ensures that the type
// is checked properly when instantiating from the template definition.
template <typename Ty>
// expected-error@+2{{'reqd_sub_group_size' attribute requires a positive integral compile time constant expression}}
// expected-error@+1 2{{'reqd_sub_group_size' attribute requires an integer constant}}
[[intel::reqd_sub_group_size(Ty{})]] void func() {}

struct S {};
void test() {
//expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
func<S>();
//expected-note@+1{{in instantiation of function template specialization 'func<float>' requested here}}
func<float>();
//expected-note@+1{{in instantiation of function template specialization 'func<int>' requested here}}
func<int>();
}

// Test that checks expression is not a constant expression.
int foo();
// expected-error@+1{{'reqd_sub_group_size' attribute requires an integer constant}}
[[intel::reqd_sub_group_size(foo() + 12)]] void func1();

// Test that checks expression is a constant expression.
constexpr int bar() { return 0; }
[[intel::reqd_sub_group_size(bar() + 12)]] void func2(); // OK

// Test that checks template parameter support on member function of class template.
template <int SIZE>
class KernelFunctor {
public:
Expand All @@ -14,6 +41,7 @@ int main() {
KernelFunctor<-1>();
// no error expected
KernelFunctor<10>();
return 0;
}

// CHECK: ClassTemplateDecl {{.*}} {{.*}} KernelFunctor
Expand All @@ -23,3 +51,24 @@ int main() {
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}10{{$}}

// Test that checks template parameter support on function.
template <int N>
// expected-error@+1{{'reqd_sub_group_size' attribute requires a positive integral compile time constant expression}}
[[intel::reqd_sub_group_size(N)]] void func3() {}

int check() {
// no error expected
func3<12>();
//expected-note@+1{{in instantiation of function template specialization 'func3<-1>' requested here}}
func3<-1>();
return 0;
}

// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()'
// CHECK: IntelReqdSubGroupSizeAttr {{.*}}
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}12{{$}}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int foo();
constexpr int bar() { return 0; }
[[cl::reqd_work_group_size(bar() + 12, bar() + 12, bar() + 12)]] void func2(); // OK

// Test that checks template parameter suppport on member function of class template.
// Test that checks template parameter support on member function of class template.
template <int SIZE, int SIZE1, int SIZE2>
class KernelFunctor {
public:
Expand Down