GPU, Interpn and Meshgrid

Hi,
I am trying to do some interpolation on a 4 dimensional grid, taking advantage of GPU computing. However, when creating my grid with ndgrid, matlab says that only grid generated with meshgrid are valid. This is true only for the GPU version, there is no problem when I don't use a GPU array.
The problem is that meshgrid cannot be 4 dimensional (maximum is 3). Does it mean than interpn cannot be use with GPU arrays? There is probably a way to avoid this (otherwise a gpu version of interpn is imposible to use), but I cannot find it.
Advice would be welcome!
Thanks

답변 (2개)

Matt J
Matt J 2014년 8월 20일
편집: Matt J 2014년 8월 20일

0 개 추천

I suspect you are inadvertently calling interp2, rather than interpn. interp2 does require that the data be as if produced by meshgrid. In any case, you should show the code you have run so that we can reproduce it.
Ultimately, though, there is no reason to use either ndgrid or meshgrid when working with interpn or griddedInterpolant. It consumes extra memory unnecessarily and is, I believe, purely for backward compatibility. You can just call interpn with the original 1D grid vectors used as arguments to ndgrid. This is true in the CPU version and should be true on the GPU as well.

댓글 수: 4

Paul
Paul 2014년 8월 20일
Thanks for your help,
The code I am running is:
[LGRID,PGRID,NGRID,XGRID] = ndgrid(lgrid,pgrid,ngrid,Xgrid);
target_gpu=gpuArray(target);
DEV_gpu=interpn(LGRID,PGRID,NGRID,XGRID,target_gpu,xi(:,1),xi(:,2),xi(:,3),xi(:,4),'linear');
And the message I got from Matlab is:
Error using gpuArray/interpn
Input grid is not a valid MESHGRID. The grid array inputs must be finite with
increasing and non-repeating elements in corresponding dimension.
So I don't think I am calling interp2. Also, it might be true that using ndgrid is not necessary. My problem is more than even ndgrid does not work. Matlab seems to require a meshgrid, but they cannot be 4-dimensionnal..
Thanks
Matt J
Matt J 2014년 8월 20일
편집: Matt J 2014년 8월 20일
Are you using version R2014? In earlier versions, interpn does not support gpuArray, only interp1 and interp2. It might default back to interp2 in that case, though I admit that would be strange.
Have you tried instead,
DEV_gpu=interpn(lgrid(:),pgrid(:).',ngrid(:),Xgrid(:).',...
target_gpu,xi(:,1),xi(:,2),xi(:,3),xi(:,4),'linear');
If so, what happens?
Paul
Paul 2014년 8월 21일
Yes I am using R2014a, such that interpn is gpu-compatible.
I tried using the grids vector as you recommended, but I got the same error message.
Matt J
Matt J 2014년 8월 21일
I'd report it as a bug, then.

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

Jill Reese
Jill Reese 2014년 8월 27일

0 개 추천

If you look at the help for gpuArray/interpn in R2014a it shows an example of 4D interpolation. My theory is that your inputs to NDGRID don't satisfy some of the restrictions imposed on the grid by the GPU version of interpn, namely that:
  • The grid arguments must be finite vectors or N-D arrays with increasing and non-repeating elements in corresponding dimension.
  • When the grid arguments are N-D arrays, they must align with cartesian axes, as if they were produced by ndgrid.
Can you share what your inputs to ndgrid look like?

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

질문:

2014년 8월 20일

답변:

2014년 8월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by