mxInitGPU (C)
Initialize MATLAB GPU library on currently selected device
C Syntax
#include "gpu/mxGPUArray.h" int mxInitGPU()
Returns
int type with one of the following values:
MX_GPU_SUCCESSif the MATLAB GPU library is successfully initialized.MX_GPU_FAILUREif not successfully initialized.
Description
Before using any CUDA code in your MEX file, initialize the MATLAB GPU library if you intend to use any mxGPUArray functionality in MEX or any GPU calls in MATLAB. There are many ways to initialize the MATLAB GPU API, including:
Call
mxInitGPUat the beginning of your MEX file before any CUDA code.Call
gpuDevice(deviceIndex)in MATLAB before running any MEX code.Create a
gpuArrayin MATLAB before running any MEX code.
You should call mxInitGPU at the beginning of your MEX file, unless you have an alternate way of guaranteeing that the MATLAB GPU library is initialized at the start of your MEX file.
If the library is initialized, this function returns without doing any work. If the library is not initialized, the function initializes the default device. Note: At present, a MATLAB MEX file can work with only one GPU device at a time.
Version History
Introduced in R2013a