Support for GPU Arrays
You can use GPU arrays as input and output arguments to an entry-point function when generating CUDA® MEX, source code, static libraries, dynamic libraries, and executables. GPU Coder™ automatically takes care of CPU-GPU copies based on the input type and the usage of the variable in your MATLAB® design. The GPU array functionality is useful in minimizing CPU-GPU copies when you are trying to:
Integrate the generated code with an existing implementation that has its outputs on the GPU memory.
gpuArrayinputs to the generated MEX function.
To mark an input to the entry-point function as a GPU type, use one of the following approaches:
GPU Coder supports all data type supported by
For using variable dimension arrays, only the bounded types are supported.
'exe'targets, you must pass the correct pointers to the entry-point function in the example main function. For example, if an input is marked as
'Gpu', a GPU pointer should be passed when the entry-point is called from the main function.
MemoryMode(memory allocation mode) property of the code configuration object must be set to
'discrete'. For example,
cfg.GpuConfig.MallocMode = 'discrete';
During code generation, if one input to entry-point function is of the GPU array, then GPU Coder attempts to make all the output variables GPU array types, provided they are supported by
gpuArray. For example. if the entry-point function returns a
structis not supported by
gpuArray, the generated code returns a CPU output. However, if a supported matrix type is returned, then the generated code returns a GPU output.
gpuArrayinputs does not guarantee the outputs to also be
GPU Coder does not support the following types:
Scalar GPU arrays
Fixed-point data types
GPU Coder does not support the
'unified'memory mode for GPU arrays.