Skip to content

Commit

Permalink
Merge branch 'main' into splines-improve-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
blegouix authored Jun 28, 2024
2 parents 9065d88 + 9e6ea8f commit 386ad4f
Show file tree
Hide file tree
Showing 15 changed files with 848 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#
# SPDX-License-Identifier: MIT
---
Checks: '-*,bugprone-reserved-identifier,hicpp-avoid-c-arrays,modernize-use-nullptr'
Checks: '-*,bugprone-reserved-identifier,hicpp-avoid-c-arrays,modernize-use-nullptr,readability-avoid-const-params-in-decls'
WarningsAsErrors: '*'
4 changes: 2 additions & 2 deletions examples/non_uniform_heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//! [vector_generator]
std::vector<double> generate_random_vector(
int n,
int lower_bound,
int higher_bound)
double lower_bound,
double higher_bound)
{
std::random_device rd;
std::mt19937 gen(rd());
Expand Down
1 change: 1 addition & 0 deletions include/ddc/kernels/fft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ void core(
}

Kokkos::parallel_for(
"ddc_fft_normalization",
Kokkos::RangePolicy<ExecSpace>(
execSpace,
0,
Expand Down
1 change: 1 addition & 0 deletions include/ddc/kernels/splines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "splines/spline_evaluator_2d.hpp"
#include "splines/splines_linear_problem.hpp"
#include "splines/splines_linear_problem_2x2_blocks.hpp"
#include "splines/splines_linear_problem_3x3_blocks.hpp"
#include "splines/splines_linear_problem_band.hpp"
#include "splines/splines_linear_problem_dense.hpp"
#include "splines/splines_linear_problem_maker.hpp"
Expand Down
6 changes: 6 additions & 0 deletions include/ddc/kernels/splines/greville_interpolation_points.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class GrevilleInterpolationPoints
* when uniform splines are used with an odd degree and with boundary conditions which
* do not introduce additional interpolation points.
*
* @tparam Sampling The discrete dimension supporting the Greville points.
*
* @returns The mesh of uniform Greville points.
*/
template <
Expand All @@ -143,6 +145,8 @@ class GrevilleInterpolationPoints
/**
* Get the NonUniformPointSampling defining the Greville points.
*
* @tparam Sampling The discrete dimension supporting the Greville points.
*
* @returns The mesh of non-uniform Greville points.
*/
template <
Expand Down Expand Up @@ -262,6 +266,8 @@ class GrevilleInterpolationPoints
/**
* Get the domain which gives us access to all of the Greville points.
*
* @tparam Sampling The discrete dimension supporting the Greville points.
*
* @returns The domain of the Greville points.
*/
template <class Sampling>
Expand Down
4 changes: 4 additions & 0 deletions include/ddc/kernels/splines/knots_as_interpolation_points.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ namespace ddc {
* In the case of strongly non-uniform splines this choice may result in a less
* well conditioned problem, however most mathematical stability results are proven
* with this choice of interpolation points.
*
* @tparam BSplines The type of the uniform or non-uniform spline basis whose knots are used as interpolation points.
* @tparam BcXmin The lower boundary condition.
* @tparam BcXmin The upper boundary condition.
*/
template <class BSplines, ddc::BoundCond BcXmin, ddc::BoundCond BcXmax>
class KnotsAsInterpolationPoints
Expand Down
8 changes: 8 additions & 0 deletions include/ddc/kernels/splines/null_extrapolation_rule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@

namespace ddc {

/**
* @brief A functor describing a null extrapolation boundary value for 1D spline evaluator.
*/
struct NullExtrapolationRule
{
/**
* @brief Evaluates the spline at a coordinate outside of the domain.
*
* @return A double with the value of the function outside the domain (here, 0.).
*/
template <class CoordType, class ChunkSpan>
KOKKOS_FUNCTION double operator()(CoordType, ChunkSpan) const
{
Expand Down
28 changes: 15 additions & 13 deletions include/ddc/kernels/splines/spline_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,13 @@ class SplineBuilder
ddc::ChunkSpan<double, batched_spline_domain_type, Layout, memory_space> spline,
ddc::ChunkSpan<double const, batched_interpolation_domain_type, Layout, memory_space>
vals,
std::optional<ddc::ChunkSpan<
double const,
batched_derivs_domain_type,
Layout,
memory_space>> const derivs_xmin
std::optional<
ddc::ChunkSpan<double const, batched_derivs_domain_type, Layout, memory_space>>
derivs_xmin
= std::nullopt,
std::optional<ddc::ChunkSpan<
double const,
batched_derivs_domain_type,
Layout,
memory_space>> const derivs_xmax
std::optional<
ddc::ChunkSpan<double const, batched_derivs_domain_type, Layout, memory_space>>
derivs_xmax
= std::nullopt) const;

private:
Expand Down Expand Up @@ -770,6 +766,7 @@ operator()(
auto derivs_xmin_values = *derivs_xmin;
auto const dx_proxy = m_dx;
ddc::parallel_for_each(
"ddc_splines_hermite_compute_lower_coefficients",
exec_space(),
batch_domain(),
KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type j) {
Expand All @@ -787,6 +784,7 @@ operator()(
auto const& interp_size_proxy = interpolation_domain().extents();
auto const& nbasis_proxy = ddc::discrete_space<bsplines_type>().nbasis();
ddc::parallel_for_each(
"ddc_splines_fill_rhs",
exec_space(),
batch_domain(),
KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type j) {
Expand All @@ -807,6 +805,7 @@ operator()(
auto derivs_xmax_values = *derivs_xmax;
auto const dx_proxy = m_dx;
ddc::parallel_for_each(
"ddc_splines_hermite_compute_upper_coefficients",
exec_space(),
batch_domain(),
KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type j) {
Expand All @@ -820,12 +819,13 @@ operator()(
}

// TODO : Consider optimizing
// Allocate and fill a transposed version of spline in order to get dimension of interest as last dimension (optimal for GPU, necessary for Ginkgo)
// Allocate and fill a transposed version of spline in order to get dimension of interest as last dimension (optimal for GPU, necessary for Ginkgo). Also select only relevant rows in case of periodic boundaries
ddc::Chunk spline_tr_alloc(
batched_spline_tr_domain(),
ddc::KokkosAllocator<double, memory_space>());
ddc::ChunkSpan spline_tr = spline_tr_alloc.span_view();
ddc::parallel_for_each(
"ddc_splines_transpose_rhs",
exec_space(),
batch_domain(),
KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
Expand All @@ -841,8 +841,9 @@ operator()(
batch_domain().size());
// Compute spline coef
matrix->solve(bcoef_section);
// Transpose back spline_tr in spline
// Transpose back spline_tr into spline.
ddc::parallel_for_each(
"ddc_splines_transpose_back_rhs",
exec_space(),
batch_domain(),
KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
Expand All @@ -852,9 +853,10 @@ operator()(
}
});

// Not sure yet of what this part do
// Duplicate the lower spline coefficients to the upper side in case of periodic boundaries
if (bsplines_type::is_periodic()) {
ddc::parallel_for_each(
"ddc_splines_periodic_rows_duplicate_rhs",
exec_space(),
batch_domain(),
KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
Expand Down
64 changes: 24 additions & 40 deletions include/ddc/kernels/splines/spline_builder_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,53 +350,37 @@ class SplineBuilder2D
ddc::ChunkSpan<double, batched_spline_domain_type, Layout, memory_space> spline,
ddc::ChunkSpan<double const, batched_interpolation_domain_type, Layout, memory_space>
vals,
std::optional<ddc::ChunkSpan<
double const,
batched_derivs_domain_type1,
Layout,
memory_space>> const derivs_min1
std::optional<
ddc::ChunkSpan<double const, batched_derivs_domain_type1, Layout, memory_space>>
derivs_min1
= std::nullopt,
std::optional<ddc::ChunkSpan<
double const,
batched_derivs_domain_type1,
Layout,
memory_space>> const derivs_max1
std::optional<
ddc::ChunkSpan<double const, batched_derivs_domain_type1, Layout, memory_space>>
derivs_max1
= std::nullopt,
std::optional<ddc::ChunkSpan<
double const,
batched_derivs_domain_type2,
Layout,
memory_space>> const derivs_min2
std::optional<
ddc::ChunkSpan<double const, batched_derivs_domain_type2, Layout, memory_space>>
derivs_min2
= std::nullopt,
std::optional<ddc::ChunkSpan<
double const,
batched_derivs_domain_type2,
Layout,
memory_space>> const derivs_max2
std::optional<
ddc::ChunkSpan<double const, batched_derivs_domain_type2, Layout, memory_space>>
derivs_max2
= std::nullopt,
std::optional<ddc::ChunkSpan<
double const,
batched_derivs_domain_type,
Layout,
memory_space>> const mixed_derivs_min1_min2
std::optional<
ddc::ChunkSpan<double const, batched_derivs_domain_type, Layout, memory_space>>
mixed_derivs_min1_min2
= std::nullopt,
std::optional<ddc::ChunkSpan<
double const,
batched_derivs_domain_type,
Layout,
memory_space>> const mixed_derivs_max1_min2
std::optional<
ddc::ChunkSpan<double const, batched_derivs_domain_type, Layout, memory_space>>
mixed_derivs_max1_min2
= std::nullopt,
std::optional<ddc::ChunkSpan<
double const,
batched_derivs_domain_type,
Layout,
memory_space>> const mixed_derivs_min1_max2
std::optional<
ddc::ChunkSpan<double const, batched_derivs_domain_type, Layout, memory_space>>
mixed_derivs_min1_max2
= std::nullopt,
std::optional<ddc::ChunkSpan<
double const,
batched_derivs_domain_type,
Layout,
memory_space>> const mixed_derivs_max1_max2
std::optional<
ddc::ChunkSpan<double const, batched_derivs_domain_type, Layout, memory_space>>
mixed_derivs_max1_max2
= std::nullopt) const;
};

Expand Down
Loading

0 comments on commit 386ad4f

Please sign in to comment.