Main Content

isgpuarray

Determine whether input is gpuArray

Since R2020b

    Description

    TF = isgpuarray(X) returns logical 1 (true) if X is a gpuArray, and logical 0 (false) otherwise. You can use this function with an if statement to avoid executing code that expects gpuArray input.

    example

    Examples

    collapse all

    Create an array of random numbers.

    X = rand(3,3);

    Copy the array onto the GPU.

    Y = gpuArray(X);

    Use the function isgpuArray to verify that Y is a gpuArray.

    isgpuArray(Y)
    ans = 
       1
    

    Verify that X is not a gpuArray.

    isgpuarray(X)
    ans = 
       0
    

    Input Arguments

    collapse all

    Input variable, specified as a workspace variable. X can be any data type.

    Extended Capabilities

    Version History

    Introduced in R2020b