|
| 1 | +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2017 -Wno-sycl-2017-compat -verify -DEXPECT_PROP -DTRIGGER_ERROR %s |
| 2 | +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2017 -Wno-sycl-2017-compat -ast-dump -DEXPECT_PROP %s | FileCheck %s |
| 3 | + |
| 4 | +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2020 -verify -DTRIGGER_ERROR %s |
| 5 | +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -ast-dump %s | FileCheck %s |
| 6 | + |
| 7 | +// Test for AST of work_group_size_hint kernel attribute in SYCL 1.2.1. and SYCL 2020 modes. |
| 8 | +#include "sycl.hpp" |
| 9 | + |
| 10 | +// Check the basics. |
| 11 | +#ifdef TRIGGER_ERROR |
| 12 | +[[sycl::work_group_size_hint]] void f0(); // expected-error {{'work_group_size_hint' attribute takes at least 1 argument}} |
| 13 | +[[sycl::work_group_size_hint(12, 12, 12, 12)]] void f1(); // expected-error {{'work_group_size_hint' attribute takes no more than 3 arguments}} |
| 14 | +[[sycl::work_group_size_hint("derp", 1, 2)]] void f2(); // expected-error {{integral constant expression must have integral or unscoped enumeration type, not 'const char[5]'}} |
| 15 | +[[sycl::work_group_size_hint(1, 1, 1)]] int i; // expected-error {{'work_group_size_hint' attribute only applies to functions}} |
| 16 | +#endif |
| 17 | + |
| 18 | +// Produce a conflicting attribute warning when the args are different. |
| 19 | +[[sycl::work_group_size_hint(4, 1, 1)]] void f3(); // expected-note {{previous attribute is here}} |
| 20 | +[[sycl::work_group_size_hint(1, 1, 32)]] void f3() {} // expected-warning {{attribute 'work_group_size_hint' is already applied with different arguments}} |
| 21 | + |
| 22 | +// 1 and 2 dim versions |
| 23 | +[[sycl::work_group_size_hint(2)]] void f4(); // ok |
| 24 | +[[sycl::work_group_size_hint(2, 1)]] void f5(); // ok |
| 25 | + |
| 26 | +// FIXME: This turns out to be wrong as there aren't really default values |
| 27 | +// (that is an implementation detail we use but shouldn't expose to the user). |
| 28 | +// Instead, the dimensionality of the attribute needs to match that of the |
| 29 | +// kernel, so the one, two, and three arg forms of the attribute are actually |
| 30 | +// *different* attributes. This means that you should not be able to redeclare |
| 31 | +// the function with a different dimensionality. |
| 32 | +// As a result these two (re)declarations should result in errors. |
| 33 | +[[sycl::work_group_size_hint(2)]] void f5(); |
| 34 | +[[sycl::work_group_size_hint(2, 1, 1)]] void f5(); |
| 35 | + |
| 36 | +// Catch the easy case where the attributes are all specified at once with |
| 37 | +// different arguments. |
| 38 | +[[sycl::work_group_size_hint(4, 1, 1), sycl::work_group_size_hint(32, 1, 1)]] void f7(); // expected-warning {{attribute 'work_group_size_hint' is already applied with different arguments}} expected-note {{previous attribute is here}} |
| 39 | + |
| 40 | +// Show that the attribute works on member functions. |
| 41 | +class Functor_1 { |
| 42 | +public: |
| 43 | + [[sycl::work_group_size_hint(16, 1, 1)]] [[sycl::work_group_size_hint(16, 1, 1)]] void operator()() const; |
| 44 | + [[sycl::work_group_size_hint(16, 1, 1)]] [[sycl::work_group_size_hint(32, 1, 1)]] void operator()(int) const; // expected-warning {{attribute 'work_group_size_hint' is already applied with different arguments}} expected-note {{previous attribute is here}} |
| 45 | +}; |
| 46 | + |
| 47 | +// Ensure that template arguments behave appropriately based on instantiations. |
| 48 | +template <int N> |
| 49 | +[[sycl::work_group_size_hint(N, 1, 1)]] void f8(); // #f8 |
| 50 | + |
| 51 | +// Test that template redeclarations also get diagnosed properly. |
| 52 | +template <int X, int Y, int Z> |
| 53 | +[[sycl::work_group_size_hint(1, 1, 1)]] void f9(); // #f9prev |
| 54 | + |
| 55 | +template <int X, int Y, int Z> |
| 56 | +[[sycl::work_group_size_hint(X, Y, Z)]] void f9() {} // #f9 |
| 57 | + |
| 58 | +// Test that a template redeclaration where the difference is known up front is |
| 59 | +// diagnosed immediately, even without instantiation. |
| 60 | +template <int X, int Y, int Z> |
| 61 | +[[sycl::work_group_size_hint(X, 1, Z)]] void f10(); // expected-note {{previous attribute is here}} |
| 62 | +template <int X, int Y, int Z> |
| 63 | +[[sycl::work_group_size_hint(X, 2, Z)]] void f10(); // expected-warning {{attribute 'work_group_size_hint' is already applied with different arguments}} |
| 64 | + |
| 65 | +#ifdef TRIGGER_ERROR |
| 66 | +[[sycl::work_group_size_hint(1, 2, 0)]] void f11(); // expected-error {{'work_group_size_hint' attribute requires a positive integral compile time constant expression}} |
| 67 | +#endif |
| 68 | + |
| 69 | +void instantiate() { |
| 70 | + f8<1>(); // OK |
| 71 | +#ifdef TRIGGER_ERROR |
| 72 | + // expected-error@#f8 {{'work_group_size_hint' attribute requires a positive integral compile time constant expression}} |
| 73 | + f8<-1>(); // expected-note {{in instantiation}} |
| 74 | + // expected-error@#f8 {{'work_group_size_hint' attribute requires a positive integral compile time constant expression}} |
| 75 | + f8<0>(); // expected-note {{in instantiation}} |
| 76 | +#endif |
| 77 | + |
| 78 | + f9<1, 1, 1>(); // OK, args are the same on the redecl. |
| 79 | + |
| 80 | + // expected-warning@#f9 {{attribute 'work_group_size_hint' is already applied with different arguments}} |
| 81 | + // expected-note@#f9prev {{previous attribute is here}} |
| 82 | + f9<1, 2, 3>(); // expected-note {{in instantiation}} |
| 83 | +} |
| 84 | + |
| 85 | +// Show that the attribute works on member functions. |
| 86 | +class Functor16x2x1 { |
| 87 | +public: |
| 88 | + [[sycl::work_group_size_hint(16, 2, 1)]] void operator()() const {}; |
| 89 | +}; |
| 90 | + |
| 91 | +// CHECK: CXXRecordDecl {{.*}} {{.*}}Functor16x2x1 |
| 92 | +// CHECK: WorkGroupSizeHintAttr {{.*}} |
| 93 | +// CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 94 | +// CHECK-NEXT: value: Int 16 |
| 95 | +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} |
| 96 | +// CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 97 | +// CHECK-NEXT: value: Int 2 |
| 98 | +// CHECK-NEXT: IntegerLiteral{{.*}}2{{$}} |
| 99 | +// CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 100 | +// CHECK-NEXT: value: Int 1 |
| 101 | +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} |
| 102 | + |
| 103 | +class Functor4x4x4 { |
| 104 | +public: |
| 105 | + [[sycl::work_group_size_hint(4, 4, 4)]] void operator()() const {}; |
| 106 | +}; |
| 107 | + |
| 108 | +// Checking whether propagation of the attribute happens or not, according to the SYCL version. |
| 109 | +#if defined(EXPECT_PROP) // if attribute is propagated, then we expect errors here |
| 110 | +void f8x8x8(){}; |
| 111 | +#else // otherwise no error |
| 112 | +[[sycl::work_group_size_hint(8, 8, 8)]] void f8x8x8(){}; |
| 113 | +#endif |
| 114 | +class FunctorNoProp { |
| 115 | +public: |
| 116 | + void operator()() const { |
| 117 | + f8x8x8(); |
| 118 | + }; |
| 119 | +}; |
| 120 | + |
| 121 | +void invoke() { |
| 122 | + Functor16x2x1 f16x2x1; |
| 123 | + Functor4x4x4 f4x4x4; |
| 124 | + |
| 125 | + sycl::queue q; |
| 126 | + |
| 127 | + q.submit([&](sycl::handler &h) { |
| 128 | + h.single_task<class kernel_1>(f16x2x1); |
| 129 | + // CHECK: FunctionDecl {{.*}} {{.*}}kernel_1 |
| 130 | + // CHECK: WorkGroupSizeHintAttr {{.*}} |
| 131 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 132 | + // CHECK-NEXT: value: Int 16 |
| 133 | + // CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} |
| 134 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 135 | + // CHECK-NEXT: value: Int 2 |
| 136 | + // CHECK-NEXT: IntegerLiteral{{.*}}2{{$}} |
| 137 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 138 | + // CHECK-NEXT: value: Int 1 |
| 139 | + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} |
| 140 | + |
| 141 | + // Checking that attributes are propagated to the kernel from functions in SYCL 1.2.1 mode. |
| 142 | +#ifdef EXPECT_PROP |
| 143 | + h.single_task<class kernel_2>([=]() { |
| 144 | + f4x4x4(); |
| 145 | + }); |
| 146 | +#else |
| 147 | + // Otherwise using a functor that has the required attributes |
| 148 | + h.single_task<class kernel_2>(f4x4x4); |
| 149 | +#endif |
| 150 | + // CHECK: FunctionDecl {{.*}} {{.*}}kernel_2 |
| 151 | + // CHECK: WorkGroupSizeHintAttr {{.*}} |
| 152 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 153 | + // CHECK-NEXT: value: Int 4 |
| 154 | + // CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} |
| 155 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 156 | + // CHECK-NEXT: value: Int 4 |
| 157 | + // CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} |
| 158 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 159 | + // CHECK-NEXT: value: Int 4 |
| 160 | + // CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} |
| 161 | + |
| 162 | + // Check that conflicts are reported if the attribute is propagated in SYCL 1.2.1 mode. |
| 163 | + |
| 164 | + FunctorNoProp fNoProp; |
| 165 | + h.single_task<class kernel_3>(fNoProp); |
| 166 | + // CHECK: FunctionDecl {{.*}} {{.*}}kernel_3 |
| 167 | + // CHECK-NOT: WorkGroupSizeHintAttr |
| 168 | + |
| 169 | + }); |
| 170 | + |
| 171 | + // FIXME: Add tests with the C++23 lambda attribute syntax. |
| 172 | +} |
0 commit comments