Check gpu availability on a non-gpu machine with CUDA.jl


I need to check the availability of the gpu on the machine - if exists one. How do we check it ?

using CUDA

CUDA.deviceid() != - 1 ? CuArray : Array 

But this seems not working with a gpuless computer - the compiler yells erorrs :

ERROR: CUDA.jl did not successfully initialize, and is not usable.
If you did not see any other error message, try again in a new session
with the JULIA_DEBUG environment variable set to ‘CUDA’.
[1] error(::String) at ./error.jl:33
[2] libcuda() at /Users/kg/.julia/packages/CUDA/wTQsK/src/initialization.jl:48
[3] (::CUDA.var"#690#cache_fptr!#9")() at /Users/kg/.julia/packages/CUDA/wTQsK/lib/utils/call.jl:31
[4] macro expansion at /Users/kg/.julia/packages/CUDA/wTQsK/lib/utils/call.jl:39 [inlined]
[5] macro expansion at /Users/kg/.julia/packages/CUDA/wTQsK/lib/cudadrv/libcuda.jl:29 [inlined]
[6] macro expansion at /Users/kg/.julia/packages/CUDA/wTQsK/lib/cudadrv/error.jl:102 [inlined]
[7] cuDeviceGet(::Base.RefValue{Int32}, ::Int64) at /Users/kg/.julia/packages/CUDA/wTQsK/lib/utils/call.jl:93
[8] CuDevice(::Int64) at /Users/kg/.julia/packages/CUDA/wTQsK/lib/cudadrv/devices.jl:25
[9] initialize_thread(::Int64) at /Users/kg/.julia/packages/CUDA/wTQsK/src/state.jl:121
[10] prepare_cuda_call() at /Users/kg/.julia/packages/CUDA/wTQsK/src/state.jl:80
[11] device at /Users/kg/.julia/packages/CUDA/wTQsK/src/state.jl:227 [inlined]
[12] deviceid() at /Users/kg/.julia/packages/CUDA/wTQsK/src/state.jl:365
[13] top-level scope at REPL[10]:1

I know that I should not install CUDA .jl to a gpu-free computer but then how can I use it on other machines ? I mean the sw needs CUDA.jl if there is a GPU. How can I check if there is a gpu or not ? Is there any other method ?


See Conditional use · CUDA.jl. You can, for now, install the package on a system without CUDA. In the future, we’ll probably change that, instead building on Preferences.jl to conditionally load CUDA.jl when a GPU is available.