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

**URL:** <https://discourse.julialang.org/t/check-gpu-availability-on-a-non-gpu-machine-with-cuda-jl/56862>\
**Category:** General Usage\
**Tags:** question, cuda\
**Created:** [March 10, 2021, 9:18am UTC](https://discourse.julialang.org/t/check-gpu-availability-on-a-non-gpu-machine-with-cuda-jl/56862 "2021-03-10T09:18:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadir-gunel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kadir-gunel/32/35790_2.png) [@kadir-gunel](https://discourse.julialang.org/u/kadir-gunel)\
**Post date:** [March 10, 2021, 9:18am UTC](https://discourse.julialang.org/t/check-gpu-availability-on-a-non-gpu-machine-with-cuda-jl/56862/1 "2021-03-10T09:18:24Z")

</div>

Hello,

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

```julia
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’.  
> Stacktrace:  
> [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 ?

B.R.

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [March 10, 2021, 9:23am UTC](https://discourse.julialang.org/t/check-gpu-availability-on-a-non-gpu-machine-with-cuda-jl/56862/2 "2021-03-10T09:23:09Z")

</div>

See [Conditional use · CUDA.jl](https://juliagpu.github.io/CUDA.jl/stable/installation/conditional/). 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.
