Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize CUDA lazily. #1711

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/Flux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export Descent, ADAM, Momentum, Nesterov, RMSProp,


using CUDA
const use_cuda = Ref(false)
const use_cuda = Ref{Union{Nothing,Bool}}(nothing)

include("utils.jl")
include("zeros.jl")
Expand All @@ -57,13 +57,4 @@ include("deprecations.jl")

include("cuda/cuda.jl")

function __init__()
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
end

end # module
11 changes: 10 additions & 1 deletion src/functor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,16 @@ julia> typeof(m_gpu.W) # notice the type of the array changed to a CuArray
CuArray{Float32, 2}
```
"""
gpu(x) = use_cuda[] ? fmap(_gpu_array, x; exclude = _isbitsarray) : x
function gpu(x)
if use_cuda[] === nothing
use_cuda[] = CUDA.functional()
if use_cuda[] && !CUDA.has_cudnn()
@warn "CUDA.jl found cuda, but did not find libcudnn. Some functionality will not be available."
end
end

use_cuda[] ? fmap(_gpu_array, x; exclude = _isbitsarray) : x
end

_gpu_array(x::AbstractArray) = CUDA.cu(x)

Expand Down
1 change: 0 additions & 1 deletion src/losses/Losses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ export mse, mae, msle,
include("utils.jl")
include("functions.jl")
include("ctc.jl")
if CUDA.functional() include("ctc-gpu.jl") end

end #module
233 changes: 0 additions & 233 deletions src/losses/ctc-gpu.jl

This file was deleted.

Loading