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

Fix and test reverse on wrapped array. #439

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[compat]
AbstractFFTs = "0.4, 0.5"
Adapt = "2.0"
Adapt = "2.2"
BFloat16s = "0.1"
BinaryProvider = "0.3, 0.4, 0.5"
CEnum = "0.2, 0.3, 0.4"
Expand Down
5 changes: 0 additions & 5 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,6 @@ end
Adapt.adapt_structure(to::Adaptor, A::SubArray) =
SubArray(adapt(to, parent(A)), adapt(to, adapt(CuArray, parentindices(A))))

function Base.unsafe_convert(::Type{CuPtr{T}}, V::SubArray{T,N,P,<:Tuple{Vararg{Base.RangeIndex}}}) where {T,N,P<:CuArray}
return Base.unsafe_convert(CuPtr{T}, parent(V)) +
Base._memory_offset(V.parent, map(first, V.indices)...)
end


## reshape

Expand Down
8 changes: 8 additions & 0 deletions src/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ Base.unsafe_convert(::Type{P}, x::CuPtr) where {P<:CuPtr} = convert(P, x)
# from arrays
Base.unsafe_convert(::Type{CuPtr{S}}, a::AbstractArray{T}) where {S,T} =
convert(CuPtr{S}, Base.unsafe_convert(CuPtr{T}, a))
Base.unsafe_convert(::Type{CuPtr{T}}, a::AbstractArray{T}) where {T} =
error("conversion to pointer not defined for $(typeof(a))")

# from contiguous subarrays
function Base.unsafe_convert(::Type{CuPtr{T}}, V::SubArray{T,N,P,<:Tuple{Vararg{Base.RangeIndex}}}) where {T,N,P}
return Base.unsafe_convert(CuPtr{T}, parent(V)) +
Base._memory_offset(V.parent, map(first, V.indices)...)
end


## limited pointer arithmetic & comparison
Expand Down
3 changes: 3 additions & 0 deletions test/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ end
reverse!(gpu; dims=dim)
@test Array(gpu) == reverse(cpu; dims=dim)
end

# wrapped array
@test testf(x->reverse(x), reshape(rand(2,2), 4))
end

@testset "findall" begin
Expand Down