existsOnGPU

Determine if gpuArray or CUDAKernel is available on GPU

Syntax

TF = existsOnGPU(DATA)

Description

TF = existsOnGPU(DATA) returns a logical value indicating whether the gpuArray or CUDAKernel object represented by DATA is still present on the GPU and available from your MATLAB session. The result is false if DATA is no longer valid and cannot be used. Such arrays and kernels are invalidated when the GPU device has been reset with any of the following:

reset(dev)    % Where dev is the current gpuDevice
gpuDevice(ix) % Where ix is valid index of current or different device
gpuDevice([]) % With an empty argument (as opposed to no argument)

Examples

collapse all

Create a gpuArray on the selected GPU device, then reset the device. Query array’s existence and content before and after resetting.

g = gpuDevice(1);
M = gpuArray(magic(4));
M_exists = existsOnGPU(M)
    1
M  % Display gpuArray
    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1
reset(g);
M_exists = existsOnGPU(M)
    0
M  % Try to display gpuArray
Data no longer exists on the GPU.
clear M

Introduced in R2012a

Was this topic helpful?