ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
fft_bundle.h
Go to the documentation of this file.
1#ifndef FFT_TEMP_H
2#define FFT_TEMP_H
3
4#include "fft_base.h"
5#include "fft_cpu.h"
6
7#include <memory>
8namespace ModuleBase
9{
11{
12 public:
23 FFT_Bundle(std::string device_in, std::string precision_in) : device(device_in), precision(precision_in) {};
24
33 void setfft(std::string device_in, std::string precision_in);
34
41 void set_dsp_cluster_id(int id) { this->dsp_cluster_id_ = id; }
42
62 void initfft(int nx_in,
63 int ny_in,
64 int nz_in,
65 int lixy_in,
66 int rixy_in,
67 int ns_in,
68 int nplane_in,
69 int nproc_in,
70 bool gamma_only_in,
71 bool xprime_in = true,
72 bool mpifft_in = false);
73
80
81 void initfftmode(int fft_mode_in)
82 {
83 this->fft_mode = fft_mode_in;
84 }
85
86 void setupFFT();
87
88 void clearFFT();
89
90 void clear();
91
92 void resource_handler(const int flag) const;
100 template <typename FPTYPE>
101 FPTYPE* get_rspace_data() const;
109 template <typename FPTYPE>
110 std::complex<FPTYPE>* get_auxr_data() const;
118 template <typename FPTYPE>
119 std::complex<FPTYPE>* get_auxg_data() const;
127 template <typename FPTYPE>
128 std::complex<FPTYPE>* get_auxr_3d_data() const;
129
140 template <typename FPTYPE>
141 void fftzfor(std::complex<FPTYPE>* in, std::complex<FPTYPE>* out) const;
151 template <typename FPTYPE>
152 void fftxyfor(std::complex<FPTYPE>* in, std::complex<FPTYPE>* out) const;
162 template <typename FPTYPE>
163 void fftzbac(std::complex<FPTYPE>* in, std::complex<FPTYPE>* out) const;
173 template <typename FPTYPE>
174 void fftxybac(std::complex<FPTYPE>* in, std::complex<FPTYPE>* out) const;
175
185 template <typename FPTYPE>
186 void fftxyr2c(FPTYPE* in, std::complex<FPTYPE>* out) const;
196 template <typename FPTYPE>
197 void fftxyc2r(std::complex<FPTYPE>* in, FPTYPE* out) const;
198
199 template <typename FPTYPE>
200 void fft3D_forward(std::complex<FPTYPE>* in, std::complex<FPTYPE>* out) const;
201 template <typename FPTYPE>
202 void fft3D_backward(std::complex<FPTYPE>* in, std::complex<FPTYPE>* out) const;
203
205 std::string get_device() const { return device; }
207 std::string get_precision() const { return precision; }
208
209 private:
210 int fft_mode = 0;
211 bool float_flag = false;
212 bool double_flag = false;
213 // Backends selected by `device`: an FFT_CPU instance for "cpu",
214 // FFT_CUDA/FFT_ROCM for "gpu", FFT_DSP for "dsp". They serve the
215 // device-memory ("gpu-like") 3D FFT interface; on "cpu" they also serve
216 // the host-memory ("cpu-like") interface.
217 std::shared_ptr<FFT_BASE<float>> fft_float = nullptr;
218 std::shared_ptr<FFT_BASE<double>> fft_double = nullptr;
219 // Extra CPU backends serving the host-memory ("cpu-like") interface when
220 // the configured device is not "cpu", since the gpu/dsp backends implement
221 // only the 3D FFT interface. They keep host post-processing such as the
222 // Wannier90 interface and Berry phase working, since those run on the CPU
223 // wavefunction mirror even in GPU calculations. Null when
224 // device == "cpu", where fft_float/fft_double already serve both
225 // interfaces.
226 std::shared_ptr<FFT_BASE<float>> host_fft_float = nullptr;
227 std::shared_ptr<FFT_BASE<double>> host_fft_double = nullptr;
228
229 // The backend that serves the host-memory interface, whichever it is.
231 {
232 return (this->device == "cpu") ? this->fft_float.get() : this->host_fft_float.get();
233 }
235 {
236 return (this->device == "cpu") ? this->fft_double.get() : this->host_fft_double.get();
237 }
238
239 std::string device = "cpu";
240 std::string precision = "double";
242};
243// Use RAII (Resource Acquisition Is Initialization) to
244// control the resources used by hthread when setting the DSP
246 {
248 FFT_Guard(const FFT_Bundle& fft) : fft_(fft)
249 {fft_.resource_handler(1);}
251 {
252 fft_.resource_handler(0);
253 }
254 };
255
256} // namespace ModuleBase
257#endif // FFT_H
Definition fft_base.h:25
Definition fft_bundle.h:11
void fftxyc2r(std::complex< FPTYPE > *in, FPTYPE *out) const
Complex to real fft in x-y direction.
bool float_flag
Definition fft_bundle.h:211
void fft3D_forward(std::complex< FPTYPE > *in, std::complex< FPTYPE > *out) const
FPTYPE * get_rspace_data() const
Get the real space data.
std::shared_ptr< FFT_BASE< float > > host_fft_float
Definition fft_bundle.h:226
FFT_Bundle(std::string device_in, std::string precision_in)
Constructor with device and precision.
Definition fft_bundle.h:23
std::shared_ptr< FFT_BASE< double > > host_fft_double
Definition fft_bundle.h:227
std::shared_ptr< FFT_BASE< float > > fft_float
Definition fft_bundle.h:217
void fftxybac(std::complex< FPTYPE > *in, std::complex< FPTYPE > *out) const
Backward fft in x-y direction.
~FFT_Bundle()
Definition fft_bundle.cpp:24
std::string device
Definition fft_bundle.h:239
void set_dsp_cluster_id(int id)
Set the DSP cluster id for the FFT_DSP backend.
Definition fft_bundle.h:41
void initfft(int nx_in, int ny_in, int nz_in, int lixy_in, int rixy_in, int ns_in, int nplane_in, int nproc_in, bool gamma_only_in, bool xprime_in=true, bool mpifft_in=false)
Initialize the fft parameters.
Definition fft_bundle.cpp:35
FFT_BASE< float > * get_host_fft_float() const
Definition fft_bundle.h:230
void clearFFT()
Definition fft_bundle.cpp:157
std::string precision
Definition fft_bundle.h:240
void fftxyr2c(FPTYPE *in, std::complex< FPTYPE > *out) const
Real to complex fft in x-y direction.
FFT_Bundle()
Definition fft_bundle.h:13
void fft3D_backward(std::complex< FPTYPE > *in, std::complex< FPTYPE > *out) const
int dsp_cluster_id_
Definition fft_bundle.h:241
void initfftmode(int fft_mode_in)
Initialize the fft mode.
Definition fft_bundle.h:81
void fftzbac(std::complex< FPTYPE > *in, std::complex< FPTYPE > *out) const
Backward fft in z direction.
std::complex< FPTYPE > * get_auxr_3d_data() const
Get the auxr 3d data.
std::string get_device() const
the device this bundle was configured for, "cpu" or "gpu"
Definition fft_bundle.h:205
void fftxyfor(std::complex< FPTYPE > *in, std::complex< FPTYPE > *out) const
Forward fft in x-y direction.
void setupFFT()
Definition fft_bundle.cpp:137
void fftzfor(std::complex< FPTYPE > *in, std::complex< FPTYPE > *out) const
Forward fft in z direction.
std::complex< FPTYPE > * get_auxg_data() const
Get the auxg data.
void clear()
Definition fft_bundle.cpp:176
FFT_BASE< double > * get_host_fft_double() const
Definition fft_bundle.h:234
int fft_mode
Definition fft_bundle.h:210
std::complex< FPTYPE > * get_auxr_data() const
Get the auxr data.
std::string get_precision() const
the precision this bundle was configured for, "single" or "double"
Definition fft_bundle.h:207
std::shared_ptr< FFT_BASE< double > > fft_double
Definition fft_bundle.h:218
void setfft(std::string device_in, std::string precision_in)
Set device and precision.
Definition fft_bundle.cpp:29
bool double_flag
Definition fft_bundle.h:212
void resource_handler(const int flag) const
Definition fft_bundle.cpp:197
Definition clebsch_gordan_coeff.cpp:8
~FFT_Guard()
Definition fft_bundle.h:250
FFT_Guard(const FFT_Bundle &fft)
Definition fft_bundle.h:248
const FFT_Bundle & fft_
Definition fft_bundle.h:247