Nektar++
Loading...
Searching...
No Matches
DerivZDeviceFFT.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: DerivZDeviceFFT.h
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Device z-derivative (D2Z + wavenumber multiply + Z2D) for the
32// Nektar++ homogeneous-1D DerivZ operators.
33//
34///////////////////////////////////////////////////////////////////////////////
35
36#pragma once
37
38#include <cstddef>
39
41{
42
43/// \brief Which z-derivative the pipeline takes.
44///
45/// The two share their plans and differ only in the wavenumber multiply, so
46/// one entry point covers both and the second derivative costs one transform
47/// pair rather than the two that applying the first twice would need.
48enum class DerivZOrder
49{
50 /// Multiplier \f$ik\beta\f$, giving \f$\partial_z u\f$. Imaginary and
51 /// odd, so a mode moves to its conjugate partner plane.
52 First,
53 /// Multiplier \f$-(k\beta)^2\f$, giving \f$\partial_z^2 u\f$. Real, so
54 /// a mode stays in its own plane.
55 Second,
56};
57
58/// \brief Compute a z-derivative of a real field in the homogeneous
59/// direction on the device (D2Z + wavenumber multiply + Z2D).
60///
61/// The three stages run as cuFFT, hipFFT or oneMath calls, or fused into a
62/// single cuFFTDx kernel when the build defines NEKTAR_USE_CUFFTDX.
63/// Explicitly instantiated for both precisions, both orders and both APPEND
64/// modes in each backend's implementation file; every instantiation takes the
65/// same path in any one build.
66///
67/// The field is in plane-major layout: \c d_in[plane * compStride + xy].
68/// \c d_in and \c d_out may alias the same buffer when overwriting; that is
69/// not meaningful when appending, which reads \c d_out as well.
70///
71/// \tparam DERIVORDER
72/// Which derivative to take; see DerivZOrder. Both orders
73/// zero the mean and the mode at \f$k = N/2\f$, which
74/// Nektar's eFourier basis cannot represent.
75/// \tparam APPEND false overwrites \c d_out, true adds the result on top
76/// of what is already there, for a caller whose xy pass has
77/// written a partial result. The fused cuFFTDx kernel
78/// accumulates in its own final store and costs nothing
79/// extra; over cuFFT, hipFFT and oneMath the library owns
80/// that store, so the inverse transform lands in a buffer
81/// the plan holds for the purpose and is summed in
82/// afterwards. Either way the caller needs no scratch of
83/// its own.
84///
85/// \param d_in Device pointer to the input real field.
86/// \param d_out Device pointer to the output real field.
87/// \param nhomo Number of homogeneous planes (must be even).
88/// \param NXY Number of points per plane (FFT batch size).
89/// \param compStride Stride between successive planes in the buffers
90/// (>= NXY; equals NXY when there is no padding).
91/// \param beta Wavenumber factor \f$2\pi/L_z\f$.
92/// \param streamID Id of the stream on which all work is submitted. The
93/// id keeps this header free of the CUDA, HIP and SYCL
94/// headers: each backend resolves it through its own
95/// CUDAStream / HIPStream / SYCLQueue registry, so the
96/// same id always names the same stream or queue.
97template <typename TData, DerivZOrder DERIVORDER, bool APPEND>
98void DerivZDirect(const TData *d_in, TData *d_out, unsigned int nhomo,
99 size_t NXY, size_t compStride, TData beta,
100 unsigned int streamID);
101
102/// \brief Create and cache everything DerivZDirect() needs for this
103/// problem size on this stream, without submitting any of the pipeline.
104///
105/// DerivZDirect() does this itself on a cache miss, but the setup
106/// allocates, and under cuFFT and hipFFT it also runs a warm-up transform and
107/// synchronises the stream. None of that is legal inside a device graph
108/// capture, so a caller that captures its very first call has to prepare each
109/// stream beforehand. A call for an entry that already has everything it
110/// needs does nothing. The fused cuFFTDx pipeline holds no such state, so
111/// there it is a no-op.
112///
113/// \tparam APPEND Must match the DerivZDirect() calls that follow, which
114/// dereference the accumulate buffer without checking it.
115/// When true that buffer is allocated here, since
116/// allocating inside a graph capture is not allowed; an
117/// entry first created by an overwriting caller gains one
118/// on the first appending prepare.
119///
120/// \param nhomo Number of homogeneous planes (must be even).
121/// \param NXY Number of points per plane (FFT batch size).
122/// \param compStride Stride between successive planes in the buffers.
123/// \param streamID Id of the stream the prepared state belongs to; it has
124/// to match the one passed to DerivZDirect() later.
125template <typename TData, bool APPEND>
126void DerivZPrepare(unsigned int nhomo, size_t NXY, size_t compStride,
127 unsigned int streamID);
128
129} // namespace Nektar::LibUtilities
DerivZOrder
Which z-derivative the pipeline takes.
@ First
Multiplier , giving . Imaginary and odd, so a mode moves to its conjugate partner plane.
@ Second
Multiplier , giving . Real, so a mode stays in its own plane.
void DerivZDirect(const TData *d_in, TData *d_out, unsigned int nhomo, size_t NXY, size_t compStride, TData beta, unsigned int streamID)
Compute a z-derivative of a real field in the homogeneous direction on the device (D2Z + wavenumber m...
void DerivZPrepare(unsigned int nhomo, size_t NXY, size_t compStride, unsigned int streamID)
Create and cache everything DerivZDirect() needs for this problem size on this stream,...
@ beta
Gauss Radau pinned at x=-1,.
Definition PointsType.h:59