canUseGPU

Tells whether a supported GPU is available for computation.

Category: Programming > Programming Utilities

Syntax

tf = canUseGPU

Returns true if a usable GPU is present, false otherwise.

Description

Code that can run on either the CPU or a GPU uses this as a guard: move data to the GPU only when the answer is true, and fall back to ordinary arrays otherwise. The call does not allocate anything or start the GPU.

Output arguments

tf
Logical scalar.

Example

Choosing a code path

if canUseGPU
    disp('GPU available')
else
    disp('using the CPU')
end
Output
using the CPU

Notes

MatLivre has no GPU support, so canUseGPU always returns false.

See also

canUseParallelPool maxNumCompThreads class