Skip to content

Commit

Permalink
Merge branch 'kokkos-kernels-backend' into spmv-in-2x2
Browse files Browse the repository at this point in the history
  • Loading branch information
blegouix committed Jul 17, 2024
2 parents 8961259 + 91c9f45 commit 01267da
Show file tree
Hide file tree
Showing 22 changed files with 603 additions and 504 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v4
- uses: DoozyX/clang-format-lint-action@v0.17
with:
source: 'include/ddc/ tests/ examples/'
source: 'benchmarks/ examples/ include/ddc/ tests/'
exclude: ''
extensions: 'hpp,cpp'
clangFormatVersion: 12
Expand Down
5 changes: 3 additions & 2 deletions benchmarks/splines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(SPLINES_CPP)
BSplinesX,
ddc::BoundCond::PERIODIC,
ddc::BoundCond::PERIODIC>;
struct DDimX : GrevillePoints::interpolation_mesh_type
struct DDimX : GrevillePoints::interpolation_discrete_dimension_type
{
};

Expand Down Expand Up @@ -148,7 +148,8 @@ static void characteristics_advection(benchmark::State& state)
ddc::parallel_for_each(
feet_coords.domain(),
KOKKOS_LAMBDA(ddc::DiscreteElement<DDimX, DDimY> const e) {
feet_coords(e) = ddc::coordinate(ddc::select<DDimX>(e)) - ddc::Coordinate<X>(0.0176429863);
feet_coords(e) = ddc::coordinate(ddc::select<DDimX>(e))
- ddc::Coordinate<X>(0.0176429863);
});
Kokkos::Profiling::popRegion();
Kokkos::Profiling::pushRegion("SplineBuilder");
Expand Down
2 changes: 1 addition & 1 deletion examples/characteristics_advection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct BSplinesX : ddc::UniformBSplines<X, s_degree_x>
};
using GrevillePoints = ddc::
GrevilleInterpolationPoints<BSplinesX, BoundCond, BoundCond>;
struct DDimX : GrevillePoints::interpolation_mesh_type
struct DDimX : GrevillePoints::interpolation_discrete_dimension_type
{
};
//! [X-discretization]
Expand Down
51 changes: 27 additions & 24 deletions include/ddc/kernels/splines/bsplines_non_uniform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class NonUniformBSplines : detail::NonUniformBSplinesBase

public:
/// @brief The type of the knots defining the B-splines.
using knot_mesh_type = NonUniformBsplinesKnots<DDim>;
using knot_discrete_dimension_type = NonUniformBsplinesKnots<DDim>;

/// @brief The type of the discrete dimension representing the B-splines.
using discrete_dimension_type = NonUniformBSplines;
Expand All @@ -104,8 +104,8 @@ class NonUniformBSplines : detail::NonUniformBSplinesBase
using discrete_vector_type = DiscreteVector<DDim>;

private:
ddc::DiscreteDomain<knot_mesh_type> m_knot_domain;
ddc::DiscreteDomain<knot_mesh_type> m_break_point_domain;
ddc::DiscreteDomain<knot_discrete_dimension_type> m_knot_domain;
ddc::DiscreteDomain<knot_discrete_dimension_type> m_break_point_domain;

public:
Impl() = default;
Expand Down Expand Up @@ -265,10 +265,11 @@ class NonUniformBSplines : detail::NonUniformBSplinesBase
* @param[in] ix DiscreteElement identifying the B-spline.
* @return DiscreteElement of the lower bound of the support of the B-spline.
*/
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<knot_mesh_type> get_first_support_knot(
discrete_element_type const& ix) const
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<knot_discrete_dimension_type>
get_first_support_knot(discrete_element_type const& ix) const
{
return ddc::DiscreteElement<knot_mesh_type>((ix - discrete_element_type(0)).value());
return ddc::DiscreteElement<knot_discrete_dimension_type>(
(ix - discrete_element_type(0)).value());
}

/** @brief Returns the coordinate of the last support knot associated to a DiscreteElement identifying a B-spline.
Expand All @@ -280,10 +281,11 @@ class NonUniformBSplines : detail::NonUniformBSplinesBase
* @param[in] ix DiscreteElement identifying the B-spline.
* @return DiscreteElement of the upper bound of the support of the B-spline.
*/
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<knot_mesh_type> get_last_support_knot(
discrete_element_type const& ix) const
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<knot_discrete_dimension_type>
get_last_support_knot(discrete_element_type const& ix) const
{
return get_first_support_knot(ix) + ddc::DiscreteVector<knot_mesh_type>(degree() + 1);
return get_first_support_knot(ix)
+ ddc::DiscreteVector<knot_discrete_dimension_type>(degree() + 1);
}

/** @brief Returns the coordinate of the first break point of the domain on which the B-splines are defined.
Expand Down Expand Up @@ -339,7 +341,8 @@ class NonUniformBSplines : detail::NonUniformBSplinesBase
*
* @return The discrete domain describing the break points.
*/
KOKKOS_INLINE_FUNCTION ddc::DiscreteDomain<knot_mesh_type> break_point_domain() const
KOKKOS_INLINE_FUNCTION ddc::DiscreteDomain<knot_discrete_dimension_type>
break_point_domain() const
{
return m_break_point_domain;
}
Expand Down Expand Up @@ -379,8 +382,8 @@ class NonUniformBSplines : detail::NonUniformBSplinesBase
}

private:
KOKKOS_INLINE_FUNCTION discrete_element_type
get_first_bspline_in_cell(ddc::DiscreteElement<knot_mesh_type> const& ic) const
KOKKOS_INLINE_FUNCTION discrete_element_type get_first_bspline_in_cell(
ddc::DiscreteElement<knot_discrete_dimension_type> const& ic) const
{
return discrete_element_type((ic - m_break_point_domain.front()).value());
}
Expand All @@ -390,7 +393,7 @@ class NonUniformBSplines : detail::NonUniformBSplinesBase
* @param x The point whose location must be determined.
* @returns The DiscreteElement describing the knot at the lower bound of the cell of interest.
*/
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<knot_mesh_type> find_cell_start(
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<knot_discrete_dimension_type> find_cell_start(
ddc::Coordinate<CDim> const& x) const;
};
};
Expand All @@ -415,13 +418,13 @@ NonUniformBSplines<CDim, D>::Impl<DDim, MemorySpace>::Impl(
RandomIt const break_begin,
RandomIt const break_end)
: m_knot_domain(
ddc::DiscreteElement<knot_mesh_type>(0),
ddc::DiscreteVector<knot_mesh_type>(
ddc::DiscreteElement<knot_discrete_dimension_type>(0),
ddc::DiscreteVector<knot_discrete_dimension_type>(
(break_end - break_begin)
+ 2 * degree())) // Create a mesh of knots including the eventual periodic point
, m_break_point_domain(
ddc::DiscreteElement<knot_mesh_type>(degree()),
ddc::DiscreteVector<knot_mesh_type>(
ddc::DiscreteElement<knot_discrete_dimension_type>(degree()),
ddc::DiscreteVector<knot_discrete_dimension_type>(
(break_end - break_begin))) // Create a mesh of break points
{
std::vector<ddc::Coordinate<CDim>> knots((break_end - break_begin) + 2 * degree());
Expand Down Expand Up @@ -449,7 +452,7 @@ NonUniformBSplines<CDim, D>::Impl<DDim, MemorySpace>::Impl(
knots[degree() + npoints() - 1 + i] = rmax;
}
}
ddc::init_discrete_space<knot_mesh_type>(knots);
ddc::init_discrete_space<knot_discrete_dimension_type>(knots);
}

template <class CDim, std::size_t D>
Expand All @@ -467,7 +470,7 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<DDim> NonUniformBSplines<CDim, D>::
assert(values.size() == degree() + 1);

// 1. Compute cell index 'icell'
ddc::DiscreteElement<knot_mesh_type> const icell = find_cell_start(x);
ddc::DiscreteElement<knot_discrete_dimension_type> const icell = find_cell_start(x);

assert(icell >= m_break_point_domain.front());
assert(icell <= m_break_point_domain.back());
Expand Down Expand Up @@ -505,7 +508,7 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<DDim> NonUniformBSplines<CDim, D>::
assert(derivs.size() == degree() + 1);

// 1. Compute cell index 'icell'
ddc::DiscreteElement<knot_mesh_type> const icell = find_cell_start(x);
ddc::DiscreteElement<knot_discrete_dimension_type> const icell = find_cell_start(x);

assert(icell >= m_break_point_domain.front());
assert(icell <= m_break_point_domain.back());
Expand Down Expand Up @@ -581,7 +584,7 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<DDim> NonUniformBSplines<CDim, D>::
assert(derivs.extent(1) == 1 + n);

// 1. Compute cell index 'icell' and x_offset
ddc::DiscreteElement<knot_mesh_type> const icell = find_cell_start(x);
ddc::DiscreteElement<knot_discrete_dimension_type> const icell = find_cell_start(x);

assert(icell >= m_break_point_domain.front());
assert(icell <= m_break_point_domain.back());
Expand Down Expand Up @@ -672,9 +675,9 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<NonUniformBsplinesKnots<DDim>> NonUn
return m_break_point_domain.back() - 1;

// Binary search
ddc::DiscreteElement<knot_mesh_type> low = m_break_point_domain.front();
ddc::DiscreteElement<knot_mesh_type> high = m_break_point_domain.back();
ddc::DiscreteElement<knot_mesh_type> icell = low + (high - low) / 2;
ddc::DiscreteElement<knot_discrete_dimension_type> low = m_break_point_domain.front();
ddc::DiscreteElement<knot_discrete_dimension_type> high = m_break_point_domain.back();
ddc::DiscreteElement<knot_discrete_dimension_type> icell = low + (high - low) / 2;
while (x < ddc::coordinate(icell) || x >= ddc::coordinate(icell + 1)) {
if (x < ddc::coordinate(icell)) {
high = icell;
Expand Down
48 changes: 26 additions & 22 deletions include/ddc/kernels/splines/bsplines_uniform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class UniformBSplines : detail::UniformBSplinesBase

public:
/// @brief The type of the knots defining the B-splines.
using knot_mesh_type = UniformBsplinesKnots<DDim>;
using knot_discrete_dimension_type = UniformBsplinesKnots<DDim>;

/// @brief The type of the discrete dimension representing the B-splines.
using discrete_dimension_type = UniformBSplines;
Expand All @@ -105,8 +105,8 @@ class UniformBSplines : detail::UniformBSplinesBase

private:
// In the periodic case, they contain the periodic point twice!!!
ddc::DiscreteDomain<knot_mesh_type> m_knot_domain;
ddc::DiscreteDomain<knot_mesh_type> m_break_point_domain;
ddc::DiscreteDomain<knot_discrete_dimension_type> m_knot_domain;
ddc::DiscreteDomain<knot_discrete_dimension_type> m_break_point_domain;

public:
Impl() = default;
Expand All @@ -120,16 +120,17 @@ class UniformBSplines : detail::UniformBSplinesBase
explicit Impl(ddc::Coordinate<CDim> rmin, ddc::Coordinate<CDim> rmax, std::size_t ncells)
{
assert(ncells > 0);
ddc::DiscreteDomain<knot_mesh_type> pre_ghost;
ddc::DiscreteDomain<knot_mesh_type> post_ghost;
ddc::DiscreteDomain<knot_discrete_dimension_type> pre_ghost;
ddc::DiscreteDomain<knot_discrete_dimension_type> post_ghost;
std::tie(m_break_point_domain, m_knot_domain, pre_ghost, post_ghost)
= ddc::init_discrete_space<knot_mesh_type>(
knot_mesh_type::template init_ghosted<knot_mesh_type>(
= ddc::init_discrete_space<knot_discrete_dimension_type>(
knot_discrete_dimension_type::template init_ghosted<
knot_discrete_dimension_type>(
rmin,
rmax,
ddc::DiscreteVector<knot_mesh_type>(ncells + 1),
ddc::DiscreteVector<knot_mesh_type>(degree()),
ddc::DiscreteVector<knot_mesh_type>(degree())));
ddc::DiscreteVector<knot_discrete_dimension_type>(ncells + 1),
ddc::DiscreteVector<knot_discrete_dimension_type>(degree()),
ddc::DiscreteVector<knot_discrete_dimension_type>(degree())));
}

/** @brief Copy-constructs from another Impl with a different Kokkos memory space.
Expand Down Expand Up @@ -246,10 +247,11 @@ class UniformBSplines : detail::UniformBSplinesBase
* @param[in] ix DiscreteElement identifying the B-spline.
* @return DiscreteElement of the lower bound of the support of the B-spline.
*/
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<knot_mesh_type> get_first_support_knot(
discrete_element_type const& ix) const
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<knot_discrete_dimension_type>
get_first_support_knot(discrete_element_type const& ix) const
{
return ddc::DiscreteElement<knot_mesh_type>((ix - discrete_element_type(0)).value());
return ddc::DiscreteElement<knot_discrete_dimension_type>(
(ix - discrete_element_type(0)).value());
}

/** @brief Returns the coordinate of the last support knot associated to a DiscreteElement identifying a B-spline.
Expand All @@ -261,10 +263,11 @@ class UniformBSplines : detail::UniformBSplinesBase
* @param[in] ix DiscreteElement identifying the B-spline.
* @return DiscreteElement of the upper bound of the support of the B-spline.
*/
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<knot_mesh_type> get_last_support_knot(
discrete_element_type const& ix) const
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<knot_discrete_dimension_type>
get_last_support_knot(discrete_element_type const& ix) const
{
return get_first_support_knot(ix) + ddc::DiscreteVector<knot_mesh_type>(degree() + 1);
return get_first_support_knot(ix)
+ ddc::DiscreteVector<knot_discrete_dimension_type>(degree() + 1);
}

/** @brief Returns the coordinate of the lower bound of the domain on which the B-splines are defined.
Expand Down Expand Up @@ -320,7 +323,8 @@ class UniformBSplines : detail::UniformBSplinesBase
*
* @return The discrete domain describing the break points.
*/
KOKKOS_INLINE_FUNCTION ddc::DiscreteDomain<knot_mesh_type> break_point_domain() const
KOKKOS_INLINE_FUNCTION ddc::DiscreteDomain<knot_discrete_dimension_type>
break_point_domain() const
{
return m_break_point_domain;
}
Expand Down Expand Up @@ -351,7 +355,7 @@ class UniformBSplines : detail::UniformBSplinesBase
private:
KOKKOS_INLINE_FUNCTION double inv_step() const noexcept
{
return 1.0 / ddc::step<knot_mesh_type>();
return 1.0 / ddc::step<knot_discrete_dimension_type>();
}

KOKKOS_INLINE_FUNCTION discrete_element_type
Expand Down Expand Up @@ -427,7 +431,7 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<DDim> UniformBSplines<CDim, D>::
// 3. Compute derivatives of aforementioned B-splines
// Derivatives are normalized, hence they should be divided by dx
double xx, temp, saved;
derivs(0) = 1.0 / ddc::step<knot_mesh_type>();
derivs(0) = 1.0 / ddc::step<knot_discrete_dimension_type>();
for (std::size_t j = 1; j < degree(); ++j) {
xx = -offset;
saved = 0.0;
Expand Down Expand Up @@ -596,7 +600,7 @@ UniformBSplines<CDim, D>::Impl<DDim, MemorySpace>::integrals(
discrete_domain_type const dom_bsplines(
full_dom_splines.take_first(discrete_vector_type {nbasis()}));
for (auto ix : dom_bsplines) {
int_vals(ix) = ddc::step<knot_mesh_type>();
int_vals(ix) = ddc::step<knot_discrete_dimension_type>();
}
if (int_vals.size() == size()) {
discrete_domain_type const dom_bsplines_repeated(
Expand All @@ -610,7 +614,7 @@ UniformBSplines<CDim, D>::Impl<DDim, MemorySpace>::integrals(
= full_dom_splines
.remove(discrete_vector_type(degree()), discrete_vector_type(degree()));
for (auto ix : dom_bspline_entirely_in_domain) {
int_vals(ix) = ddc::step<knot_mesh_type>();
int_vals(ix) = ddc::step<knot_discrete_dimension_type>();
}

std::array<double, degree() + 2> edge_vals_ptr;
Expand All @@ -625,7 +629,7 @@ UniformBSplines<CDim, D>::Impl<DDim, MemorySpace>::integrals(
for (std::size_t i = 0; i < degree(); ++i) {
double const c_eval = ddc::detail::sum(edge_vals, 0, degree() - i);

double const edge_value = ddc::step<knot_mesh_type>() * (d_eval - c_eval);
double const edge_value = ddc::step<knot_discrete_dimension_type>() * (d_eval - c_eval);

int_vals(discrete_element_type(i)) = edge_value;
int_vals(discrete_element_type(nbasis() - 1 - i)) = edge_value;
Expand Down
Loading

0 comments on commit 01267da

Please sign in to comment.