Main Content

GPU Computing inMATLAB

Accelerate your code using basic GPU computing

To speed up your code, first try profiling and vectorizing it. For information, seePerformance 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 usegpuArrayto transfer input data to the GPU, and callgatherto retrieve the output data from the GPU. To get started with GPU computing, seeRun MATLAB Functions on a GPU.

For deep learning, MATLAB®provides automatic parallel support for multiple GPUs. SeeDeep Learning with MATLAB on Multiple GPUs(Deep Learning Toolbox).

Functions

expand all

gpuArray Array stored on GPU
gather Transfer distributed array or gpuArray to local workspace
gpuDevice Query or select a GPU device
GPUDeviceManager Manager for GPU Devices
gpuDeviceCount Number of GPU devices present
gpuDeviceTable Table of properties of GPU devices
reset Reset GPU device and clear its memory
wait (GPUDevice) Wait for GPU calculation to complete
gputimeit Time required to run function on GPU
existsOnGPU Determine if gpuArray or CUDAKernel is available on GPU
isgpuarray Determine whether input isgpuArray
arrayfun Apply function to each element of array on GPU
pagefun Apply function to each page of distributed array or gpuArray
gpurng Control random number generation for GPU calculations
parallel.gpu.RandStream Random number stream on a GPU
parallel.gpu.enableCUDAForwardCompatibility Query and set forward compatibility for GPU devices

Topics

RunMATLABCode on GPU

Run MATLAB Functions on a GPU

Hundreds of functions in MATLAB and other toolboxes run automatically on a GPU if you supply agpuArrayargument.

Identify and Select a GPU Device

This example shows how to usegpuDeviceto identify and select which device you want to use.

GPU Support by Release

Support for NVIDIA®GPU architectures by MATLAB release.

Establish Arrays on a GPU

AgpuArrayin MATLAB represents an array that is stored on the GPU.

Using FFT2 on the GPU to Simulate Diffraction Patterns

This example uses Parallel Computing Toolbox™ to perform a two-dimensional Fast Fourier Transform (FFT) on a GPU.

Run MATLAB Functions on Multiple GPUs

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

Improve Performance of Element-wise MATLAB® Functions on the GPU using ARRAYFUN

This example shows howarrayfuncan be used to run a MATLAB® function natively on the GPU.

Improve Performance of Small Matrix Problems on the GPU using PAGEFUN

This example shows how to usepagefunto improve the performance of applying a large number of independent rotations and translations to objects in a 3-D environment.

Measure and Improve GPU Performance

Use benchmark tests in MATLAB to measure the performance of your GPU.

Benchmarking A\b on the GPU

This example looks at how we can benchmark the solving of a linear system on the GPU.

Learn More

概要文件代码来改善Performance

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.

Vectorization

Revise loop-based, scalar-oriented code to use MATLAB matrix and vector operations.

Random Number Streams on a GPU

Control the random number streams on a GPU to generate the same sequences of random numbers as on the CPU.

Generating Random Numbers on a GPU

This example shows how to switch between the different random number generators that are supported on the GPU.

Stencil Operations on a GPU

This example uses Conway's "Game of Life" to demonstrate how stencil operations can be performed using a GPU.

Featured Examples