Skip to content

Commit 4e09dbf

Browse files
authored
[FPGA][NFC] improves tests for [[intel::no_global_work_offset]] attribute (#6184)
[FPGA][NFC] improves tests for no-global-work-offset attribute This patch updates test bases for [[intel::no_global_work_offset]] attribute: 1. separates AST and diagnostics to make it easier to read/follow-up. 2. removes duplicate test cases. 3. no compiler changes. Signed-off-by: Soumi Manna <soumi.manna@intel.com>
1 parent 5e6642a commit 4e09dbf

File tree

3 files changed

+165
-150
lines changed

3 files changed

+165
-150
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -Wno-sycl-2017-compat -ast-dump %s | FileCheck %s
2+
3+
// Tests for AST of Intel FPGA no_global_work_offset function attribute.
4+
5+
#include "sycl.hpp"
6+
7+
using namespace cl::sycl;
8+
queue q;
9+
10+
struct FuncObj {
11+
[[intel::no_global_work_offset]] void operator()() const {}
12+
};
13+
14+
// CHECK: FunctionDecl {{.*}} func 'void ()'
15+
// CHECK-NEXT: CompoundStmt
16+
// CHECK-NEXT: SYCLIntelNoGlobalWorkOffsetAttr
17+
// CHECK-NEXT: ConstantExpr{{.*}}'int'
18+
// CHECK-NEXT: value: Int 1
19+
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
20+
[[intel::no_global_work_offset(1)]] void func() {}
21+
22+
class KernelFunctor {
23+
public:
24+
void operator()() const {
25+
func();
26+
}
27+
};
28+
29+
// CHECK: FunctionTemplateDecl {{.*}} func1
30+
// CHECK: FunctionDecl {{.*}} func1 'void ()'
31+
// CHECK-NEXT: CompoundStmt
32+
// CHECK_NEXT: SYCLIntelNoGlobalWorkOffsetAttr
33+
// CHECK_NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'N' 'int'
34+
// CHECK: FunctionDecl {{.*}} func1 'void ()'
35+
// CHECK-NEXT: TemplateArgument integral 1
36+
// CHECK-NEXT: CompoundStmt
37+
// CHECK-NEXT: SYCLIntelNoGlobalWorkOffsetAttr
38+
// CHECK-NEXT: ConstantExpr{{.*}}'int'
39+
// CHECK-NEXT: value: Int 1
40+
// CHECK-NEXT: SubstNonTypeTemplateParmExpr
41+
// CHECK-NEXT: NonTypeTemplateParmDecl
42+
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
43+
44+
// Test that checks template parameter support on function.
45+
template <int N>
46+
[[intel::no_global_work_offset(N)]] void func1() {}
47+
48+
// Test that checks template parameter support on member function of class template.
49+
template <int SIZE>
50+
class KernelFunctor2 {
51+
public:
52+
[[intel::no_global_work_offset(SIZE)]] void operator()() const {}
53+
};
54+
55+
int main() {
56+
q.submit([&](handler &h) {
57+
// CHECK: FunctionDecl {{.*}}test_kernel1
58+
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr
59+
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
60+
// CHECK-NEXT: value: Int 1
61+
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
62+
h.single_task<class test_kernel1>(FuncObj());
63+
64+
// CHECK: FunctionDecl {{.*}}test_kernel2
65+
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr
66+
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
67+
// CHECK-NEXT: value: Int 0
68+
// CHECK-NEXT: IntegerLiteral{{.*}}0{{$}}
69+
h.single_task<class test_kernel2>(
70+
[]() [[intel::no_global_work_offset(0)]] {});
71+
72+
// CHECK: FunctionDecl {{.*}}test_kernel3
73+
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr
74+
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
75+
// CHECK-NEXT: value: Int 42
76+
// CHECK-NEXT: IntegerLiteral{{.*}}42{{$}}
77+
h.single_task<class test_kernel3>(
78+
[]() [[intel::no_global_work_offset(42)]] {});
79+
80+
// CHECK: FunctionDecl {{.*}}test_kernel4
81+
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr
82+
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
83+
// CHECK-NEXT: value: Int -1
84+
// CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-'
85+
// CHECK-NEXT-NEXT: IntegerLiteral{{.*}}1{{$}}
86+
h.single_task<class test_kernel4>(
87+
[]() [[intel::no_global_work_offset(-1)]] {});
88+
89+
// Ignore duplicate attribute.
90+
h.single_task<class test_kernel5>(
91+
// CHECK: FunctionDecl {{.*}}test_kernel5
92+
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr
93+
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
94+
// CHECK-NEXT: value: Int 1
95+
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
96+
// CHECK-NOT: SYCLIntelNoGlobalWorkOffsetAttr
97+
[]() [[intel::no_global_work_offset,
98+
intel::no_global_work_offset]] {}); // OK
99+
100+
// Test attribute does not get propagated.
101+
// CHECK: FunctionDecl {{.*}}test_kernel6
102+
// CHECK-NOT: SYCLIntelLoopFuseAttr
103+
KernelFunctor f1;
104+
h.single_task<class test_kernel6>(f1);
105+
106+
// CHECK: FunctionDecl {{.*}}test_kernel7
107+
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr
108+
// CHECK-NEXT: ConstantExpr{{.*}}'int'
109+
// CHECK-NEXT: value: Int 1
110+
// CHECK-NEXT: SubstNonTypeTemplateParmExpr
111+
// CHECK-NEXT: NonTypeTemplateParmDecl
112+
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
113+
KernelFunctor2<1> f2;
114+
h.single_task<class test_kernel7>(f2);
115+
});
116+
func1<1>();
117+
return 0;
118+
}
Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,61 @@
1-
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -Wno-return-type -sycl-std=2017 -Wno-sycl-2017-compat -fcxx-exceptions -fsyntax-only -ast-dump -verify -pedantic %s | FileCheck %s
1+
// RUN: %clang_cc1 -fsycl-is-device -verify %s
22

3-
#include "sycl.hpp"
3+
// Test that checks 'no_global_work_offset' attribute support on function.
44

5-
using namespace cl::sycl;
6-
queue q;
5+
// Tests for incorrect argument values for Intel FPGA 'no_global_work_offset' function attribute.
6+
[[intel::no_global_work_offset(1)]] int a; // expected-error{{'no_global_work_offset' attribute only applies to functions}}
77

8-
//expected-warning@+1 {{unknown attribute 'no_global_work_offset' ignored}}
9-
[[intelfpga::no_global_work_offset]] void RemovedSpell();
8+
[[intel::no_global_work_offset("foo")]] void test() {} // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'const char[4]'}}
109

11-
struct FuncObj {
12-
[[intel::no_global_work_offset]] void operator()() const {}
13-
};
10+
[[intel::no_global_work_offset(0, 1)]] void test1() {} // expected-error{{'no_global_work_offset' attribute takes no more than 1 argument}}
1411

15-
int main() {
16-
q.submit([&](handler &h) {
17-
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr {{.*}}
18-
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
19-
// CHECK-NEXT: value: Int 1
20-
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
21-
h.single_task<class test_kernel1>(FuncObj());
12+
[[intelfpga::no_global_work_offset]] void RemovedSpell(); // expected-warning {{unknown attribute 'no_global_work_offset' ignored}}
2213

23-
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr {{.*}}
24-
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
25-
// CHECK-NEXT: value: Int 0
26-
// CHECK-NEXT: IntegerLiteral{{.*}}0{{$}}
27-
h.single_task<class test_kernel2>(
28-
[]() [[intel::no_global_work_offset(0)]]{});
14+
// Test that checks wrong function template instantiation and ensures that the type
15+
// is checked properly when instantiating from the template definition.
16+
template <typename Ty>
17+
// expected-error@+1{{integral constant expression must have integral or unscoped enumeration type, not 'S'}}
18+
[[intel::no_global_work_offset(Ty{})]] void func() {}
2919

30-
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr{{.*}}
31-
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
32-
// CHECK-NEXT: value: Int 42
33-
// CHECK-NEXT: IntegerLiteral{{.*}}42{{$}}
34-
h.single_task<class test_kernel3>(
35-
[]() [[intel::no_global_work_offset(42)]]{});
20+
struct S {};
21+
void var() {
22+
// expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
23+
func<S>();
24+
}
25+
26+
// Test that checks expression is not a constant expression.
27+
// expected-note@+1{{declared here}}
28+
int foo();
29+
// expected-error@+2{{expression is not an integral constant expression}}
30+
// expected-note@+1{{non-constexpr function 'foo' cannot be used in a constant expression}}
31+
[[intel::no_global_work_offset(foo() + 12)]] void func1();
32+
33+
// Test that checks expression is a constant expression.
34+
constexpr int bar() { return 0; }
35+
[[intel::no_global_work_offset(bar() + 12)]] void func2(); // OK
36+
37+
// No diagnostic is thrown since arguments match. Silently ignore duplicate attribute.
38+
[[intel::no_global_work_offset]] void func3();
39+
[[intel::no_global_work_offset(1)]] void func3() {} // OK
3640

37-
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr{{.*}}
38-
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
39-
// CHECK-NEXT: value: Int -1
40-
// CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-'
41-
// CHECK-NEXT-NEXT: IntegerLiteral{{.*}}1{{$}}
42-
h.single_task<class test_kernel4>(
43-
[]() [[intel::no_global_work_offset(-1)]]{});
41+
[[intel::no_global_work_offset(0)]] void func4(); // expected-note {{previous attribute is here}}
42+
[[intel::no_global_work_offset]] void func4(); // expected-warning{{attribute 'no_global_work_offset' is already applied with different arguments}}
4443

45-
// Ignore duplicate attribute.
46-
h.single_task<class test_kernel5>(
47-
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr {{.*}}
48-
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
49-
// CHECK-NEXT: value: Int 1
50-
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
51-
[]() [[intel::no_global_work_offset,
52-
intel::no_global_work_offset]]{}); // OK
44+
// No diagnostic is emitted because the arguments match.
45+
[[intel::no_global_work_offset(1)]] void func5();
46+
[[intel::no_global_work_offset(1)]] void func5() {} // OK
5347

54-
// expected-error@+2{{integral constant expression must have integral or unscoped enumeration type, not 'const char[4]'}}
55-
h.single_task<class test_kernel6>(
56-
[]() [[intel::no_global_work_offset("foo")]]{});
48+
// Diagnostic is emitted because the arguments mismatch.
49+
[[intel::no_global_work_offset(0)]] void func6(); // expected-note {{previous attribute is here}}
50+
[[intel::no_global_work_offset(1)]] void func6(); // expected-warning{{attribute 'no_global_work_offset' is already applied with different arguments}}
5751

58-
h.single_task<class test_kernel7>([]() {
59-
// expected-error@+1{{'no_global_work_offset' attribute only applies to functions}}
60-
[[intel::no_global_work_offset(1)]] int a;
61-
});
52+
// Test that checks template parameter support on function.
53+
template <int N>
54+
[[intel::no_global_work_offset(0)]] void func7(); // expected-note {{previous attribute is here}}
55+
template <int N>
56+
[[intel::no_global_work_offset(N)]] void func7() {} // expected-warning {{attribute 'no_global_work_offset' is already applied with different arguments}}
6257

63-
h.single_task<class test_kernel8>(
64-
[]() [[intel::no_global_work_offset(0), // expected-note {{previous attribute is here}}
65-
intel::no_global_work_offset(1)]]{}); // expected-warning{{attribute 'no_global_work_offset' is already applied with different arguments}}
66-
});
58+
int check() {
59+
func7<1>(); // expected-note {{in instantiation of function template specialization 'func7<1>' requested here}}
6760
return 0;
6861
}

clang/test/SemaSYCL/sycl-device-intel-fpga-no-global-work-offset.cpp

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)