Type for MATLAB gpuArray
mxGPUArray is an opaque C language type that allows a MEX function access to the elements in a MATLAB gpuArray. Using the mxGPU API, you can perform calculations on a MATLAB gpuArray, and return gpuArray results to MATLAB.
All MEX functions receive inputs and pass outputs as mxArrays. A gpuArray in MATLAB is a special kind of mxArray that represents an array stored on the GPU. In your MEX function, you use mxGPUArray objects to access an array stored on the GPU: these objects correspond to MATLAB gpuArrays.
The mxGPU API contains functions that manipulate mxGPUArray
objects.
These functions allow you to extract mxGPUArrays from input mxArrays,
to wrap output mxGPUArrays as mxArrays for return to MATLAB, to determine
the characteristics of the arrays, and to get pointers to the underlying
elements. You can perform calculations by passing the pointers to
CUDA functions that you write or that are available in external libraries.
The basic structure of a GPU MEX function is:
Call mxInitGPU
to
initialize MathWorks GPU library.
Determine which mxArray
inputs
contain GPU data.
Create mxGPUArray
objects from
the input mxArray
arguments, and get pointers to
the input elements on the device.
Create mxGPUArray
objects to hold
the outputs, and get the pointers to the output elements on the device.
Call a CUDA function, passing it the device pointers.
Wrap the output mxGPUArray
as an mxArray
for
return to MATLAB.
Destroy the mxGPUArray
objects
you created.
The header file that contains this type is mxGPUArray.h
.
You include it with the line:
#include "gpu/mxGPUArray.h"