Skip to content

Commit

Permalink
Deprecate restrict in favor of restrict_with (#689)
Browse files Browse the repository at this point in the history
* Deprecate restrict in favor of restrict_with

* Add configure option to disable deprecated code
  • Loading branch information
tpadioleau authored Nov 27, 2024
1 parent 49a69d5 commit c61a9da
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 9 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ project(DDC VERSION 0.1.0 LANGUAGES CXX)
# List of options

option(DDC_BUILD_BENCHMARKS "Build DDC benchmarks." OFF)
option(DDC_BUILD_DEPRECATED_CODE "Build DDC deprecated code." ON)
option(DDC_BUILD_DOCUMENTATION "Build DDC documentation/website" OFF)
option(
DDC_BUILD_DOUBLE_PRECISION
Expand Down
2 changes: 2 additions & 0 deletions cmake/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

#pragma once

#cmakedefine DDC_BUILD_DEPRECATED_CODE

#cmakedefine DDC_BUILD_DOUBLE_PRECISION
2 changes: 2 additions & 0 deletions include/ddc/chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator>

using discrete_domain_type = typename base_type::discrete_domain_type;

#if defined(DDC_BUILD_DEPRECATED_CODE)
using mdomain_type [[deprecated("Use `discrete_domain_type` instead")]] =
typename base_type::mdomain_type;
#endif

using memory_space = typename Allocator::memory_space;

Expand Down
2 changes: 2 additions & 0 deletions include/ddc/chunk_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class ChunkCommon<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy>
public:
using discrete_domain_type = DiscreteDomain<DDims...>;

#if defined(DDC_BUILD_DEPRECATED_CODE)
using mdomain_type [[deprecated("Use `discrete_domain_type` instead")]]
= DiscreteDomain<DDims...>;
#endif

/// The dereferenceable part of the co-domain but with a different domain, starting at 0
using allocation_mdspan_type = Kokkos::mdspan<
Expand Down
10 changes: 6 additions & 4 deletions include/ddc/chunk_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ class ChunkSpan<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy, Memo

using discrete_domain_type = typename base_type::discrete_domain_type;

#if defined(DDC_BUILD_DEPRECATED_CODE)
using mdomain_type [[deprecated("Use `discrete_domain_type` instead")]]
= DiscreteDomain<DDims...>;
#endif

using memory_space = MemorySpace;

Expand Down Expand Up @@ -311,15 +313,15 @@ class ChunkSpan<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy, Memo
a(subview.data_handle(), mapping_stride);
return ChunkSpan<
ElementType,
decltype(this->m_domain.restrict(odomain)),
decltype(this->m_domain.restrict_with(odomain)),
Kokkos::layout_stride,
memory_space>(a, this->m_domain.restrict(odomain));
memory_space>(a, this->m_domain.restrict_with(odomain));
} else {
return ChunkSpan<
ElementType,
decltype(this->m_domain.restrict(odomain)),
decltype(this->m_domain.restrict_with(odomain)),
layout_type,
memory_space>(subview, this->m_domain.restrict(odomain));
memory_space>(subview, this->m_domain.restrict_with(odomain));
}
}

Expand Down
23 changes: 21 additions & 2 deletions include/ddc/discrete_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,17 @@ class DiscreteDomain
return DiscreteDomain(front() + n1, extents() - n1 - n2);
}

#if defined(DDC_BUILD_DEPRECATED_CODE)
template <class... ODDims>
KOKKOS_FUNCTION constexpr auto restrict(DiscreteDomain<ODDims...> const& odomain) const
[[deprecated("Use `restrict_with` instead")]] KOKKOS_FUNCTION constexpr auto restrict(
DiscreteDomain<ODDims...> const& odomain) const
{
return restrict_with(odomain);
}
#endif

template <class... ODDims>
KOKKOS_FUNCTION constexpr auto restrict_with(DiscreteDomain<ODDims...> const& odomain) const
{
assert(((uid<ODDims>(m_element_begin) <= uid<ODDims>(odomain.m_element_begin)) && ...));
assert(((uid<ODDims>(m_element_end) >= uid<ODDims>(odomain.m_element_end)) && ...));
Expand Down Expand Up @@ -349,8 +358,18 @@ class DiscreteDomain<>
return *this;
}

#if defined(DDC_BUILD_DEPRECATED_CODE)
template <class... ODims>
[[deprecated("Use `restrict_with` instead")]] KOKKOS_FUNCTION constexpr DiscreteDomain restrict(
DiscreteDomain<ODims...> const& odomain) const
{
return restrict_with(odomain);
}
#endif

template <class... ODims>
KOKKOS_FUNCTION constexpr DiscreteDomain restrict(DiscreteDomain<ODims...> const&) const
KOKKOS_FUNCTION constexpr DiscreteDomain restrict_with(
DiscreteDomain<ODims...> const& /* odomain */) const
{
return *this;
}
Expand Down
2 changes: 2 additions & 0 deletions include/ddc/kernels/fft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ ddc::DiscreteDomain<DDimFx...> fourier_mesh(ddc::DiscreteDomain<DDimX...> x_mesh
ddc::detail::fft::N<DDimX>(x_mesh)))))...);
}

#if defined(DDC_BUILD_DEPRECATED_CODE)
/**
* @brief Get the Fourier mesh.
*
Expand All @@ -385,6 +386,7 @@ template <typename... DDimFx, typename... DDimX>
{
return fourier_mesh<DDimFx...>(x_mesh, C2C);
}
#endif

/**
* @brief A structure embedding the configuration of the exposed FFT function with the type of normalization.
Expand Down
4 changes: 4 additions & 0 deletions include/ddc/kernels/splines/bsplines_non_uniform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class NonUniformBSplines : detail::NonUniformBSplinesBase
ddc::Coordinate<CDim> const& x,
std::size_t n) const;

#if defined(DDC_BUILD_DEPRECATED_CODE)
/** @brief Compute the integrals of the B-splines.
*
* The integral of each of the B-splines over their support within the domain on which this basis was defined.
Expand All @@ -257,6 +258,7 @@ class NonUniformBSplines : detail::NonUniformBSplinesBase
ChunkSpan<double, ddc::DiscreteDomain<DDim>, Layout, MemorySpace2>
integrals(ddc::ChunkSpan<double, discrete_domain_type, Layout, MemorySpace2>
int_vals) const;
#endif

/** @brief Returns the coordinate of the first support knot associated to a DiscreteElement identifying a B-spline.
*
Expand Down Expand Up @@ -695,6 +697,7 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<NonUniformBsplinesKnots<DDim>> NonUn
return icell;
}

#if defined(DDC_BUILD_DEPRECATED_CODE)
template <class CDim, std::size_t D>
template <class DDim, class MemorySpace>
template <class Layout, class MemorySpace2>
Expand Down Expand Up @@ -731,5 +734,6 @@ NonUniformBSplines<CDim, D>::Impl<DDim, MemorySpace>::integrals(
}
return int_vals;
}
#endif

} // namespace ddc
4 changes: 4 additions & 0 deletions include/ddc/kernels/splines/bsplines_uniform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class UniformBSplines : detail::UniformBSplinesBase
ddc::Coordinate<CDim> const& x,
std::size_t n) const;

#if defined(DDC_BUILD_DEPRECATED_CODE)
/** @brief Compute the integrals of the B-splines.
*
* The integral of each of the B-splines over their support within the domain on which this basis was defined.
Expand All @@ -249,6 +250,7 @@ class UniformBSplines : detail::UniformBSplinesBase
ChunkSpan<double, ddc::DiscreteDomain<DDim>, Layout, MemorySpace2>
integrals(ddc::ChunkSpan<double, discrete_domain_type, Layout, MemorySpace2>
int_vals) const;
#endif

/** @brief Returns the coordinate of the first support knot associated to a DiscreteElement identifying a B-spline.
*
Expand Down Expand Up @@ -598,6 +600,7 @@ KOKKOS_INLINE_FUNCTION void UniformBSplines<CDim, D>::Impl<DDim, MemorySpace>::g
}
}

#if defined(DDC_BUILD_DEPRECATED_CODE)
template <class CDim, std::size_t D>
template <class DDim, class MemorySpace>
template <class Layout, class MemorySpace2>
Expand Down Expand Up @@ -655,5 +658,6 @@ UniformBSplines<CDim, D>::Impl<DDim, MemorySpace>::integrals(
}
return int_vals;
}
#endif

} // namespace ddc
2 changes: 2 additions & 0 deletions include/ddc/kernels/splines/spline_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ class SplineBuilder
ddc::DiscreteVector<deriv_type>(s_nbc_xmax)));
}

#if defined(DDC_BUILD_DEPRECATED_CODE)
/**
* @brief Get the interpolation matrix.
*
Expand All @@ -378,6 +379,7 @@ class SplineBuilder
{
return *matrix;
}
#endif

/**
* @brief Compute a spline approximation of a function.
Expand Down
6 changes: 3 additions & 3 deletions tests/discrete_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ TEST(DiscreteDomainTest, Subdomain)
ddc::DiscreteElement<DDimX> const lbound_subdomain_x(lbound_x + 1);
ddc::DiscreteVector<DDimX> const npoints_subdomain_x(nelems_x - 2);
DDomX const subdomain_x(lbound_subdomain_x, npoints_subdomain_x);
DDomXY const subdomain = dom_x_y.restrict(subdomain_x);
DDomXY const subdomain = dom_x_y.restrict_with(subdomain_x);
EXPECT_EQ(
subdomain,
DDomXY(ddc::DiscreteElement<DDimX, DDimY>(lbound_subdomain_x, lbound_y),
Expand Down Expand Up @@ -252,7 +252,7 @@ TEST(DiscreteDomainTest, SliceDomainXTooearly)
DDomXY const dom_x_y(lbound_x_y, nelems_x_y);
// the error message is checked with clang & gcc only
EXPECT_DEATH(
dom_x_y.restrict(subdomain_x),
dom_x_y.restrict_with(subdomain_x),
R"rgx([Aa]ssert.*uid<ODDims>\(m_element_begin\).*uid<ODDims>\(odomain\.m_element_begin\))rgx");
#else
GTEST_SKIP();
Expand All @@ -266,7 +266,7 @@ TEST(DiscreteDomainTest, SliceDomainXToolate)
DDomXY const dom_x_y(lbound_x_y, nelems_x_y);
// the error message is checked with clang & gcc only
EXPECT_DEATH(
dom_x_y.restrict(subdomain_x),
dom_x_y.restrict_with(subdomain_x),
R"rgx([Aa]ssert.*uid<ODDims>\(m_element_end\).*uid<ODDims>\(odomain\.m_element_end\).*)rgx");
#else
GTEST_SKIP();
Expand Down

0 comments on commit c61a9da

Please sign in to comment.