From 7adf0bda0009f240ec19efbc1721c9e4cabb6333 Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Thu, 12 Sep 2024 17:37:12 +0900 Subject: [PATCH] Add an example to generate compile time errors --- examples/08_awful_usage/08_awful_usage.cpp | 80 ++++++++++++++++++++++ examples/08_awful_usage/CMakeLists.txt | 6 ++ examples/CMakeLists.txt | 1 + 3 files changed, 87 insertions(+) create mode 100644 examples/08_awful_usage/08_awful_usage.cpp create mode 100644 examples/08_awful_usage/CMakeLists.txt diff --git a/examples/08_awful_usage/08_awful_usage.cpp b/examples/08_awful_usage/08_awful_usage.cpp new file mode 100644 index 00000000..c08b57e6 --- /dev/null +++ b/examples/08_awful_usage/08_awful_usage.cpp @@ -0,0 +1,80 @@ +// SPDX-FileCopyrightText: (C) The Kokkos-FFT development team, see COPYRIGHT.md file +// +// SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception + +#include +#include +#include +#include + +using execution_space = Kokkos::DefaultExecutionSpace; +template +using View1D = Kokkos::View; + +template +using View2D = Kokkos::View; + +template +using View3D = Kokkos::View; + +template +using axis_type = KokkosFFT::axis_type; +template +using shape_type = KokkosFFT::shape_type; + +int main(int argc, char* argv[]) { + Kokkos::initialize(argc, argv); + { + constexpr int n0 = 128, n1 = 128, n2 = 16; + const Kokkos::complex I(1.0, 1.0); + + shape_type<3> shape; + shape[0] = n0; + shape[1] = n1; + shape[2] = n2; + + View1D > xc("xc", n0); + View2D > xc2("xc2", n0, n1); + View1D xr("xr", n0); + View2D xr2("xr2", n0, n1); + + Kokkos::Random_XorShift64_Pool<> random_pool(12345); + execution_space exec; + Kokkos::fill_random(exec, xc, random_pool, I); + exec.fence(); + +#if 0 + // Compilte time error for inconsistent types + // You will get the following compilation errors if you uncomment this block + // error: static assertion failed with "rfft: InViewType must be real" + // error: static assertion failed with "rfft: OutViewType must be complex" + KokkosFFT::rfft(exec, xc, xr); // Incorrect, input is complex and output is real + KokkosFFT::rfft(exec, xr, xc); // Correct, input is real and output is complex +#endif + +#if 0 + // Compilte time error if FFT rank > View rank (2D FFT on 1D View) + // You will get the following compilation errors if you uncomment this block + // error: static assertion failed with "rfft2: View rank must be larger than or equal to 2" + KokkosFFT::rfft2(exec, xr, xc); // Incorrect, input and output are 1D Views + KokkosFFT::rfft2(exec, xr2, xc2); // Correct, input and output are 2D Views +#endif + +#if 0 + // Compilte time error if FFT plan and execution is inconsistent + // You will get the following compilation errors if you uncomment this block + // error: static assertion failed with "Plan::good: InViewType for plan and execution are not identical." + // error: static assertion failed with "Plan::good: OutViewType for plan and execution are not identical." + int axis = -1; + KokkosFFT::Impl::Plan rfft_plan(exec, xr, xc, + KokkosFFT::Direction::forward, axis); + KokkosFFT::Impl::fft_exec_impl(rfft_plan, xc, xr); // Incorrect, input and output are reversed + KokkosFFT::Impl::fft_exec_impl(rfft_plan, xr, xc); // Correct, same input and output +#endif + + exec.fence(); + } + Kokkos::finalize(); + + return 0; +} diff --git a/examples/08_awful_usage/CMakeLists.txt b/examples/08_awful_usage/CMakeLists.txt new file mode 100644 index 00000000..5949ebdf --- /dev/null +++ b/examples/08_awful_usage/CMakeLists.txt @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: (C) The Kokkos-FFT development team, see COPYRIGHT.md file +# +# SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception + +add_executable(08_awful_usage 08_awful_usage.cpp) +target_link_libraries(08_awful_usage PUBLIC KokkosFFT::fft) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f587f4c2..27704f63 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -9,3 +9,4 @@ add_subdirectory(04_batchedFFT) add_subdirectory(05_1DFFT_HOST_DEVICE) add_subdirectory(06_1DFFT_reuse_plans) add_subdirectory(07_unmanaged_views) +add_subdirectory(08_awful_usage)