Parallel looped interp1 on GPU

21 Ansichten (letzte 30 Tage)
D. Plotnick
D. Plotnick am 18 Mär. 2016
Kommentiert: Harun Cetinkaya am 11 Jun. 2018
I have a set of data where I am interpolating each row onto a different 2-D grid using interp1. I have been using gpuArray to run interp1 using a for loop (which gives me good speed), but since this is a series of independent parallel computations I was hoping for a way to parallelize the operation on the GPU.
I am including a minimum working example. The idea is to remove the for loop and run the interp1 calculations in parallel. Note that the actual datasets will be much larger, so yes the for loop would be great to toss.
%%InterpLoop MWE
Data = gpuArray(rand(100,1000));
x = 1:1000;
y = 1:100;
[X,Y] = meshgrid(x,y);
Xq = X-Y;
imagesc(Xq);
Vqs= cell(100,1);
x = gpuArray(x);
Xq = gpuArray(Xq);
for ii = 1:100
Vqs{ii} = interp1(x,Data(ii,:),Xq+x(ii),'linear',0);
end
Note also that storing the interpolated data in a cell array is also optional. The goal is parallel gpu loop over interp1 operations from 1-D to 2-D grid where the grid varies.
Side question, if somebody knows of an interp1 fast code that will do spline interpolation on the GPU I would love to know about it, interp1 only supports linear and nearest on gpuArray.

Akzeptierte Antwort

Joss Knight
Joss Knight am 21 Mär. 2016
The best way to parallelize multiple 1D interpolations is to use 2D interpolation, and just set the Y interp point to (1:M)', i.e:
Vqs = interp2(x, Data, Xq+x, (1:100)', 'linear', 0);
  4 Kommentare
D. Plotnick
D. Plotnick am 28 Sep. 2016
Thanks for the answer, you are correct that this runs faster (about a 10x speed improvement for the application I am working on).
Question: is interp2 'smart enough' to know that the y-interpolation points and the source points are identical, and thus not add computational burden, or is it still performing a true 2-D interpolation? If the latter, I still wonder if there is a way to run this faster using some form of parallel 1-D interpolation in order to skip the redundant interpolation in the y-direction.
Also, thanks Jan Simon and Joss Knight, you both keep showing up on my threads in quite useful places.
Harun Cetinkaya
Harun Cetinkaya am 11 Jun. 2018
Hi Joss Knight,
I have tried to use your code for interpolation issue (interp2). I simply took the same code as you wrote here... Unfortunately it does not work on my computer... But there is an error given as 'The input arguments are invalid. For supported syntaxes, see help gpuArray.interp2'.
I could not understand why it does not work...
thank you in advance for your interest...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jan
Jan am 19 Mär. 2016
This is not running onthe GPU, but much faster than interp1 on the CPU: FEX: ScaleTime.

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by