Xmipp  v3.23.11-Nereus
fftwT.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_FFTWT_H_
27 #define LIBRARIES_RECONSTRUCTION_FFTWT_H_
28 
29 #include <fftw3.h>
30 
31 #include "data/aft.h"
32 #include "data/cpu.h"
33 
37 namespace FFTwT_planType {
38  template<class T>
39  struct plan{ typedef T type; };
40  template<>
41  struct plan<float>{ typedef fftwf_plan type; };
42  template<>
43  struct plan<double>{ typedef fftw_plan type; };
44 }
45 
47 public:
49  fftw_init_threads();
50  fftwf_init_threads();}
52  fftw_cleanup();
53  fftwf_cleanup();
54  fftw_cleanup_threads();
55  fftwf_cleanup_threads();
56  }
57 };
58 
59 template<typename T>
60 class FFTwT : public AFT<T> {
61 public:
62 
63  FFTwT() {
64  setDefault();
65  };
66  ~FFTwT() {
67  release();
68  }
69  void init(const HW &cpu, const FFTSettings<T> &settings, bool reuse=true);
70  void release();
71  size_t estimatePlanBytes(const FFTSettings<T> &settings);
72  std::complex<T>* fft(T *inOut);
73  std::complex<T>* fft(const T *in, std::complex<T> *out);
74 
75  T* ifft(std::complex<T> *inOut);
76  T* ifft(const std::complex<T> *in, T *out);
77 
78  template<typename P>
79  static std::complex<T>* fft(const P plan,
80  const T *in, std::complex<T> *out);
81  template<typename P>
82  static std::complex<T>* fft(const P plan,
83  T *inOut);
84 
85  static std::complex<T>* fft(void *plan,
86  const T *in, std::complex<T> *out) {
87  return fft(cast(plan), in, out);
88  }
89  static std::complex<T>* fft(void *plan, T *inOut) {
90  return fft(cast(plan), inOut);
91  }
92 
93  template<typename P>
94  static T* ifft(const P plan,
95  std::complex<T> *in, T *out); // no const in as it can be overwritten!
96  template<typename P>
97  static T* ifft(const P plan,
98  std::complex<T> *inOut);
99 
100  static T* ifft(void *plan,
101  std::complex<T> *in, T *out) { // no const in as it can be overwritten!
102  return ifft(cast(plan), in, out);
103  }
104  static T* ifft(void *plan,
105  std::complex<T> *inOut) {
106  return ifft(cast(plan), inOut);
107  }
108 
109  static const fftw_plan createPlan(
110  const CPU &cpu,
111  const FFTSettings<double> &settings,
112  bool isDataAligned=false);
113  static const fftwf_plan createPlan(
114  const CPU &cpu,
115  const FFTSettings<float> &settings,
116  bool isDataAligned=false);
117 
118  template<typename P>
119  static void release(P plan);
120 
121  static void release(void *plan);
122 
123  template<typename D>
124  static void release(D *alignedData);
125  static void* allocateAligned(size_t bytes);
126 
127 private:
128  static void *m_mockOut;
129 
130  void *m_plan;
131  const FFTSettings<T> *m_settings;
132  T *m_SD;
133  std::complex<T> *m_FD;
134 
135  const CPU *m_cpu;
136 
137  bool m_isInit;
138 
139  template<typename U, typename F>
140  static U planHelper(const FFTSettings<T> &settings, F function,
141  int threads, bool isDataAligned);
142 
143  void setDefault();
144  void check();
145  void allocate();
146 
147  void release(T *SD, std::complex<T> *FD);
148 
149  bool needsAuxArray(const FFTSettings<T> &settings);
150 
151  static typename FFTwT_planType::plan<T>::type cast(void *p) {
152  return static_cast<typename FFTwT_planType::plan<T>::type>(p);
153  }
154 };
156 #endif /* LIBRARIES_RECONSTRUCTION_FFTWT_H_ */
~FFTwT()
Definition: fftwT.h:66
FFTwT()
Definition: fftwT.h:63
Definition: hw.h:35
static std::complex< T > * fft(void *plan, T *inOut)
Definition: fftwT.h:89
int in
Definition: aft.h:39
~FFTwT_Startup()
Definition: fftwT.h:51
FFTwT_Startup()
Definition: fftwT.h:48
static T * ifft(void *plan, std::complex< T > *inOut)
Definition: fftwT.h:104
Definition: cpu.h:37
static T * ifft(void *plan, std::complex< T > *in, T *out)
Definition: fftwT.h:100
static std::complex< T > * fft(void *plan, const T *in, std::complex< T > *out)
Definition: fftwT.h:85
Definition: fftwT.h:60
check(nparam, nf, nfsr, &Linfty, nineq, nineqn, neq, neqn, ncsrl, ncsrn, mode, &modem, eps, bgbnd, param)