Skip to content

Commit

Permalink
Merge pull request #97 from kokkos/simplify-plan-reuse-API
Browse files Browse the repository at this point in the history
Simplify plan reuse api
  • Loading branch information
yasahi-hpc authored Apr 22, 2024
2 parents 8d822ea + e03c547 commit 2e9d218
Show file tree
Hide file tree
Showing 18 changed files with 324 additions and 1,562 deletions.
1 change: 0 additions & 1 deletion docs/api/hermitian/hfft.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ KokkosFFT::hfft
---------------

.. doxygenfunction:: KokkosFFT::hfft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
.. doxygenfunction:: KokkosFFT::hfft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
1 change: 0 additions & 1 deletion docs/api/hermitian/ihfft.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ KokkosFFT::ihfft
----------------

.. doxygenfunction:: KokkosFFT::ihfft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
.. doxygenfunction:: KokkosFFT::ihfft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
3 changes: 1 addition & 2 deletions docs/api/real/irfft.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
KokkosFFT::irfft
----------------

.. doxygenfunction:: KokkosFFT::irfft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
.. doxygenfunction:: KokkosFFT::irfft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
.. doxygenfunction:: KokkosFFT::irfft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
3 changes: 1 addition & 2 deletions docs/api/real/irfft2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
KokkosFFT::irfft2
-----------------
.. doxygenfunction:: KokkosFFT::irfft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, axis_type<2> axes, shape_type<DIM> s)
.. doxygenfunction:: KokkosFFT::irfft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, KokkosFFT::Normalization norm, axis_type<2> axes, shape_type<DIM> s)
.. doxygenfunction:: KokkosFFT::irfft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, axis_type<2> axes, shape_type<2> s)
5 changes: 2 additions & 3 deletions docs/api/real/irfftn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
KokkosFFT::irfftn
-----------------
.. doxygenfunction:: KokkosFFT::irfftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, shape_type<DIM> s)
.. doxygenfunction:: KokkosFFT::irfftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, axis_type<DIM1> axes, KokkosFFT::Normalization, shape_type<DIM2> s)
.. doxygenfunction:: KokkosFFT::irfftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, axis_type<DIM1> axes, KokkosFFT::Normalization norm, shape_type<DIM2> s)

.. doxygenfunction:: KokkosFFT::irfftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, axis_type<DIM> axes, KokkosFFT::Normalization, shape_type<DIM> s)

3 changes: 1 addition & 2 deletions docs/api/real/rfft.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
KokkosFFT::rfft
---------------

.. doxygenfunction:: KokkosFFT::rfft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
.. doxygenfunction:: KokkosFFT::rfft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
.. doxygenfunction:: KokkosFFT::rfft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
3 changes: 1 addition & 2 deletions docs/api/real/rfft2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
KokkosFFT::rfft2
----------------

.. doxygenfunction:: KokkosFFT::rfft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, axis_type<2> axes, shape_type<DIM> s)
.. doxygenfunction:: KokkosFFT::rfft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, KokkosFFT::Normalization norm, axis_type<2> axes, shape_type<DIM> s)
.. doxygenfunction:: KokkosFFT::rfft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, axis_type<2> axes, shape_type<2> s)
3 changes: 1 addition & 2 deletions docs/api/real/rfftn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
KokkosFFT::rfftn
----------------
.. doxygenfunction:: KokkosFFT::rfftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, shape_type<DIM> s)

.. doxygenfunction:: KokkosFFT::rfftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, axis_type<DIM1> axes, KokkosFFT::Normalization, shape_type<DIM2> s)
.. doxygenfunction:: KokkosFFT::rfftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, axis_type<DIM1> axes, KokkosFFT::Normalization norm, shape_type<DIM2> s)
3 changes: 1 addition & 2 deletions docs/api/standard/fft.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
KokkosFFT::fft
--------------

.. doxygenfunction:: KokkosFFT::fft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
.. doxygenfunction:: KokkosFFT::fft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, KokkosFFT::Normalization norm, int axis, std::optional<std::size_t> n)
.. doxygenfunction:: KokkosFFT::fft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
3 changes: 1 addition & 2 deletions docs/api/standard/fft2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
KokkosFFT::fft2
---------------

.. doxygenfunction:: KokkosFFT::fft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, axis_type<2> axes, shape_type<DIM> s)
.. doxygenfunction:: KokkosFFT::fft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, KokkosFFT::Normalization norm, axis_type<2> axes, shape_type<DIM> s)
.. doxygenfunction:: KokkosFFT::fft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, axis_type<2> axes, shape_type<2> s)
4 changes: 1 addition & 3 deletions docs/api/standard/fftn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
KokkosFFT::fftn
---------------

.. doxygenfunction:: KokkosFFT::fftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, shape_type<DIM> s)
.. doxygenfunction:: KokkosFFT::fftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, axis_type<DIM1> axes, KokkosFFT::Normalization, shape_type<DIM2> s)
.. doxygenfunction:: KokkosFFT::fftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, axis_type<DIM1> axes, KokkosFFT::Normalization norm, shape_type<DIM2> s)
.. doxygenfunction:: KokkosFFT::fftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, axis_type<DIM> axes, KokkosFFT::Normalization, shape_type<DIM> s)
3 changes: 1 addition & 2 deletions docs/api/standard/ifft.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
KokkosFFT::ifft
---------------

.. doxygenfunction:: KokkosFFT::ifft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
.. doxygenfunction:: KokkosFFT::ifft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
.. doxygenfunction:: KokkosFFT::ifft(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, int axis, std::optional<std::size_t> n)
1 change: 0 additions & 1 deletion docs/api/standard/ifft2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ KokkosFFT::ifft2
----------------

.. doxygenfunction:: KokkosFFT::ifft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, axis_type<2> axes, shape_type<DIM> s)
.. doxygenfunction:: KokkosFFT::ifft2(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, KokkosFFT::Normalization norm, axis_type<2> axes, shape_type<DIM> s)
4 changes: 1 addition & 3 deletions docs/api/standard/ifftn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
KokkosFFT::ifftn
----------------

.. doxygenfunction:: KokkosFFT::ifftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, KokkosFFT::Normalization, shape_type<DIM> s)
.. doxygenfunction:: KokkosFFT::ifftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, axis_type<DIM1> axes, KokkosFFT::Normalization, shape_type<DIM2> s)
.. doxygenfunction:: KokkosFFT::ifftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, const PlanType& plan, axis_type<DIM1> axes, KokkosFFT::Normalization norm, shape_type<DIM2> s)
.. doxygenfunction:: KokkosFFT::ifftn(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, axis_type<DIM> axes, KokkosFFT::Normalization, shape_type<DIM> s)
8 changes: 4 additions & 4 deletions examples/06_1DFFT_reuse_plans/06_1DFFT_reuse_plans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ int main(int argc, char* argv[]) {
int axis = -1;
KokkosFFT::Impl::Plan fft_plan(exec, xc2c, xc2c_hat,
KokkosFFT::Direction::forward, axis);
KokkosFFT::fft(exec, xc2c, xc2c_hat, fft_plan);
KokkosFFT::Impl::fft_exec_impl(fft_plan, xc2c, xc2c_hat);
exec.fence();

KokkosFFT::Impl::Plan ifft_plan(exec, xc2c_hat, xc2c_inv,
KokkosFFT::Direction::backward, axis);
KokkosFFT::ifft(exec, xc2c_hat, xc2c_inv, ifft_plan);
KokkosFFT::Impl::fft_exec_impl(ifft_plan, xc2c_hat, xc2c_inv);
exec.fence();

// 1D R2C FFT
Expand All @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) {

KokkosFFT::Impl::Plan rfft_plan(exec, xr2c, xr2c_hat,
KokkosFFT::Direction::forward, axis);
KokkosFFT::rfft(exec, xr2c, xr2c_hat, rfft_plan);
KokkosFFT::Impl::fft_exec_impl(rfft_plan, xr2c, xr2c_hat);
exec.fence();

// 1D C2R FFT
Expand All @@ -57,7 +57,7 @@ int main(int argc, char* argv[]) {

KokkosFFT::Impl::Plan irfft_plan(exec, xc2r, xc2r_hat,
KokkosFFT::Direction::backward, axis);
KokkosFFT::irfft(exec, xc2r, xc2r_hat, irfft_plan);
KokkosFFT::Impl::fft_exec_impl(irfft_plan, xc2r, xc2r_hat);
exec.fence();
}
Kokkos::finalize();
Expand Down
34 changes: 15 additions & 19 deletions fft/src/KokkosFFT_Plans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,15 @@ class Plan {
///
/// \param in [in] Input data
/// \param out [in] Ouput data
/// \param direction [in] Direction of FFT (forward/backward)
/// \param axes [in] Axes over which FFT is performed
template <typename ExecutionSpace2, typename InViewType2,
typename OutViewType2>
void good(const InViewType2& in, const OutViewType2& out,
KokkosFFT::Direction direction, axis_type<DIM> axes) const {
static_assert(std::is_same_v<ExecutionSpace2, execSpace>,
"Plan::good: Execution spaces for plan and "
"execution are not identical.");
template <typename InViewType2, typename OutViewType2>
void good(const InViewType2& in, const OutViewType2& out) const {
static_assert(
Kokkos::SpaceAccessibility<
ExecutionSpace2, typename InViewType2::memory_space>::accessible,
ExecutionSpace, typename InViewType2::memory_space>::accessible,
"Plan::good: execution_space cannot access data in InViewType");
static_assert(
Kokkos::SpaceAccessibility<
ExecutionSpace2, typename OutViewType2::memory_space>::accessible,
ExecutionSpace, typename OutViewType2::memory_space>::accessible,
"Plan::good: execution_space cannot access data in OutViewType");

using nonConstInViewType2 = std::remove_cv_t<InViewType2>;
Expand All @@ -313,16 +306,21 @@ class Plan {
"Plan::good: OutViewType for plan and "
"execution are not identical.");

if (direction != m_direction) {
using in_value_type = typename InViewType2::non_const_value_type;
using out_value_type = typename OutViewType2::non_const_value_type;

if (std::is_floating_point<in_value_type>::value &&
m_direction != KokkosFFT::Direction::forward) {
throw std::runtime_error(
"Plan::good: directions for plan and execution are "
"not identical.");
"Plan::good: real to complex transform is constrcuted with backward "
"direction.");
}

if (axes != m_axes) {
if (std::is_floating_point<out_value_type>::value &&
m_direction != KokkosFFT::Direction::backward) {
throw std::runtime_error(
"Plan::good: axes for plan and execution are "
"not identical.");
"Plan::good: complex to real transform is constrcuted with forward "
"direction.");
}

auto in_extents = KokkosFFT::Impl::extract_extents(in);
Expand Down Expand Up @@ -357,8 +355,6 @@ class Plan {
extents_type shape() const { return m_shape; }
map_type map() const { return m_map; }
map_type map_inv() const { return m_map_inv; }
nonConstInViewType& in_T() { return m_in_T; }
nonConstOutViewType& out_T() { return m_out_T; }
};
} // namespace Impl
} // namespace KokkosFFT
Expand Down
Loading

0 comments on commit 2e9d218

Please sign in to comment.