MATLAB: Do I get an error after running a CUDA MEX file having a gpuArray as an input in Parallel Computing Toolbox 6.2 in MATLAB 8.1 (R2013a) 64-bit

mxgpugetdimensionsmxgpugetnumberofdimensionsParallel Computing Toolbox

When I define a 4×4 gpuArray, and pass it into a CUDA MEX file which outputs the values and number of dimensions, I get incorrect gpuArray dimensions and get a “Maximum variable size allowed on the device is exceeded” error message.

Best Answer

The CUDA file needs to be compiled with the -largeArrayDims flag of the mex function. For example, the cudaExample.cu file will be compiled as follows :
>> mex -largeArrayDims cudaExample.cu
The 64 bit version MATLAB uses 64-bit data type to store array lengths for gpuArray as 64-bit is the native pointer length on the processor. In future, it might be possible to allocate arrays on the GPU with more than 2^31 elements. MATLAB is designed considering this possibility. Thus, in future when this change happens, redesigning can be prevented.
Related Question