File Exchange

image thumbnail

NVIDIA CUDA-based bilinear (2D) interpolation

version (57.8 KB) by Gerald Buchgraber
Incredible speed boost in comparison to the Matlab implementation. (interp2)


Updated 30 Jun 2009

View Version History

View License

This code was inspired by Alexander Huth's bilinear interpolation approach
( )
also using the GPU's built-in bilinear texture interpolation capability, which is indeed very fast.

The speedup is depending on your CUDA enabled graphics hardware. The more multiprocessors, texture units, ... the better the results will be.

In comparison to Alexander's cudainterp2, I added some performance improvements and the capability to interpolate complex numbers too.

Feel free to write some feedback or a comment.

Cite As

Gerald Buchgraber (2020). NVIDIA CUDA-based bilinear (2D) interpolation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (11)


Could anybody help me to get this to run on a more current version of MATLAB, e.g. 2013b?

I copied the file as instructed but then get this error (clearly, the "options file" is outdated):

Error: Using options file:
You cannot use this file with the UNKNOWN architecture because it enables a compiler for a different architecture.
Choose a file that is compatible with the UNKNOWN architecture.

Emil Entchev

When I try to compile the mex file I am getting "\ error: taking reference of texture/surface variable not allowed in __device__/__global__ functions".

Any solution?


hi how could we calculate exact speed up .... i mean in the comments section it has been given that relative speed up of 5 means approx 1/10 th of performance improvement for GPU....

could some one explain it..

Qi Wang

Please correct me if I am wrong.

In "bilininterp_speed_test.m", cudainterp2 and matlab's interp2 generate a output matrix, however bilininterp only interpolate one point in each loop. That is why it gets faster when the matrix getting bigger.

The input to bilininterp should be same like interp2 to have the same output dimension. And if it is done correctly, bilininterp's speedup is ~5 compared to cudainterp2's speedup of ~8 on my GTX460.


I tried this on a XP64 machine with Matlab 64. I found one problem: If options are placed into an rsp file by the nvmex_helper script the nvmex compiler cannot parse them. So I added

if (grep /\.rsp$/i, @ARGV) { # arg is a rsp file
my $fn = substr($ARGV[0],1);
my $holdNewline = $/;
undef $/;
my $inf;
open $inf, "<" . $fn;
my $buf = <$inf>;
close $inf;
$/ = $holdNewline;
$_ = $buf;
s/"(.*)\s(.*)"/"\"$1_!_$2\""/eg; # avoid splitting at spaces with quotes,e.g,. "Program Files/"
s/\s+/" "/eg; # collapse multiple spaces
$buf = $_;
@items = split / /, $buf; #split the input string into individual words
grep(s/_!_/" "/eg, @items);
@ARGV = @items;

to to allow that. Now I can pass -win32 as an option, and with some add'l tweaks (using win32 matlab and cuda libs, setting LINKER_OPTIONS to /MACHINE:X86 and esnuring that the 32-bit nvcc is called, I can now compile and run 32-bit mex executables from the 64-bit matlab command line.

Oliver Woodford

I wrote my own compile script for linux. See:

Gerald Buchgraber

Well, I haven't tried it yet, but I'm sure it's possible. The included build tools are dedicated to MS Windows. Please leave a notice if you get it running.

Oliver Woodford

Is this supposed to compile on linux, or only on Windows? I can't get it to compile on linux.

Gerald Buchgraber

Dear Darius,
you can find all build params described in nvmex.m
For adding additional include or library paths just use (similar to gcc) the params: -I<pathname> (for include path), -L<directory> (for lib dir) and -l<name> (for lib file).

Hopefully this helps and you get it running!


Having trouble getting it running:

"Can't locate File/ in @INC (@INC contains: C:/Program Files/MATLAB/R2007a...)"

How does one ensure valid "include" and "library" paths in "build_mex.m" ?

Yi Cao

The code works as described. On my GeForce 8400 GPU, it can achieve over 200 on relative speedup. The nvmex compiler also works smoothly on MATLAB R2009A. Excellent!

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: 2D CUDA-based bilinear interpolation

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!