Skip to content

Commit

Permalink
make execute a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuichi Asahi committed Jan 28, 2025
1 parent ccdedaa commit 9aa26d5
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 89 deletions.
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 @@ -29,11 +29,11 @@ int main(int argc, char* argv[]) {
int axis = -1;
KokkosFFT::Plan fft_plan(exec, xc2c, xc2c_hat,
KokkosFFT::Direction::forward, axis);
fft_plan.execute(xc2c, xc2c_hat);
KokkosFFT::execute(fft_plan, xc2c, xc2c_hat);

KokkosFFT::Plan ifft_plan(exec, xc2c_hat, xc2c_inv,
KokkosFFT::Direction::backward, axis);
ifft_plan.execute(xc2c_hat, xc2c_inv);
KokkosFFT::execute(ifft_plan, xc2c_hat, xc2c_inv);

// 1D R2C FFT
View1D<double> xr2c("xr2c", n0);
Expand All @@ -42,7 +42,7 @@ int main(int argc, char* argv[]) {

KokkosFFT::Plan rfft_plan(exec, xr2c, xr2c_hat,
KokkosFFT::Direction::forward, axis);
rfft_plan.execute(xr2c, xr2c_hat);
KokkosFFT::execute(rfft_plan, xr2c, xr2c_hat);

// 1D C2R FFT
View1D<Kokkos::complex<double> > xc2r("xc2r_hat", n0 / 2 + 1);
Expand All @@ -51,7 +51,7 @@ int main(int argc, char* argv[]) {

KokkosFFT::Plan irfft_plan(exec, xc2r, xc2r_hat,
KokkosFFT::Direction::backward, axis);
irfft_plan.execute(xc2r, xc2r_hat);
KokkosFFT::execute(irfft_plan, xc2r, xc2r_hat);
exec.fence();
}
Kokkos::finalize();
Expand Down
4 changes: 2 additions & 2 deletions examples/09_derivative/09_derivative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void compute_derivative(const int nx, const int ny, const int nz,
Kokkos::Timer timer;

// Forward transform u -> u_hat (=FFT (u))
r2c_plan.execute(u, u_hat);
KokkosFFT::execute(r2c_plan, u, u_hat);

// Compute derivatives by multiplications in Fourier space
Kokkos::parallel_for(
Expand All @@ -181,7 +181,7 @@ void compute_derivative(const int nx, const int ny, const int nz,
});

// Backward transform u_hat -> u (=IFFT (u_hat))
c2r_plan.execute(u_hat, u); // normalization is made here
KokkosFFT::execute(c2r_plan, u_hat, u); // normalization is made here
exec.fence();
seconds = timer.seconds();

Expand Down
11 changes: 3 additions & 8 deletions fft/src/KokkosFFT_Plans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,9 @@ class Plan {
Plan& operator=(Plan&&) = delete;
Plan(Plan&&) = delete;

/// \brief Execute FFT on input and output Views with normalization
///
/// \param in [in] Input data
/// \param out [out] Output data
/// \param norm [in] How the normalization is applied (default, backward)
void execute(const InViewType& in, const OutViewType& out,
KokkosFFT::Normalization norm =
KokkosFFT::Normalization::backward) const {
void execute_impl(const InViewType& in, const OutViewType& out,
KokkosFFT::Normalization norm =
KokkosFFT::Normalization::backward) const {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<execSpace, InViewType,
OutViewType>,
Expand Down
31 changes: 25 additions & 6 deletions fft/src/KokkosFFT_Transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@
#include "KokkosFFT_Plans.hpp"

namespace KokkosFFT {

/// \brief Execute FFT given by the Plan on input and output Views with
/// normalization
///
/// \tparam PlanType: KokkosFFT Plan type
/// \tparam InViewType: Input View type for the fft
/// \tparam OutViewType: Output View type for the fft
///
/// \param plan [in] KokkosFFT Plan to be executed
/// \param in [in] Input data
/// \param out [out] Output data
/// \param norm [in] How the normalization is applied (default, backward)
template <typename PlanType, typename InViewType, typename OutViewType>
void execute(
const PlanType& plan, const InViewType& in, const OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward) {
plan.execute_impl(in, out, norm);
}

/// \brief One dimensional FFT in forward direction
///
/// \param exec_space [in] Kokkos execution space
Expand Down Expand Up @@ -42,7 +61,7 @@ void fft(const ExecutionSpace& exec_space, const InViewType& in,
"axes are invalid for in/out views");
KokkosFFT::Plan plan(exec_space, in, out, KokkosFFT::Direction::forward, axis,
n);
plan.execute(in, out, norm);
plan.execute_impl(in, out, norm);
}

/// \brief One dimensional FFT in backward direction
Expand Down Expand Up @@ -74,7 +93,7 @@ void ifft(const ExecutionSpace& exec_space, const InViewType& in,
"axes are invalid for in/out views");
KokkosFFT::Plan plan(exec_space, in, out, KokkosFFT::Direction::backward,
axis, n);
plan.execute(in, out, norm);
plan.execute_impl(in, out, norm);
}

/// \brief One dimensional FFT for real input
Expand Down Expand Up @@ -272,7 +291,7 @@ void fft2(const ExecutionSpace& exec_space, const InViewType& in,
"axes are invalid for in/out views");
KokkosFFT::Plan plan(exec_space, in, out, KokkosFFT::Direction::forward, axes,
s);
plan.execute(in, out, norm);
plan.execute_impl(in, out, norm);
}

/// \brief Two dimensional FFT in backward direction
Expand Down Expand Up @@ -304,7 +323,7 @@ void ifft2(const ExecutionSpace& exec_space, const InViewType& in,
"axes are invalid for in/out views");
KokkosFFT::Plan plan(exec_space, in, out, KokkosFFT::Direction::backward,
axes, s);
plan.execute(in, out, norm);
plan.execute_impl(in, out, norm);
}

/// \brief Two dimensional FFT for real input
Expand Down Expand Up @@ -425,7 +444,7 @@ void fftn(
"axes are invalid for in/out views");
KokkosFFT::Plan plan(exec_space, in, out, KokkosFFT::Direction::forward, axes,
s);
plan.execute(in, out, norm);
plan.execute_impl(in, out, norm);
}

/// \brief Inverse of fftn
Expand Down Expand Up @@ -470,7 +489,7 @@ void ifftn(
"axes are invalid for in/out views");
KokkosFFT::Plan plan(exec_space, in, out, KokkosFFT::Direction::backward,
axes, s);
plan.execute(in, out, norm);
plan.execute_impl(in, out, norm);
}

/// \brief N-dimensional FFT for real input
Expand Down
Loading

0 comments on commit 9aa26d5

Please sign in to comment.