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 # if __has_include(<rocfft/rocfft.h>) // ROCm 5.3+
18 # include <rocfft/rocfft.h>
19 # else
20 # include <rocfft.h>
21 # endif
22 #else
23 # include <fftw3.h>
24 #endif
25 
32 namespace AnyFFT
33 {
34  // First, define library-dependent types (complex, FFT plan)
35 
37 #if defined(AMREX_USE_CUDA)
38 # ifdef AMREX_USE_FLOAT
39  using Complex = cuComplex;
40 # else
41  using Complex = cuDoubleComplex;
42 # endif
43 #elif defined(AMREX_USE_HIP)
44 # ifdef AMREX_USE_FLOAT
45  using Complex = float2;
46 # else
47  using Complex = double2;
48 # endif
49 #else
50 # ifdef AMREX_USE_FLOAT
51  using Complex = fftwf_complex;
52 # else
53  using Complex = fftw_complex;
54 # endif
55 #endif
56 
60 #if defined(AMREX_USE_CUDA)
61  using VendorFFTPlan = cufftHandle;
62 #elif defined(AMREX_USE_HIP)
63  using VendorFFTPlan = rocfft_plan;
64 #else
65 # ifdef AMREX_USE_FLOAT
66  using VendorFFTPlan = fftwf_plan;
67 # else
68  using VendorFFTPlan = fftw_plan;
69 # endif
70 #endif
71 
72  // Second, define library-independent API
73 
75  enum struct direction {R2C, C2R};
76 
79  struct FFTplan
80  {
81  amrex::Real* m_real_array;
85  int m_dim;
86  };
87 
90 
99  FFTplan CreatePlan(const amrex::IntVect& real_size, amrex::Real* real_array,
100  Complex* complex_array, direction dir, int dim);
101 
105  void DestroyPlan(FFTplan& fft_plan);
106 
110  void Execute(FFTplan& fft_plan);
111 }
112 
113 #endif // ANYFFT_H_
Definition: AnyFFT.H:33
void Execute(FFTplan &fft_plan)
Perform FFT with backend library.
Definition: WrapCuFFT.cpp:74
fftw_plan VendorFFTPlan
Definition: AnyFFT.H:68
direction
Definition: AnyFFT.H:75
fftw_complex Complex
Definition: AnyFFT.H:53
void DestroyPlan(FFTplan &fft_plan)
Destroy library FFT plan.
Definition: WrapCuFFT.cpp:69
FFTplan CreatePlan(const amrex::IntVect &real_size, amrex::Real *real_array, Complex *complex_array, direction dir, int dim)
create FFT plan for the backend FFT library.
Definition: WrapCuFFT.cpp:25
Definition: AnyFFT.H:80
Complex * m_complex_array
Definition: AnyFFT.H:82
amrex::Real * m_real_array
Definition: AnyFFT.H:81
int m_dim
Definition: AnyFFT.H:85
direction m_dir
Definition: AnyFFT.H:84
VendorFFTPlan m_plan
Definition: AnyFFT.H:83