GPU Computing in MATLAB
To speed up your code, first try profiling and vectorizing it. For information, see
Performance and Memory. After profiling and vectorizing, you can also try using your computer’s GPU to speed up
your calculations. If all the functions that you want to use are supported on the GPU, you
can simply use
gpuArray to transfer input data to the GPU, and call
gather to retrieve the output data from the GPU. To get started with GPU
computing, see Run MATLAB Functions on a GPU.
For deep learning, MATLAB® provides automatic parallel support for multiple GPUs. See Deep Learning with MATLAB on Multiple GPUs (Deep Learning Toolbox).
Key Functions and Classes
|Number of GPU devices present|
|Table of properties of GPU devices|
|Reset GPU device and clear its memory|
|Wait for GPU calculation to complete|
|Time required to run function on GPU|
|Determine if gpuArray or CUDAKernel is available on GPU|
|Determine whether input is |
|Apply function to each element of array on GPU|
|Apply function to each page of distributed array or gpuArray|
|Control random number generation for GPU calculations|
|Random number stream on a GPU|
|Query and set forward compatibility for GPU devices|
Run MATLAB Code on GPU
Hundreds of functions in MATLAB and other toolboxes run automatically on a GPU if you supply a
This example shows how to use
gpuDevice to identify and select which device you want to use.
Support for NVIDIA® GPU architectures by MATLAB release.
gpuArray in MATLAB represents an array that is stored on the GPU.
This example uses Parallel Computing Toolbox™ to perform a two-dimensional Fast Fourier Transform (FFT) on a GPU.
This example shows how to run MATLAB code on multiple GPUs in parallel, first on your local machine, then scaling up to a cluster.
Train Network Using Automatic Multi-GPU Support (Deep Learning Toolbox)
This example shows how to use multiple GPUs on your local machine for deep learning training using automatic parallel support.
Improve Performance on GPU
This example shows how
arrayfun can be used to run a MATLAB® function natively on the GPU.
This example shows how to use
pagefun to improve the performance of applying a large number of independent rotations and translations to objects in a 3-D environment.
Use benchmark tests in MATLAB to measure the performance of your GPU.
This example looks at how we can benchmark the solving of a linear system on the GPU.
Use the Profiler to measure the time it takes to run your code and identify which lines of code consume the most time or which lines do not run.
Revise loop-based, scalar-oriented code to use MATLAB matrix and vector operations.
Control the random number streams on a GPU to generate the same sequences of random numbers as on the CPU.
This example shows how to switch between the different random number generators that are supported on the GPU.
This example uses Conway's "Game of Life" to demonstrate how stencil operations can be performed using a GPU.