Documentation Center

  • Trials
  • Product Updates

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:

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:

  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:

    parallel.gpu.CUDADevice handle
    Package: parallel.gpu
                        Name: 'Tesla C1060'
                       Index: 1
           ComputeCapability: '1.3'
              SupportsDouble: 1
               DriverVersion: 5
              ToolkitVersion: 5
          MaxThreadsPerBlock: 512
            MaxShmemPerBlock: 16384
          MaxThreadBlockSize: [512 512 64]
                 MaxGridSize: [65535 65535 1]
                   SIMDWidth: 32
                 TotalMemory: 4.2948e+09
                  FreeMemory: 4.2563e+09
         MultiprocessorCount: 30
                ClockRateKHz: 1296000
                 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):


    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?