GPU库使用cuFFT实现图像卷积? [英] GPU library that implements Image Convolution using cuFFT?

查看:971
本文介绍了GPU库使用cuFFT实现图像卷积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 Nvidia Performance Primitives(NPP)中的图片卷积功能。然而,我的内核相对于图像大小相当大,我听说有传言NPP的卷积是直接卷积,而不是基于FFT的卷积。 (我不认为NPP源代码是可用的,所以我不知道它是如何实现的。)



我想看一下基于cuFFT 的卷积函数可以在我正在处理的图像处理应用程序中运行。



你可能会说嘿,只是把你的形象放入cuFFT,看看它是多快!如果我使用Matlab,你会是对的 - 这是一个

 %假设图像被填充
convolved = ifft2(fft2(image)。* fft2(filter));






但是,需要获取cuFFT进行图像卷积。所以,我正在寻找的代码,做一个基于cuFFT的卷积和抽象的实现。而且,确实,我发现了一些东西:






警告:GpuFFTConvOp目前不返回好的回答
TODO:扩展覆盖更多的情况,因为在许多情况下我们会崩溃!




  • =http://www.vtk.org/Wiki/ITK/Release_4/GPU_Acceleration#GPUImage =nofollow> Kitware VTK / ITK 代码库提供了基于cuFFT的图像卷积。唉,事实证明(至多)做基于cuFFT的例程是计划未来版本


  • 我发现一些代码在Matlab文件交换做2D卷积。重要的部分在C / CUDA中实现,但有一个Matlab包装器。我正在努力剥离Matlab包装以支持纯C / C ++ / CUDA,但我仍然很好奇是否有任何更优雅和/或证明的解决方案。




这三个选项中的任何建议?



else

解决方案

你可以使用基于cuFFT的图像卷积的预构建代码。请尝试阵列火



在ArrayFire中,您可以执行以下操作。

  (rows,columns,h_image); 
数组过滤器(frows,fcols,h_filter);
array res = convolve(image,filter);

根据过滤器的大小,conolve命令使用cufft或更快的手动调整内核。如果您喜欢使用 fft2 ,您可以执行以下操作:

  res = ifft2(fft2(image)* fft2(filter)); 

但我强烈建议您使用 convolve



更多实用的链接:


  1. 傅立叶变换

  2. 卷积和过滤

免责声明:




  • ArrayFire不是开源。但是它可以免费使用版本。

  • 我在AccelerEyes工作并开发arrayfire。我链接到我们的产品,因为@solvingPuzzles专门请求类似于arrayfire做的库。


I've been using the image convolution function from Nvidia Performance Primitives (NPP). However, my kernel is fairly large with respect to the image size, and I've heard rumors that NPP's convolution is a direct convolution instead of an FFT-based convolution. (I don't think the NPP source code is available, so I'm not sure how it's implemented.)

I'd like to see how fast a cuFFT-based convolution function could run in the image processing application that I'm working on.

You might say "hey, just put your image into cuFFT and see how fast it is!" And if I were using Matlab, you'd be right--it's a one-line call in Matlab:

%assuming the images are padded
convolved = ifft2(fft2(image).* fft2(filter));


However, there's a lot of boiler-plate stuff needed to get cuFFT to do image convolution. So, I'm looking for code that does a cuFFT-based convolution and abstracts away the implementation. And, indeed, I did find a few things:

    WARNING: GpuFFTConvOp currently don't return the good answer
    TODO: extend to cover more case, as in many case we will crash!

  • I had it in my head that the Kitware VTK/ITK codebase provided cuFFT-based image convolution. Alas, it turns out that (at best) doing cuFFT-based routines is planned for future releases.

  • I found some code on the Matlab File Exchange that does 2D convolution. The important parts are implemented in C/CUDA, but there's a Matlab wrapper. I'm working on stripping away the Matlab wrapper in favor of pure C/C++/CUDA, but I'm still curious whether there are any solutions that are more elegant and/or proven.

Any recommendations among these three options?

What else is out there in terms of pre-built code that does cuFFT-based image convolution?

解决方案

You could try arrayfire.

In ArrayFire, you can do the following.

array image(rows, columns, h_image);
array filter(frows, fcols, h_filter);
array res = convolve(image, filter); 

Depending on the size of the filter, the conolve command either uses cufft or a faster hand tuned kernel. If you prefer to use fft2, you could do the following

array res = ifft2(fft2(image) * fft2(filter));

But I highly recommend you use convolve instead because it has been optimized to get the best performance out of cufft.

More useful links:

  1. Fourier Transforms
  2. Convolution and filtering

Disclaimer:

  • ArrayFire is not open source. However it has a free to use version.
  • I work at AccelerEyes and develop arrayfire. I am linking to our product because @solvingPuzzles specifically asked for a library similar to what arrayfire is doing.

这篇关于GPU库使用cuFFT实现图像卷积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆