WarpX
AnyFFT.H
Go to the documentation of this file.
1 /* Copyright 2019-2020
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 
8 #ifndef ANYFFT_H_
9 #define ANYFFT_H_
10 
11 #ifdef AMREX_USE_GPU
12 # include <cufft.h>
13 #else
14 # include <fftw3.h>
15 #endif
16 
17 #include <AMReX_LayoutData.H>
18 
25 namespace AnyFFT
26 {
27  // First, define library-dependent types (complex, FFT plan)
28 
30 #ifdef AMREX_USE_GPU
31 # ifdef AMREX_USE_FLOAT
32  using Complex = cuComplex;
33 # else
34  using Complex = cuDoubleComplex;
35 # endif
36 #else
37 # ifdef AMREX_USE_FLOAT
38  using Complex = fftwf_complex;
39 # else
40  using Complex = fftw_complex;
41 # endif
42 #endif
43 
47 #ifdef AMREX_USE_GPU
48  using VendorFFTPlan = cufftHandle;
49 #else
50 # ifdef AMREX_USE_FLOAT
51  using VendorFFTPlan = fftwf_plan;
52 # else
53  using VendorFFTPlan = fftw_plan;
54 # endif
55 #endif
56 
57  // Second, define library-independent API
58 
60  enum struct direction {R2C, C2R};
61 
64  struct FFTplan
65  {
66  amrex::Real* m_real_array;
70  int m_dim;
71  };
72 
74  using FFTplans = amrex::LayoutData<FFTplan>;
75 
84  FFTplan CreatePlan(const amrex::IntVect& real_size, amrex::Real * const real_array,
85  Complex * const complex_array, const direction dir, const int dim);
86 
90  void DestroyPlan(FFTplan& fft_plan);
91 
95  void Execute(FFTplan& fft_plan);
96 }
97 
98 #endif // ANYFFT_H_
FFTplan CreatePlan(const amrex::IntVect &real_size, amrex::Real *const real_array, Complex *const complex_array, const direction dir, const int dim)
create FFT plan for the backend FFT library.
Definition: WrapCuFFT.cpp:23
void Execute(FFTplan &fft_plan)
Perform FFT with backend library.
Definition: WrapCuFFT.cpp:71
direction m_dir
Definition: AnyFFT.H:69
VendorFFTPlan m_plan
Definition: AnyFFT.H:68
Complex * m_complex_array
Definition: AnyFFT.H:67
direction
Definition: AnyFFT.H:60
Definition: AnyFFT.H:25
amrex::Real * m_real_array
Definition: AnyFFT.H:66
void DestroyPlan(FFTplan &fft_plan)
Destroy library FFT plan.
Definition: WrapCuFFT.cpp:66
fftw_plan VendorFFTPlan
Definition: AnyFFT.H:53
amrex::LayoutData< FFTplan > FFTplans
Definition: AnyFFT.H:74
fftw_complex Complex
Definition: AnyFFT.H:40
int m_dim
Definition: AnyFFT.H:70
Definition: AnyFFT.H:64