-
Notifications
You must be signed in to change notification settings - Fork 770
[SYCL] Add template parameter support for no_global_work_offset attribute #2839
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
romanovvlad
merged 13 commits into
intel:sycl
from
smanna12:AddTempSupportNoglobalworkoffset
Dec 17, 2020
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5918ff3
[SYCL] Add template parameter support for no_global_work_offset attri…
smanna12 b54e401
Fix Clang format issues
smanna12 7791b8a
Fix Clang format issues
smanna12 7ceb024
Add support for optional attribute parameter
smanna12 77cb8e9
Fix calng format and address review comments
smanna12 e51dfff
Address review comments
smanna12 19685c3
Fix Clang format issues
smanna12 bdd752a
Fix error
smanna12 7810812
Remove diagnostic and update patch
smanna12 2a0df89
Address review comments and add new test cases
smanna12 fca61c5
Fix Clang format errors
smanna12 87cb866
address review comments
smanna12 6471266
Add CHECKs for Integer literals
smanna12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 36 additions & 15 deletions
51
clang/test/CodeGenSYCL/intel-fpga-no-global-work-offset.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,49 @@ | ||
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s | ||
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s | ||
|
||
#include "sycl.hpp" | ||
|
||
using namespace cl::sycl; | ||
queue q; | ||
|
||
class Foo { | ||
public: | ||
[[intel::no_global_work_offset(1)]] void operator()() const {} | ||
}; | ||
|
||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) { | ||
kernelFunc(); | ||
} | ||
template <int SIZE> | ||
class Functor { | ||
public: | ||
[[intel::no_global_work_offset(SIZE)]] void operator()() const {} | ||
AaronBallman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
template <int N> | ||
[[intel::no_global_work_offset(N)]] void func() {} | ||
|
||
int main() { | ||
q.submit([&](handler &h) { | ||
Foo boo; | ||
h.single_task<class kernel_name1>(boo); | ||
|
||
h.single_task<class kernel_name2>( | ||
[]() [[intel::no_global_work_offset]]{}); | ||
|
||
void bar() { | ||
Foo boo; | ||
kernel<class kernel_name1>(boo); | ||
h.single_task<class kernel_name3>( | ||
[]() [[intel::no_global_work_offset(0)]]{}); | ||
|
||
kernel<class kernel_name2>( | ||
[]() [[intel::no_global_work_offset]]{}); | ||
Functor<1> f; | ||
h.single_task<class kernel_name4>(f); | ||
|
||
kernel<class kernel_name3>( | ||
[]() [[intel::no_global_work_offset(0)]]{}); | ||
h.single_task<class kernel_name5>([]() { | ||
func<1>(); | ||
}); | ||
}); | ||
return 0; | ||
} | ||
|
||
// CHECK: define spir_kernel void @{{.*}}kernel_name1() {{.*}} !no_global_work_offset ![[NUM5:[0-9]+]] | ||
// CHECK: define spir_kernel void @{{.*}}kernel_name2() {{.*}} !no_global_work_offset ![[NUM5]] | ||
// CHECK: define spir_kernel void @{{.*}}kernel_name3() {{.*}} ![[NUM4:[0-9]+]] | ||
// CHECK: define spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !no_global_work_offset ![[NUM5:[0-9]+]] | ||
// CHECK: define spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !no_global_work_offset ![[NUM5]] | ||
// CHECK: define spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} ![[NUM4:[0-9]+]] | ||
// CHECK: define spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !no_global_work_offset ![[NUM5]] | ||
// CHECK: define spir_kernel void @{{.*}}kernel_name5"() #0 {{.*}} !no_global_work_offset ![[NUM5]] | ||
// CHECK-NOT: ![[NUM4]] = !{i32 0} | ||
// CHECK: ![[NUM5]] = !{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,50 @@ | ||
// RUN: %clang_cc1 -fsycl -fsycl-is-device -Wno-return-type -fcxx-exceptions -fsyntax-only -ast-dump -verify -pedantic %s | FileCheck %s | ||
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -Wno-return-type -Wno-sycl-2017-compat -fcxx-exceptions -fsyntax-only -ast-dump -verify -pedantic %s | FileCheck %s | ||
|
||
#include "sycl.hpp" | ||
|
||
using namespace cl::sycl; | ||
queue q; | ||
|
||
struct FuncObj { | ||
//expected-warning@+2 {{attribute 'intelfpga::no_global_work_offset' is deprecated}} | ||
//expected-note@+1 {{did you mean to use 'intel::no_global_work_offset' instead?}} | ||
[[intelfpga::no_global_work_offset]] void operator()() {} | ||
[[intelfpga::no_global_work_offset]] void operator()() const {} | ||
}; | ||
|
||
template <typename name, typename Func> | ||
void kernel(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
|
||
int main() { | ||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr{{.*}}Enabled | ||
kernel<class test_kernel1>([]() { | ||
FuncObj(); | ||
}); | ||
|
||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr | ||
// CHECK-NOT: Enabled | ||
kernel<class test_kernel2>( | ||
[]() [[intel::no_global_work_offset(0)]]{}); | ||
|
||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr{{.*}}Enabled | ||
// expected-warning@+2{{'no_global_work_offset' attribute should be 0 or 1. Adjusted to 1}} | ||
kernel<class test_kernel3>( | ||
[]() [[intel::no_global_work_offset(42)]]{}); | ||
|
||
// expected-error@+2{{'no_global_work_offset' attribute requires a non-negative integral compile time constant expression}} | ||
kernel<class test_kernel4>( | ||
[]() [[intel::no_global_work_offset(-1)]]{}); | ||
|
||
// expected-error@+2{{'no_global_work_offset' attribute requires parameter 0 to be an integer constant}} | ||
kernel<class test_kernel5>( | ||
[]() [[intel::no_global_work_offset("foo")]]{}); | ||
|
||
kernel<class test_kernel6>([]() { | ||
// expected-error@+1{{'no_global_work_offset' attribute only applies to functions}} | ||
[[intel::no_global_work_offset(1)]] int a; | ||
q.submit([&](handler &h) { | ||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr {{.*}} | ||
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} | ||
h.single_task<class test_kernel1>(FuncObj()); | ||
|
||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr {{.*}} | ||
// CHECK-NEXT: IntegerLiteral{{.*}}0{{$}} | ||
h.single_task<class test_kernel2>( | ||
[]() [[intel::no_global_work_offset(0)]]{}); | ||
|
||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr{{.*}} | ||
// CHECK-NEXT: IntegerLiteral{{.*}}42{{$}} | ||
h.single_task<class test_kernel3>( | ||
[]() [[intel::no_global_work_offset(42)]]{}); | ||
|
||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr{{.*}} | ||
// CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-' | ||
// CHECK-NEXT-NEXT: IntegerLiteral{{.*}}1{{$}} | ||
h.single_task<class test_kernel4>( | ||
[]() [[intel::no_global_work_offset(-1)]]{}); | ||
elizabethandrews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// expected-error@+2{{'no_global_work_offset' attribute requires an integer constant}} | ||
h.single_task<class test_kernel5>( | ||
[]() [[intel::no_global_work_offset("foo")]]{}); | ||
|
||
h.single_task<class test_kernel6>([]() { | ||
// expected-error@+1{{'no_global_work_offset' attribute only applies to functions}} | ||
[[intel::no_global_work_offset(1)]] int a; | ||
}); | ||
|
||
// expected-warning@+2{{attribute 'no_global_work_offset' is already applied}} | ||
h.single_task<class test_kernel7>( | ||
[]() [[intel::no_global_work_offset(0), intel::no_global_work_offset(1)]]{}); | ||
}); | ||
AaronBallman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr{{.*}} | ||
// CHECK-NOT: Enabled | ||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr{{.*}}Enabled | ||
// expected-warning@+2{{attribute 'no_global_work_offset' is already applied}} | ||
kernel<class test_kernel7>( | ||
[]() [[intel::no_global_work_offset(0), intel::no_global_work_offset(1)]]{}); | ||
|
||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
clang/test/SemaSYCL/sycl-device-intel-fpga-no-global-work-offset.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -ast-dump -verify -pedantic %s | FileCheck %s | ||
|
||
// Test that checks template parameter support for 'no_global_work_offset' 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{{'no_global_work_offset' attribute requires an integer constant}} | ||
[[intel::no_global_work_offset(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{{'no_global_work_offset' attribute requires an integer constant}} | ||
[[intel::no_global_work_offset(foo() + 12)]] void func1(); | ||
|
||
// Test that checks expression is a constant expression. | ||
constexpr int bar() { return 0; } | ||
[[intel::no_global_work_offset(bar() + 12)]] void func2(); // OK | ||
|
||
// Test that checks template parameter suppport on member function of class template. | ||
template <int SIZE> | ||
class KernelFunctor { | ||
public: | ||
[[intel::no_global_work_offset(SIZE)]] void operator()() {} | ||
}; | ||
|
||
int main() { | ||
KernelFunctor<1>(); | ||
} | ||
|
||
// CHECK: ClassTemplateDecl {{.*}} {{.*}} KernelFunctor | ||
// CHECK: ClassTemplateSpecializationDecl {{.*}} {{.*}} class KernelFunctor definition | ||
// CHECK: CXXRecordDecl {{.*}} {{.*}} implicit class KernelFunctor | ||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr {{.*}} | ||
// CHECK: SubstNonTypeTemplateParmExpr {{.*}} | ||
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} | ||
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} | ||
|
||
// Test that checks template parameter suppport on function. | ||
template <int N> | ||
[[intel::no_global_work_offset(N)]] void func3() {} | ||
|
||
int check() { | ||
func3<1>(); | ||
return 0; | ||
} | ||
|
||
// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3 | ||
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N | ||
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()' | ||
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr {{.*}} | ||
// CHECK: SubstNonTypeTemplateParmExpr {{.*}} | ||
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} | ||
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.