function ok = canUseGPU()
%canUseGPU  Verify that a supported GPU is available for use
%   tf = canUseGPU() returns true if the MATLAB installation
%   and environment can support GPU functionality. Returns false when there
%   is no available supported GPU, the driver is missing or not up-to-date,
%   or Parallel Computing Toolbox is not installed or licensed.
%
%   Example:
%       % Solve a linear system on the GPU if possible, otherwise use the
%       % CPU
%       N = 1000;
%       A = rand(N,N);
%       B = rand(N,1);
%       if canUseGPU()
%           A = gpuArray(A);
%       end
%       X = A \ B;
%
%   See also: gpuDeviceCount, gpuDevice, canUseParallelPool.

% Copyright 2012-2020 The MathWorks, Inc.

ok = matlab.internal.parallel.isPCTInstalled() ...
    && matlab.internal.parallel.isPCTLicensed() ...
    && parallel.gpu.GPUDevice.isAvailable();

end

