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:
Function | Description |
---|---|
gpuDeviceCount | The number of GPU devices in your computer |
gpuDevice | Select which device to use, or see which device is selected and view its properties |
This example shows how to identify and select a GPU for your computations.
Determine how many GPU devices are in your computer:
gpuDeviceCount
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: 7 ToolkitVersion: 7 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: 705500 ComputeMode: 'Default' GPUOverlapsTransfers: 1 KernelExecutionTimeout: 0 CanMapHostMemory: 1 DeviceSupported: 1 DeviceSelected: 1
If this is the device you want to use, you can proceed.
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. |