This example shows how to identify and select a GPU for your computations.
To determine how many GPU devices are available in your computer, use the
gpuDeviceCount
function.
gpuDeviceCount
2
When there are multiple devices, the first is the default. You can examine its
properties with the gpuDevice
function to determine if that
is the one you want to use.
d = gpuDevice
d = CUDADevice with properties: Name: 'GeForce GTX 1080' Index: 1 ComputeCapability: '6.1' SupportsDouble: 1 DriverVersion: 9.2000 ToolkitVersion: 9 MaxThreadsPerBlock: 1024 MaxShmemPerBlock: 49152 MaxThreadBlockSize: [1024 1024 64] MaxGridSize: [2.1475e+09 65535 65535] SIMDWidth: 32 TotalMemory: 8.5899e+09 AvailableMemory: 7.0053e+09 MultiprocessorCount: 20 ClockRateKHz: 1733500 ComputeMode: 'Default' GPUOverlapsTransfers: 1 KernelExecutionTimeout: 1 CanMapHostMemory: 1 DeviceSupported: 1 DeviceSelected: 1
If d
is the device you want to use, you can proceed. To run
computations on the GPU, use gpuArray
enabled functions.
For more information, see Run MATLAB Functions on a GPU.
To use another device, call gpuDevice
with the index of the
other device.
gpuDevice(2)
Establish Arrays on a GPU | GPU Capabilities and Performance | Measure and Improve GPU Performance | Run MATLAB Functions on a GPU