|
| 1 | +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2017 -Wno-sycl-2017-compat -verify -DTRIGGER_ERROR %s |
| 2 | +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2017 -Wno-sycl-2017-compat -ast-dump %s | FileCheck %s |
| 3 | + |
| 4 | +#include "sycl.hpp" |
| 5 | + |
| 6 | +using namespace cl::sycl; |
| 7 | +queue q; |
| 8 | + |
| 9 | +[[intel::reqd_sub_group_size(4)]] void foo() {} // expected-note {{conflicting attribute is here}} |
| 10 | +// expected-note@-1 {{conflicting attribute is here}} |
| 11 | +[[intel::reqd_sub_group_size(32)]] void baz() {} // expected-note {{conflicting attribute is here}} |
| 12 | + |
| 13 | +// No diagnostic is emitted because the arguments match. |
| 14 | +[[intel::reqd_sub_group_size(12)]] void bar(); |
| 15 | +[[intel::reqd_sub_group_size(12)]] void bar() {} // OK |
| 16 | + |
| 17 | +// No diagnostic because the attributes are synonyms with identical behavior. |
| 18 | +[[sycl::reqd_sub_group_size(12)]] void bar(); // OK |
| 19 | + |
| 20 | +// Diagnostic is emitted because the arguments mismatch. |
| 21 | +[[intel::reqd_sub_group_size(12)]] void quux(); // expected-note {{previous attribute is here}} |
| 22 | +[[intel::reqd_sub_group_size(100)]] void quux(); // expected-warning {{attribute 'reqd_sub_group_size' is already applied with different arguments}} expected-note {{previous attribute is here}} |
| 23 | +[[sycl::reqd_sub_group_size(200)]] void quux(); // expected-warning {{attribute 'reqd_sub_group_size' is already applied with different arguments}} |
| 24 | + |
| 25 | +#ifdef TRIGGER_ERROR |
| 26 | +// Make sure there's at least one argument passed. |
| 27 | +[[sycl::reqd_sub_group_size]] void quibble(); // expected-error {{'reqd_sub_group_size' attribute takes one argument}} |
| 28 | +#endif // TRIGGER_ERROR |
| 29 | + |
| 30 | +class Functor16 { |
| 31 | +public: |
| 32 | + [[intel::reqd_sub_group_size(16)]] void operator()() const {} |
| 33 | +}; |
| 34 | + |
| 35 | +class Functor8 { // expected-error {{conflicting attributes applied to a SYCL kernel}} |
| 36 | +public: |
| 37 | + [[intel::reqd_sub_group_size(8)]] void operator()() const { // expected-note {{conflicting attribute is here}} |
| 38 | + foo(); |
| 39 | + } |
| 40 | +}; |
| 41 | + |
| 42 | +class Functor4 { |
| 43 | +public: |
| 44 | + [[intel::reqd_sub_group_size(12)]] void operator()() const {} |
| 45 | +}; |
| 46 | + |
| 47 | +class Functor { |
| 48 | +public: |
| 49 | + void operator()() const { |
| 50 | + foo(); |
| 51 | + } |
| 52 | +}; |
| 53 | + |
| 54 | +int main() { |
| 55 | + q.submit([&](handler &h) { |
| 56 | + Functor16 f16; |
| 57 | + h.single_task<class kernel_name1>(f16); |
| 58 | + |
| 59 | + Functor f; |
| 60 | + h.single_task<class kernel_name2>(f); |
| 61 | + |
| 62 | +#ifdef TRIGGER_ERROR |
| 63 | + Functor8 f8; |
| 64 | + h.single_task<class kernel_name3>(f8); |
| 65 | + |
| 66 | + h.single_task<class kernel_name4>([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} |
| 67 | + foo(); |
| 68 | + baz(); |
| 69 | + }); |
| 70 | +#endif |
| 71 | + |
| 72 | + h.single_task<class kernel_name5>([]() [[intel::reqd_sub_group_size(2)]]{}); |
| 73 | + h.single_task<class kernel_name6>([]() [[intel::reqd_sub_group_size(4)]] { foo(); }); |
| 74 | + h.single_task<class kernel_name7>([]() [[intel::reqd_sub_group_size(6)]]{}); |
| 75 | + |
| 76 | + Functor4 f4; |
| 77 | + h.single_task<class kernel_name8>(f4); |
| 78 | + }); |
| 79 | + return 0; |
| 80 | +} |
| 81 | + |
| 82 | +[[intel::reqd_sub_group_size(16)]] SYCL_EXTERNAL void B(); |
| 83 | +[[intel::reqd_sub_group_size(16)]] void A() { |
| 84 | +} |
| 85 | + |
| 86 | +[[intel::reqd_sub_group_size(16)]] SYCL_EXTERNAL void B() { |
| 87 | + A(); |
| 88 | +} |
| 89 | + |
| 90 | +#ifdef TRIGGER_ERROR |
| 91 | +// expected-note@+1 {{conflicting attribute is here}} |
| 92 | +[[intel::reqd_sub_group_size(2)]] void sg_size2() {} |
| 93 | + |
| 94 | +// expected-note@+2 {{conflicting attribute is here}} |
| 95 | +// expected-error@+1 {{conflicting attributes applied to a SYCL kernel}} |
| 96 | +[[intel::reqd_sub_group_size(4)]] __attribute__((sycl_device)) void sg_size4() { |
| 97 | + sg_size2(); |
| 98 | +} |
| 99 | +#endif |
| 100 | + |
| 101 | +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1 |
| 102 | +// CHECK: IntelReqdSubGroupSizeAttr {{.*}} |
| 103 | +// CHECK-NEXT: ConstantExpr {{.*}} 'int' |
| 104 | +// CHECK-NEXT: value: Int 16 |
| 105 | +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} |
| 106 | +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2 |
| 107 | +// CHECK: IntelReqdSubGroupSizeAttr {{.*}} |
| 108 | +// CHECK-NEXT: ConstantExpr {{.*}} 'int' |
| 109 | +// CHECK-NEXT: value: Int 4 |
| 110 | +// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} |
| 111 | +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5 |
| 112 | +// CHECK: IntelReqdSubGroupSizeAttr {{.*}} |
| 113 | +// CHECK-NEXT: ConstantExpr {{.*}} 'int' |
| 114 | +// CHECK-NEXT: value: Int 2 |
| 115 | +// CHECK-NEXT: IntegerLiteral{{.*}}2{{$}} |
| 116 | +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name7 |
| 117 | +// CHECK: IntelReqdSubGroupSizeAttr {{.*}} |
| 118 | +// CHECK-NEXT: ConstantExpr {{.*}} 'int' |
| 119 | +// CHECK-NEXT: value: Int 6 |
| 120 | +// CHECK-NEXT: IntegerLiteral{{.*}}6{{$}} |
| 121 | +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name8 |
| 122 | +// CHECK: IntelReqdSubGroupSizeAttr {{.*}} |
| 123 | +// CHECK-NEXT: ConstantExpr {{.*}} 'int' |
| 124 | +// CHECK-NEXT: value: Int 12 |
| 125 | +// CHECK-NEXT: IntegerLiteral{{.*}}12{{$}} |
0 commit comments