图像去模糊算法在CUDA上的实现,基于MATLAB平台

来源:互联网 发布:饥荒修改数据手杖 编辑:程序博客网 时间:2024/06/05 03:14

任务:完成图像去模糊算法的GPU加速,采用CUDA架构,实现shockFilter/psfEstimation/NonBlindDeconvolution三个算法的CUDA程序

1.下载软件: [2]

安装完后可以用GPU-Z软件检查是否满足CUDA运行环境。

2. 采用的运行平台: Vista/MATLAB   这里自然需要用到MATLAB在CUDA中的加速方法,参考[4]所写的白皮书,或者[5]中介绍的。

   虽然这里用的是Vista下的MATLAB,但更倾向于linux系统,只是时间紧迫。MATLAB用CUDA类似MATLAB与C的混合编程,自然需要对MEX熟悉。可以参考《精通MATLAB与C/C++混合程序设计》

   关于nvmex平台搭建的一些问题解决方案:

   a. 首先在安装matlab和vc的时候要注意版本问题,matlab要比vc版本高,这样才能找到编译器

   b. 在下载matlab-cuda plug-in[8]后,会遇到

Undefined subroutine &main::uuidgen called at E:\MATLAB\R2010b\bin\nvmex.pl line 728. 

??? Error using ==> nvmex at 206

Unable to complete successfully. 这样的问题基本上是因为Plug-in文件自身的问题,即使是nvidia官方给出的也因没有即使更新而存在问题,这里推荐[6]中给出的nvmex.pl和nvmexopts.bat,我在采用这两个新的文件后,问题少了很多;

   c. 但随后又遇到新的问题,

   LINK : fatal error LNK1181: cannot open input file 'kernel32.lib'  

  E:\MATLAB\R2010B\BIN\NVMEX.PL: Error: Link of 'Szeta.mexw32' failed. 参考[7]中的方案

Quoted from [7]:

LINK : fatal error LNK1181: cannot

I have found the solution (at least for my machine, Matlab 2009a, Visual Studio 2008 (9.0) )
1st: The linker searches for some libraries, such as kernel32.lib, in %MATLAB%\extern\lib\win32\microsoft% (see nvmexopt.bat)
The libraries are in the MSVC SDK path in "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin"
Copy all the files (*.lib) of the second (MSVC) to the first directory (MATLAB).
2nd: After that I encountered a problem with the mt command in the pre-last line of the nvmexopts.bat file
set POSTLINK_CMDS2=mt ... bla bla
replace it with 
set POSTLINK_CMDS2="C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe" ... bla bla
3rd: One minor change is the path of the visual studio:
set VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio 9.0
instead of Visual Studio 8.0 
Of course, maybe somebody can give a more efficient solution.

I hope it will work for you! 

This post has been edited by gchantas: 18 April 2009 - 05:03 PM

或者也可以把上述路径添加至nvmexopt.bat内的库路径中去,应该也可以解决。

3. CUDA编程,编程方法学习可以从[3]中找到详尽的资料。完成shockFilter算法的CUDA实现后,在Matlab下采用命令nvmex -f nvmexopts.bat gpuShock.cu -IC:\cuda\include -LC:\cuda\lib -lcufft -lcudart 即可得到gpuShock.mexw32文件,随后便可在M文件中直接调用gpuShock(args[])

需要注意的一个问题是在涉及到CUFFT变换的时候,值会放大M*N大小,因此在做反变换的时候需要除以这个scale;

还有就是当kernel函数涉及到shared memory时,在调用的时候,需要写入第三个参数,即共享内存的大小

4.调试,CUDA提供了cuPrintf函数,可参考NVIDIA GPU Computer SDK中的范例simplePrintf

   

Reference: 1. http://forums.nvidia.com/index.php?s=38f92bf65550e4ad5a354b30172bd1e2&showforum=62

                     2. http://developer.nvidia.com/cuda-toolkit-40

                     3. http://cudabbs.it168.com/

                     4. http://www.systematics.co.il/mathworks/News/Pdf/2009/nvidia.pdf

                     5. http://staff.washington.edu/dushaw/epubs/Matlab_CUDA_Tutorial_2_10.pdf

                     6. http://forums.nvidia.com/index.php?showtopic=66961

                     7. http://forums.nvidia.com/index.php?showtopic=54084

                     8. http://developer.nvidia.com/object/matlab_cuda.html

原创粉丝点击