This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


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:

  1. Call mxInitGPU to initialize MathWorks GPU library.

  2. Determine which mxArray inputs contain GPU data.

  3. Create mxGPUArray objects from the input mxArray arguments, and get pointers to the input elements on the device.

  4. Create mxGPUArray objects to hold the outputs, and get the pointers to the output elements on the device.

  5. Call a CUDA function, passing it the device pointers.

  6. Wrap the output mxGPUArray as an mxArray for return to MATLAB.

  7. 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"

See Also

gpuArray, mxArray

Introduced in R2013a

Was this topic helpful?