This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

GPU CUDA and MEX Programming

Further accelerate your code using advanced GPU CUDA and MEX programming


expand all

mexcudaCompile MEX-function for GPU computation
parallel.gpu.CUDAKernelCreate GPU CUDA kernel object from PTX and CU code
fevalEvaluate kernel on GPU
setConstantMemorySet some constant memory on GPU
mxGPUCopyFromMxArrayCopy mxArray to mxGPUArray
mxGPUCopyGPUArrayDuplicate (deep copy) mxGPUArray object
mxGPUCopyImag Copy imaginary part of mxGPUArray
mxGPUCopyReal Copy real part of mxGPUArray
mxGPUCreateComplexGPUArrayCreate complex GPU array from two real gpuArrays
mxGPUCreateFromMxArrayCreate read-only mxGPUArray object from input mxArray
mxGPUCreateGPUArrayCreate mxGPUArray object, allocating memory on GPU
mxGPUCreateMxArrayOnCPUCreate mxArray for returning CPU data to MATLAB with data from GPU
mxGPUCreateMxArrayOnGPUCreate mxArray for returning GPU data to MATLAB
mxGPUDestroyGPUArrayDelete mxGPUArray object
mxGPUGetClassIDmxClassID associated with data on GPU
mxGPUGetComplexityComplexity of data on GPU
mxGPUGetDataRaw pointer to underlying data
mxGPUGetDataReadOnlyRead-only raw pointer to underlying data
mxGPUGetDimensionsmxGPUArray dimensions
mxGPUGetNumberOfDimensionsSize of dimension array for mxGPUArray
mxGPUGetNumberOfElementsNumber of elements on GPU for array
mxGPUIsSameDetermine if two mxGPUArrays refer to same GPU data
mxGPUIsSparseDetermine if mxGPUArray contains sparse GPU data
mxGPUIsValidGPUDataDetermine if mxArray is pointer to valid GPU data
mxGPUSetDimensionsModify number of dimensions and size of each dimension
mxIsGPUArrayDetermine if mxArray contains GPU data
mxInitGPUInitialize MATLAB GPU library on currently selected device


expand all

CUDAKernelKernel executable on GPU
mxGPUArrayType for MATLAB gpuArray


Run CUDA or PTX Code on GPU

This topic explains how to create an executable kernel from CU or PTX (parallel thread execution) files, and run that kernel on a GPU from MATLAB®.

Run MEX-Functions Containing CUDA Code

As with any MEX-files, those containing CUDA® code have a single entry point, known as mexFunction.

Featured Examples