ARTEMIS
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 #if 1 //use_fft
12 #include <AMReX_Config.H>
13 #include <AMReX_LayoutData.H>
14 
15 # if defined(AMREX_USE_CUDA)
16 # include <cufft.h>
17 # include <cuComplex.h>
18 # elif defined(AMREX_USE_HIP)
19 # if __has_include(<rocfft/rocfft.h>) // ROCm 5.3+
20 # include <rocfft/rocfft.h>
21 # else
22 # include <rocfft.h>
23 # endif
24 # include <hip/hip_complex.h>
25 # elif defined(AMREX_USE_SYCL)
26 # include <oneapi/mkl/dft.hpp>
27 # else
28 # include <fftw3.h>
29 # endif
30 #endif
31 
38 namespace AnyFFT
39 {
40  // First, define library-dependent types (complex, FFT plan)
41 
43 #if defined(AMREX_USE_CUDA)
44 # ifdef AMREX_USE_FLOAT
45  using Complex = cuComplex;
46 # else
47  using Complex = cuDoubleComplex;
48 # endif
49 #elif defined(AMREX_USE_HIP)
50 # ifdef AMREX_USE_FLOAT
51  using Complex = float2;
52 # else
53  using Complex = double2;
54 # endif
55 #else
56 # ifdef AMREX_USE_FLOAT
57  using Complex = fftwf_complex;
58 # else
59  using Complex = fftw_complex;
60 # endif
61 #endif
62 
66 #if defined(AMREX_USE_CUDA)
67  using VendorFFTPlan = cufftHandle;
68 #elif defined(AMREX_USE_HIP)
69  using VendorFFTPlan = rocfft_plan;
70 #else
71 # ifdef AMREX_USE_FLOAT
72  using VendorFFTPlan = fftwf_plan;
73 # else
74  using VendorFFTPlan = fftw_plan;
75 # endif
76 #endif
77 
78  // Second, define library-independent API
79 
81  enum struct direction {R2C, C2R};
82 
85  struct FFTplan
86  {
87  amrex::Real* m_real_array;
91  int m_dim;
92  };
93 
96 
105  FFTplan CreatePlan(const amrex::IntVect& real_size, amrex::Real * const real_array,
106  Complex * const complex_array, const direction dir, const int dim);
107 
111  void DestroyPlan(FFTplan& fft_plan);
112 
116  void Execute(FFTplan& fft_plan);
117 }
118 
119 #endif // ANYFFT_H_
Definition: AnyFFT.H:39
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
fftw_plan VendorFFTPlan
Definition: AnyFFT.H:74
direction
Definition: AnyFFT.H:81
fftw_complex Complex
Definition: AnyFFT.H:59
void DestroyPlan(FFTplan &fft_plan)
Destroy library FFT plan.
Definition: WrapCuFFT.cpp:69
Definition: AnyFFT.H:86
Complex * m_complex_array
Definition: AnyFFT.H:88
amrex::Real * m_real_array
Definition: AnyFFT.H:87
int m_dim
Definition: AnyFFT.H:91
direction m_dir
Definition: AnyFFT.H:90
VendorFFTPlan m_plan
Definition: AnyFFT.H:89