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 #include <AMReX_Config.H>
12 #include <AMReX_LayoutData.H>
13 
14 #if defined(AMREX_USE_CUDA)
15 # include <cufft.h>
16 #elif defined(AMREX_USE_HIP)
17 // cstddef: work-around for ROCm/rocFFT <=4.3.0
18 // https://github.com/ROCmSoftwarePlatform/rocFFT/blob/rocm-4.3.0/library/include/rocfft.h#L36-L42
19 # include <cstddef>
20 # include <rocfft.h>
21 #else
22 # include <fftw3.h>
23 #endif
24 
31 namespace AnyFFT
32 {
33  // First, define library-dependent types (complex, FFT plan)
34 
36 #if defined(AMREX_USE_CUDA)
37 # ifdef AMREX_USE_FLOAT
38  using Complex = cuComplex;
39 # else
40  using Complex = cuDoubleComplex;
41 # endif
42 #elif defined(AMREX_USE_HIP)
43 # ifdef AMREX_USE_FLOAT
44  using Complex = float2;
45 # else
46  using Complex = double2;
47 # endif
48 #else
49 # ifdef AMREX_USE_FLOAT
50  using Complex = fftwf_complex;
51 # else
52  using Complex = fftw_complex;
53 # endif
54 #endif
55 
59 #if defined(AMREX_USE_CUDA)
60  using VendorFFTPlan = cufftHandle;
61 #elif defined(AMREX_USE_HIP)
62  using VendorFFTPlan = rocfft_plan;
63 #else
64 # ifdef AMREX_USE_FLOAT
65  using VendorFFTPlan = fftwf_plan;
66 # else
67  using VendorFFTPlan = fftw_plan;
68 # endif
69 #endif
70 
71  // Second, define library-independent API
72 
74  enum struct direction {R2C, C2R};
75 
78  struct FFTplan
79  {
80  amrex::Real* m_real_array;
84  int m_dim;
85  };
86 
89 
98  FFTplan CreatePlan(const amrex::IntVect& real_size, amrex::Real * const real_array,
99  Complex * const complex_array, const direction dir, const int dim);
100 
104  void DestroyPlan(FFTplan& fft_plan);
105 
109  void Execute(FFTplan& fft_plan);
110 }
111 
112 #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:25
void Execute(FFTplan &fft_plan)
Perform FFT with backend library.
Definition: WrapCuFFT.cpp:74
direction m_dir
Definition: AnyFFT.H:83
VendorFFTPlan m_plan
Definition: AnyFFT.H:82
Complex * m_complex_array
Definition: AnyFFT.H:81
direction
Definition: AnyFFT.H:74
Definition: AnyFFT.H:31
amrex::Real * m_real_array
Definition: AnyFFT.H:80
void DestroyPlan(FFTplan &fft_plan)
Destroy library FFT plan.
Definition: WrapCuFFT.cpp:69
fftw_plan VendorFFTPlan
Definition: AnyFFT.H:67
fftw_complex Complex
Definition: AnyFFT.H:52
int m_dim
Definition: AnyFFT.H:84
Definition: AnyFFT.H:78