Skip to content

Commit 545dc69

Browse files
yasahi-hpcYuuichi Asahi
and
Yuuichi Asahi
authored
Update docs (#144)
* docs: Add default explanations for APIs * Add docs for unmanaged view example * docs: Explain the meanings of axes * docs: we do not rely on assertions any more * docs: fix based on a review * docs: fix title for unmanaged view example * fix: docs of fftshift based on reviews * docs: improve the explanations for axes parameters * docs: further fix * docs: fixed typo based on reviews --------- Co-authored-by: Yuuichi Asahi <y.asahi@nr.titech.ac.jp>
1 parent 81ece5b commit 545dc69

File tree

7 files changed

+123
-53
lines changed

7 files changed

+123
-53
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
1313
> EXPERIMENTAL FFT interfaces for Kokkos C++ Performance Portability Programming EcoSystem
1414
1515
Kokkos-fft implements local interfaces between [Kokkos](https://github.com/kokkos/kokkos) and de facto standard FFT libraries, including [fftw](http://www.fftw.org), [cufft](https://developer.nvidia.com/cufft), [hipfft](https://github.com/ROCm/hipFFT) ([rocfft](https://github.com/ROCm/rocFFT)), and [oneMKL](https://spec.oneapi.io/versions/latest/elements/oneMKL/source/index.html). "Local" means not using MPI, or running within a single MPI process without knowing about MPI. We are inclined to implement the [numpy.fft](https://numpy.org/doc/stable/reference/routines.fft.html)-like interfaces adapted for [Kokkos](https://github.com/kokkos/kokkos).
16-
A key concept is that **"As easy as numpy, as fast as vendor libraries"**. Accordingly, our API follows the API by [numpy.fft](https://numpy.org/doc/stable/reference/routines.fft.html) with minor differences. A fft library dedicated to Kokkos Device backend (e.g. [cufft](https://developer.nvidia.com/cufft) for CUDA backend) is automatically used. If something is wrong with runtime values (say `View` extents), it will raise runtime errors (C++ exceptions or assertions). See [documentations](https://kokkosfft.readthedocs.io/) for more information.
16+
A key concept is that **"As easy as numpy, as fast as vendor libraries"**. Accordingly, our API follows the API by [numpy.fft](https://numpy.org/doc/stable/reference/routines.fft.html) with minor differences. A fft library dedicated to Kokkos Device backend (e.g. [cufft](https://developer.nvidia.com/cufft) for CUDA backend) is automatically used. If something is wrong with runtime values (say `View` extents), it will raise runtime errors (C++ `std::runtime_error`). See [documentations](https://kokkosfft.readthedocs.io/) for more information.
1717

1818
Here is an example for 1D real to complex transform with `rfft` in Kokkos-fft.
1919
```C++

common/src/KokkosFFT_Helpers.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace KokkosFFT {
151151
///
152152
/// \param exec_space [in] Kokkos execution space
153153
/// \param n [in] Window length
154-
/// \param d [in] Sample spacing
154+
/// \param d [in] Sample spacing (default, 1)
155155
///
156156
/// \return Sampling frequency
157157
template <typename ExecutionSpace, typename RealType>
@@ -186,7 +186,7 @@ auto fftfreq(const ExecutionSpace&, const std::size_t n,
186186
///
187187
/// \param exec_space [in] Kokkos execution space
188188
/// \param n [in] Window length
189-
/// \param d [in] Sample spacing
189+
/// \param d [in] Sample spacing (default, 1)
190190
///
191191
/// \return Sampling frequency starting from zero
192192
template <typename ExecutionSpace, typename RealType>
@@ -215,7 +215,8 @@ auto rfftfreq(const ExecutionSpace&, const std::size_t n,
215215
///
216216
/// \param exec_space [in] Kokkos execution space
217217
/// \param inout [in,out] Spectrum
218-
/// \param axes [in] Axes over which to shift, optional
218+
/// \param axes [in] Axes over which to shift (default: nullopt, shifting over
219+
/// all axes)
219220
template <typename ExecutionSpace, typename ViewType>
220221
void fftshift(const ExecutionSpace& exec_space, ViewType& inout,
221222
std::optional<int> axes = std::nullopt) {
@@ -264,7 +265,8 @@ void fftshift(const ExecutionSpace& exec_space, ViewType& inout,
264265
///
265266
/// \param exec_space [in] Kokkos execution space
266267
/// \param inout [in,out] Spectrum
267-
/// \param axes [in] Axes over which to shift, optional
268+
/// \param axes [in] Axes over which to shift (default: nullopt, shifting over
269+
/// all axes)
268270
template <typename ExecutionSpace, typename ViewType>
269271
void ifftshift(const ExecutionSpace& exec_space, ViewType& inout,
270272
std::optional<int> axes = std::nullopt) {

docs/examples.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Examples
99

1010
There are some `examples
1111
<https://github.com/kokkos/kokkos-fft/tree/main/examples>`_ in the
12-
Kokkos-fft repository. Each example includes Kokkos and numpy implementations.
12+
Kokkos-fft repository. Most of the examples include Kokkos and numpy implementations.
1313
For example, `01_1DFFT
1414
<https://github.com/kokkos/kokkos-fft/tree/main/examples/01_1DFFT>`_ includes,
1515

@@ -32,4 +32,5 @@ Please find the examples from following links.
3232
samples/03_NDFFT.rst
3333
samples/04_batchedFFT.rst
3434
samples/05_1DFFT_HOST_DEVICE.rst
35-
samples/06_1DFFT_reuse_plans.rst
35+
samples/06_1DFFT_reuse_plans.rst
36+
samples/07_unmanaged_views.rst

docs/intro/using.rst

+47-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ If the rank of Views is higher than the dimension of FFT, a batched FFT plan is
3434
APIs start from ``i`` represent inverse transforms.
3535
For Real FFTs, users have to pay attention to the input and output data types as well as their extents.
3636
Inconsistent data types are suppressed by compilation errors. If extents are inconsistent,
37-
it will raise runtime errors (C++ exceptions or assertions).
37+
it will raise runtime errors (C++ ``std::runtime_error``).
3838
The following listing shows good and bad examples of Real FFTs.
3939

4040
.. code-block:: C++
@@ -130,3 +130,49 @@ In some backend, FFT plan creation leads to some overhead, wherein we need this
130130
.. note::
131131

132132
Input and Output Views used to call FFT APIs must have the same types and extents as the ones used for plan creation.
133+
134+
Axes parameters
135+
---------------
136+
137+
As well as ``numpy.fft``, you can specify negative axes to perform FFT over chosen axes, which is not common in C++.
138+
Actually for FFT APIs, default axes are set as ``{-DIM, -(DIM-1), ...}`` where ``DIM`` is the rank of the FFT dimensions,
139+
corresponding to the FFTs over last ``DIM`` axes. If we consider that default View layout is C layout (row-major or ``Kokkos::LayoutRight``),
140+
this default axes parameter results in FFTs performed over the contiguous dimensions. For example, ``KokkosFFT::fft2(execution_space(), in, out)`` is equivalent to ``KokkosFFT::fft2(execution_space(), in, out, axis_type<2>({-2, -1}))``.
141+
Negative axes are counted from the last axis, which is the same as ``numpy.fft``.
142+
For example, ``-1`` means the last axis, ``-2`` means the second last axis, and so on.
143+
Negative axes ``-1`` and ``-2`` respectively correspond to ``rank-1`` and ``rank-2``, where the ``rank`` is the rank of the Views.
144+
145+
The following listing shows examples of axes parameters with negative or positive values.
146+
147+
.. code-block:: C++
148+
149+
template <typename T> using View2D = Kokkos::View<T**, Kokkos::LayoutLeft, execution_space>;
150+
template <typename T> using View3D = Kokkos::View<T***, Kokkos::LayoutLeft, execution_space>;
151+
constexpr int n0 = 4, n1 = 8, n2 = 5;
152+
153+
View2D<double> x2("x2", n0, n1);
154+
View3D<double> x3("x3", n0, n1, n2);
155+
View2D<Kokkos::complex<double> > x2_hat("x2_hat", n0/2+1, n1);
156+
View3D<Kokkos::complex<double> > x3_hat("x3_hat", n0, n1/2+1, n2);
157+
158+
// Following codes are all equivalent to np.fft(np.rfft(x2, axis=0), axis=1)
159+
// negative axes are converted as follows:
160+
// -2 -> 0 (= Rank(2) - 2), -1 -> 1 (= Rank(2) - 1)
161+
KokkosFFT::rfft2(execution_space(), x2, x2_hat, /*axes=*/{-1, -2});
162+
KokkosFFT::rfft2(execution_space(), x2, x2_hat, /*axes=*/{-1, 0});
163+
KokkosFFT::rfft2(execution_space(), x2, x2_hat, /*axes=*/{1, -2});
164+
KokkosFFT::rfft2(execution_space(), x2, x2_hat, /*axes=*/{1, 0});
165+
166+
// Following codes are all equivalent to np.fft(np.rfft(x3, axis=1), axis=2)
167+
// negative axes are converted as follows:
168+
// -2 -> 1 (= Rank(3) - 2), -1 -> 2 (= Rank(3) - 1)
169+
KokkosFFT::rfft2(execution_space(), x3, x3_hat, /*axes=*/{-1, -2});
170+
KokkosFFT::rfft2(execution_space(), x3, x3_hat, /*axes=*/{-1, 1});
171+
KokkosFFT::rfft2(execution_space(), x3, x3_hat, /*axes=*/{2, -2});
172+
KokkosFFT::rfft2(execution_space(), x3, x3_hat, /*axes=*/{2, 1});
173+
174+
.. note::
175+
176+
If you rely on negative axes, you can specify last axes no matter what the rank of Views is.
177+
However, the corresponding positive axes to last axes are different depending on the rank of Views.
178+
Thus, it is recommended to use negative axes for simplicity.

docs/samples/07_unmanaged_views.rst

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.. SPDX-FileCopyrightText: (C) The Kokkos-FFT development team, see COPYRIGHT.md file
2+
..
3+
.. SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
4+
5+
.. _07_unmanaged_views:
6+
7+
Using Unmanaged Views
8+
=====================
9+
10+
KokkosFFT
11+
---------
12+
13+
.. literalinclude:: ../../examples/07_unmanaged_views/07_unmanaged_views.cpp
14+
:language: C++

fft/src/KokkosFFT_Plans.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ class Plan {
153153
/// \param out [in] Ouput data
154154
/// \param direction [in] Direction of FFT (forward/backward)
155155
/// \param axis [in] Axis over which FFT is performed
156-
/// \param n [in] Length of the transformed axis of the output (optional)
156+
/// \param n [in] Length of the transformed axis of the output (default,
157+
/// nullopt)
157158
//
158159
explicit Plan(const ExecutionSpace& exec_space, InViewType& in,
159160
OutViewType& out, KokkosFFT::Direction direction, int axis,
@@ -211,11 +212,11 @@ class Plan {
211212
/// \param out [in] Ouput data
212213
/// \param direction [in] Direction of FFT (forward/backward)
213214
/// \param axes [in] Axes over which FFT is performed
214-
/// \param s [in] Shape of the transformed axis of the output (optional)
215+
/// \param s [in] Shape of the transformed axis of the output (default, {})
215216
//
216217
explicit Plan(const ExecutionSpace& exec_space, InViewType& in,
217218
OutViewType& out, KokkosFFT::Direction direction,
218-
axis_type<DIM> axes, shape_type<DIM> s = {0})
219+
axis_type<DIM> axes, shape_type<DIM> s = {})
219220
: m_exec_space(exec_space), m_axes(axes), m_direction(direction) {
220221
static_assert(KokkosFFT::Impl::is_AllowedSpace_v<ExecutionSpace>,
221222
"Plan::Plan: ExecutionSpace is not allowed ");

0 commit comments

Comments
 (0)