Identify and Select a GPU Device

If you have only one GPU in your computer, that GPU is the default. If you have more than one GPU device in your computer, you can use the following functions to identify and select which device you want to use:

FunctionDescription
gpuDeviceCountThe number of GPU devices in your computer
gpuDeviceSelect which device to use, or see which device is selected and view its properties

Example: Select a GPU

This example shows how to identify and select a GPU for your computations.

  1. Determine how many GPU devices are in your computer:

    gpuDeviceCount
        2
  2. With two devices, the first is the default. You can examine its properties to determine if that is the one you want to use:

    d = gpuDevice
    
    d =
    
      CUDADevice with properties:
    
                          Name: 'Tesla K20c'
                         Index: 1
             ComputeCapability: '3.5'
                SupportsDouble: 1
                 DriverVersion: 5.5000
                ToolkitVersion: 5.5000
            MaxThreadsPerBlock: 1024
              MaxShmemPerBlock: 49152
            MaxThreadBlockSize: [1024 1024 64]
                   MaxGridSize: [2.1475e+09 65535 65535]
                     SIMDWidth: 32
                   TotalMemory: 5.0327e+09
               AvailableMemory: 4.9190e+09
           MultiprocessorCount: 13
                  ClockRateKHz: 614500
                   ComputeMode: 'Default'
          GPUOverlapsTransfers: 1
        KernelExecutionTimeout: 0
              CanMapHostMemory: 1
               DeviceSupported: 1
                DeviceSelected: 1

    If this is the device you want to use, you can proceed.

  3. To use another device, call gpuDevice with the index of the other device, and view its properties to verify that it is the one you want. For example, this step chooses and views the second device (indexing is 1-based):

    gpuDevice(2)
    

    Note   If you select a device that does not have sufficient compute capability, you get a warning and you will not be able to use that device.

Was this topic helpful?