Skip to content

Commit

Permalink
Merge pull request #2360 from FluxML/bc/amd-rng-fix
Browse files Browse the repository at this point in the history
Use stable API for AMDGPU RNG conversion
  • Loading branch information
ToucheSir authored Dec 19, 2023
2 parents f4b4761 + 2587e05 commit e9fb65c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ext/FluxAMDGPUExt/functor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ end
adapt_storage(::FluxAMDGPUAdaptor, x::Zygote.FillArrays.AbstractFill) =
ROCArray(collect(x))
adapt_storage(::FluxAMDGPUAdaptor, x::Zygote.OneElement) = ROCArray(collect(x))
adapt_storage(::FluxAMDGPUAdaptor, x::Random.TaskLocalRNG) =
AMDGPU.rocRAND.default_rng()
adapt_storage(::FluxAMDGPUAdaptor, x::Random.TaskLocalRNG) = AMDGPU.rocrand_rng()
adapt_storage(::FluxAMDGPUAdaptor, x::AMDGPU.rocRAND.RNG) = x
adapt_storage(::FluxAMDGPUAdaptor, x::AbstractRNG) = error("""
Cannot map RNG of type $(typeof(x)) to AMDGPU.
Expand Down
7 changes: 7 additions & 0 deletions test/ext_amdgpu/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ end
@test parent(Flux.gpu(g3)) isa ROCMatrix{Float32}
end

@testset "cpu and gpu on RNGs" begin
crng = Random.default_rng()
grng = gpu(crng)
@test grng isa AMDGPU.rocRAND.RNG
@test cpu(grng) === crng
end

@testset "Flux.onecold gpu" begin
y = Flux.onehotbatch(ones(3), 1:10) |> Flux.gpu
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
Expand Down

0 comments on commit e9fb65c

Please sign in to comment.