Skip to content

Commit 956415c

Browse files
committed
Properly move isbits and numeric arrays to GPU
Fixes #1517.
1 parent 64884e9 commit 956415c

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)