MATLAB: GPU computation on mesh using MatLab

arrayfuncudagpuMATLABmeshnvidiaParallel Computing Toolbox

Hello,
I am new to GPU computation in Matlab and would like some advice.
I would like to calculate certain physical properties (stress) on a 2D mesh. The value at each grid point is the sum of a number of stresses (which need to be in turn calculated).
Therefore, one could have either 1 loop over the mesh points and a vectorized version of the calculation of the constituent stresses (summing them altogether at the end), or two nested for loops.
The number of constituent stresses does not necessarily match the number of mesh points. Hence, I do not believe I can use the arrayfun tool in Matlab. Furthermore, I would also have to pass through certain physical constants.
I have tried evaluating the first possible structure (i.e. 1 loop over the mesh points and a vectorial calculation of the inputs), by transferring the grids etc. onto the gpu using gpuArray. I find however that the performance is terrible (orders of magnitude slower than CPU computing, even though I have a fairly powerful graphics card, Nvidia GTX670).
A question is, if one has a for loop using arrays on the gpu, does Matlab automatically assign them to different threads?
I have a C version of the calculation of a single input on a single mesh point, so I wonder whether I should simply write a kernel function in CUDA?
Kind Regards,
F

Best Answer

A question is, if one has a for loop using arrays on the gpu, does Matlab automatically assign them to different threads?
No. In fact, I don't think it ever does.
I have a C version of the calculation of a single input on a single mesh point, so I wonder whether I should simply write a kernel function in CUDA?
Maybe, but knowing more about what that calculation looks like might help us see how to do it with built-in gpuArray commands.
Related Question