gpuDevice

Query or select GPU device

Syntax

D = gpuDevice
D = gpuDevice()
D = gpuDevice(IDX)
gpuDevice([])

Description

D = gpuDevice or D = gpuDevice(), if no device is already selected, selects the default GPU device and returns a GPUDevice object representing that device. If a GPU device is already selected, this returns an object representing that device without clearing it.

D = gpuDevice(IDX) selects the GPU device specified by index IDX. IDX must be in the range of 1 to gpuDeviceCount. A warning or error might occur if the specified GPU device is not supported. This form of the command with a specified index resets the device and clears its memory (even if this device is already currently selected, equivalent to reset); so all workspace variables representing gpuArray or CUDAKernel variables are now invalid, and you should clear them from the workspace or redefine them.

gpuDevice([]), with an empty argument (as opposed to no argument), deselects the GPU device and clears its memory of gpuArray and CUDAKernel variables. This leaves no GPU device selected as the current device.

Examples

Create an object representing the default GPU device.

g = gpuDevice;

Query the compute capabilities of all available GPU devices.

for ii = 1:gpuDeviceCount
    g = gpuDevice(ii);
    fprintf(1,'Device %i has ComputeCapability %s \n', ...
            g.Index,g.ComputeCapability)
end
Device 1 has ComputeCapability 3.5
Device 2 has ComputeCapability 2.0

Introduced in R2010b

Was this topic helpful?