Hipace
AnyFFT.H
Go to the documentation of this file.
1 /* Copyright 2020-2021
2  *
3  * This file is part of HiPACE++.
4  *
5  * Authors: Axel Huebl, MaxThevenet, Remi Lehe, Severin Diederichs
6  * WeiqunZhang
7  * License: BSD-3-Clause-LBNL
8  */
9 /* Copyright 2019-2020
10  *
11  * This file is part of WarpX.
12  *
13  * License: BSD-3-Clause-LBNL
14  */
15 #ifndef ANYFFT_H_
16 #define ANYFFT_H_
17 
18 #include <AMReX_Config.H>
19 
20 #ifdef AMREX_USE_CUDA
21 # include <cufft.h>
22 #elif defined(AMREX_USE_HIP)
23 # if __has_include(<rocfft/rocfft.h>) // ROCm 5.3+
24 # include <rocfft/rocfft.h>
25 # else
26 # include <rocfft.h>
27 # endif
28 #else
29 # include <fftw3.h>
30 #endif
31 
32 #include <AMReX_LayoutData.H>
33 
42 namespace AnyFFT
43 {
44  // First, define library-dependent types (complex, FFT plan)
45 
47 #ifdef AMREX_USE_CUDA
48 # ifdef AMREX_USE_FLOAT
49  using Complex = cuComplex;
50 # else
51  using Complex = cuDoubleComplex;
52 # endif
53 #elif defined(AMREX_USE_HIP)
54 # ifdef AMREX_USE_FLOAT
55  using Complex = float2;
56 # else
57  using Complex = double2;
58 # endif
59 #else
60 # ifdef AMREX_USE_FLOAT
61  using Complex = fftwf_complex;
62 # else
63  using Complex = fftw_complex;
64 # endif
65 #endif
66 
70 #ifdef AMREX_USE_CUDA
71  using VendorFFTPlan = cufftHandle;
72 #elif defined(AMREX_USE_HIP)
73  using VendorFFTPlan = rocfft_plan;
74 #else
75 # ifdef AMREX_USE_FLOAT
76  using VendorFFTPlan = fftwf_plan;
77 # else
78  using VendorFFTPlan = fftw_plan;
79 # endif
80 #endif
81 
82  // Second, define library-independent API
83 
85  enum struct direction {R2C, C2R};
86 
89  struct FFTplan
90  {
91  amrex::Real* m_real_array;
95  };
96 
99 
106  FFTplan CreatePlan (const amrex::IntVect& real_size, amrex::Real * const real_array,
107  Complex * const complex_array, const direction dir);
108 
112  void DestroyPlan (FFTplan& fft_plan);
113 
117  void Execute (FFTplan& fft_plan);
118 }
119 
120 #endif // ANYFFT_H_
Wrapper around multiple FFT libraries.
Definition: AnyFFT.H:43
void Execute(FFTplan &fft_plan)
Perform FFT with backend library.
Definition: WrapCuFFT.cpp:68
fftw_plan VendorFFTPlan
Definition: AnyFFT.H:78
direction
Definition: AnyFFT.H:85
FFTplan CreatePlan(const amrex::IntVect &real_size, amrex::Real *const real_array, Complex *const complex_array, const direction dir)
create FFT plan for the backend FFT library.
Definition: WrapCuFFT.cpp:29
fftw_complex Complex
Definition: AnyFFT.H:63
void DestroyPlan(FFTplan &fft_plan)
Destroy library FFT plan.
Definition: WrapCuFFT.cpp:63
This struct contains the vendor FFT plan and additional metadata.
Definition: AnyFFT.H:90
Complex * m_complex_array
Definition: AnyFFT.H:92
amrex::Real * m_real_array
Definition: AnyFFT.H:91
direction m_dir
Definition: AnyFFT.H:94
VendorFFTPlan m_plan
Definition: AnyFFT.H:93