From fd4591cfe194b0cf65d8e94ce3e5e223392b5c57 Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Fri, 19 Jun 2020 00:36:03 -0700 Subject: [PATCH 01/11] [SYCL] Fixing comment about propagation of attributes to kernel --- clang/lib/Sema/SemaSYCL.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 8cbd33b279e8f..09511b5fcc411 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -516,10 +516,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor { Attrs.insert(A); if (auto *A = FD->getAttr()) Attrs.insert(A); - // Allow the following kernel attributes only on lambda functions and - // function objects that are called directly from a kernel (i.e. the one - // passed to the parallel_for function). For all other cases, - // emit a warning and ignore. + // Allow the following kernel attributes only on lambdas, functions and + // function objects that are called directly from a kernel. + // For all other cases, emit a warning and ignore. if (auto *A = FD->getAttr()) { if (ParentFD == SYCLKernel) { Attrs.insert(A); From 6b5d4a913b561fc22622325936d02a86f0606c17 Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Fri, 19 Jun 2020 00:36:03 -0700 Subject: [PATCH 02/11] [SYCL] Fixing comment about propagation of attributes to kernel --- .../check-indirect-attribute-propagation.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 clang/test/SemaSYCL/check-indirect-attribute-propagation.cpp diff --git a/clang/test/SemaSYCL/check-indirect-attribute-propagation.cpp b/clang/test/SemaSYCL/check-indirect-attribute-propagation.cpp new file mode 100644 index 0000000000000..532fff4e38f3a --- /dev/null +++ b/clang/test/SemaSYCL/check-indirect-attribute-propagation.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl -fsycl-is-device -verify %s + +[[intelfpga::no_global_work_offset]] void indirect_func() {} //expected-warning {{'no_global_work_offset' attribute ignored}} + +void func() { indirect_func(); } + +template +[[clang::sycl_kernel]] void __my_kernel__(Type bar) { + bar(); + func(); +} + +template +void parallel_for(Type lambda) { + __my_kernel__(lambda); +} + +void invoke_foo2() { + parallel_for([]() {}); +} From 3857f545064206f2c9e9650e02bd9eccb37e7298 Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Fri, 19 Jun 2020 00:36:03 -0700 Subject: [PATCH 03/11] [SYCL] Fixing comment about propagation of attributes to kernel Also adding a test to check that the kernel does not get attributes from functions that are not directly called by it. --- .../check-notdirect-attribute-propagation.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp diff --git a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp new file mode 100644 index 0000000000000..ed859f12e46a1 --- /dev/null +++ b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl -fsycl-is-device -verify %s + +[[intelfpga::no_global_work_offset]] void not_direct() {} //expected-warning {{'no_global_work_offset' attribute ignored}} + +void func() { not_direct(); } + +template +[[clang::sycl_kernel]] void __my_kernel__(Type bar) { + bar(); + func(); +} + +template +void parallel_for(Type lambda) { + __my_kernel__(lambda); +} + +void invoke_foo2() { + parallel_for([]() {}); +} From ef2deeabea1c4feb0da8f4f7f71be21e6ea7e646 Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Thu, 9 Jul 2020 21:33:10 -0700 Subject: [PATCH 04/11] Propagate attributes from transitive calls to kernel - Remove the (incorrect) distinction between direct and transitive calls for the propagation of attributes to kernel - Add a test showing propagation of attributes from transitive call to kernel --- clang/lib/Sema/SemaSYCL.cpp | 60 ++++++------------- .../check-notdirect-attribute-propagation.cpp | 2 +- 2 files changed, 18 insertions(+), 44 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 09511b5fcc411..9bda485d47a74 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -514,51 +514,25 @@ class MarkDeviceFunction : public RecursiveASTVisitor { if (auto *A = FD->getAttr()) Attrs.insert(A); + if (auto *A = FD->getAttr()) Attrs.insert(A); - // Allow the following kernel attributes only on lambdas, functions and - // function objects that are called directly from a kernel. - // For all other cases, emit a warning and ignore. - if (auto *A = FD->getAttr()) { - if (ParentFD == SYCLKernel) { - Attrs.insert(A); - } else { - SemaRef.Diag(A->getLocation(), diag::warn_attribute_ignored) << A; - FD->dropAttr(); - } - } - if (auto *A = FD->getAttr()) { - if (ParentFD == SYCLKernel) { - Attrs.insert(A); - } else { - SemaRef.Diag(A->getLocation(), diag::warn_attribute_ignored) << A; - FD->dropAttr(); - } - } - if (auto *A = FD->getAttr()) { - if (ParentFD == SYCLKernel) { - Attrs.insert(A); - } else { - SemaRef.Diag(A->getLocation(), diag::warn_attribute_ignored) << A; - FD->dropAttr(); - } - } - if (auto *A = FD->getAttr()) { - if (ParentFD == SYCLKernel) { - Attrs.insert(A); - } else { - SemaRef.Diag(A->getLocation(), diag::warn_attribute_ignored) << A; - FD->dropAttr(); - } - } - if (auto *A = FD->getAttr()) { - if (ParentFD == SYCLKernel) { - Attrs.insert(A); - } else { - SemaRef.Diag(A->getLocation(), diag::warn_attribute_ignored) << A; - FD->dropAttr(); - } - } + + if (auto *A = FD->getAttr()) + Attrs.insert(A); + + if (auto *A = FD->getAttr()) + Attrs.insert(A); + + if (auto *A = FD->getAttr()) + Attrs.insert(A); + + if (auto *A = FD->getAttr()) + Attrs.insert(A); + + if (auto *A = FD->getAttr()) + Attrs.insert(A); + if (auto *A = FD->getAttr()) Attrs.insert(A); // Propagate the explicit SIMD attribute through call graph - it is used diff --git a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp index ed859f12e46a1..9d369b0e098a9 100644 --- a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp +++ b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl -fsycl-is-device -verify %s -[[intelfpga::no_global_work_offset]] void not_direct() {} //expected-warning {{'no_global_work_offset' attribute ignored}} +[[intelfpga::no_global_work_offset]] void not_direct() {} // expected-no-warning void func() { not_direct(); } From 3426ef0fc17cfb7d604da655fe41ef1f4fe11c2b Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Fri, 10 Jul 2020 16:55:37 -0700 Subject: [PATCH 05/11] Correct failing lit tests --- .../SemaSYCL/check-notdirect-attribute-propagation.cpp | 7 +++++-- clang/test/SemaSYCL/intel-max-global-work-dim.cpp | 2 +- clang/test/SemaSYCL/intel-max-work-group-size.cpp | 2 +- clang/test/SemaSYCL/intel-restrict.cpp | 2 +- clang/test/SemaSYCL/num_simd_work_items.cpp | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp index 9d369b0e098a9..46702f979a822 100644 --- a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp +++ b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl -fsycl-is-device -verify %s +// RUN: %clang %s -fsyntax-only -Xclang -ast-dump -fsycl-device-only | FileCheck %s -[[intelfpga::no_global_work_offset]] void not_direct() {} // expected-no-warning +[[intelfpga::no_global_work_offset]] void not_direct() {} void func() { not_direct(); } @@ -16,5 +16,8 @@ void parallel_for(Type lambda) { } void invoke_foo2() { + // CHECK-LABEL: FunctionDecl {{.*}} invoke_foo2 'void ()' + // CHECK: `-FunctionDecl {{.*}} _ZTSZ11invoke_foo2vE10KernelName 'void ()' + // CHECK: -SYCLIntelNoGlobalWorkOffsetAttr {{.*}} Enabled parallel_for([]() {}); } diff --git a/clang/test/SemaSYCL/intel-max-global-work-dim.cpp b/clang/test/SemaSYCL/intel-max-global-work-dim.cpp index 85db992f46cca..49bfe5ed7179a 100644 --- a/clang/test/SemaSYCL/intel-max-global-work-dim.cpp +++ b/clang/test/SemaSYCL/intel-max-global-work-dim.cpp @@ -20,7 +20,7 @@ void foo() { #else // __SYCL_DEVICE_ONLY__ -[[intelfpga::max_global_work_dim(2)]] // expected-warning{{'max_global_work_dim' attribute ignored}} +[[intelfpga::max_global_work_dim(2)]] void func_ignore() {} struct FuncObj { diff --git a/clang/test/SemaSYCL/intel-max-work-group-size.cpp b/clang/test/SemaSYCL/intel-max-work-group-size.cpp index 441c1fea7df7e..792c01ca7371a 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size.cpp @@ -20,7 +20,7 @@ void foo() { #else // __SYCL_DEVICE_ONLY__ -[[intelfpga::max_work_group_size(2, 2, 2)]] // expected-warning{{'max_work_group_size' attribute ignored}} +[[intelfpga::max_work_group_size(2, 2, 2)]] void func_ignore() {} struct FuncObj { diff --git a/clang/test/SemaSYCL/intel-restrict.cpp b/clang/test/SemaSYCL/intel-restrict.cpp index 810e7b0b3a5d3..981f5862989f0 100644 --- a/clang/test/SemaSYCL/intel-restrict.cpp +++ b/clang/test/SemaSYCL/intel-restrict.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 %s -fsyntax-only -fsycl -fsycl-is-device -triple spir64 -DCHECKDIAG -verify // RUN: %clang_cc1 %s -fsyntax-only -ast-dump -fsycl -fsycl-is-device -triple spir64 | FileCheck %s -[[intel::kernel_args_restrict]] // expected-warning{{'kernel_args_restrict' attribute ignored}} +[[intel::kernel_args_restrict]] void func_ignore() {} struct FuncObj { diff --git a/clang/test/SemaSYCL/num_simd_work_items.cpp b/clang/test/SemaSYCL/num_simd_work_items.cpp index 4eaf95080e275..0491dab5615bc 100644 --- a/clang/test/SemaSYCL/num_simd_work_items.cpp +++ b/clang/test/SemaSYCL/num_simd_work_items.cpp @@ -20,7 +20,7 @@ void foo() { #else // __SYCL_DEVICE_ONLY__ -[[intelfpga::num_simd_work_items(2)]] // expected-warning{{'num_simd_work_items' attribute ignored}} +[[intelfpga::num_simd_work_items(2)]] void func_ignore() {} struct FuncObj { From acb7a655c70d52173f4b9efec25ad18f437f4899 Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Mon, 13 Jul 2020 12:48:42 -0700 Subject: [PATCH 06/11] Minor changes to address comments and resolve branch merge conflicts --- .../check-indirect-attribute-propagation.cpp | 20 ------------------- .../check-notdirect-attribute-propagation.cpp | 6 +++--- .../SemaSYCL/intel-max-global-work-dim.cpp | 6 +++--- .../SemaSYCL/intel-max-work-group-size.cpp | 6 +++--- clang/test/SemaSYCL/intel-restrict.cpp | 6 +++--- clang/test/SemaSYCL/num_simd_work_items.cpp | 6 +++--- 6 files changed, 15 insertions(+), 35 deletions(-) delete mode 100644 clang/test/SemaSYCL/check-indirect-attribute-propagation.cpp diff --git a/clang/test/SemaSYCL/check-indirect-attribute-propagation.cpp b/clang/test/SemaSYCL/check-indirect-attribute-propagation.cpp deleted file mode 100644 index 532fff4e38f3a..0000000000000 --- a/clang/test/SemaSYCL/check-indirect-attribute-propagation.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl -fsycl-is-device -verify %s - -[[intelfpga::no_global_work_offset]] void indirect_func() {} //expected-warning {{'no_global_work_offset' attribute ignored}} - -void func() { indirect_func(); } - -template -[[clang::sycl_kernel]] void __my_kernel__(Type bar) { - bar(); - func(); -} - -template -void parallel_for(Type lambda) { - __my_kernel__(lambda); -} - -void invoke_foo2() { - parallel_for([]() {}); -} diff --git a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp index 46702f979a822..a36bb3e70f9da 100644 --- a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp +++ b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp @@ -1,4 +1,4 @@ -// RUN: %clang %s -fsyntax-only -Xclang -ast-dump -fsycl-device-only | FileCheck %s +// RUN: %clang_cc1 %s -fsyntax-only -ast-dump -fsycl -fsycl-is-device -triple spir64 | FileCheck %s [[intelfpga::no_global_work_offset]] void not_direct() {} @@ -17,7 +17,7 @@ void parallel_for(Type lambda) { void invoke_foo2() { // CHECK-LABEL: FunctionDecl {{.*}} invoke_foo2 'void ()' - // CHECK: `-FunctionDecl {{.*}} _ZTSZ11invoke_foo2vE10KernelName 'void ()' - // CHECK: -SYCLIntelNoGlobalWorkOffsetAttr {{.*}} Enabled + // CHECK: `-FunctionDecl {{.*}}KernelName 'void ()' + // CHECK: -SYCLIntelNoGlobalWorkOffsetAttr {{.*}} Enabled parallel_for([]() {}); } diff --git a/clang/test/SemaSYCL/intel-max-global-work-dim.cpp b/clang/test/SemaSYCL/intel-max-global-work-dim.cpp index 49bfe5ed7179a..3b3e9d4e47cf1 100644 --- a/clang/test/SemaSYCL/intel-max-global-work-dim.cpp +++ b/clang/test/SemaSYCL/intel-max-global-work-dim.cpp @@ -21,7 +21,7 @@ void foo() { #else // __SYCL_DEVICE_ONLY__ [[intelfpga::max_global_work_dim(2)]] -void func_ignore() {} +void func_do_not_ignore() {} struct FuncObj { [[intelfpga::max_global_work_dim(1)]] @@ -68,9 +68,9 @@ int main() { []() [[intelfpga::max_global_work_dim(2)]] {}); // CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 - // CHECK-NOT: SYCLIntelMaxGlobalWorkDimAttr {{.*}} + // CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}} kernel( - []() {func_ignore();}); + []() {func_do_not_ignore();}); kernel( TRIFuncObjGood1()); diff --git a/clang/test/SemaSYCL/intel-max-work-group-size.cpp b/clang/test/SemaSYCL/intel-max-work-group-size.cpp index 792c01ca7371a..bce07a6b5ea2d 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size.cpp @@ -21,7 +21,7 @@ void foo() { #else // __SYCL_DEVICE_ONLY__ [[intelfpga::max_work_group_size(2, 2, 2)]] -void func_ignore() {} +void func_do_not_ignore() {} struct FuncObj { [[intelfpga::max_work_group_size(4, 4, 4)]] @@ -53,9 +53,9 @@ int main() { []() [[intelfpga::max_work_group_size(8, 8, 8)]] {}); // CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 - // CHECK-NOT: SYCLIntelMaxWorkGroupSizeAttr {{.*}} + // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} kernel( - []() {func_ignore();}); + []() {func_do_not_ignore();}); #ifdef TRIGGER_ERROR [[intelfpga::max_work_group_size(1, 1, 1)]] int Var = 0; // expected-error{{'max_work_group_size' attribute only applies to functions}} diff --git a/clang/test/SemaSYCL/intel-restrict.cpp b/clang/test/SemaSYCL/intel-restrict.cpp index 981f5862989f0..fa65ff6621bc2 100644 --- a/clang/test/SemaSYCL/intel-restrict.cpp +++ b/clang/test/SemaSYCL/intel-restrict.cpp @@ -2,7 +2,7 @@ // RUN: %clang_cc1 %s -fsyntax-only -ast-dump -fsycl -fsycl-is-device -triple spir64 | FileCheck %s [[intel::kernel_args_restrict]] -void func_ignore() {} +void func_do_not_ignore() {} struct FuncObj { [[intel::kernel_args_restrict]] @@ -29,7 +29,7 @@ int main() { []() [[intel::kernel_args_restrict]] {}); // CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 - // CHECK-NOT: SYCLIntelKernelArgsRestrictAttr + // CHECK: SYCLIntelKernelArgsRestrictAttr kernel( - []() {func_ignore();}); + []() {func_do_not_ignore();}); } diff --git a/clang/test/SemaSYCL/num_simd_work_items.cpp b/clang/test/SemaSYCL/num_simd_work_items.cpp index 0491dab5615bc..006e9bbb0d3a3 100644 --- a/clang/test/SemaSYCL/num_simd_work_items.cpp +++ b/clang/test/SemaSYCL/num_simd_work_items.cpp @@ -21,7 +21,7 @@ void foo() { #else // __SYCL_DEVICE_ONLY__ [[intelfpga::num_simd_work_items(2)]] -void func_ignore() {} +void func_do_not_ignore() {} struct FuncObj { [[intelfpga::num_simd_work_items(42)]] @@ -45,9 +45,9 @@ int main() { []() [[intelfpga::num_simd_work_items(8)]] {}); // CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 - // CHECK-NOT: SYCLIntelNumSimdWorkItemsAttr {{.*}} 2 + // CHECK: SYCLIntelNumSimdWorkItemsAttr {{.*}} 2 kernel( - []() {func_ignore();}); + []() {func_do_not_ignore();}); #ifdef TRIGGER_ERROR [[intelfpga::num_simd_work_items(0)]] int Var = 0; // expected-error{{'num_simd_work_items' attribute only applies to functions}} From eb3a32e340ef69ed876529b00c07cb0327b3cdc9 Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Tue, 14 Jul 2020 10:19:39 -0700 Subject: [PATCH 07/11] Fix formatting issues reported by clang-format-check bot --- clang/test/SemaSYCL/intel-max-global-work-dim.cpp | 5 ++--- clang/test/SemaSYCL/intel-max-work-group-size.cpp | 5 ++--- clang/test/SemaSYCL/intel-restrict.cpp | 5 ++--- clang/test/SemaSYCL/num_simd_work_items.cpp | 5 ++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/clang/test/SemaSYCL/intel-max-global-work-dim.cpp b/clang/test/SemaSYCL/intel-max-global-work-dim.cpp index 3b3e9d4e47cf1..d391924773f1e 100644 --- a/clang/test/SemaSYCL/intel-max-global-work-dim.cpp +++ b/clang/test/SemaSYCL/intel-max-global-work-dim.cpp @@ -20,8 +20,7 @@ void foo() { #else // __SYCL_DEVICE_ONLY__ -[[intelfpga::max_global_work_dim(2)]] -void func_do_not_ignore() {} +[[intelfpga::max_global_work_dim(2)]] void func_do_not_ignore() {} struct FuncObj { [[intelfpga::max_global_work_dim(1)]] @@ -70,7 +69,7 @@ int main() { // CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 // CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}} kernel( - []() {func_do_not_ignore();}); + []() { func_do_not_ignore(); }); kernel( TRIFuncObjGood1()); diff --git a/clang/test/SemaSYCL/intel-max-work-group-size.cpp b/clang/test/SemaSYCL/intel-max-work-group-size.cpp index bce07a6b5ea2d..f5b2a67599e8b 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size.cpp @@ -20,8 +20,7 @@ void foo() { #else // __SYCL_DEVICE_ONLY__ -[[intelfpga::max_work_group_size(2, 2, 2)]] -void func_do_not_ignore() {} +[[intelfpga::max_work_group_size(2, 2, 2)]] void func_do_not_ignore() {} struct FuncObj { [[intelfpga::max_work_group_size(4, 4, 4)]] @@ -55,7 +54,7 @@ int main() { // CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} kernel( - []() {func_do_not_ignore();}); + []() { func_do_not_ignore(); }); #ifdef TRIGGER_ERROR [[intelfpga::max_work_group_size(1, 1, 1)]] int Var = 0; // expected-error{{'max_work_group_size' attribute only applies to functions}} diff --git a/clang/test/SemaSYCL/intel-restrict.cpp b/clang/test/SemaSYCL/intel-restrict.cpp index fa65ff6621bc2..b998b261f4320 100644 --- a/clang/test/SemaSYCL/intel-restrict.cpp +++ b/clang/test/SemaSYCL/intel-restrict.cpp @@ -1,8 +1,7 @@ // RUN: %clang_cc1 %s -fsyntax-only -fsycl -fsycl-is-device -triple spir64 -DCHECKDIAG -verify // RUN: %clang_cc1 %s -fsyntax-only -ast-dump -fsycl -fsycl-is-device -triple spir64 | FileCheck %s -[[intel::kernel_args_restrict]] -void func_do_not_ignore() {} +[[intel::kernel_args_restrict]] void func_do_not_ignore() {} struct FuncObj { [[intel::kernel_args_restrict]] @@ -31,5 +30,5 @@ int main() { // CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 // CHECK: SYCLIntelKernelArgsRestrictAttr kernel( - []() {func_do_not_ignore();}); + []() { func_do_not_ignore(); }); } diff --git a/clang/test/SemaSYCL/num_simd_work_items.cpp b/clang/test/SemaSYCL/num_simd_work_items.cpp index 006e9bbb0d3a3..638539917a283 100644 --- a/clang/test/SemaSYCL/num_simd_work_items.cpp +++ b/clang/test/SemaSYCL/num_simd_work_items.cpp @@ -20,8 +20,7 @@ void foo() { #else // __SYCL_DEVICE_ONLY__ -[[intelfpga::num_simd_work_items(2)]] -void func_do_not_ignore() {} +[[intelfpga::num_simd_work_items(2)]] void func_do_not_ignore() {} struct FuncObj { [[intelfpga::num_simd_work_items(42)]] @@ -47,7 +46,7 @@ int main() { // CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 // CHECK: SYCLIntelNumSimdWorkItemsAttr {{.*}} 2 kernel( - []() {func_do_not_ignore();}); + []() { func_do_not_ignore(); }); #ifdef TRIGGER_ERROR [[intelfpga::num_simd_work_items(0)]] int Var = 0; // expected-error{{'num_simd_work_items' attribute only applies to functions}} From 49c747ce52e0adc6347d7d1761be962239e15eba Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Mon, 20 Jul 2020 14:24:20 -0700 Subject: [PATCH 08/11] Add diagnostics for conflicting attributes from transitive calls --- clang/lib/Sema/SemaSYCL.cpp | 28 ++++++++++++- .../check-notdirect-attribute-propagation.cpp | 39 +++++++++++++++++-- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 9bda485d47a74..6342293c3d4db 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2027,6 +2027,33 @@ void Sema::MarkDevice(void) { Diag(Attr->getLocation(), diag::note_conflicting_attribute); SYCLKernel->setInvalidDecl(); } + } else if (auto *Existing = SYCLKernel->getAttr()) { + if (Existing->getXDim() < Attr->getXDim() || + Existing->getYDim() < Attr->getYDim() || + Existing->getZDim() < Attr->getZDim()) { + Diag(SYCLKernel->getLocation(), + diag::err_conflicting_sycl_kernel_attributes); + Diag(Existing->getLocation(), diag::note_conflicting_attribute); + Diag(Attr->getLocation(), diag::note_conflicting_attribute); + SYCLKernel->setInvalidDecl(); + } + } else { + SYCLKernel->addAttr(A); + } + break; + } + case attr::Kind::SYCLIntelMaxWorkGroupSize: { + auto *Attr = cast(A); + if (auto *Existing = SYCLKernel->getAttr()) { + if (Existing->getXDim() > Attr->getXDim() || + Existing->getYDim() > Attr->getYDim() || + Existing->getZDim() > Attr->getZDim()) { + Diag(SYCLKernel->getLocation(), + diag::err_conflicting_sycl_kernel_attributes); + Diag(Existing->getLocation(), diag::note_conflicting_attribute); + Diag(Attr->getLocation(), diag::note_conflicting_attribute); + SYCLKernel->setInvalidDecl(); + } } else { SYCLKernel->addAttr(A); } @@ -2035,7 +2062,6 @@ void Sema::MarkDevice(void) { case attr::Kind::SYCLIntelKernelArgsRestrict: case attr::Kind::SYCLIntelNumSimdWorkItems: case attr::Kind::SYCLIntelMaxGlobalWorkDim: - case attr::Kind::SYCLIntelMaxWorkGroupSize: case attr::Kind::SYCLIntelNoGlobalWorkOffset: case attr::Kind::SYCLSimd: { if ((A->getKind() == attr::Kind::SYCLSimd) && KernelBody && diff --git a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp index a36bb3e70f9da..18080f75b444c 100644 --- a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp +++ b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp @@ -1,13 +1,39 @@ +// RUN: %clang_cc1 %s -fsyntax-only -fsycl -fsycl-is-device -triple spir64 -verify +// RUN: %clang_cc1 %s -fsyntax-only -fsycl -fsycl-is-device -triple spir64 -DTRIGGER_ERROR -verify // RUN: %clang_cc1 %s -fsyntax-only -ast-dump -fsycl -fsycl-is-device -triple spir64 | FileCheck %s -[[intelfpga::no_global_work_offset]] void not_direct() {} +#ifndef TRIGGER_ERROR +[[intelfpga::no_global_work_offset]] void not_direct_one() {} // expected-no-diagnostics -void func() { not_direct(); } +[[cl::intel_reqd_sub_group_size(1)]] void func_one() { + not_direct_one(); +} + +#else +[[cl::reqd_work_group_size(2, 2, 2)]] void not_direct_two() {} // expected-note {{conflicting attribute is here}} + +[[intelfpga::max_work_group_size(1, 1, 1)]] // expected-note {{conflicting attribute is here}} +void +func_two() { + not_direct_two(); +} + +[[cl::reqd_work_group_size(4, 4, 4)]] // expected-note 2 {{conflicting attribute is here}} +void +func_three() { + not_direct_two(); +} +#endif template [[clang::sycl_kernel]] void __my_kernel__(Type bar) { bar(); - func(); +#ifndef TRIGGER_ERROR + func_one(); +#else + func_two(); + func_three(); +#endif } template @@ -16,8 +42,13 @@ void parallel_for(Type lambda) { } void invoke_foo2() { +#ifndef TRIGGER_ERROR // CHECK-LABEL: FunctionDecl {{.*}} invoke_foo2 'void ()' // CHECK: `-FunctionDecl {{.*}}KernelName 'void ()' - // CHECK: -SYCLIntelNoGlobalWorkOffsetAttr {{.*}} Enabled + // CHECK: -IntelReqdSubGroupSizeAttr {{.*}} + // CHECK: `-SYCLIntelNoGlobalWorkOffsetAttr {{.*}} Enabled parallel_for([]() {}); +#else + parallel_for([]() {}); // expected-error 2 {{conflicting attributes applied to a SYCL kernel or SYCL_EXTERNAL function}} +#endif } From e3e79b11b97bb1aeeb65e5c795353507b247d750 Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Tue, 21 Jul 2020 13:58:41 -0700 Subject: [PATCH 09/11] Fix formatting --- clang/lib/Sema/SemaSYCL.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 6342293c3d4db..71e9bc00f16ce 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2027,7 +2027,8 @@ void Sema::MarkDevice(void) { Diag(Attr->getLocation(), diag::note_conflicting_attribute); SYCLKernel->setInvalidDecl(); } - } else if (auto *Existing = SYCLKernel->getAttr()) { + } else if (auto *Existing = + SYCLKernel->getAttr()) { if (Existing->getXDim() < Attr->getXDim() || Existing->getYDim() < Attr->getYDim() || Existing->getZDim() < Attr->getZDim()) { From 882b3d004f9b4ce11637a9b3acaec19ecec3e799 Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Fri, 24 Jul 2020 11:19:59 -0700 Subject: [PATCH 10/11] Fix lit test failure caused by newer commits to repo --- clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp index 18080f75b444c..3dd98f12b0120 100644 --- a/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp +++ b/clang/test/SemaSYCL/check-notdirect-attribute-propagation.cpp @@ -5,7 +5,7 @@ #ifndef TRIGGER_ERROR [[intelfpga::no_global_work_offset]] void not_direct_one() {} // expected-no-diagnostics -[[cl::intel_reqd_sub_group_size(1)]] void func_one() { +[[intel::reqd_sub_group_size(1)]] void func_one() { not_direct_one(); } From 1735df42727bb3175b30021435683fb23af0a1b4 Mon Sep 17 00:00:00 2001 From: Sindhu Chittireddy Date: Mon, 27 Jul 2020 16:03:22 -0700 Subject: [PATCH 11/11] Fix the bug causing lit test failure --- clang/lib/Sema/SemaSYCL.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 71e9bc00f16ce..710afe5f543f2 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2037,6 +2037,8 @@ void Sema::MarkDevice(void) { Diag(Existing->getLocation(), diag::note_conflicting_attribute); Diag(Attr->getLocation(), diag::note_conflicting_attribute); SYCLKernel->setInvalidDecl(); + } else { + SYCLKernel->addAttr(A); } } else { SYCLKernel->addAttr(A); @@ -2054,6 +2056,8 @@ void Sema::MarkDevice(void) { Diag(Existing->getLocation(), diag::note_conflicting_attribute); Diag(Attr->getLocation(), diag::note_conflicting_attribute); SYCLKernel->setInvalidDecl(); + } else { + SYCLKernel->addAttr(A); } } else { SYCLKernel->addAttr(A);