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

fix: make gpu(x) return unmodified x when GPU backends aren't loaded #2295

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions src/functor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ function gpu(::FluxCUDAAdaptor, x)
`CUDA.jl` must be loaded to access it.
Add `using CUDA` or `import CUDA` to your code.
""" maxlog=1
return x
end
end

Expand All @@ -361,6 +362,7 @@ function gpu(::FluxAMDAdaptor, x)
`AMDGPU.jl` must be loaded to access it.
Add `using AMDGPU` or `import AMDGPU` to your code.
""" maxlog=1
return x
end
end

Expand All @@ -380,6 +382,7 @@ function gpu(::FluxMetalAdaptor, x)
The Metal functionality is being called but
`Metal.jl` must be loaded to access it.
""" maxlog=1
return x
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/functors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
x = rand(Float32, 10, 10)
if Flux.CUDA_LOADED[]
@test x !== gpu(x)
elseif Flux.AMD_LOADED[]
@test x !== gpu(x)
elseif Flux.METAL_LOADED[]
@test x !== gpu(x)
else
@test x === gpu(x)
end
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Random.seed!(0)
include("outputsize.jl")
end

@testset "functors" begin
include("functors.jl")
end

if get(ENV, "FLUX_TEST_CUDA", "false") == "true"
using CUDA
Expand Down
Loading