Skip to content

Commit

Permalink
Remove ddc::select calls
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau committed Dec 26, 2024
1 parent 37ef437 commit 26c0428
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 93 deletions.
2 changes: 1 addition & 1 deletion benchmarks/deepcopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static void deepcopy_subchunk_2d(benchmark::State& state)
ChunkSpanXY<double> const src(src_data.data(), dom);
ChunkSpanXY<double> const dst(dst_data.data(), dom);
for (auto _ : state) {
for (DElemX const i : ddc::select<DDimX>(dom)) {
for (DElemX const i : DDomX(dom)) {
ddc::ChunkSpan const dst_i = dst[i];
ddc::ChunkSpan const src_i = src[i];
ddc::parallel_deepcopy(dst_i, src_i);
Expand Down
8 changes: 5 additions & 3 deletions benchmarks/splines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ static void characteristics_advection_unitary(benchmark::State& state)
ExecSpace(),
x_mesh,
KOKKOS_LAMBDA(ddc::DiscreteElement<DDimX<IsNonUniform, s_degree_x>, DDimY> const ixy) {
double const x = ddc::coordinate(ddc::select<DDimX<IsNonUniform, s_degree_x>>(ixy));
double const y = ddc::coordinate(ddc::select<DDimY>(ixy));
double const x = ddc::coordinate(
ddc::DiscreteElement<DDimX<IsNonUniform, s_degree_x>>(ixy));
double const y = ddc::coordinate(ddc::DiscreteElement<DDimY>(ixy));
density(ixy) = 9.999 * Kokkos::exp(-(x * x + y * y) / 0.1 / 2);
// initial_density(ixy) = 9.999 * ((x * x + y * y) < 0.25);
});
Expand Down Expand Up @@ -191,7 +192,8 @@ static void characteristics_advection_unitary(benchmark::State& state)
KOKKOS_LAMBDA(
ddc::DiscreteElement<DDimX<IsNonUniform, s_degree_x>, DDimY> const e) {
feet_coords(e)
= ddc::coordinate(ddc::select<DDimX<IsNonUniform, s_degree_x>>(e))
= ddc::coordinate(
ddc::DiscreteElement<DDimX<IsNonUniform, s_degree_x>>(e))
- ddc::Coordinate<X>(0.0176429863);
});
Kokkos::Profiling::popRegion();
Expand Down
11 changes: 6 additions & 5 deletions examples/characteristics_advection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ int main(int argc, char** argv)
ddc::parallel_for_each(
x_mesh,
KOKKOS_LAMBDA(ddc::DiscreteElement<DDimX, DDimY> const ixy) {
double const x
= ddc::coordinate(ddc::select<DDimX>(ixy));
double const y
= ddc::coordinate(ddc::select<DDimY>(ixy));
double const x = ddc::coordinate(
ddc::DiscreteElement<DDimX>(ixy));
double const y = ddc::coordinate(
ddc::DiscreteElement<DDimY>(ixy));
initial_density(ixy)
= 9.999
* Kokkos::exp(-(x * x + y * y) / 0.1 / 2);
Expand Down Expand Up @@ -280,7 +280,8 @@ int main(int argc, char** argv)
KOKKOS_LAMBDA(
ddc::DiscreteElement<DDimX, DDimY> const e) {
feet_coords(e)
= ddc::coordinate(ddc::select<DDimX>(e))
= ddc::coordinate(
ddc::DiscreteElement<DDimX>(e))
- ddc::Coordinate<X>(
vx * ddc::step<DDimT>());
});
Expand Down
16 changes: 6 additions & 10 deletions examples/game_of_life.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ void blinker_init(
ddc::parallel_for_each(
domain,
KOKKOS_LAMBDA(ddc::DiscreteElement<DDimX, DDimY> const ixy) {
ddc::DiscreteElement<DDimX> const ix
= ddc::select<DDimX>(ixy);
ddc::DiscreteElement<DDimY> const iy
= ddc::select<DDimY>(ixy);
ddc::DiscreteElement<DDimX> const ix(ixy);
ddc::DiscreteElement<DDimY> const iy(ixy);
if (iy == ddc::DiscreteElement<DDimY>(2)
&& (ix >= ddc::DiscreteElement<DDimX>(1)
&& ix <= ddc::DiscreteElement<DDimX>(3))) {
Expand All @@ -56,10 +54,10 @@ std::ostream& print_2DChunk(
chunk)
{
ddc::for_each(
ddc::select<DDimY>(chunk.domain()),
ddc::DiscreteDomain<DDimY>(chunk.domain()),
[&](ddc::DiscreteElement<DDimY> const iy) {
ddc::for_each(
ddc::select<DDimX>(chunk.domain()),
ddc::DiscreteDomain<DDimX>(chunk.domain()),
[&](ddc::DiscreteElement<DDimX> const ix) {
os << (chunk(ix, iy) ? "*" : ".");
});
Expand Down Expand Up @@ -108,10 +106,8 @@ int main()
inner_domain_xy,
KOKKOS_LAMBDA(
ddc::DiscreteElement<DDimX, DDimY> const ixy) {
ddc::DiscreteElement<DDimX> const ix
= ddc::select<DDimX>(ixy);
ddc::DiscreteElement<DDimY> const iy
= ddc::select<DDimY>(ixy);
ddc::DiscreteElement<DDimX> const ix(ixy);
ddc::DiscreteElement<DDimY> const iy(ixy);
int alive_neighbors = 0;
// Iterate on neighbors and increase the count of alive neighbors when necessary
for (int i = -1; i < 2; ++i) {
Expand Down
14 changes: 6 additions & 8 deletions examples/heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ int main(int argc, char** argv)
ddc::parallel_for_each(
ddc::DiscreteDomain<DDimX, DDimY>(x_domain, y_domain),
KOKKOS_LAMBDA(ddc::DiscreteElement<DDimX, DDimY> const ixy) {
double const x
= ddc::coordinate(ddc::select<DDimX>(ixy));
double const y
= ddc::coordinate(ddc::select<DDimY>(ixy));
double const x = ddc::coordinate(
ddc::DiscreteElement<DDimX>(ixy));
double const y = ddc::coordinate(
ddc::DiscreteElement<DDimY>(ixy));
ghosted_initial_temp(ixy)
= 9.999 * ((x * x + y * y) < 0.25);
});
Expand Down Expand Up @@ -334,10 +334,8 @@ int main(int argc, char** argv)
next_temp.domain(),
KOKKOS_LAMBDA(
ddc::DiscreteElement<DDimX, DDimY> const ixy) {
ddc::DiscreteElement<DDimX> const ix
= ddc::select<DDimX>(ixy);
ddc::DiscreteElement<DDimY> const iy
= ddc::select<DDimY>(ixy);
ddc::DiscreteElement<DDimX> const ix(ixy);
ddc::DiscreteElement<DDimY> const iy(ixy);
double const dx_l = ddc::distance_at_left(ix);
double const dx_r = ddc::distance_at_right(ix);
double const dx_m = 0.5 * (dx_l + dx_r);
Expand Down
6 changes: 2 additions & 4 deletions examples/non_uniform_heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,8 @@ int main(int argc, char** argv)
next_temp.domain(),
KOKKOS_LAMBDA(
ddc::DiscreteElement<DDimX, DDimY> const ixy) {
ddc::DiscreteElement<DDimX> const ix
= ddc::select<DDimX>(ixy);
ddc::DiscreteElement<DDimY> const iy
= ddc::select<DDimY>(ixy);
ddc::DiscreteElement<DDimX> const ix(ixy);
ddc::DiscreteElement<DDimY> const iy(ixy);
double const dx_l = ddc::distance_at_left(ix);
double const dx_r = ddc::distance_at_right(ix);
double const dx_m = 0.5 * (dx_l + dx_r);
Expand Down
4 changes: 2 additions & 2 deletions include/ddc/discrete_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ replace_dim_of_1d(
[[maybe_unused]] DiscreteDomain<DDimsB...> const& DDom_b) noexcept
{
if constexpr (std::is_same_v<DDimA, DDim1>) {
return ddc::select<DDim2>(DDom_b);
return ddc::DiscreteDomain<DDim2>(DDom_b);
} else {
return DDom_a;
}
Expand All @@ -492,7 +492,7 @@ KOKKOS_FUNCTION constexpr auto replace_dim_of(
DDim1,
DDim2,
DDimsA,
DDimsB...>(ddc::select<DDimsA>(DDom_a), DDom_b)...);
DDimsB...>(ddc::DiscreteDomain<DDimsA>(DDom_a), DDom_b)...);
}

// Replace dimensions from a domain type
Expand Down
15 changes: 8 additions & 7 deletions include/ddc/kernels/splines/constant_extrapolation_rule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ struct ConstantExtrapolationRule<DimI, DimNI>
*
* In the dimension defined in the constructor Dim1 (or Dim2), it sets the coordinate pos_1 (or pos_2)
* given at the m_eval_pos coordinate if it is outside the domain.
* If the coordinate on the complementary dimension of the boundary condition dimension ddc::select<DimNI>(coord_extrap) is
* If the coordinate on the complementary dimension of the boundary condition dimension ddc::Coordinate<DimNI>(coord_extrap) is
* outside the domain, then it also sets the coordinate at eval_pos_not_interest_min
* (if ddc::select<DimNI>(coord_extrap) @f$ < @f$ eval_pos_not_interest_min) or
* at eval_pos_not_interest_max (if ddc::select<DimNI>(coord_extrap) @f$ > @f$ eval_pos_not_interest_max).
* (if ddc::Coordinate<DimNI>(coord_extrap) @f$ < @f$ eval_pos_not_interest_min) or
* at eval_pos_not_interest_max (if ddc::Coordinate<DimNI>(coord_extrap) @f$ > @f$ eval_pos_not_interest_max).
*
* @param[in] coord_extrap
* The coordinates where we want to evaluate the function on B-splines
Expand All @@ -169,12 +169,13 @@ struct ConstantExtrapolationRule<DimI, DimNI>

ddc::Coordinate<DimI, DimNI> eval_pos;
if constexpr (DimNI::PERIODIC) {
eval_pos = ddc::Coordinate<DimI, DimNI>(m_eval_pos, ddc::select<DimNI>(coord_extrap));
eval_pos = ddc::
Coordinate<DimI, DimNI>(m_eval_pos, ddc::Coordinate<DimNI>(coord_extrap));
} else {
eval_pos = ddc::Coordinate<DimI, DimNI>(
m_eval_pos,
Kokkos::
clamp(ddc::select<DimNI>(coord_extrap),
clamp(ddc::Coordinate<DimNI>(coord_extrap),
m_eval_pos_not_interest_min,
m_eval_pos_not_interest_max));
}
Expand All @@ -188,10 +189,10 @@ struct ConstantExtrapolationRule<DimI, DimNI>

ddc::DiscreteElement<BSplines1> const idx1 = ddc::discrete_space<BSplines1>().eval_basis(
vals1,
ddc::select<typename BSplines1::continuous_dimension_type>(eval_pos));
ddc::Coordinate<typename BSplines1::continuous_dimension_type>(eval_pos));
ddc::DiscreteElement<BSplines2> const idx2 = ddc::discrete_space<BSplines2>().eval_basis(
vals2,
ddc::select<typename BSplines2::continuous_dimension_type>(eval_pos));
ddc::Coordinate<typename BSplines2::continuous_dimension_type>(eval_pos));

double y = 0.0;
for (std::size_t i = 0; i < BSplines1::degree() + 1; ++i) {
Expand Down
6 changes: 2 additions & 4 deletions include/ddc/kernels/splines/spline_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ class SplineEvaluator
ddc::ChunkSpan<double const, spline_domain_type, Layout, memory_space> const
spline_coef) const
{
ddc::Coordinate<continuous_dimension_type> coord_eval_interest
= ddc::select<continuous_dimension_type>(coord_eval);
ddc::Coordinate<continuous_dimension_type> coord_eval_interest(coord_eval);
if constexpr (bsplines_type::is_periodic()) {
if (coord_eval_interest < ddc::discrete_space<bsplines_type>().rmin()
|| coord_eval_interest > ddc::discrete_space<bsplines_type>().rmax()) {
Expand Down Expand Up @@ -520,8 +519,7 @@ class SplineEvaluator
std::array<double, bsplines_type::degree() + 1> vals_ptr;
Kokkos::mdspan<double, Kokkos::extents<std::size_t, bsplines_type::degree() + 1>> const
vals(vals_ptr.data());
ddc::Coordinate<continuous_dimension_type> const coord_eval_interest
= ddc::select<continuous_dimension_type>(coord_eval);
ddc::Coordinate<continuous_dimension_type> const coord_eval_interest(coord_eval);
if constexpr (std::is_same_v<EvalType, eval_type>) {
jmin = ddc::discrete_space<bsplines_type>().eval_basis(vals, coord_eval_interest);
} else if constexpr (std::is_same_v<EvalType, eval_deriv_type>) {
Expand Down
6 changes: 2 additions & 4 deletions include/ddc/kernels/splines/spline_evaluator_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,10 +1186,8 @@ class SplineEvaluator2D
std::array<double, bsplines_type2::degree() + 1> vals2_ptr;
Kokkos::mdspan<double, Kokkos::extents<std::size_t, bsplines_type2::degree() + 1>> const
vals2(vals2_ptr.data());
ddc::Coordinate<continuous_dimension_type1> const coord_eval_interest1
= ddc::select<continuous_dimension_type1>(coord_eval);
ddc::Coordinate<continuous_dimension_type2> const coord_eval_interest2
= ddc::select<continuous_dimension_type2>(coord_eval);
ddc::Coordinate<continuous_dimension_type1> const coord_eval_interest1(coord_eval);
ddc::Coordinate<continuous_dimension_type2> const coord_eval_interest2(coord_eval);

if constexpr (std::is_same_v<EvalType1, eval_type>) {
jmin1 = ddc::discrete_space<bsplines_type1>().eval_basis(vals1, coord_eval_interest1);
Expand Down
2 changes: 1 addition & 1 deletion tests/chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ TEST(Chunk2DTest, DeepcopyReordered)
chunk(ix, iy) = 1.739 * ix.uid() + 1.412 * iy.uid();
}
}
ChunkYX<double> chunk2(ddc::select<DDimY, DDimX>(chunk.domain()));
ChunkYX<double> chunk2(DDomYX(chunk.domain()));
ddc::ChunkSpan<double, DDomXY, Kokkos::layout_left> const
chunk2_view(chunk2.data_handle(), chunk.domain());
ddc::parallel_deepcopy(chunk2_view, chunk);
Expand Down
12 changes: 6 additions & 6 deletions tests/discrete_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,12 @@ TEST(DiscreteDomainTest, Transpose3DConstructor)
DDomZ const dom_z(lbound_z, nelems_z);
DDomXYZ const dom_x_y_z(dom_x, dom_y, dom_z);
DDomZYX const dom_z_y_x(dom_x_y_z);
EXPECT_EQ(ddc::select<DDimX>(dom_x_y_z.front()), ddc::select<DDimX>(dom_z_y_x.front()));
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.front()), ddc::select<DDimY>(dom_z_y_x.front()));
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.front()), ddc::select<DDimZ>(dom_z_y_x.front()));
EXPECT_EQ(ddc::select<DDimX>(dom_x_y_z.back()), ddc::select<DDimX>(dom_z_y_x.back()));
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.back()), ddc::select<DDimY>(dom_z_y_x.back()));
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.back()), ddc::select<DDimZ>(dom_z_y_x.back()));
EXPECT_EQ(DElemX(dom_x_y_z.front()), DElemX(dom_z_y_x.front()));
EXPECT_EQ(DElemY(dom_x_y_z.front()), DElemY(dom_z_y_x.front()));
EXPECT_EQ(DElemZ(dom_x_y_z.front()), DElemZ(dom_z_y_x.front()));
EXPECT_EQ(DElemX(dom_x_y_z.back()), DElemX(dom_z_y_x.back()));
EXPECT_EQ(DElemY(dom_x_y_z.back()), DElemY(dom_z_y_x.back()));
EXPECT_EQ(DElemZ(dom_x_y_z.back()), DElemZ(dom_z_y_x.back()));
}

TEST(DiscreteDomainTest, CartesianProduct)
Expand Down
6 changes: 2 additions & 4 deletions tests/fft/fft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ static void test_fft()
exec_space,
f.domain(),
KOKKOS_LAMBDA(DElem<DDim<X>...> const e) {
ddc::Real const xn2
= (Kokkos::pow(ddc::coordinate(ddc::select<DDim<X>>(e)), 2) + ...);
ddc::Real const xn2 = (Kokkos::pow(ddc::coordinate(DElem<DDim<X>>(e)), 2) + ...);
f(e) = Kokkos::exp(-xn2 / 2);
});
ddc::Chunk f_bis_alloc(f.domain(), ddc::KokkosAllocator<Tin, MemorySpace>());
Expand Down Expand Up @@ -144,8 +143,7 @@ static void test_fft()
0.,
ddc::reducer::sum<double>(),
[=](DElem<DFDim<ddc::Fourier<X>>...> const e) {
double const xn2
= (pow2(ddc::coordinate(ddc::select<DFDim<ddc::Fourier<X>>>(e))) + ...);
double const xn2 = (pow2(ddc::coordinate(DElem<DFDim<ddc::Fourier<X>>>(e))) + ...);
double const diff = Kokkos::abs(Ff_host(e)) - Kokkos::exp(-xn2 / 2);
std::size_t const denom
= (ddc::detail::fft::LastSelector<std::size_t, X, X...>(Nx / 2, Nx) * ...);
Expand Down
Loading

0 comments on commit 26c0428

Please sign in to comment.