From b09b2ba25dfbffd44329d39ee943b41e33255917 Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Sun, 13 Oct 2024 12:26:28 +0200 Subject: [PATCH 1/8] Make a 1d full normalization --- include/ddc/kernels/fft.hpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/include/ddc/kernels/fft.hpp b/include/ddc/kernels/fft.hpp index afe93271e..e2e79a5da 100644 --- a/include/ddc/kernels/fft.hpp +++ b/include/ddc/kernels/fft.hpp @@ -176,6 +176,21 @@ void rescale( }); } +template +Real forward_full_norm_coef(DiscreteDomain const& ddom) noexcept +{ + return (coordinate(ddom.back()) - coordinate(ddom.front())) + / (ddc::get(ddom.extents()) - 1) / Kokkos::sqrt(2 * Kokkos::numbers::pi); +} + +template +Real backward_full_norm_coef(DiscreteDomain const& ddom) noexcept +{ + return Kokkos::sqrt(2 * Kokkos::numbers::pi) + / (coordinate(ddom.back()) - coordinate(ddom.front())) + * (ddc::get(ddom.extents()) - 1) / ddc::get(ddom.extents()); +} + /// @brief Core internal function to perform the FFT. template < typename Tin, @@ -257,20 +272,9 @@ void impl( if (kwargs.normalization == ddc::FFT_Normalization::FULL) { real_type_t norm_coef; if (kwargs.direction == ddc::FFT_Direction::FORWARD) { - norm_coef - = (((coordinate(ddc::select(in.domain()).back()) - - coordinate(ddc::select(in.domain()).front())) - / (ddc::get(in.domain().extents()) - 1) - / Kokkos::sqrt(2 * Kokkos::numbers::pi)) - * ...); + norm_coef = (forward_full_norm_coef(ddc::select(in.domain())) * ...); } else { - norm_coef - = ((Kokkos::sqrt(2 * Kokkos::numbers::pi) - / (coordinate(ddc::select(out.domain()).back()) - - coordinate(ddc::select(out.domain()).front())) - * (ddc::get(out.domain().extents()) - 1) - / ddc::get(out.domain().extents())) - * ...); + norm_coef = (backward_full_norm_coef(ddc::select(out.domain())) * ...); } rescale(exec_space, out, norm_coef); From c9a0854a6d24c6141985126323b846c6fd3208ba Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Sun, 13 Oct 2024 12:29:51 +0200 Subject: [PATCH 2/8] Remove usage of the select function --- include/ddc/kernels/fft.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/ddc/kernels/fft.hpp b/include/ddc/kernels/fft.hpp index e2e79a5da..33e63da02 100644 --- a/include/ddc/kernels/fft.hpp +++ b/include/ddc/kernels/fft.hpp @@ -272,9 +272,11 @@ void impl( if (kwargs.normalization == ddc::FFT_Normalization::FULL) { real_type_t norm_coef; if (kwargs.direction == ddc::FFT_Direction::FORWARD) { - norm_coef = (forward_full_norm_coef(ddc::select(in.domain())) * ...); + DiscreteDomain const ddom_in = in.domain(); + norm_coef = (forward_full_norm_coef(DiscreteDomain(ddom_in)) * ...); } else { - norm_coef = (backward_full_norm_coef(ddc::select(out.domain())) * ...); + DiscreteDomain const ddom_out = out.domain(); + norm_coef = (backward_full_norm_coef(DiscreteDomain(ddom_out)) * ...); } rescale(exec_space, out, norm_coef); From 72bce1b24deb3c154934bb37af344a37570148c8 Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Sun, 13 Oct 2024 12:30:14 +0200 Subject: [PATCH 3/8] Rename template parameters --- include/ddc/kernels/fft.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/ddc/kernels/fft.hpp b/include/ddc/kernels/fft.hpp index 33e63da02..70120b5bf 100644 --- a/include/ddc/kernels/fft.hpp +++ b/include/ddc/kernels/fft.hpp @@ -176,19 +176,19 @@ void rescale( }); } -template -Real forward_full_norm_coef(DiscreteDomain const& ddom) noexcept +template +Real forward_full_norm_coef(DiscreteDomain const& ddom) noexcept { return (coordinate(ddom.back()) - coordinate(ddom.front())) - / (ddc::get(ddom.extents()) - 1) / Kokkos::sqrt(2 * Kokkos::numbers::pi); + / (ddc::get(ddom.extents()) - 1) / Kokkos::sqrt(2 * Kokkos::numbers::pi); } -template -Real backward_full_norm_coef(DiscreteDomain const& ddom) noexcept +template +Real backward_full_norm_coef(DiscreteDomain const& ddom) noexcept { return Kokkos::sqrt(2 * Kokkos::numbers::pi) / (coordinate(ddom.back()) - coordinate(ddom.front())) - * (ddc::get(ddom.extents()) - 1) / ddc::get(ddom.extents()); + * (ddc::get(ddom.extents()) - 1) / ddc::get(ddom.extents()); } /// @brief Core internal function to perform the FFT. From 09439ae79f87ff107b0e837e0f1174d16785780b Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Sun, 13 Oct 2024 12:30:40 +0200 Subject: [PATCH 4/8] Use rlength --- include/ddc/kernels/fft.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/ddc/kernels/fft.hpp b/include/ddc/kernels/fft.hpp index 70120b5bf..91608008d 100644 --- a/include/ddc/kernels/fft.hpp +++ b/include/ddc/kernels/fft.hpp @@ -179,15 +179,14 @@ void rescale( template Real forward_full_norm_coef(DiscreteDomain const& ddom) noexcept { - return (coordinate(ddom.back()) - coordinate(ddom.front())) - / (ddc::get(ddom.extents()) - 1) / Kokkos::sqrt(2 * Kokkos::numbers::pi); + return rlength(ddom) / (ddc::get(ddom.extents()) - 1) + / Kokkos::sqrt(2 * Kokkos::numbers::pi); } template Real backward_full_norm_coef(DiscreteDomain const& ddom) noexcept { - return Kokkos::sqrt(2 * Kokkos::numbers::pi) - / (coordinate(ddom.back()) - coordinate(ddom.front())) + return Kokkos::sqrt(2 * Kokkos::numbers::pi) / rlength(ddom) * (ddc::get(ddom.extents()) - 1) / ddc::get(ddom.extents()); } From a6f9f5253478b97620a6aa138f322f2937bfce3d Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Sun, 13 Oct 2024 12:34:57 +0200 Subject: [PATCH 5/8] Reorganize computation --- include/ddc/kernels/fft.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/ddc/kernels/fft.hpp b/include/ddc/kernels/fft.hpp index 91608008d..74bdd09d7 100644 --- a/include/ddc/kernels/fft.hpp +++ b/include/ddc/kernels/fft.hpp @@ -179,15 +179,16 @@ void rescale( template Real forward_full_norm_coef(DiscreteDomain const& ddom) noexcept { - return rlength(ddom) / (ddc::get(ddom.extents()) - 1) - / Kokkos::sqrt(2 * Kokkos::numbers::pi); + return rlength(ddom) / Kokkos::sqrt(2 * Kokkos::numbers::pi) + / (ddc::get(ddom.extents()) - 1); } template Real backward_full_norm_coef(DiscreteDomain const& ddom) noexcept { - return Kokkos::sqrt(2 * Kokkos::numbers::pi) / rlength(ddom) - * (ddc::get(ddom.extents()) - 1) / ddc::get(ddom.extents()); + return (Kokkos::sqrt(2 * Kokkos::numbers::pi) * (ddc::get(ddom.extents()) - 1) + / rlength(ddom)) + / ddc::get(ddom.extents()); } /// @brief Core internal function to perform the FFT. From 4520b942e322877d0758eff0ca338d6d3455d5a3 Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Sun, 13 Oct 2024 12:37:58 +0200 Subject: [PATCH 6/8] Reuse forward_full_norm_coef --- include/ddc/kernels/fft.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/ddc/kernels/fft.hpp b/include/ddc/kernels/fft.hpp index 74bdd09d7..2ac781a8d 100644 --- a/include/ddc/kernels/fft.hpp +++ b/include/ddc/kernels/fft.hpp @@ -186,9 +186,7 @@ Real forward_full_norm_coef(DiscreteDomain const& ddom) noexcept template Real backward_full_norm_coef(DiscreteDomain const& ddom) noexcept { - return (Kokkos::sqrt(2 * Kokkos::numbers::pi) * (ddc::get(ddom.extents()) - 1) - / rlength(ddom)) - / ddc::get(ddom.extents()); + return 1 / (forward_full_norm_coef(ddom) * ddc::get(ddom.extents())); } /// @brief Core internal function to perform the FFT. From 2a1cb65747e312b7a8a6bf7e69e3143bff4fdb16 Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Sun, 13 Oct 2024 12:44:16 +0200 Subject: [PATCH 7/8] Use value instead of get --- include/ddc/kernels/fft.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/ddc/kernels/fft.hpp b/include/ddc/kernels/fft.hpp index 2ac781a8d..06cca0543 100644 --- a/include/ddc/kernels/fft.hpp +++ b/include/ddc/kernels/fft.hpp @@ -179,14 +179,13 @@ void rescale( template Real forward_full_norm_coef(DiscreteDomain const& ddom) noexcept { - return rlength(ddom) / Kokkos::sqrt(2 * Kokkos::numbers::pi) - / (ddc::get(ddom.extents()) - 1); + return rlength(ddom) / Kokkos::sqrt(2 * Kokkos::numbers::pi) / (ddom.extents() - 1).value(); } template Real backward_full_norm_coef(DiscreteDomain const& ddom) noexcept { - return 1 / (forward_full_norm_coef(ddom) * ddc::get(ddom.extents())); + return 1 / (forward_full_norm_coef(ddom) * ddom.extents().value()); } /// @brief Core internal function to perform the FFT. From 4c95c14e7f2db103b08875b6f35fa91506e84c6f Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Tue, 15 Oct 2024 11:52:21 +0200 Subject: [PATCH 8/8] Review from Yuuichi --- include/ddc/kernels/fft.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/ddc/kernels/fft.hpp b/include/ddc/kernels/fft.hpp index 06cca0543..33d19ca65 100644 --- a/include/ddc/kernels/fft.hpp +++ b/include/ddc/kernels/fft.hpp @@ -179,7 +179,8 @@ void rescale( template Real forward_full_norm_coef(DiscreteDomain const& ddom) noexcept { - return rlength(ddom) / Kokkos::sqrt(2 * Kokkos::numbers::pi) / (ddom.extents() - 1).value(); + return rlength(ddom) / Kokkos::sqrt(2 * Kokkos::numbers::pi_v) + / (ddom.extents() - 1).value(); } template @@ -267,7 +268,7 @@ void impl( // The FULL normalization is mesh-dependant and thus handled by DDC if (kwargs.normalization == ddc::FFT_Normalization::FULL) { - real_type_t norm_coef; + Real norm_coef; if (kwargs.direction == ddc::FFT_Direction::FORWARD) { DiscreteDomain const ddom_in = in.domain(); norm_coef = (forward_full_norm_coef(DiscreteDomain(ddom_in)) * ...); @@ -276,7 +277,7 @@ void impl( norm_coef = (backward_full_norm_coef(DiscreteDomain(ddom_out)) * ...); } - rescale(exec_space, out, norm_coef); + rescale(exec_space, out, static_cast>(norm_coef)); } }