From 2ee677173daa0e9f2f59e7b6350a45a8a4a73d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A9vis=20Morvany?= Date: Fri, 7 Mar 2025 15:37:14 +0100 Subject: [PATCH] Rename the DDom template parameter - Rename the template parameters for the discrete domain to improve readability - Change the AUTHORS file --- AUTHORS | 3 + .../ddc/kernels/splines/spline_builder.hpp | 136 +++++++---- .../ddc/kernels/splines/spline_builder_2d.hpp | 132 +++++++---- .../ddc/kernels/splines/spline_evaluator.hpp | 109 +++++---- .../kernels/splines/spline_evaluator_2d.hpp | 223 +++++++++++------- 5 files changed, 389 insertions(+), 214 deletions(-) diff --git a/AUTHORS b/AUTHORS index 704743132..a92fb5f5c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -35,3 +35,6 @@ Baptiste Legouix - CEA (baptiste.legouix@cea.fr) Thierry Antoun - CEA (thierry.antoun@cea.fr) * Work on Documentation * Work on adding new features + +Trévis Morvany - CEA (trevis.morvany@cea.fr) +* Work on splines diff --git a/include/ddc/kernels/splines/spline_builder.hpp b/include/ddc/kernels/splines/spline_builder.hpp index b5fc6ebb1..66c9e91e6 100644 --- a/include/ddc/kernels/splines/spline_builder.hpp +++ b/include/ddc/kernels/splines/spline_builder.hpp @@ -94,8 +94,10 @@ class SplineBuilder * * @tparam The batched discrete domain on which the interpolation points are defined. */ - template >> - using batched_interpolation_domain_type = DDom; + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + using batched_interpolation_domain_type = BatchedInterpolationDDom; /** * @brief The type of the batch domain (obtained by removing the dimension of interest @@ -106,8 +108,11 @@ class SplineBuilder * Example: For batched_interpolation_domain_type = DiscreteDomain and a dimension of interest Y, * this is DiscreteDomain */ - template >> - using batch_domain_type = ddc::remove_dims_of_t; + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + using batch_domain_type = ddc:: + remove_dims_of_t; /** * @brief The type of the whole spline domain (cartesian product of 1D spline domain @@ -118,9 +123,13 @@ class SplineBuilder * Example: For batched_interpolation_domain_type = DiscreteDomain and a dimension of interest Y * (associated to a B-splines tag BSplinesY), this is DiscreteDomain. */ - template >> - using batched_spline_domain_type - = ddc::replace_dim_of_t; + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + using batched_spline_domain_type = ddc::replace_dim_of_t< + BatchedInterpolationDDom, + interpolation_discrete_dimension_type, + bsplines_type>; private: /** @@ -132,12 +141,14 @@ class SplineBuilder * Example: For batched_interpolation_domain_type = DiscreteDomain and a dimension of interest Y * (associated to a B-splines tag BSplinesY), this is DiscreteDomain. */ - template >> + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> using batched_spline_tr_domain_type = typename ddc::detail::convert_type_seq_to_discrete_domain_t, ddc::type_seq_remove_t< - ddc::to_type_seq_t, + ddc::to_type_seq_t, ddc::detail::TypeSeq>>>; public: @@ -150,9 +161,13 @@ class SplineBuilder * Example: For batched_interpolation_domain_type = DiscreteDomain and a dimension of interest Y, * this is DiscreteDomain,Z> */ - template >> - using batched_derivs_domain_type - = ddc::replace_dim_of_t; + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + using batched_derivs_domain_type = ddc::replace_dim_of_t< + BatchedInterpolationDDom, + interpolation_discrete_dimension_type, + deriv_type>; /// @brief Indicates if the degree of the splines is odd or even. static constexpr bool s_odd = BSplines::degree() % 2; @@ -250,9 +265,11 @@ class SplineBuilder * * @see MatrixSparse */ - template >> + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> explicit SplineBuilder( - DDom const& batched_interpolation_domain, + BatchedInterpolationDDom const& batched_interpolation_domain, std::optional cols_per_chunk = std::nullopt, std::optional preconditioner_max_block_size = std::nullopt) : SplineBuilder( @@ -307,9 +324,13 @@ class SplineBuilder * * @return The domain for the interpolation mesh. */ - template >> - DDom batched_interpolation_domain(DDom const& batched_interpolation_domain) const noexcept + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + BatchedInterpolationDDom batched_interpolation_domain( + BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept { + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); return batched_interpolation_domain; } @@ -322,9 +343,11 @@ class SplineBuilder * * @return The batch domain. */ - template - batch_domain_type batch_domain(DDom const& batched_interpolation_domain) const noexcept + template + batch_domain_type batch_domain( + BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept { + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); return ddc::remove_dims_of(batched_interpolation_domain, interpolation_domain()); } @@ -349,10 +372,11 @@ class SplineBuilder * * @return The domain for the spline coefficients. */ - template - batched_spline_domain_type batched_spline_domain( - DDom const& batched_interpolation_domain) const noexcept + template + batched_spline_domain_type batched_spline_domain( + BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept { + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); return ddc::replace_dim_of< interpolation_discrete_dimension_type, bsplines_type>(batched_interpolation_domain, spline_domain()); @@ -368,11 +392,12 @@ class SplineBuilder * * @return The (transposed) domain for the spline coefficients. */ - template - batched_spline_tr_domain_type batched_spline_tr_domain( - DDom const& batched_interpolation_domain) const noexcept + template + batched_spline_tr_domain_type batched_spline_tr_domain( + BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept { - return batched_spline_tr_domain_type( + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); + return batched_spline_tr_domain_type( ddc::replace_dim_of( batched_spline_domain(batched_interpolation_domain), ddc::DiscreteDomain( @@ -391,10 +416,11 @@ class SplineBuilder * * @return The domain for the Derivs values. */ - template - batched_derivs_domain_type batched_derivs_xmin_domain( - DDom const& batched_interpolation_domain) const noexcept + template + batched_derivs_domain_type batched_derivs_xmin_domain( + BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept { + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); return ddc::replace_dim_of( batched_interpolation_domain, ddc::DiscreteDomain( @@ -411,10 +437,11 @@ class SplineBuilder * * @return The domain for the Derivs values. */ - template - batched_derivs_domain_type batched_derivs_xmax_domain( - DDom const& batched_interpolation_domain) const noexcept + template + batched_derivs_domain_type batched_derivs_xmax_domain( + BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept { + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); return ddc::replace_dim_of( batched_interpolation_domain, ddc::DiscreteDomain( @@ -441,19 +468,23 @@ class SplineBuilder * @param[in] derivs_xmax The values of the derivatives at the upper boundary * (used only with BoundCond::HERMITE upper boundary condition). */ - template + template void operator()( - ddc::ChunkSpan, Layout, memory_space> spline, - ddc::ChunkSpan vals, + ddc::ChunkSpan< + double, + batched_spline_domain_type, + Layout, + memory_space> spline, + ddc::ChunkSpan vals, std::optional, + batched_derivs_domain_type, Layout, memory_space>> derivs_xmin = std::nullopt, std::optional, + batched_derivs_domain_type, Layout, memory_space>> derivs_xmax = std::nullopt) const; @@ -762,25 +793,29 @@ template < ddc::BoundCond BcLower, ddc::BoundCond BcUpper, SplineSolver Solver> -template +template void SplineBuilder:: operator()( - ddc::ChunkSpan, Layout, memory_space> spline, - ddc::ChunkSpan vals, + ddc::ChunkSpan< + double, + batched_spline_domain_type, + Layout, + memory_space> spline, + ddc::ChunkSpan vals, std::optional, + batched_derivs_domain_type, Layout, memory_space>> const derivs_xmin, std::optional, + batched_derivs_domain_type, Layout, memory_space>> const derivs_xmax) const { auto const batched_interpolation_domain = vals.domain(); - assert(interpolation_domain_type(batched_interpolation_domain) == m_interpolation_domain); + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); assert(vals.template extent() == ddc::discrete_space().nbasis() - s_nbc_xmin - s_nbc_xmax); @@ -807,7 +842,9 @@ operator()( "ddc_splines_hermite_compute_lower_coefficients", exec_space(), batch_domain(batched_interpolation_domain), - KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type j) { + KOKKOS_LAMBDA( + typename batch_domain_type::discrete_element_type + j) { for (int i = s_nbc_xmin; i > 0; --i) { spline(ddc::DiscreteElement(s_nbc_xmin - i), j) = derivs_xmin_values(ddc::DiscreteElement(i), j) @@ -850,7 +887,9 @@ operator()( "ddc_splines_hermite_compute_upper_coefficients", exec_space(), batch_domain(batched_interpolation_domain), - KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type j) { + KOKKOS_LAMBDA( + typename batch_domain_type::discrete_element_type + j) { for (int i = 0; i < s_nbc_xmax; ++i) { spline(ddc::DiscreteElement(nbasis_proxy - s_nbc_xmax - i), j) @@ -870,7 +909,8 @@ operator()( "ddc_splines_transpose_rhs", exec_space(), batch_domain(batched_interpolation_domain), - KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type const j) { + KOKKOS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { for (std::size_t i = 0; i < nbasis_proxy; ++i) { spline_tr(ddc::DiscreteElement(i), j) = spline(ddc::DiscreteElement(i + offset_proxy), j); @@ -888,7 +928,8 @@ operator()( "ddc_splines_transpose_back_rhs", exec_space(), batch_domain(batched_interpolation_domain), - KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type const j) { + KOKKOS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { for (std::size_t i = 0; i < nbasis_proxy; ++i) { spline(ddc::DiscreteElement(i + offset_proxy), j) = spline_tr(ddc::DiscreteElement(i), j); @@ -901,7 +942,8 @@ operator()( "ddc_splines_periodic_rows_duplicate_rhs", exec_space(), batch_domain(batched_interpolation_domain), - KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type const j) { + KOKKOS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { if (offset_proxy != 0) { for (int i = 0; i < offset_proxy; ++i) { spline(ddc::DiscreteElement(i), j) = spline( diff --git a/include/ddc/kernels/splines/spline_builder_2d.hpp b/include/ddc/kernels/splines/spline_builder_2d.hpp index 4758a8ea8..03dc45e10 100644 --- a/include/ddc/kernels/splines/spline_builder_2d.hpp +++ b/include/ddc/kernels/splines/spline_builder_2d.hpp @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -99,8 +100,10 @@ class SplineBuilder2D * * @tparam The batched discrete domain on which the interpolation points are defined. */ - template >> - using batched_interpolation_domain_type = DDom; + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + using batched_interpolation_domain_type = BatchedInterpolationDDom; /** * @brief The type of the batch domain (obtained by removing the dimensions of interest @@ -111,9 +114,11 @@ class SplineBuilder2D * Example: For batched_interpolation_domain_type = DiscreteDomain and dimensions of interest X and Y, * this is DiscreteDomain. */ - template >> + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> using batch_domain_type = ddc::remove_dims_of_t< - DDom, + BatchedInterpolationDDom, interpolation_discrete_dimension_type1, interpolation_discrete_dimension_type2>; @@ -126,10 +131,12 @@ class SplineBuilder2D * Example: For batched_interpolation_domain_type = DiscreteDomain and dimensions of interest X and Y * (associated to B-splines tags BSplinesX and BSplinesY), this is DiscreteDomain */ - template >> + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> using batched_spline_domain_type = ddc::detail::convert_type_seq_to_discrete_domain_t, + ddc::to_type_seq_t, ddc::detail::TypeSeq< interpolation_discrete_dimension_type1, interpolation_discrete_dimension_type2>, @@ -144,9 +151,11 @@ class SplineBuilder2D * Example: For batched_interpolation_domain_type = DiscreteDomain and dimensions of interest X and Y, * this is DiscreteDomain, Y, Z>. */ - template >> + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> using batched_derivs_domain_type1 = - typename builder_type1::template batched_derivs_domain_type; + typename builder_type1::template batched_derivs_domain_type; /** * @brief The type of the whole Derivs domain (cartesian product of the 1D Deriv domain @@ -157,9 +166,13 @@ class SplineBuilder2D * Example: For batched_interpolation_domain_type = DiscreteDomain and dimensions of interest X and Y, * this is DiscreteDomain, Z>. */ - template >> - using batched_derivs_domain_type2 - = ddc::replace_dim_of_t; + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + using batched_derivs_domain_type2 = ddc::replace_dim_of_t< + BatchedInterpolationDDom, + interpolation_discrete_dimension_type2, + deriv_type2>; /** * @brief The type of the whole Derivs domain (cartesian product of the 2D Deriv domain @@ -170,10 +183,12 @@ class SplineBuilder2D * Example: For batched_interpolation_domain_type = DiscreteDomain and dimensions of interest X and Y, * this is DiscreteDomain, Deriv, Z>. */ - template >> + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> using batched_derivs_domain_type = ddc::detail::convert_type_seq_to_discrete_domain_t, + ddc::to_type_seq_t, ddc::detail::TypeSeq< interpolation_discrete_dimension_type1, interpolation_discrete_dimension_type2>, @@ -227,9 +242,11 @@ class SplineBuilder2D * * @see SplinesLinearProblemSparse */ - template >> + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> explicit SplineBuilder2D( - DDom const& batched_interpolation_domain, + BatchedInterpolationDDom const& batched_interpolation_domain, std::optional cols_per_chunk = std::nullopt, std::optional preconditioner_max_block_size = std::nullopt) : SplineBuilder2D( @@ -286,9 +303,13 @@ class SplineBuilder2D * * @return The domain for the interpolation mesh. */ - template >> - DDom batched_interpolation_domain(DDom const& batched_interpolation_domain) const noexcept + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + BatchedInterpolationDDom batched_interpolation_domain( + BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept { + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); return batched_interpolation_domain; } @@ -301,9 +322,13 @@ class SplineBuilder2D * * @return The batch domain. */ - template >> - batch_domain_type batch_domain(DDom const& batched_interpolation_domain) const noexcept + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + batch_domain_type batch_domain( + BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept { + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); return ddc::remove_dims_of(batched_interpolation_domain, interpolation_domain()); } @@ -330,10 +355,13 @@ class SplineBuilder2D * * @return The domain for the spline coefficients. */ - template >> - batched_spline_domain_type batched_spline_domain( - DDom const& batched_interpolation_domain) const noexcept + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + batched_spline_domain_type batched_spline_domain( + BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept { + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); return ddc::replace_dim_of( ddc::replace_dim_of< interpolation_discrete_dimension_type2, @@ -377,55 +405,59 @@ class SplineBuilder2D * The values of the the cross-derivatives at the upper boundary in the first dimension * and the upper boundary in the second dimension. */ - template + template void operator()( - ddc::ChunkSpan, Layout, memory_space> spline, - ddc::ChunkSpan vals, + ddc::ChunkSpan< + double, + batched_spline_domain_type, + Layout, + memory_space> spline, + ddc::ChunkSpan vals, std::optional, + batched_derivs_domain_type1, Layout, memory_space>> derivs_min1 = std::nullopt, std::optional, + batched_derivs_domain_type1, Layout, memory_space>> derivs_max1 = std::nullopt, std::optional, + batched_derivs_domain_type2, Layout, memory_space>> derivs_min2 = std::nullopt, std::optional, + batched_derivs_domain_type2, Layout, memory_space>> derivs_max2 = std::nullopt, std::optional, + batched_derivs_domain_type, Layout, memory_space>> mixed_derivs_min1_min2 = std::nullopt, std::optional, + batched_derivs_domain_type, Layout, memory_space>> mixed_derivs_max1_min2 = std::nullopt, std::optional, + batched_derivs_domain_type, Layout, memory_space>> mixed_derivs_min1_max2 = std::nullopt, std::optional, + batched_derivs_domain_type, Layout, memory_space>> mixed_derivs_max1_max2 = std::nullopt) const; @@ -444,7 +476,7 @@ template < ddc::BoundCond BcLower2, ddc::BoundCond BcUpper2, ddc::SplineSolver Solver> -template +template void SplineBuilder2D< ExecSpace, MemorySpace, @@ -458,55 +490,63 @@ void SplineBuilder2D< BcUpper2, Solver>:: operator()( - ddc::ChunkSpan, Layout, memory_space> spline, - ddc::ChunkSpan vals, + ddc::ChunkSpan< + double, + batched_spline_domain_type, + Layout, + memory_space> spline, + ddc::ChunkSpan vals, std::optional, + batched_derivs_domain_type1, Layout, memory_space>> const derivs_min1, std::optional, + batched_derivs_domain_type1, Layout, memory_space>> const derivs_max1, std::optional, + batched_derivs_domain_type2, Layout, memory_space>> const derivs_min2, std::optional, + batched_derivs_domain_type2, Layout, memory_space>> const derivs_max2, std::optional, + batched_derivs_domain_type, Layout, memory_space>> const mixed_derivs_min1_min2, std::optional, + batched_derivs_domain_type, Layout, memory_space>> const mixed_derivs_max1_min2, std::optional, + batched_derivs_domain_type, Layout, memory_space>> const mixed_derivs_min1_max2, std::optional, + batched_derivs_domain_type, Layout, memory_space>> const mixed_derivs_max1_max2) const { + auto const batched_interpolation_domain = vals.domain(); + + assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain)); + // TODO: perform computations along dimension 1 on different streams ? // Spline1-approximate derivs_min2 (to spline1_deriv_min) auto const batched_interpolation_deriv_domain = ddc::replace_dim_of( - vals.domain(), + batched_interpolation_domain, ddc::DiscreteDomain( ddc::DiscreteElement(1), ddc::DiscreteVector(bsplines_type2::degree() / 2))); @@ -528,7 +568,7 @@ operator()( // Spline1-approximate vals (to spline1) ddc::Chunk spline1_alloc( - m_spline_builder1.batched_spline_domain(vals.domain()), + m_spline_builder1.batched_spline_domain(batched_interpolation_domain), ddc::KokkosAllocator()); ddc::ChunkSpan const spline1 = spline1_alloc.span_view(); diff --git a/include/ddc/kernels/splines/spline_evaluator.hpp b/include/ddc/kernels/splines/spline_evaluator.hpp index 7a924d7b5..0b60426e8 100644 --- a/include/ddc/kernels/splines/spline_evaluator.hpp +++ b/include/ddc/kernels/splines/spline_evaluator.hpp @@ -78,8 +78,10 @@ class SplineEvaluator * * @tparam The batched discrete domain on which the interpolation points are defined. */ - template >> - using batched_evaluation_domain_type = DDom; + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + using batched_evaluation_domain_type = BatchedInterpolationDDom; /// @brief The type of the 1D spline domain corresponding to the dimension of interest. using spline_domain_type = ddc::DiscreteDomain; @@ -90,8 +92,11 @@ class SplineEvaluator * * @tparam The batched discrete domain on which the interpolation points are defined. */ - template >> - using batch_domain_type = ddc::remove_dims_of_t; + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + using batch_domain_type + = ddc::remove_dims_of_t; /** * @brief The type of the whole spline domain (cartesian product of 1D spline domain @@ -99,9 +104,13 @@ class SplineEvaluator * * @tparam The batched discrete domain on which the interpolation points are defined. */ - template >> - using batched_spline_domain_type - = ddc::replace_dim_of_t; + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + using batched_spline_domain_type = ddc::replace_dim_of_t< + BatchedInterpolationDDom, + evaluation_discrete_dimension_type, + bsplines_type>; /// @brief The type of the extrapolation rule at the lower boundary. using lower_extrapolation_rule_type = LowerExtrapolationRule; @@ -266,26 +275,35 @@ class SplineEvaluator * the set of 1D spline coefficients retained to perform the evaluation). * @param[in] spline_coef A ChunkSpan storing the spline coefficients. */ - template + template < + class Layout1, + class Layout2, + class Layout3, + class BatchedInterpolationDDom, + class... CoordsDims> void operator()( - ddc::ChunkSpan const spline_eval, - ddc::ChunkSpan const, DDom, Layout2, memory_space> const - coords_eval, + ddc::ChunkSpan const + spline_eval, + ddc::ChunkSpan< + ddc::Coordinate const, + BatchedInterpolationDDom, + Layout2, + memory_space> const coords_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout3, memory_space> const spline_coef) const { evaluation_domain_type const evaluation_domain(spline_eval.domain()); - batch_domain_type const batch_domain(spline_eval.domain()); + batch_domain_type const batch_domain(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_evaluate", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_1D = spline_eval[j]; const auto coords_eval_1D = coords_eval[j]; const auto spline_coef_1D = spline_coef[j]; @@ -313,24 +331,25 @@ class SplineEvaluator * of the mesh. * @param[in] spline_coef A ChunkSpan storing the spline coefficients. */ - template + template void operator()( - ddc::ChunkSpan const spline_eval, + ddc::ChunkSpan const + spline_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout2, memory_space> const spline_coef) const { evaluation_domain_type const evaluation_domain(spline_eval.domain()); - batch_domain_type const batch_domain(spline_eval.domain()); + batch_domain_type const batch_domain(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_evaluate", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_1D = spline_eval[j]; const auto spline_coef_1D = spline_coef[j]; for (auto const i : evaluation_domain) { @@ -379,26 +398,35 @@ class SplineEvaluator * the set of 1D spline coefficients retained to perform the evaluation). * @param[in] spline_coef A ChunkSpan storing the spline coefficients. */ - template + template < + class Layout1, + class Layout2, + class Layout3, + class BatchedInterpolationDDom, + class... CoordsDims> void deriv( - ddc::ChunkSpan const spline_eval, - ddc::ChunkSpan const, DDom, Layout2, memory_space> const - coords_eval, + ddc::ChunkSpan const + spline_eval, + ddc::ChunkSpan< + ddc::Coordinate const, + BatchedInterpolationDDom, + Layout2, + memory_space> const coords_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout3, memory_space> const spline_coef) const { evaluation_domain_type const evaluation_domain(spline_eval.domain()); - batch_domain_type const batch_domain(spline_eval.domain()); + batch_domain_type const batch_domain(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_differentiate", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_1D = spline_eval[j]; const auto coords_eval_1D = coords_eval[j]; const auto spline_coef_1D = spline_coef[j]; @@ -423,24 +451,25 @@ class SplineEvaluator * @param[out] spline_eval The derivatives of the spline function at the coordinates. * @param[in] spline_coef A ChunkSpan storing the spline coefficients. */ - template + template void deriv( - ddc::ChunkSpan const spline_eval, + ddc::ChunkSpan const + spline_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout2, memory_space> const spline_coef) const { evaluation_domain_type const evaluation_domain(spline_eval.domain()); - batch_domain_type const batch_domain(spline_eval.domain()); + batch_domain_type const batch_domain(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_differentiate", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_1D = spline_eval[j]; const auto spline_coef_1D = spline_coef[j]; for (auto const i : evaluation_domain) { @@ -465,9 +494,9 @@ class SplineEvaluator * points represented by this domain are unused and irrelevant. * @param[in] spline_coef A ChunkSpan storing the spline coefficients. */ - template + template void integrate( - ddc::ChunkSpan const integrals, + ddc::ChunkSpan const integrals, ddc::ChunkSpan const spline_coef) const { @@ -476,10 +505,10 @@ class SplineEvaluator "The spline coefficients domain must contain the bsplines dimension"); using batch_domain_type = ddc::remove_dims_of_t; static_assert( - std::is_same_v, + std::is_same_v, "The integrals domain must only contain the batch dimensions"); - BatchDDom const batch_domain(integrals.domain()); + BatchedDDom const batch_domain(integrals.domain()); ddc::Chunk values_alloc( ddc::DiscreteDomain(spline_coef.domain()), ddc::KokkosAllocator()); @@ -490,7 +519,7 @@ class SplineEvaluator "ddc_splines_integrate", exec_space(), batch_domain, - KOKKOS_LAMBDA(typename BatchDDom::discrete_element_type const j) { + KOKKOS_LAMBDA(typename BatchedDDom::discrete_element_type const j) { integrals(j) = 0; for (typename spline_domain_type::discrete_element_type const i : values.domain()) { diff --git a/include/ddc/kernels/splines/spline_evaluator_2d.hpp b/include/ddc/kernels/splines/spline_evaluator_2d.hpp index 494d228e1..681b14683 100644 --- a/include/ddc/kernels/splines/spline_evaluator_2d.hpp +++ b/include/ddc/kernels/splines/spline_evaluator_2d.hpp @@ -102,8 +102,10 @@ class SplineEvaluator2D * * @tparam The batched discrete domain on which the interpolation points are defined. */ - template >> - using batched_evaluation_domain_type = DDom; + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> + using batched_evaluation_domain_type = BatchedInterpolationDDom; /// @brief The type of the 1D spline domain corresponding to the first dimension of interest. using spline_domain_type1 = ddc::DiscreteDomain; @@ -120,9 +122,11 @@ class SplineEvaluator2D * * @tparam The batched discrete domain on which the interpolation points are defined. */ - template >> + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> using batch_domain_type = typename ddc::remove_dims_of_t< - DDom, + BatchedInterpolationDDom, evaluation_discrete_dimension_type1, evaluation_discrete_dimension_type2>; @@ -132,10 +136,12 @@ class SplineEvaluator2D * * @tparam The batched discrete domain on which the interpolation points are defined. */ - template >> + template < + class BatchedInterpolationDDom, + class = std::enable_if_t>> using batched_spline_domain_type = typename ddc::detail::convert_type_seq_to_discrete_domain_t, + ddc::to_type_seq_t, ddc::detail::TypeSeq< evaluation_discrete_dimension_type1, evaluation_discrete_dimension_type2>, @@ -381,26 +387,35 @@ class SplineEvaluator2D * the set of 2D spline coefficients retained to perform the evaluation). * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template < + class Layout1, + class Layout2, + class Layout3, + class BatchedInterpolationDDom, + class... CoordsDims> void operator()( - ddc::ChunkSpan const spline_eval, - ddc::ChunkSpan const, DDom, Layout2, memory_space> const - coords_eval, + ddc::ChunkSpan const + spline_eval, + ddc::ChunkSpan< + ddc::Coordinate const, + BatchedInterpolationDDom, + Layout2, + memory_space> const coords_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout3, memory_space> const spline_coef) const { - batch_domain_type const batch_domain(coords_eval.domain()); + batch_domain_type const batch_domain(coords_eval.domain()); evaluation_domain_type1 const evaluation_domain1(spline_eval.domain()); evaluation_domain_type2 const evaluation_domain2(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_evaluate_2d", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_2D = spline_eval[j]; const auto coords_eval_2D = coords_eval[j]; const auto spline_coef_2D = spline_coef[j]; @@ -427,24 +442,25 @@ class SplineEvaluator2D * @param[out] spline_eval The values of the 2D spline function at their coordinates. * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template void operator()( - ddc::ChunkSpan const spline_eval, + ddc::ChunkSpan const + spline_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout2, memory_space> const spline_coef) const { - batch_domain_type const batch_domain(spline_eval.domain()); + batch_domain_type const batch_domain(spline_eval.domain()); evaluation_domain_type1 const evaluation_domain1(spline_eval.domain()); evaluation_domain_type2 const evaluation_domain2(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_evaluate_2d", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_2D = spline_eval[j]; const auto spline_coef_2D = spline_coef[j]; for (auto const i1 : evaluation_domain1) { @@ -606,26 +622,35 @@ class SplineEvaluator2D * the set of 2D spline coefficients retained to perform the evaluation). * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template < + class Layout1, + class Layout2, + class Layout3, + class BatchedInterpolationDDom, + class... CoordsDims> void deriv_dim_1( - ddc::ChunkSpan const spline_eval, - ddc::ChunkSpan const, DDom, Layout2, memory_space> const - coords_eval, + ddc::ChunkSpan const + spline_eval, + ddc::ChunkSpan< + ddc::Coordinate const, + BatchedInterpolationDDom, + Layout2, + memory_space> const coords_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout3, memory_space> const spline_coef) const { - batch_domain_type const batch_domain(coords_eval.domain()); + batch_domain_type const batch_domain(coords_eval.domain()); evaluation_domain_type1 const evaluation_domain1(spline_eval.domain()); evaluation_domain_type2 const evaluation_domain2(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_differentiate_2d_dim_1", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_2D = spline_eval[j]; const auto coords_eval_2D = coords_eval[j]; const auto spline_coef_2D = spline_coef[j]; @@ -652,24 +677,25 @@ class SplineEvaluator2D * @param[out] spline_eval The derivatives of the 2D spline function at the desired coordinates. * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template void deriv_dim_1( - ddc::ChunkSpan const spline_eval, + ddc::ChunkSpan const + spline_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout2, memory_space> const spline_coef) const { - batch_domain_type const batch_domain(spline_eval.domain()); + batch_domain_type const batch_domain(spline_eval.domain()); evaluation_domain_type1 const evaluation_domain1(spline_eval.domain()); evaluation_domain_type2 const evaluation_domain2(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_differentiate_2d_dim_1", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_2D = spline_eval[j]; const auto spline_coef_2D = spline_coef[j]; for (auto const i1 : evaluation_domain1) { @@ -702,26 +728,35 @@ class SplineEvaluator2D * the set of 2D spline coefficients retained to perform the evaluation). * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template < + class Layout1, + class Layout2, + class Layout3, + class BatchedInterpolationDDom, + class... CoordsDims> void deriv_dim_2( - ddc::ChunkSpan const spline_eval, - ddc::ChunkSpan const, DDom, Layout2, memory_space> const - coords_eval, + ddc::ChunkSpan const + spline_eval, + ddc::ChunkSpan< + ddc::Coordinate const, + BatchedInterpolationDDom, + Layout2, + memory_space> const coords_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout3, memory_space> const spline_coef) const { - batch_domain_type const batch_domain(coords_eval.domain()); + batch_domain_type const batch_domain(coords_eval.domain()); evaluation_domain_type1 const evaluation_domain1(spline_eval.domain()); evaluation_domain_type2 const evaluation_domain2(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_differentiate_2d_dim_2", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_2D = spline_eval[j]; const auto coords_eval_2D = coords_eval[j]; const auto spline_coef_2D = spline_coef[j]; @@ -748,24 +783,25 @@ class SplineEvaluator2D * @param[out] spline_eval The derivatives of the 2D spline function at the desired coordinates. * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template void deriv_dim_2( - ddc::ChunkSpan const spline_eval, + ddc::ChunkSpan const + spline_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout2, memory_space> const spline_coef) const { - batch_domain_type const batch_domain(spline_eval.domain()); + batch_domain_type const batch_domain(spline_eval.domain()); evaluation_domain_type1 const evaluation_domain1(spline_eval.domain()); evaluation_domain_type2 const evaluation_domain2(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_differentiate_2d_dim_2", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_2D = spline_eval[j]; const auto spline_coef_2D = spline_coef[j]; for (auto const i1 : evaluation_domain1) { @@ -798,26 +834,35 @@ class SplineEvaluator2D * the set of 2D spline coefficients retained to perform the evaluation). * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template < + class Layout1, + class Layout2, + class Layout3, + class BatchedInterpolationDDom, + class... CoordsDims> void deriv_1_and_2( - ddc::ChunkSpan const spline_eval, - ddc::ChunkSpan const, DDom, Layout2, memory_space> const - coords_eval, + ddc::ChunkSpan const + spline_eval, + ddc::ChunkSpan< + ddc::Coordinate const, + BatchedInterpolationDDom, + Layout2, + memory_space> const coords_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout3, memory_space> const spline_coef) const { - batch_domain_type const batch_domain(coords_eval.domain()); + batch_domain_type const batch_domain(coords_eval.domain()); evaluation_domain_type1 const evaluation_domain1(spline_eval.domain()); evaluation_domain_type2 const evaluation_domain2(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_cross_differentiate", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_2D = spline_eval[j]; const auto coords_eval_2D = coords_eval[j]; const auto spline_coef_2D = spline_coef[j]; @@ -844,24 +889,25 @@ class SplineEvaluator2D * @param[out] spline_eval The cross-derivatives of the 2D spline function at the desired coordinates. * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template void deriv_1_and_2( - ddc::ChunkSpan const spline_eval, + ddc::ChunkSpan const + spline_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout2, memory_space> const spline_coef) const { - batch_domain_type const batch_domain(spline_eval.domain()); + batch_domain_type const batch_domain(spline_eval.domain()); evaluation_domain_type1 const evaluation_domain1(spline_eval.domain()); evaluation_domain_type2 const evaluation_domain2(spline_eval.domain()); ddc::parallel_for_each( "ddc_splines_cross_differentiate", exec_space(), batch_domain, - KOKKOS_CLASS_LAMBDA( - typename batch_domain_type::discrete_element_type const j) { + KOKKOS_CLASS_LAMBDA(typename batch_domain_type< + BatchedInterpolationDDom>::discrete_element_type const j) { const auto spline_eval_2D = spline_eval[j]; const auto spline_coef_2D = spline_coef[j]; for (auto const i1 : evaluation_domain1) { @@ -900,15 +946,19 @@ class SplineEvaluator2D class Layout1, class Layout2, class Layout3, - class DDom, + class BatchedInterpolationDDom, class... CoordsDims> void deriv( - ddc::ChunkSpan const spline_eval, - ddc::ChunkSpan const, DDom, Layout2, memory_space> const - coords_eval, + ddc::ChunkSpan const + spline_eval, + ddc::ChunkSpan< + ddc::Coordinate const, + BatchedInterpolationDDom, + Layout2, + memory_space> const coords_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout3, memory_space> const spline_coef) const { @@ -944,12 +994,13 @@ class SplineEvaluator2D * @param[out] spline_eval The derivatives of the 2D spline function at the desired coordinates. * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template void deriv( - ddc::ChunkSpan const spline_eval, + ddc::ChunkSpan const + spline_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout2, memory_space> const spline_coef) const { @@ -1000,15 +1051,19 @@ class SplineEvaluator2D class Layout1, class Layout2, class Layout3, - class DDom, + class BatchedInterpolationDDom, class... CoordsDims> void deriv2( - ddc::ChunkSpan const spline_eval, - ddc::ChunkSpan const, DDom, Layout2, memory_space> const - coords_eval, + ddc::ChunkSpan const + spline_eval, + ddc::ChunkSpan< + ddc::Coordinate const, + BatchedInterpolationDDom, + Layout2, + memory_space> const coords_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout3, memory_space> const spline_coef) const { @@ -1042,12 +1097,18 @@ class SplineEvaluator2D * @param[out] spline_eval The derivatives of the 2D spline function at the desired coordinates. * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template < + class InterestDim1, + class InterestDim2, + class Layout1, + class Layout2, + class BatchedInterpolationDDom> void deriv2( - ddc::ChunkSpan const spline_eval, + ddc::ChunkSpan const + spline_eval, ddc::ChunkSpan< double const, - batched_spline_domain_type, + batched_spline_domain_type, Layout2, memory_space> const spline_coef) const { @@ -1076,9 +1137,9 @@ class SplineEvaluator2D * points represented by this domain are unused and irrelevant. * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients. */ - template + template void integrate( - ddc::ChunkSpan const integrals, + ddc::ChunkSpan const integrals, ddc::ChunkSpan const spline_coef) const { @@ -1090,7 +1151,7 @@ class SplineEvaluator2D using batch_domain_type = ddc::remove_dims_of_t; static_assert( - std::is_same_v, + std::is_same_v, "The integrals domain must only contain the batch dimensions"); batch_domain_type batch_domain(integrals.domain());