JuliaGPU / Adapt.jl

Other
86 stars 24 forks source link

Adapt SubArray indices #16

Open maleadt opened 5 years ago

maleadt commented 5 years ago
julia> view(CuArray([1]), CuArray([1]))
1-element view(::CuArray{Int64,1}, [1]) with eltype Int64:
 1

julia> parentindices(ans)
([1],)

julia> typeof(ans)
Tuple{CuArray{Int64,1}}

The indices needs an adapt as well:

Adapt.adapt_structure(to, A::SubArray{<:Any,<:Any,AT}) where {AT} = SubArray(adapt(to, parent(A)), adapt.(Ref(to), parentindices(A)))

Reported by @ali-ramadhan

maleadt commented 4 years ago

This is actually a little more complex, because the view constructor does bounds checking:

julia> view(CuArray([1]), CuArray([1]))
ERROR: scalar getindex is disallowed