Contenido principal

existsOnGPU

R2026b

Determine if gpuArray or CUDAKernel is available on GPU

Description

tf = existsOnGPU(data) returns 1 (true) if the gpuArray or CUDAKernel object data is present on the GPU and available from your MATLAB® session. Otherwise, it returns 0 (false).

If data is not present on the GPU, 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(ind), where ind is an index in the range 1 to gpuDeviceCount.

  • gpuDevice([]), with an empty argument (as opposed to no argument).

example

Examples

collapse all

Create a gpuArray, then query its existence.

M = gpuArray(magic(4));
existsOnGPU(M)
ans = logical
   1

Reset the GPU device, then query the existence of the gpuArray again.

dev = gpuDevice;
reset(dev)
existsOnGPU(M)
ans = logical
   0

Try to display the gpuArray.

disp(M)
    Data no longer exists on the GPU.

Clear the gpuArray from the workspace.

clear M

Input Arguments

collapse all

GPU data, specified as a gpuArray or a parallel.gpu.CUDAKernel object.

Extended Capabilities

expand all

Version History

Introduced in R2012a