Main Content

Identify and Select a GPU Device

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

To determine how many GPU devices are available in your computer, use the gpuDeviceCount function.

ans = 2

When there are multiple devices, the first is the default. You can examine its properties with the gpuDeviceTable function to determine if that is the one you want to use.

ans=2×5 table
    Index           Name           ComputeCapability    DeviceAvailable    DeviceSelected
    _____    __________________    _________________    _______________    ______________

      1      "NVIDIA RTX A5000"          "8.6"               true              false     
      2      "Quadro P620"               "6.1"               true              true      

If the first device 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.

ans = 
  CUDADevice with properties:

                      Name: 'Quadro P620'
                     Index: 2
         ComputeCapability: '6.1'
            SupportsDouble: 1
     GraphicsDriverVersion: '511.79'
               DriverModel: 'WDDM'
            ToolkitVersion: 11.2000
        MaxThreadsPerBlock: 1024
          MaxShmemPerBlock: 49152 (49.15 KB)
        MaxThreadBlockSize: [1024 1024 64]
               MaxGridSize: [2.1475e+09 65535 65535]
                 SIMDWidth: 32
               TotalMemory: 2147287040 (2.15 GB)
           AvailableMemory: 1615209678 (1.62 GB)
               CachePolicy: 'balanced'
       MultiprocessorCount: 4
              ClockRateKHz: 0
               ComputeMode: 'Default'
      GPUOverlapsTransfers: 1
    KernelExecutionTimeout: 1
          CanMapHostMemory: 1
           DeviceSupported: 1
           DeviceAvailable: 1
            DeviceSelected: 1

Alternatively, you can determine how many GPU devices are available, inspect some of their properties, and select a device to use from the MATLAB® desktop. On the Home tab, in the Environment area, select Parallel > Select GPU Environment.


See Also

| | |

Related Topics