Skip to content

Commit 335286a

Browse files
bors[bot]ToucheSir
andauthored
Merge #1620
1620: Properly move isbits and numeric arrays to GPU r=darsnack a=ToucheSir Fixes #1517. Credit to @darsnack in #1517 (comment) for the code. ### PR Checklist - [x] Tests are added - [ ] Entry in NEWS.md - [ ] ~Documentation, if applicable~ - [ ] ~API changes require approval from a committer (different from the author, if applicable)~ Co-authored-by: Brian Chen <ToucheSir@users.noreply.github.com>
2 parents 64884e9 + 956415c commit 335286a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/functor.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ end
6666

6767
cpu(m) = fmap(x -> adapt(Array, x), m)
6868

69-
gpu(x) = use_cuda[] ? fmap(CUDA.cu, x) : x
69+
_isbitsarray(::AbstractArray{<:Number}) = true
70+
_isbitsarray(::AbstractArray{T}) where T = isbitstype(T)
71+
_isbitsarray(x) = false
72+
gpu(x) = use_cuda[] ? fmap(CUDA.cu, x; exclude = _isbitsarray) : x
7073

7174
# Precision
7275

test/cuda/cuda.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,14 @@ end
7373
Q_cpu = Q_gpu |> cpu
7474
@test Q_cpu == cholesky(eltype(Q_gpu).(M))
7575
end
76+
77+
@testset "isbits array types" begin
78+
struct SimpleBits
79+
field::Int32
80+
end
81+
82+
@test gpu((;a=ones(1))).a isa CuVector{Float32}
83+
@test gpu((;a=['a', 'b', 'c'])).a isa CuVector{Char}
84+
@test gpu((;a=[SimpleBits(1)])).a isa CuVector{SimpleBits}
85+
end
7686
end

0 commit comments

Comments
 (0)