From b53a0a0a37d7924b2a0a3a44396a7a6dc783a089 Mon Sep 17 00:00:00 2001 From: KornevNikita Date: Fri, 7 Oct 2022 08:01:25 -0700 Subject: [PATCH 1/4] [SYCL] Test exception throwing for unsupported kernel feature --- ...throw-exception-for-unsupported-aspect.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp diff --git a/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp b/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp new file mode 100644 index 0000000000..5daf6ed39c --- /dev/null +++ b/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp @@ -0,0 +1,20 @@ +// RUN: %clangxx -fsycl -O0 %s -o %t.out + +// RUN: %CPU_RUN_PLACEHOLDER %t.out &> %t.txt +// RUN: FileCheck %s --input-file %t.txt + +// CHECK: Required aspect gpu is not supported on the device + +#include + +[[__sycl_detail__::__uses_aspects__(sycl::aspect::gpu)]] void foo() {} + +int main() { + sycl::queue q; + q.submit([&](sycl::handler &h) { + h.single_task([=]() { + foo(); + }); + }); + return 0; +} From f4bde376998cffe6f26b5ee6ac36a0771e105168 Mon Sep 17 00:00:00 2001 From: KornevNikita Date: Mon, 10 Oct 2022 07:06:23 -0700 Subject: [PATCH 2/4] Apply suggestion --- .../throw-exception-for-unsupported-aspect.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp b/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp index 5daf6ed39c..b9e100bf47 100644 --- a/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp +++ b/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp @@ -5,16 +5,17 @@ // CHECK: Required aspect gpu is not supported on the device +#include #include [[__sycl_detail__::__uses_aspects__(sycl::aspect::gpu)]] void foo() {} int main() { sycl::queue q; - q.submit([&](sycl::handler &h) { - h.single_task([=]() { - foo(); - }); - }); + try { + q.submit([&](sycl::handler &h) { h.single_task([=]() { foo(); }); }); + } catch (sycl::exception &e) { + std::cout << e.what() << std::endl; + } return 0; } From a3546a76f5d095a4c545f51850ad6d7b8eb14353 Mon Sep 17 00:00:00 2001 From: KornevNikita Date: Thu, 27 Oct 2022 08:52:25 -0700 Subject: [PATCH 3/4] Add "requires" string --- .../throw-exception-for-unsupported-aspect.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp b/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp index b9e100bf47..0056eae1e2 100644 --- a/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp +++ b/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp @@ -1,3 +1,5 @@ +// REQUIRES: cpu + // RUN: %clangxx -fsycl -O0 %s -o %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out &> %t.txt From 3b5a5a3dcda84e31ec501db04c72def0344c7e22 Mon Sep 17 00:00:00 2001 From: KornevNikita Date: Thu, 27 Oct 2022 11:02:18 -0700 Subject: [PATCH 4/4] Improvement --- .../throw-exception-for-unsupported-aspect.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp b/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp index 0056eae1e2..734052b346 100644 --- a/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp +++ b/SYCL/OptionalKernelFeatures/throw-exception-for-unsupported-aspect.cpp @@ -1,23 +1,22 @@ // REQUIRES: cpu // RUN: %clangxx -fsycl -O0 %s -o %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out -// RUN: %CPU_RUN_PLACEHOLDER %t.out &> %t.txt -// RUN: FileCheck %s --input-file %t.txt - -// CHECK: Required aspect gpu is not supported on the device - -#include #include -[[__sycl_detail__::__uses_aspects__(sycl::aspect::gpu)]] void foo() {} +[[sycl::device_has(sycl::aspect::gpu)]] void foo() {} int main() { sycl::queue q; try { q.submit([&](sycl::handler &h) { h.single_task([=]() { foo(); }); }); + q.wait(); } catch (sycl::exception &e) { - std::cout << e.what() << std::endl; + const char *ErrMsg = "Required aspect gpu is not supported on the device"; + if (std::string(e.what()).find(ErrMsg) != std::string::npos) { + return 0; + } } - return 0; + return 1; }