Documentation Center

  • Trial Software
  • Product Updates


Create array on GPU


G = gpuArray(X)


G = gpuArray(X) copies the numeric data X to the GPU, and returns a gpuArray object. You can operate on this data by passing it to the feval method of a CUDA kernel object, or by using one of the methods defined for gpuArray objects in Establish Arrays on a GPU.

The MATLAB data X must be numeric (for example: single, double, int8, etc.) or logical, and the GPU device must have sufficient free memory to store the data. X must be a full matrix, not sparse.

If the input argument is already a gpuArray, the output is the same as the input.


Transfer a 10-by-10 matrix of random single-precision values to the GPU, then use the GPU to square each element.

X = rand(10, 'single');
G = gpuArray(X);
classUnderlying(G)   % Returns 'single'
G2 = G .* G;         % Performed on GPU
whos G2              % Result on GPU

See Also

| | | | | |

Was this topic helpful?