Parallel looped interp1 on GPU

조회 수: 17 (최근 30일)
D. Plotnick
D. Plotnick 2016년 3월 18일
댓글: Harun Cetinkaya 2018년 6월 11일
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.

채택된 답변

Joss Knight
Joss Knight 2016년 3월 21일
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
D. Plotnick
D. Plotnick 2016년 9월 28일
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 2018년 6월 11일
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...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2016년 3월 19일
This is not running onthe GPU, but much faster than interp1 on the CPU: FEX: ScaleTime.

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by