简体   繁体   English

1个二维ftf与numbapro cuda卷积

[英]1 dimentional fftconvolve with numbapro cuda

I have been following an example ( https://github.com/ContinuumIO/numbapro-examples/blob/master/convolution/fftconvolve.py ) given to do fftconvolve with an image and a kernel, both are 2D arrays. 我一直在关注一个示例( https://github.com/ContinuumIO/numbapro-examples/blob/master/convolution/fftconvolve.py ),该示例用于对图像和内核进行fftconvolve,这两个都是二维数组。 In my use case I would like to do fftconvolve with two 1D arrays to look for possible match and delay between. 在我的用例中,我想对两个1D数组进行fftconvolve查找可能的匹配和延迟。 I have tried to convert the example to 1D but received a few Invalid type combination errors. 我试图将示例转换为1D,但是收到一些Invalid type combination错误。 Is there possibly a better example to follow for 1-dimentional array fftconvolve using CUDA through numbapro? 对于通过numbapro使用CUDA的1维数组fftconvolve,可能有更好的例子吗? thanks 谢谢

Doing convolution in time domain is equivalent of doing fft in the Fourier domain. 在时域中进行卷积等同于在傅立叶域中进行fft。 This is one of the fundamentals in signal processing. 这是信号处理的基础之一。

Therefore, to do convolution of vector1 and vector2, you can simply apply fft (1D) to vector1 and vector2, and multiply the two complex transform together (filtering), and then inverse fft the product back into original domain. 因此,要对vector1和vector2进行卷积,只需将fft(1D)应用于vector1和vector2,然后将两个复数变换相乘(滤波),然后将乘积逆反返回原始域。

In cuda, it should be something like this: 在cuda中,应该是这样的:

cufftHandle _planKernel   // you fft handle
cufftPlan1d(&_planKernel, _fftLen, CUFFT_C2C,               1);   // create 1D fft handle
cufftComplex* VECTOR1, *VECTOR2, *PRODUCT;
MakeVector1Complex<<<blockSize, GridSize>>>()  // simply set real part of the VECTOR1 = vector1, and set the imaginary part VECTOR to 0 
MakeVector2Complex<<<blockSize, GridSize>>>()  // simply set real part of the VECTOR2 = vector2, and set the imaginary part VECTOR to 0
cufftExecC2C(planKernel, VECTOR1, VECTOR1, CUFFT_FORWARD);  // apply fft to VECTOR1
cufftExecC2C(planKernel, VECTOR2, VECTOR2, CUFFT_FORWARD);  // apply fft to VECTOR2
ComplexMutiplication<<<blockSize, GridSize>>>(VECTOR1, VECTOR2) // complex multiplication of VECTOR1 and VECTOR2

cufftExecC2C(planKernel, PRODUCT, PRODUCT, CUFFT_INVERSE); // inverse fft on the product of VECTOR1 AND VECTOR2

MakeProductReal<<<blockSize, GridSize>>>(PRODUCT) // extract the real part of PRODUCT

Now your job is done. 现在您的工作完成了。 There is also an example called " simpleCUFFT " in cuda toolkit, which you can find in C:\\ProgramData\\NVIDIA Corporation\\CUDA Samples 在cuda工具包中还有一个名为“ simpleCUFFT ”的示例,您可以在C:\\ ProgramData \\ NVIDIA Corporation \\ CUDA Samples中找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM