Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,28 @@

// 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{{'max_global_work_dim' attribute requires an integer constant}}
[[intel::max_global_work_dim(Ty{})]] void func() {}

struct S {};
void var() {
//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.

}

// 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 suppport on member function of class template.
template <int SIZE>
class KernelFunctor {
public:
Expand All @@ -23,3 +45,20 @@ int main() {
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}2{{$}}

// Test that checks template parameter support on function.
template <int N>
[[intel::max_global_work_dim(N)]] void func3() {}

int check() {
func3<2>();
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 @@ -2,6 +2,28 @@

// 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@+1{{'num_simd_work_items' attribute requires an integer constant}}
[[intel::num_simd_work_items(Ty{})]] void func() {}

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

// 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 suppport on member function of class template.
template <int SIZE>
class KernelFunctor {
public:
Expand All @@ -23,3 +45,20 @@ int main() {
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}10{{$}}

// Test that checks template parameter support on function.
template <int N>
[[intel::num_simd_work_items(N)]] void func3() {}

int check() {
func3<8>();
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,28 @@

// 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@+1{{'reqd_sub_group_size' attribute requires an integer constant}}
[[intel::reqd_sub_group_size(Ty{})]] void func() {}

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

// 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 suppport on member function of class template.
template <int SIZE>
class KernelFunctor {
public:
Expand All @@ -23,3 +45,20 @@ int main() {
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}10{{$}}

// Test that checks template parameter support on function.
template <int N>
[[intel::reqd_sub_group_size(N)]] void func3() {}

int check() {
func3<12>();
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{{$}}