KokkosFFT::Plan
-
template<typename ExecutionSpace, typename InViewType, typename OutViewType, std::size_t DIM = 1>
class Plan A class that manages a FFT plan of backend FFT library.
This class is used to manage the FFT plan of backend FFT library. Depending on the input and output Views and axes, appropriate FFT plans are created. If there are inconsistency in input and output views, the compilation would fail.
- Template Parameters:
ExecutionSpace – The type of Kokkos execution space
InViewType – Input View type for the FFT
OutViewType – Output View type for the FFT
DIM – The dimensionality of the FFT
Public Functions
-
inline explicit Plan(const ExecutionSpace &exec_space, const InViewType &in, const OutViewType &out, KokkosFFT::Direction direction, int axis, std::optional<std::size_t> n = std::nullopt)
Constructor for one-dimensional FFT.
- Parameters:
exec_space – [in] Kokkos execution space for this plan
in – [in] Input data
out – [in] Output data
direction – [in] Direction of FFT (forward/backward)
axis – [in] Axis over which FFT is performed
n – [in] Length of the transformed axis of the output (default, nullopt)
-
inline explicit Plan(const ExecutionSpace &exec_space, const InViewType &in, const OutViewType &out, KokkosFFT::Direction direction, axis_type<DIM> axes, shape_type<DIM> s = {})
Constructor for multidimensional FFT.
- Parameters:
exec_space – [in] Kokkos execution space for this plan
in – [in] Input data
out – [in] Output data
direction – [in] Direction of FFT (forward/backward)
axes – [in] Axes over which FFT is performed
s – [in] Shape of the transformed axis of the output (default, {})
Note
We can reuse the FFT plan created once to perform FFTs multiple times on different data given that they have the same properties. In some backend, FFT plan creation leads to some overhead, wherein we need this functionality.
Examples
In this example, we use the 2D View with LayoutRight to avoid the internal transpose. This allows execute to perform 1D FFT on the outermost dimension without transpose.
1#include <iostream>
2#include <Kokkos_Core.hpp>
3#include <Kokkos_Complex.hpp>
4#include <KokkosFFT.hpp>
5
6/// \brief Example of Plan usage in documentation
7/// This corresponds to 1D batched rfft on 2D Views
8/// x = [[1, 2, 3, 4],
9/// [5, 6, 7, 8],
10/// [9, 10, 11, 12]]
11/// x_hat = [[10.+0.j, -2.+2.j, -2.+0.j],
12/// [26.+0.j, -2.+2.j, -2.+0.j],
13/// [42.+0.j, -2.+2.j, -2.+0.j]]
14int main(int argc, char* argv[]) {
15 Kokkos::ScopeGuard guard(argc, argv);
16 using ExecutionSpace = Kokkos::DefaultExecutionSpace;
17 using View2D = Kokkos::View<double**, Kokkos::LayoutRight, ExecutionSpace>;
18 using ComplexView2D = Kokkos::View<Kokkos::complex<double>**,
19 Kokkos::LayoutRight, ExecutionSpace>;
20
21 const int n0 = 3, n1 = 4;
22
23 View2D x("x", n0, n1);
24 ComplexView2D x_hat("x_hat", n0, n1 / 2 + 1),
25 x_hat2("x_hat2", n0, n1 / 2 + 1);
26 auto h_x = Kokkos::create_mirror_view(x);
27 for (int i = 0; i < n0; ++i) {
28 for (int j = 0; j < n1; ++j) {
29 h_x(i, j) = i * n1 + j + 1;
30 }
31 }
32 Kokkos::deep_copy(x, h_x);
33
34 ExecutionSpace exec;
35
36 int axis = -1;
37 KokkosFFT::Plan plan(exec, x, x_hat, KokkosFFT::Direction::forward, axis);
38 KokkosFFT::execute(plan, x, x_hat2);
39
40 auto h_x_hat2 =
41 Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, x_hat2);
42
43 for (int i = 0; i < h_x_hat2.extent_int(0); ++i) {
44 for (int j = 0; j < h_x_hat2.extent_int(1); ++j) {
45 std::cout << " " << h_x_hat2(i, j);
46 }
47 std::cout << std::endl;
48 }
49 std::cout << std::endl;
50
51 return 0;
52}
Expected output:
(10,0) (-2,2) (-2,0)
(26,0) (-2,2) (-2,0)
(42,0) (-2,2) (-2,0)