How to check if Flux.jl is using the GPU?

Viewed 315

I want to check to see if Flux is using the GPU or CPU on my computer. Is this possible with a built-in Flux.jl function?

1 Answers

The way that this seems possible is by doing:

julia> using Flux

julia> Flux.use_cuda[]
false

It seems this works since I do not have CUDA working on my Mac and under the hood, Flux checks this condition and then sets the use_cuda flag to false. You can see the source code that does this here: https://github.com/FluxML/Flux.jl/blob/de76e0853db8f0216addaaa4eacf6de39630d834/src/Flux.jl#L58 but it looks something like:

 use_cuda[] = CUDA.functional() # Can be overridden after load with `Flux.use_cuda[] = false`
 if CUDA.functional()
   if !CUDA.has_cudnn()
     @warn "CUDA.jl found cuda, but did not find libcudnn. Some functionality will not be available."
   end
 end
Related