Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
tgymnich committed Mar 12, 2024
1 parent 09f92c4 commit 030ca30
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/MetalKernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,20 @@ Adapt.adapt_storage(::KA.CPU, a::MtlArray) = convert(Array, a)

function KA.copyto!(::MetalBackend, A::MtlArray{T}, B::MtlArray{T}) where T
if device(dest) == device(src)
GC.@preserve A B unsafe_copyto!(device(A), pointer(A, storage=Private), pointer(B, storage=Private), length(A); async=true)
GC.@preserve A B unsafe_copyto!(device(A), A, B)
return A
else
error("Copy between different devices not implemented")
end
end

function KA.copyto!(::MetalBackend, A::Array{T}, B::MtlArray{T,N,S}) where {T,N,S}
if (S == Metal.Private)
GC.@preserve A B unsafe_copyto!(device(B), pointer(A), pointer(B, storage=S), length(A); async=true)
else
GC.@preserve A B unsafe_copyto!(pointer(A), pointer(B, storage=S), length(A))
end
function KA.copyto!(::MetalBackend, A::Array{T}, B::MtlArray{T}) where T
GC.@preserve A B unsafe_copyto!(device(B), A, B)
return A
end

function KA.copyto!(::MetalBackend, A::MtlArray{T,N,S}, B::Array{T}) where {T,N,S}
if S == Private
GC.@preserve A B unsafe_copyto!(device(A), pointer(A, storage=S), pointer(B), length(A); async=true)
else
GC.@preserve A B unsafe_copyto!(pointer(A, storage=S), pointer(B), length(A))
end
function KA.copyto!(::MetalBackend, A::MtlArray{T}, B::Array{T}) where T
GC.@preserve A B unsafe_copyto!(device(A), A, B)
return A
end

Expand Down

0 comments on commit 030ca30

Please sign in to comment.