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

Adapt SubArray indices #16

Closed
maleadt opened this issue Jun 28, 2019 · 2 comments
Closed

Adapt SubArray indices #16

maleadt opened this issue Jun 28, 2019 · 2 comments
Labels

Comments

@maleadt
Copy link
Member

maleadt commented Jun 28, 2019

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 maleadt added the bug label Jun 28, 2019
@maleadt
Copy link
Member Author

maleadt commented Jul 12, 2019

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

@maleadt
Copy link
Member Author

maleadt commented Oct 22, 2024

This is an old issue, so I'm not exactly sure what the problem was, but we adapt the SubArray indices now:

julia> Adapt.adapt(CuArray, view([1], [1]))
1-element view(::CuArray{Int64, 1, CUDA.DeviceMemory}, [1]) with eltype Int64:
 1

julia> typeof(ans)
SubArray{Int64, 1, CuArray{Int64, 1, CUDA.DeviceMemory}, Tuple{CuArray{Int64, 1, CUDA.DeviceMemory}}, false}

@maleadt maleadt closed this as completed Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant