Be the first to rate this file! 45 downloads (last 30 days) File Size: 36.99 KB File ID: #20248

2D CUDA-based bilinear interpolation

by Alexander Huth

 

11 Jun 2008 (Updated 16 Jul 2008)

Code covered by the BSD License  

GPU assisted fast bilinear interpolation

Download Now | Watch this File

File Information
Description

This MEX performs 2d bilinear interpolation using an NVIDIA graphics chipset. To compile and run this software, one needs the NVIDIA CUDA Toolkit (http://www.nvidia.com/object/cuda_get.html) and, of course, an NVIDIA graphics card of reasonably modern vintage.

BUILDING INSTRUCTIONS: Change the 'MATLAB' (and if necessary, 'MEX') variables in the Makefile to appropriate values, then simply run 'make' at a prompt and an executable (mex/mexmac/mexmaci/dll?) file will be created.

This code uses your GPU's built-in bilinear texture interpolation capability, and is very fast. For reasonably sized operations (taking, say, a 50x50 matrix up to 1000x1000) CUDA-based code is 5-10x faster than linear interp2 (as tested on a MBP 2.4GHz C2D, GeForce 8600M GT).

With very (VERY) large matrices, however, it has the capability of completely crashing your computer or giving bizarre results. Be careful!

Acknowledgements
This submission has inspired the following:
NVIDIA CUDA-based bilinear (2D) interpolation
MATLAB release MATLAB 7.4 (R2007a)
Other requirements NVIDIA CUDA Toolkit: http://www.nvidia.com/object/cuda_get.html Tested on OSX 10.5, presumably works in Linux, perhaps Windows.
Zip File Content  
Other Files cudainterp2/cudainterp2.cu,
cudainterp2/cudainterp2.m,
cudainterp2/cudainterp2.mexmaci,
cudainterp2/Makefile,
cudainterp2/nvmex,
cudainterp2/nvopts.sh,
cudainterp2/README,
cudainterp2/testcudainterp2.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
12 Jun 2008 Scott Miller

Thanks for posting this. I won't review it, since I haven't run it, but it would be great if there were more routines that worked in GPUs with all the interfaces to MATLAB that would allow them to be used as direct plug-ins without needing to know all the gritty details!

14 Jun 2008 John D'Errico

While I do agree with Scott, I'll add a few comments to what he said.

It should not be necessary to have a file with the name cudainterp2_help. Instead, just rename that help file cudainterp2.m. Matlab is smart enough that it looks for help in an m-file with the same name, even if the m-file ONLY has help in it. When running the code, it uses the mexed file instead.

One thing that I do like is the author's comment about the limits of this code. I'll conjecture that the problem of crashing on very large problems is due to memory limitations in the GPU (or something like that.) As such, its probably not a bug in this code. But warning the user of known issues is a nice thing to do.

The one thing that I can say about this code is the H1 line, i.e., the first line of help. It should be a simple, concise line, that includes important key words that lookfor will find. In this code, the first line of the help was a long winded thing that went on to tell the user about installation requirements, compilation particulars, etc. Split up that line.

Finally, I see that the zip file contains some unnecessary files. These should be cleaned up before zipping the directory. The gipper utility is a nice one (found on the file exchange, written by Tim Davis) to zip directories while dropping out those files you don't want to include.

15 Jun 2008 i scardanzan

more matlab functions compiled with Nvidia CUDA please !!!
e.g. image processing toolbox functions that are generally very slow ( rotate in 3d , filtering , radon etc. etc )
cpu speed X 2 in 18 m, gpu speed X 2 in 6 !

16 Jun 2008 Alex Huth

John -- Thanks for the tips, I've submitted a version with corrected help and a better zipped version (OS X's archiver .. ).

28 Jun 2008 John D'Errico

My lack of any c expertise (or the compiler) shows here, so I can't test this.

I'd still make a bit more of a revision to the help however. Tell the user what will be returned, even though it seems logical to me that the new array will have shape (nrows,ncols). Or does this code overwrite data? Tell your user what your expectations for data are on input. Must it be a double array, or may it be single or uint8? Complex?

16 Apr 2009 Gerald Buchgraber

Hi all!
I did something similar with some improvements.
I also included a test to compare my solution (bilininterp) with cudainterp2 and as you can see here
http://www.mathworks.co.uk/matlabcentral/fileexchange/23795
it is much faster than cudainterp2.

Please login to add a comment or rating.
Updates
16 Jun 2008

Cleaned up ZIP file, help.

16 Jul 2008

Updated help, added test benchmarking script.

Tag Activity for this File
Tag Applied By Date/Time
cuda Alexander Huth 22 Oct 2008 10:05:36
2d bilinear interpolation Alexander Huth 22 Oct 2008 10:05:36
fast mex Alexander Huth 22 Oct 2008 10:05:36

Contact us at files@mathworks.com