WarpX
Toggle main menu visibility
Loading...
Searching...
No Matches
Source
ablastr
math
fft
AnyFFT.H
Go to the documentation of this file.
1
/* Copyright 2019-2023
2
*
3
* This file is part of ABLASTR.
4
*
5
* License: BSD-3-Clause-LBNL
6
*/
7
8
#ifndef ABLASTR_ANYFFT_H_
9
#define ABLASTR_ANYFFT_H_
10
11
#ifdef ABLASTR_USE_FFT
12
# include <AMReX_Config.H>
13
# include <
AMReX_GpuComplex.H
>
14
# include <
AMReX_LayoutData.H
>
15
16
# if defined(AMREX_USE_CUDA)
17
# include <cufft.h>
18
# include <cuComplex.h>
19
# elif defined(AMREX_USE_HIP)
20
# if __has_include(<rocfft/rocfft.h>)
// ROCm 5.3+
21
# include <rocfft/rocfft.h>
22
# else
23
# include <rocfft.h>
24
# endif
25
# include <hip/hip_complex.h>
26
# elif defined(AMREX_USE_SYCL)
27
# include <oneapi/mkl/dft.hpp>
28
# else
29
# include <fftw3.h>
30
# endif
31
#endif
32
33
40
namespace
ablastr::math::anyfft
41
{
42
46
void
setup
();
47
51
void
cleanup
();
52
53
#ifdef ABLASTR_USE_FFT
54
55
// First, define library-dependent types (complex, FFT plan)
56
58
# if defined(AMREX_USE_CUDA)
59
# ifdef AMREX_USE_FLOAT
60
using
Complex
= cuComplex;
61
# else
62
using
Complex
= cuDoubleComplex;
63
# endif
64
# elif defined(AMREX_USE_HIP)
65
# ifdef AMREX_USE_FLOAT
66
using
Complex
= float2;
67
# else
68
using
Complex
= double2;
69
# endif
70
# elif defined(AMREX_USE_SYCL)
71
using
Complex
=
amrex::GpuComplex<amrex::Real>
;
72
# else
73
# ifdef AMREX_USE_FLOAT
74
using
Complex
= fftwf_complex;
75
# else
76
using
Complex
= fftw_complex;
77
# endif
78
# endif
79
80
/* Library-dependent multiply helpers */
81
# if defined(AMREX_USE_CUDA)
82
# ifdef AMREX_USE_FLOAT
83
AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
void
multiply (
Complex
& c,
Complex
const
& a,
Complex
const
& b) { c = cuCmulf(a, b); }
84
# else
85
AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
void
multiply (
Complex
& c,
Complex
const
& a,
Complex
const
& b) { c = cuCmul(a, b); }
86
# endif
87
# elif defined(AMREX_USE_HIP)
88
# ifdef AMREX_USE_FLOAT
89
AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
void
multiply (
Complex
& c,
Complex
const
& a,
Complex
const
& b) { c = hipCmulf(a, b); }
90
# else
91
AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
void
multiply (
Complex
& c,
Complex
const
& a,
Complex
const
& b) { c = hipCmul(a, b); }
92
# endif
93
# elif defined(AMREX_USE_SYCL)
94
AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
void
multiply (
Complex
& c,
Complex
const
& a,
Complex
const
& b) { c = a * b; }
95
# else
96
AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
void
multiply (
Complex
& c,
Complex
const
& a,
Complex
const
& b) {
97
c[0] = a[0] * b[0] - a[1] * b[1];
98
c[1] = a[0] * b[1] + a[1] * b[0];
99
}
100
# endif
101
105
# if defined(AMREX_USE_CUDA)
106
using
VendorFFTPlan = cufftHandle;
107
# elif defined(AMREX_USE_HIP)
108
using
VendorFFTPlan = rocfft_plan;
109
# elif defined(AMREX_USE_SYCL)
110
using
VendorFFTPlan = oneapi::mkl::dft::descriptor<
111
# ifdef AMREX_USE_FLOAT
112
oneapi::mkl::dft::precision::SINGLE,
113
# else
114
oneapi::mkl::dft::precision::DOUBLE,
115
# endif
116
oneapi::mkl::dft::domain::REAL> *;
117
// dft::descriptor has no default ctor, so we have to use ptr.
118
# else
119
# ifdef AMREX_USE_FLOAT
120
using
VendorFFTPlan = fftwf_plan;
121
# else
122
using
VendorFFTPlan = fftw_plan;
123
# endif
124
# endif
125
126
// Second, define library-independent API
127
129
enum struct
direction {R2C, C2R};
130
133
struct
FFTplan
134
{
135
amrex::Real
* m_real_array;
136
Complex
* m_complex_array;
137
VendorFFTPlan m_plan;
138
direction m_dir;
139
int
m_dim;
140
#ifdef AMREX_USE_SYCL
141
amrex::gpuStream_t
m_stream;
142
#endif
143
};
144
146
using
FFTplans =
amrex::LayoutData<FFTplan>
;
147
156
FFTplan
CreatePlan
(
const
amrex::IntVect
& real_size,
amrex::Real
* real_array,
157
Complex
* complex_array, direction dir,
int
dim);
158
162
void
DestroyPlan
(FFTplan& fft_plan);
163
167
void
Execute
(FFTplan& fft_plan);
168
169
#endif
170
171
}
172
173
#endif
// ABLASTR_ANYFFT_H_
AMREX_FORCE_INLINE
#define AMREX_FORCE_INLINE
AMReX_GpuComplex.H
AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST_DEVICE
AMReX_LayoutData.H
Complex
amrex::GpuComplex< amrex::Real > Complex
Definition
WarpX_Complex.H:22
amrex::LayoutData
amrex::Real
amrex_real Real
ablastr::math::anyfft
Definition
AnyFFT.H:41
ablastr::math::anyfft::CreatePlan
FFTplan CreatePlan(const amrex::IntVect &real_size, amrex::Real *const real_array, Complex *const complex_array, const direction dir, const int dim)
Definition
WrapCuFFT.cpp:30
ablastr::math::anyfft::DestroyPlan
void DestroyPlan(FFTplan &fft_plan)
Definition
WrapCuFFT.cpp:78
ablastr::math::anyfft::cleanup
void cleanup()
Definition
WrapCuFFT.cpp:18
ablastr::math::anyfft::Execute
void Execute(FFTplan &fft_plan)
Definition
WrapCuFFT.cpp:84
ablastr::math::anyfft::setup
void setup()
Definition
WrapCuFFT.cpp:16
amrex::gpuStream_t
cudaStream_t gpuStream_t
amrex::IntVect
IntVectND< 3 > IntVect
amrex::GpuComplex
Generated by
1.17.0