From 8c235ca6fd79e9e44a6502cfb5e3233a51940ccb Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Thu, 16 Mar 2023 10:12:30 -0700 Subject: [PATCH 1/3] [SYCL] Add test for relaxed fp64 aspect requirements This commit adds a test checking the expected behavior when the use of fp64 is and isn't optimized out of a kernel. Signed-off-by: Larsen, Steffen --- SYCL/OptionalKernelFeatures/fp64_relaxed.cpp | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 SYCL/OptionalKernelFeatures/fp64_relaxed.cpp diff --git a/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp b/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp new file mode 100644 index 0000000000..68f61d0f34 --- /dev/null +++ b/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp @@ -0,0 +1,41 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -O3 -DOPTIMIZATIONS_DISABLED=0 %s -o %t_opt.out +// RUN: %CPU_RUN_PLACEHOLDER %t_opt.out +// RUN: %GPU_RUN_PLACEHOLDER %t_opt.out +// RUN: %ACC_RUN_PLACEHOLDER %t_opt.out +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -O0 -DOPTIMIZATIONS_DISABLED=1 %s -o %t_noopt.out +// RUN: %CPU_RUN_PLACEHOLDER %t_noopt.out +// RUN: %GPU_RUN_PLACEHOLDER %t_noopt.out +// RUN: %ACC_RUN_PLACEHOLDER %t_noopt.out + +// Tests that aspect::fp64 requirements are affected by optimizations. + +#include + +int main() { + sycl::queue Q; + try { + Q.single_task([=]() { + // Double will be optimized out as LoweredFloat can be set directly to a + // lowered value. + double Double = 3.14; + volatile float LoweredFloat = Double; + }); +#if OPTIMIZATIONS_DISABLED + assert(Q.get_device().has(sycl::aspect::fp64) && + "Exception should have been thrown."); +#endif // OPTIMIZATIONS_DISABLED + } catch (sycl::exception &E) { + std::cout << "Caught exception: " << E.what() << std::endl; + assert(OPTIMIZATIONS_DISABLED && + "Optimizations should have removed the fp64 requirement."); + assert(!Q.get_device().has(sycl::aspect::fp64) && + "Exception thrown despite fp64 support."); + assert(E.code() == sycl::errc::kernel_not_supported && + "Exception thrown despite fp64 support."); + } catch (...) { + std::cout << "Unexpected exception thrown!" << std::endl; + throw; + } + + return 0; +} From d34ef9c6b883891327a1efe286be8ac14c1a64e2 Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Wed, 22 Mar 2023 08:11:31 -0700 Subject: [PATCH 2/3] Fix assert message and make check explicit Signed-off-by: Larsen, Steffen --- SYCL/OptionalKernelFeatures/fp64_relaxed.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp b/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp index 68f61d0f34..e8066d7bde 100644 --- a/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp +++ b/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp @@ -20,7 +20,7 @@ int main() { double Double = 3.14; volatile float LoweredFloat = Double; }); -#if OPTIMIZATIONS_DISABLED +#if (OPTIMIZATIONS_DISABLED == 1) assert(Q.get_device().has(sycl::aspect::fp64) && "Exception should have been thrown."); #endif // OPTIMIZATIONS_DISABLED @@ -31,7 +31,7 @@ int main() { assert(!Q.get_device().has(sycl::aspect::fp64) && "Exception thrown despite fp64 support."); assert(E.code() == sycl::errc::kernel_not_supported && - "Exception thrown despite fp64 support."); + "Exception did not have the expected error code."); } catch (...) { std::cout << "Unexpected exception thrown!" << std::endl; throw; From cd975959a5303c0552de76a9c74f8d3175aa688b Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Wed, 22 Mar 2023 12:25:42 -0700 Subject: [PATCH 3/3] Switch to no-sycl-early-optimizations to avoid unrecognized -O0 Signed-off-by: Larsen, Steffen --- SYCL/OptionalKernelFeatures/fp64_relaxed.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp b/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp index e8066d7bde..f225069e37 100644 --- a/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp +++ b/SYCL/OptionalKernelFeatures/fp64_relaxed.cpp @@ -1,8 +1,8 @@ -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -O3 -DOPTIMIZATIONS_DISABLED=0 %s -o %t_opt.out +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -DOPTIMIZATIONS_DISABLED=0 %s -o %t_opt.out // RUN: %CPU_RUN_PLACEHOLDER %t_opt.out // RUN: %GPU_RUN_PLACEHOLDER %t_opt.out // RUN: %ACC_RUN_PLACEHOLDER %t_opt.out -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -O0 -DOPTIMIZATIONS_DISABLED=1 %s -o %t_noopt.out +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fno-sycl-early-optimizations -DOPTIMIZATIONS_DISABLED=1 %s -o %t_noopt.out // RUN: %CPU_RUN_PLACEHOLDER %t_noopt.out // RUN: %GPU_RUN_PLACEHOLDER %t_noopt.out // RUN: %ACC_RUN_PLACEHOLDER %t_noopt.out