Xmipp  v3.23.11-Nereus
cuda_fft.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: David Strelak (davidstrelak@gmail.com)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #ifndef LIBRARIES_RECONSTRUCTION_CUDA_CUDA_FFT_H_
27 #define LIBRARIES_RECONSTRUCTION_CUDA_CUDA_FFT_H_
28 
29 
30 #include <array>
31 #include <typeinfo>
32 
33 #include "data/aft.h"
34 #include "core/xmipp_error.h"
36 #include "gpu.h"
37 
38 // XXX HACK to avoid including cufft.h in this header
39 // https://docs.nvidia.com/cuda/cufft/index.html#cuffthandle says that type is
40 // unsigned, but the header (v.8) uses int
41 typedef int cufftHandle;
42 
46 template<typename T>
47 class CudaFFT : public AFT<T> {
48 public:
49  CudaFFT() {
50  setDefault();
51  };
53  release();
54  }
55  void init(const HW &gpu, const FFTSettings<T> &settings, bool reuse=true);
56  void release() final;
57  std::complex<T>* fft(T *h_inOut);
58  std::complex<T>* fft(const T *h_in, std::complex<T> *h_out);
59 
60  T* ifft(std::complex<T> *h_inOut);
61  T* ifft(const std::complex<T> *h_in, T *h_out);
62 
63 
64  size_t estimatePlanBytes(const FFTSettings<T> &settings);
65  static std::complex<T>* fft(cufftHandle plan, T *d_inOut);
66  static std::complex<T>* fft(cufftHandle plan,
67  const T *d_in, std::complex<T> *d_out);
68  static T* ifft(cufftHandle plan, std::complex<T> *d_inOut);
69  static T* ifft(cufftHandle plan,
70  const std::complex<T> *d_in, T *d_out);
71  static cufftHandle* createPlan(const GPU &gpu,
72  const FFTSettings<T> &settings);
73  static FFTSettings<T> *findOptimal(const GPU &gpu,
74  const FFTSettings<T> &settings,
75  size_t reserveBytes, bool squareOnly, int sigPercChange,
76  bool crop, bool verbose);
77  static FFTSettings<T> findMaxBatch(const FFTSettings<T> &settings,
78  size_t maxBytes);
80  const FFTSettings<T> &settings,
81  size_t reserveBytes, bool squareOnly, int sigPercChange,
82  bool crop, bool verbose);
83  static void release(cufftHandle *plan);
84 private:
85  cufftHandle *m_plan;
86  const FFTSettings<T> *m_settings;
87  T *m_d_SD;
88  std::complex<T> *m_d_FD;
89 
90  const GPU *m_gpu;
91 
92  bool m_isInit;
93 
94  void setDefault() final;
95  template<typename F>
96  static void manyHelper(const FFTSettings<T> &settings, F function);
97  void check();
98 };
100 #endif /* LIBRARIES_RECONSTRUCTION_CUDA_CUDA_FFT_H_ */
size_t estimatePlanBytes(const FFTSettings< T > &settings)
Definition: cuda_fft.cpp:211
~CudaFFT()
Definition: cuda_fft.h:52
Definition: hw.h:35
int cufftHandle
Definition: cuda_fft.h:41
CudaFFT()
Definition: cuda_fft.h:49
void init(const HW &gpu, const FFTSettings< T > &settings, bool reuse=true)
Definition: cuda_fft.cpp:34
Definition: aft.h:39
T * ifft(std::complex< T > *h_inOut)
Definition: cuda_fft.cpp:129
static cufftHandle * createPlan(const GPU &gpu, const FFTSettings< T > &settings)
Definition: cuda_fft.cpp:276
void release() final
Definition: cuda_fft.cpp:108
static FFTSettings< T > * findOptimal(const GPU &gpu, const FFTSettings< T > &settings, size_t reserveBytes, bool squareOnly, int sigPercChange, bool crop, bool verbose)
Definition: cuda_fft.cpp:312
Definition: gpu.h:36
std::complex< T > * fft(T *h_inOut)
Definition: cuda_fft.cpp:119
static FFTSettings< T > findOptimalSizeOrMaxBatch(GPU &gpu, const FFTSettings< T > &settings, size_t reserveBytes, bool squareOnly, int sigPercChange, bool crop, bool verbose)
Definition: cuda_fft.cpp:358
static FFTSettings< T > findMaxBatch(const FFTSettings< T > &settings, size_t maxBytes)
Definition: cuda_fft.cpp:295