Skip to content

Commit

Permalink
Template tests by discrete dimensions instead of continuous dimensions (
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau authored Jan 9, 2025
1 parent b246dfd commit b06383d
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 153 deletions.
113 changes: 55 additions & 58 deletions tests/splines/batched_2d_spline_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ struct DDimGPS : GrevillePoints<BSplines<X>>::interpolation_discrete_dimension_t
{
};

template <typename X, typename I1, typename I2>
using DDim = std::conditional_t<std::is_same_v<X, I1> || std::is_same_v<X, I2>, DDimGPS<X>, X>;

#if defined(BC_PERIODIC)
template <typename DDim1, typename DDim2>
using evaluator_type = Evaluator2D::
Expand All @@ -121,10 +118,6 @@ using DVect = ddc::DiscreteVector<DDimX...>;
template <typename... X>
using Coord = ddc::Coordinate<X...>;

// Extract batch dimensions from DDim (remove dimension of interest). Usefull
template <typename I1, typename I2, typename... X>
using BatchDims = ddc::type_seq_remove_t<ddc::detail::TypeSeq<X...>, ddc::detail::TypeSeq<I1, I2>>;

// Templated function giving first coordinate of the mesh in given dimension.
template <typename X>
KOKKOS_FUNCTION Coord<X> x0()
Expand Down Expand Up @@ -171,11 +164,16 @@ void InterestDimInitializer(std::size_t const ncells)

// Checks that when evaluating the spline at interpolation points one
// recovers values that were used to build the spline
template <typename ExecSpace, typename MemorySpace, typename I1, typename I2, typename... X>
template <
typename ExecSpace,
typename MemorySpace,
typename DDimI1,
typename DDimI2,
typename... DDims>
void Batched2dSplineTest()
{
using DDimI1 = DDimGPS<I1>;
using DDimI2 = DDimGPS<I2>;
using I1 = typename DDimI1::continuous_dimension_type;
using I2 = typename DDimI2::continuous_dimension_type;

// Instantiate execution spaces and initialize spaces
ExecSpace const exec_space;
Expand All @@ -188,14 +186,13 @@ void Batched2dSplineTest()
= GrevillePoints<BSplines<I1>>::template get_domain<DDimI1>();
ddc::DiscreteDomain<DDimI2> const interpolation_domain2
= GrevillePoints<BSplines<I2>>::template get_domain<DDimI2>();
ddc::DiscreteDomain<DDimI1, DDimI2> const
interpolation_domain(interpolation_domain1, interpolation_domain2);
// If we remove auto using the constructor syntax, nvcc does not compile
auto const dom_vals_tmp
= ddc::DiscreteDomain<X...>(ddc::DiscreteDomain<X>(DElem<X>(0), DVect<X>(ncells))...);
ddc::DiscreteDomain<DDim<X, I1, I2>...> const dom_vals = ddc::replace_dim_of<I1, DDimI1>(
ddc::replace_dim_of<I2, DDimI2>(dom_vals_tmp, interpolation_domain),
interpolation_domain);
// The following line creates a discrete domain over all dimensions (DDims...) where we immediately
// remove the dimensions DDimI1 and DDimI2.
ddc::remove_dims_of_t<ddc::DiscreteDomain<DDims...>, DDimI1, DDimI2> const dom_vals_tmp(
ddc::DiscreteDomain<DDims...>(
ddc::DiscreteDomain<DDims>(DElem<DDims>(0), DVect<DDims>(ncells))...));
ddc::DiscreteDomain<DDims...> const
dom_vals(dom_vals_tmp, interpolation_domain1, interpolation_domain2);

#if defined(BC_HERMITE)
// Create the derivs domain
Expand Down Expand Up @@ -226,7 +223,7 @@ void Batched2dSplineTest()
s_bcl,
s_bcr,
ddc::SplineSolver::GINKGO,
DDim<X, I1, I2>...> const spline_builder(dom_vals);
DDims...> const spline_builder(dom_vals);

// Compute usefull domains (dom_interpolation, dom_batch, dom_bsplines and dom_spline)
ddc::DiscreteDomain<DDimI1, DDimI2> const dom_interpolation
Expand All @@ -246,7 +243,7 @@ void Batched2dSplineTest()
ddc::parallel_for_each(
exec_space,
vals.domain(),
KOKKOS_LAMBDA(DElem<DDim<X, I1, I2>...> const e) {
KOKKOS_LAMBDA(DElem<DDims...> const e) {
vals(e) = vals_1d(DElem<DDimI1, DDimI2>(e));
});

Expand Down Expand Up @@ -478,7 +475,7 @@ void Batched2dSplineTest()
extrapolation_rule_1_type,
extrapolation_rule_2_type,
extrapolation_rule_2_type,
DDim<X, I1, I2>...> const
DDims...> const
spline_evaluator(
extrapolation_rule_1,
extrapolation_rule_1,
Expand All @@ -491,7 +488,7 @@ void Batched2dSplineTest()
ddc::parallel_for_each(
exec_space,
coords_eval.domain(),
KOKKOS_LAMBDA(DElem<DDim<X, I1, I2>...> const e) {
KOKKOS_LAMBDA(DElem<DDims...> const e) {
coords_eval(e) = ddc::coordinate(DElem<DDimI1, DDimI2>(e));
});

Expand Down Expand Up @@ -522,15 +519,15 @@ void Batched2dSplineTest()
spline_eval.domain(),
0.,
ddc::reducer::max<double>(),
KOKKOS_LAMBDA(DElem<DDim<X, I1, I2>...> const e) {
KOKKOS_LAMBDA(DElem<DDims...> const e) {
return Kokkos::abs(spline_eval(e) - vals(e));
});
double const max_norm_error_diff1 = ddc::parallel_transform_reduce(
exec_space,
spline_eval_deriv1.domain(),
0.,
ddc::reducer::max<double>(),
KOKKOS_LAMBDA(DElem<DDim<X, I1, I2>...> const e) {
KOKKOS_LAMBDA(DElem<DDims...> const e) {
Coord<I1> const x = ddc::coordinate(DElem<DDimI1>(e));
Coord<I2> const y = ddc::coordinate(DElem<DDimI2>(e));
return Kokkos::abs(spline_eval_deriv1(e) - evaluator.deriv(x, y, 1, 0));
Expand All @@ -540,7 +537,7 @@ void Batched2dSplineTest()
spline_eval_deriv2.domain(),
0.,
ddc::reducer::max<double>(),
KOKKOS_LAMBDA(DElem<DDim<X, I1, I2>...> const e) {
KOKKOS_LAMBDA(DElem<DDims...> const e) {
Coord<I1> const x = ddc::coordinate(DElem<DDimI1>(e));
Coord<I2> const y = ddc::coordinate(DElem<DDimI2>(e));
return Kokkos::abs(spline_eval_deriv2(e) - evaluator.deriv(x, y, 0, 1));
Expand All @@ -550,7 +547,7 @@ void Batched2dSplineTest()
spline_eval_deriv1.domain(),
0.,
ddc::reducer::max<double>(),
KOKKOS_LAMBDA(DElem<DDim<X, I1, I2>...> const e) {
KOKKOS_LAMBDA(DElem<DDims...> const e) {
Coord<I1> const x = ddc::coordinate(DElem<DDimI1>(e));
Coord<I2> const y = ddc::coordinate(DElem<DDimI2>(e));
return Kokkos::abs(spline_eval_deriv12(e) - evaluator.deriv(x, y, 1, 1));
Expand Down Expand Up @@ -619,32 +616,32 @@ TEST(SUFFIX(Batched2dSplineHost), 2DXY)
Batched2dSplineTest<
Kokkos::DefaultHostExecutionSpace,
Kokkos::DefaultHostExecutionSpace::memory_space,
DimX,
DimY,
DimX,
DimY>();
DDimGPS<DimX>,
DDimGPS<DimY>,
DDimGPS<DimX>,
DDimGPS<DimY>>();
}

TEST(SUFFIX(Batched2dSplineDevice), 2DXY)
{
Batched2dSplineTest<
Kokkos::DefaultExecutionSpace,
Kokkos::DefaultExecutionSpace::memory_space,
DimX,
DimY,
DimX,
DimY>();
DDimGPS<DimX>,
DDimGPS<DimY>,
DDimGPS<DimX>,
DDimGPS<DimY>>();
}

TEST(SUFFIX(Batched2dSplineHost), 3DXY)
{
Batched2dSplineTest<
Kokkos::DefaultHostExecutionSpace,
Kokkos::DefaultHostExecutionSpace::memory_space,
DimX,
DimY,
DimX,
DimY,
DDimGPS<DimX>,
DDimGPS<DimY>,
DDimGPS<DimX>,
DDimGPS<DimY>,
DDimBatch>();
}

Expand All @@ -653,34 +650,34 @@ TEST(SUFFIX(Batched2dSplineHost), 3DXZ)
Batched2dSplineTest<
Kokkos::DefaultHostExecutionSpace,
Kokkos::DefaultHostExecutionSpace::memory_space,
DimX,
DimZ,
DimX,
DDimGPS<DimX>,
DDimGPS<DimZ>,
DDimGPS<DimX>,
DDimBatch,
DimZ>();
DDimGPS<DimZ>>();
}

TEST(SUFFIX(Batched2dSplineHost), 3DYZ)
{
Batched2dSplineTest<
Kokkos::DefaultHostExecutionSpace,
Kokkos::DefaultHostExecutionSpace::memory_space,
DimY,
DimZ,
DDimGPS<DimY>,
DDimGPS<DimZ>,
DDimBatch,
DimY,
DimZ>();
DDimGPS<DimY>,
DDimGPS<DimZ>>();
}

TEST(SUFFIX(Batched2dSplineDevice), 3DXY)
{
Batched2dSplineTest<
Kokkos::DefaultExecutionSpace,
Kokkos::DefaultExecutionSpace::memory_space,
DimX,
DimY,
DimX,
DimY,
DDimGPS<DimX>,
DDimGPS<DimY>,
DDimGPS<DimX>,
DDimGPS<DimY>,
DDimBatch>();
}

Expand All @@ -689,21 +686,21 @@ TEST(SUFFIX(Batched2dSplineDevice), 3DXZ)
Batched2dSplineTest<
Kokkos::DefaultExecutionSpace,
Kokkos::DefaultExecutionSpace::memory_space,
DimX,
DimZ,
DimX,
DDimGPS<DimX>,
DDimGPS<DimZ>,
DDimGPS<DimX>,
DDimBatch,
DimZ>();
DDimGPS<DimZ>>();
}

TEST(SUFFIX(Batched2dSplineDevice), 3DYZ)
{
Batched2dSplineTest<
Kokkos::DefaultExecutionSpace,
Kokkos::DefaultExecutionSpace::memory_space,
DimY,
DimZ,
DDimGPS<DimY>,
DDimGPS<DimZ>,
DDimBatch,
DimY,
DimZ>();
DDimGPS<DimY>,
DDimGPS<DimZ>>();
}
Loading

0 comments on commit b06383d

Please sign in to comment.