Skip to content

Commit

Permalink
Sync DDC
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyBourne committed Mar 22, 2024
1 parent f463574 commit c910ac1
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 160 deletions.
3 changes: 1 addition & 2 deletions vendor/ddc/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# The discrete domain computation library (DDC)
<!--
Copyright (C) The DDC development team, see COPYRIGHT.md file
SPDX-License-Identifier: MIT
-->

# The discrete domain computation library (DDC)

See https://ddc.mdls.fr/

[DDC](https://ddc.mdls.fr/), is a C++-17 library that aims to offer to the C++/MPI world an equivalent to the [`xarray.DataArray`](https://xarray.pydata.org/en/stable/generated/xarray.DataArray.html)/[`dask.Array`](https://docs.dask.org/en/stable/array.html) python environment.
Expand Down
6 changes: 2 additions & 4 deletions vendor/ddc/benchmarks/splines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ static void characteristics_advection(benchmark::State& state)
DDimX,
DDimY>
spline_builder(x_mesh, state.range(2), state.range(3));
ddc::PeriodicExtrapolationRule<X> periodic_extrapolation;
ddc::SplineEvaluator<
Kokkos::DefaultExecutionSpace,
Kokkos::DefaultExecutionSpace::memory_space,
Expand All @@ -124,10 +125,7 @@ static void characteristics_advection(benchmark::State& state)
ddc::PeriodicExtrapolationRule<X>,
DDimX,
DDimY>
spline_evaluator(
spline_builder.spline_domain(),
ddc::PeriodicExtrapolationRule<X>(),
ddc::PeriodicExtrapolationRule<X>());
spline_evaluator(periodic_extrapolation, periodic_extrapolation);
ddc::Chunk coef_alloc(
spline_builder.spline_domain(),
ddc::KokkosAllocator<double, Kokkos::DefaultExecutionSpace::memory_space>());
Expand Down
3 changes: 1 addition & 2 deletions vendor/ddc/docs/first_steps.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Commented example: the heat equation {#first_steps}
<!--
Copyright (C) The DDC development team, see COPYRIGHT.md file
SPDX-License-Identifier: MIT
-->

# Commented example: the heat equation {#first_steps}

In \subpage heat_equation "examples/heat_equation.cpp" is a DDC example implementing a forward
finite-difference solver for the heat equation over a rectangle 2D domain with periodic boundary
conditions.
Expand Down
3 changes: 1 addition & 2 deletions vendor/ddc/docs/heat_equation.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# examples/heat_equation.cpp {#heat_equation}
<!--
Copyright (C) The DDC development team, see COPYRIGHT.md file
SPDX-License-Identifier: MIT
-->

# examples/heat_equation.cpp {#heat_equation}

\include{lineno} heat_equation.cpp
6 changes: 3 additions & 3 deletions vendor/ddc/examples/characteristics_advection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ int main(int argc, char** argv)
DDimX,
DDimY>
spline_builder(x_mesh);
ddc::PeriodicExtrapolationRule<X> periodic_extrapolation;
ddc::SplineEvaluator<
Kokkos::DefaultExecutionSpace,
Kokkos::DefaultExecutionSpace::memory_space,
Expand All @@ -224,9 +225,8 @@ int main(int argc, char** argv)
DDimX,
DDimY>
spline_evaluator(
spline_builder.spline_domain(),
ddc::PeriodicExtrapolationRule<X>(),
ddc::PeriodicExtrapolationRule<X>());
periodic_extrapolation,
periodic_extrapolation);
//! [instantiate solver]

//! [instantiate intermediate chunks]
Expand Down
10 changes: 0 additions & 10 deletions vendor/ddc/include/ddc/chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,6 @@ class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator>
{
}

/// Construct a Chunk from a deepcopy of a ChunkSpan
template <class OElementType, class... ODDims, class LayoutType>
[[deprecated("Use 'ddc::create_mirror_and_copy' instead")]] explicit Chunk(
ChunkSpan<OElementType, DiscreteDomain<ODDims...>, LayoutType> chunk_span,
Allocator allocator = Allocator())
: Chunk(chunk_span.domain(), std::move(allocator))
{
parallel_deepcopy(span_view(), chunk_span);
}

/// Deleted: use deepcopy instead
Chunk(Chunk const& other) = delete;

Expand Down
41 changes: 19 additions & 22 deletions vendor/ddc/include/ddc/kernels/splines/spline_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class SplineEvaluator

using bsplines_type = BSplinesType;

using left_extrapolation_rule_type = LeftExtrapolationRule;
using right_extrapolation_rule_type = RightExtrapolationRule;

using interpolation_mesh_type = InterpolationMesh;

using interpolation_domain_type = ddc::DiscreteDomain<interpolation_mesh_type>;
Expand All @@ -67,11 +70,9 @@ class SplineEvaluator


private:
const spline_domain_type m_spline_domain;

LeftExtrapolationRule m_left_extrap_rule;

RightExtrapolationRule m_right_bc;
RightExtrapolationRule m_right_extrap_rule;

public:
static_assert(
Expand Down Expand Up @@ -107,12 +108,10 @@ class SplineEvaluator
"RightExtrapolationRule::operator() has to be callable with usual arguments.");

explicit SplineEvaluator(
spline_domain_type const& spline_domain,
LeftExtrapolationRule const& left_extrap_rule,
RightExtrapolationRule const& right_extrap_rule)
: m_spline_domain(spline_domain)
, m_left_extrap_rule(left_extrap_rule)
, m_right_bc(right_extrap_rule)
: m_left_extrap_rule(left_extrap_rule)
, m_right_extrap_rule(right_extrap_rule)
{
}

Expand All @@ -126,21 +125,14 @@ class SplineEvaluator

SplineEvaluator& operator=(SplineEvaluator&& x) = default;



KOKKOS_FUNCTION spline_domain_type spline_domain() const noexcept
left_extrapolation_rule_type left_extrapolation_rule() const
{
return m_spline_domain;
return m_left_extrap_rule;
}

KOKKOS_FUNCTION bsplines_domain_type bsplines_domain() const noexcept // TODO : clarify name
right_extrapolation_rule_type right_extrapolation_rule() const
{
return ddc::discrete_space<bsplines_type>().full_domain();
}

KOKKOS_FUNCTION batch_domain_type batch_domain() const noexcept
{
return ddc::remove_dims_of(spline_domain(), bsplines_domain());
return m_right_extrap_rule;
}

template <class Layout, class... CoordsDims>
Expand All @@ -164,9 +156,11 @@ class SplineEvaluator
spline_coef) const
{
interpolation_domain_type const interpolation_domain(spline_eval.domain());
batch_domain_type const batch_domain(spline_eval.domain());

ddc::parallel_for_each(
exec_space(),
batch_domain(),
batch_domain,
KOKKOS_CLASS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
const auto spline_eval_1D = spline_eval[j];
const auto coords_eval_1D = coords_eval[j];
Expand Down Expand Up @@ -198,9 +192,11 @@ class SplineEvaluator
spline_coef) const
{
interpolation_domain_type const interpolation_domain(spline_eval.domain());
batch_domain_type const batch_domain(spline_eval.domain());

ddc::parallel_for_each(
exec_space(),
batch_domain(),
batch_domain,
KOKKOS_CLASS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
const auto spline_eval_1D = spline_eval[j];
const auto coords_eval_1D = coords_eval[j];
Expand All @@ -218,6 +214,7 @@ class SplineEvaluator
ddc::ChunkSpan<double const, spline_domain_type, Layout2, memory_space> const
spline_coef) const
{
batch_domain_type const batch_domain(integrals.domain());
ddc::Chunk values_alloc(
ddc::DiscreteDomain<bsplines_type>(spline_coef.domain()),
ddc::KokkosAllocator<double, memory_space>());
Expand All @@ -228,7 +225,7 @@ class SplineEvaluator

ddc::parallel_for_each(
exec_space(),
batch_domain(),
batch_domain,
KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
integrals(j) = 0;
for (typename bsplines_domain_type::discrete_element_type const i :
Expand Down Expand Up @@ -263,7 +260,7 @@ class SplineEvaluator
return m_left_extrap_rule(coord_eval_interpolation, spline_coef);
}
if (coord_eval_interpolation > ddc::discrete_space<bsplines_type>().rmax()) {
return m_right_bc(coord_eval_interpolation, spline_coef);
return m_right_extrap_rule(coord_eval_interpolation, spline_coef);
}
}
return eval_no_bc<eval_type>(coord_eval_interpolation, spline_coef);
Expand Down
67 changes: 38 additions & 29 deletions vendor/ddc/include/ddc/kernels/splines/spline_evaluator_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class SplineEvaluator2D
using bsplines_type1 = BSplinesType1;
using bsplines_type2 = BSplinesType2;

using left_extrapolation_rule_1_type = LeftExtrapolationRule1;
using right_extrapolation_rule_1_type = RightExtrapolationRule1;
using left_extrapolation_rule_2_type = LeftExtrapolationRule2;
using right_extrapolation_rule_2_type = RightExtrapolationRule2;

using interpolation_domain_type1 = ddc::DiscreteDomain<interpolation_mesh_type1>;
using interpolation_domain_type2 = ddc::DiscreteDomain<interpolation_mesh_type2>;
using interpolation_domain_type
Expand Down Expand Up @@ -78,15 +83,13 @@ class SplineEvaluator2D


private:
spline_domain_type m_spline_domain;

LeftExtrapolationRule1 m_left1_bc;
LeftExtrapolationRule1 m_left_extrap_rule_1;

RightExtrapolationRule1 m_right1_bc;
RightExtrapolationRule1 m_right_extrap_rule_1;

LeftExtrapolationRule2 m_left2_bc;
LeftExtrapolationRule2 m_left_extrap_rule_2;

RightExtrapolationRule2 m_right2_bc;
RightExtrapolationRule2 m_right_extrap_rule_2;

public:
static_assert(
Expand Down Expand Up @@ -156,16 +159,14 @@ class SplineEvaluator2D
"with usual arguments.");

explicit SplineEvaluator2D(
spline_domain_type const& spline_domain,
LeftExtrapolationRule1 const& left_extrap_rule1,
RightExtrapolationRule1 const& right_extrap_rule1,
LeftExtrapolationRule2 const& left_extrap_rule2,
RightExtrapolationRule2 const& right_extrap_rule2)
: m_spline_domain(spline_domain)
, m_left1_bc(left_extrap_rule1)
, m_right1_bc(right_extrap_rule1)
, m_left2_bc(left_extrap_rule2)
, m_right2_bc(right_extrap_rule2)
: m_left_extrap_rule_1(left_extrap_rule1)
, m_right_extrap_rule_1(right_extrap_rule1)
, m_left_extrap_rule_2(left_extrap_rule2)
, m_right_extrap_rule_2(right_extrap_rule2)
{
}

Expand All @@ -181,21 +182,24 @@ class SplineEvaluator2D



KOKKOS_FUNCTION spline_domain_type spline_domain() const noexcept
left_extrapolation_rule_1_type left_extrapolation_rule_dim_1() const
{
return m_left_extrap_rule_1;
}

right_extrapolation_rule_1_type right_extrapolation_rule_dim_1() const
{
return m_spline_domain;
return m_right_extrap_rule_1;
}

KOKKOS_FUNCTION bsplines_domain_type bsplines_domain() const noexcept // TODO : clarify name
left_extrapolation_rule_2_type left_extrapolation_rule_dim_2() const
{
return bsplines_domain_type(
ddc::discrete_space<bsplines_type1>().full_domain(),
ddc::discrete_space<bsplines_type2>().full_domain());
return m_left_extrap_rule_2;
}

KOKKOS_FUNCTION batch_domain_type batch_domain() const noexcept
right_extrapolation_rule_2_type right_extrapolation_rule_dim_2() const
{
return ddc::remove_dims_of(spline_domain(), bsplines_domain());
return m_right_extrap_rule_2;
}

template <class Layout, class... CoordsDims>
Expand All @@ -218,11 +222,12 @@ class SplineEvaluator2D
ddc::ChunkSpan<double const, spline_domain_type, Layout3, memory_space> const
spline_coef) const
{
batch_domain_type batch_domain(coords_eval.domain());
interpolation_domain_type1 const interpolation_domain1(spline_eval.domain());
interpolation_domain_type2 const interpolation_domain2(spline_eval.domain());
ddc::parallel_for_each(
exec_space(),
batch_domain(),
batch_domain,
KOKKOS_CLASS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
const auto spline_eval_2D = spline_eval[j];
const auto coords_eval_2D = coords_eval[j];
Expand Down Expand Up @@ -314,11 +319,12 @@ class SplineEvaluator2D
ddc::ChunkSpan<double const, spline_domain_type, Layout3, memory_space> const
spline_coef) const
{
batch_domain_type batch_domain(coords_eval.domain());
interpolation_domain_type1 const interpolation_domain1(spline_eval.domain());
interpolation_domain_type2 const interpolation_domain2(spline_eval.domain());
ddc::parallel_for_each(
exec_space(),
batch_domain(),
batch_domain,
KOKKOS_CLASS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
const auto spline_eval_2D = spline_eval[j];
const auto coords_eval_2D = coords_eval[j];
Expand All @@ -344,11 +350,12 @@ class SplineEvaluator2D
ddc::ChunkSpan<double const, spline_domain_type, Layout3, memory_space> const
spline_coef) const
{
batch_domain_type batch_domain(coords_eval.domain());
interpolation_domain_type1 const interpolation_domain1(spline_eval.domain());
interpolation_domain_type2 const interpolation_domain2(spline_eval.domain());
ddc::parallel_for_each(
exec_space(),
batch_domain(),
batch_domain,
KOKKOS_CLASS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
const auto spline_eval_2D = spline_eval[j];
const auto coords_eval_2D = coords_eval[j];
Expand All @@ -374,11 +381,12 @@ class SplineEvaluator2D
ddc::ChunkSpan<double const, spline_domain_type, Layout3, memory_space> const
spline_coef) const
{
batch_domain_type batch_domain(coords_eval.domain());
interpolation_domain_type1 const interpolation_domain1(spline_eval.domain());
interpolation_domain_type2 const interpolation_domain2(spline_eval.domain());
ddc::parallel_for_each(
exec_space(),
batch_domain(),
batch_domain,
KOKKOS_CLASS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
const auto spline_eval_2D = spline_eval[j];
const auto coords_eval_2D = coords_eval[j];
Expand Down Expand Up @@ -456,6 +464,7 @@ class SplineEvaluator2D
ddc::ChunkSpan<double const, spline_domain_type, Layout2, memory_space> const
spline_coef) const
{
batch_domain_type batch_domain(integrals.domain());
ddc::Chunk values1_alloc(
ddc::DiscreteDomain<bsplines_type1>(spline_coef.domain()),
ddc::KokkosAllocator<double, memory_space>());
Expand All @@ -473,7 +482,7 @@ class SplineEvaluator2D

ddc::parallel_for_each(
exec_space(),
batch_domain(),
batch_domain,
KOKKOS_LAMBDA(typename batch_domain_type::discrete_element_type const j) {
integrals(j) = 0;
for (typename bsplines_domain_type1::discrete_element_type const i1 :
Expand Down Expand Up @@ -509,10 +518,10 @@ class SplineEvaluator2D
}
} else {
if (coord_eval_interpolation1 < ddc::discrete_space<bsplines_type1>().rmin()) {
return m_left1_bc(coord_eval, spline_coef);
return m_left_extrap_rule_1(coord_eval, spline_coef);
}
if (coord_eval_interpolation1 > ddc::discrete_space<bsplines_type1>().rmax()) {
return m_right1_bc(coord_eval, spline_coef);
return m_right_extrap_rule_1(coord_eval, spline_coef);
}
}
if constexpr (bsplines_type2::is_periodic()) {
Expand All @@ -527,10 +536,10 @@ class SplineEvaluator2D
}
} else {
if (coord_eval_interpolation2 < ddc::discrete_space<bsplines_type2>().rmin()) {
return m_left2_bc(coord_eval, spline_coef);
return m_left_extrap_rule_2(coord_eval, spline_coef);
}
if (coord_eval_interpolation2 > ddc::discrete_space<bsplines_type2>().rmax()) {
return m_right2_bc(coord_eval, spline_coef);
return m_right_extrap_rule_2(coord_eval, spline_coef);
}
}
return eval_no_bc<eval_type, eval_type>(
Expand Down
Loading

0 comments on commit c910ac1

Please sign in to comment.