Skip to content

Conversation

@maleadt
Copy link
Member

@maleadt maleadt commented Oct 22, 2024

The most important change here is to rely on adapt(AT, x) instead of rolling our own adaptor that uses the array type constructor, since the former may have some more functionality registered with it. Specifically:

julia> x = view(rand(Float32, 100, 100), 2:99, 2:99);

julia> typeof(x)
SubArray{Float32, 2, Matrix{Float32}, Tuple{UnitRange{Int64}, UnitRange{Int64}}, false}

julia> x isa StridedArray
true
julia> struct ArrayAdaptor{AT} end

julia> Adapt.adapt_storage(::ArrayAdaptor{AT}, xs::AbstractArray) where {AT} = AT(xs)

julia> y = adapt(ArrayAdaptor{CuArray}(), x);

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

julia> y isa StridedCuArray
false
julia> z = adapt(CuArray, x);

julia> typeof(z)
SubArray{Float32, 2, CuArray{Float32, 2, CUDA.DeviceMemory}, Tuple{UnitRange{Int64}, UnitRange{Int64}}, false}

julia> z isa StridedCuArray
true

This may also be a bug we need to fix in Adapt, but it seems fine to rely more on adapt(AT, x) anyway.

@maleadt maleadt merged commit 44043dd into master Oct 22, 2024
11 checks passed
@maleadt maleadt deleted the tb/testsuite branch October 22, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants