27 #ifndef psdFilterCuda_hpp
28 #define psdFilterCuda_hpp
30 #include "../cuda/templateCudaPtr.hpp"
31 #include "../cuda/templateCuda.hpp"
38 #include <helper_cuda.h>
68 template<
typename _realT>
69 class psdFilter<_realT, 1>
75 typedef Eigen::Array<realT, Eigen::Dynamic, Eigen::Dynamic>
realArrayT;
76 typedef Eigen::Array<complexT, Eigen::Dynamic, Eigen::Dynamic>
complexArrayT;
78 typedef realT deviceRealPtrT;
92 cufftHandle m_fftPlan {0};
170 template<
typename realT>
171 psdFilter<realT,1>::psdFilter()
175 template<
typename realT>
176 psdFilter<realT,1>::~psdFilter()
180 checkCudaErrors(cufftDestroy(m_fftPlan));
184 template<
typename realT>
185 int psdFilter<realT,1>::setSize()
189 std::complex<realT> scale(1./(m_rows*m_cols),0);
190 m_scale.upload(&scale,1);
192 checkCudaErrors(cufftPlan2d(&m_fftPlan, m_rows, m_cols, CUFFT_C2C));
199 template<
typename realT>
200 int psdFilter<realT,1>::rows()
205 template<
typename realT>
206 int psdFilter<realT,1>::cols()
227 template<
typename realT>
228 int psdFilter<realT,1>::psdSqrt(
const realArrayT & npsdSqrt )
230 m_rows = npsdSqrt.rows();
231 m_cols = npsdSqrt.cols();
234 complexArrayT tmp( m_rows, m_cols);
236 tmp.real() = npsdSqrt;
238 m_psdSqrt.upload(tmp.data(), m_rows*m_cols);
245 template<
typename realT>
246 int psdFilter<realT,1>::psdSqrt(
const cuda::cudaPtr<std::complex<realT>> & npsdSqrt,
254 m_psdSqrt.resize(m_rows*m_cols);
257 cudaMemcpy( m_psdSqrt.m_devicePtr, npsdSqrt.m_devicePtr, m_rows*m_cols*
sizeof(std::complex<realT>), cudaMemcpyDeviceToDevice);
264 template<
typename realT>
265 void psdFilter<realT,1>::clear()
274 template<
typename realT>
275 int psdFilter<realT,1>::filter( deviceComplexPtrT * noise )
280 cufftExecC2C(m_fftPlan, (cuComplex *) noise, (cuComplex *) noise, CUFFT_FORWARD);
283 mx::cuda::pointwiseMul<cuComplex><<<32, 256>>>((cuComplex *) noise, (cufftComplex *) m_psdSqrt.m_devicePtr, m_rows*m_cols);
285 cufftExecC2C(m_fftPlan, (cuComplex *)noise, (cuComplex *)noise, CUFFT_INVERSE);
288 mx::cuda::scalarMul<cuComplex><<<32, 256>>>((cuComplex *) noise, (cuComplex *) m_scale.m_devicePtr, m_rows*m_cols);
297 template<
typename realT>
298 int psdFilter<realT,1>::operator()( realArrayT & noise )
300 return filter(noise);
303 template<
typename realT>
304 int psdFilter<realT,1>::operator()( realArrayT & noise,
308 return filter(noise, &noiseIm);
int psdSqrt(const realArrayT &npsdSqrt)
Set the sqaure-root of the PSD.
_realT realT
Real floating point type.
int filter(deviceComplexPtrT *noise)
Apply the filter.
int cols()
Get the number of columns in the filter.
std::complex< _realT > complexT
Complex floating point type.
Eigen::Array< realT, Eigen::Dynamic, Eigen::Dynamic > realArrayT
Eigen array type with Scalar==realT.
int operator()(realArrayT &noise, realArrayT &noiseIm)
Apply the filter.
mx::cuda::cudaPtr< complexT > m_scale
the scale factor.
mx::cuda::cudaPtr< complexT > m_psdSqrt
Pointer to the real array containing the square root of the PSD.
int setSize()
Set the size of the filter.
int psdSqrt(const cuda::cudaPtr< std::complex< realT >> &npsdSqrt, size_t rows, size_t cols)
Eigen::Array< complexT, Eigen::Dynamic, Eigen::Dynamic > complexArrayT
Eigen array type with Scalar==complexT.
int operator()(realArrayT &noise)
Apply the filter.
void clear()
De-allocate all working memory and reset to initial state.
int rows()
Get the number of rows in the filter.
Declares and defines a class for filtering with PSDs.