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 KernelAbstractions for Unified Memory #316

Merged
merged 2 commits into from
Mar 13, 2024
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
6 changes: 3 additions & 3 deletions src/MetalKernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +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), pointer(B), length(A); async=true)
GC.@preserve A B copyto!(A, B)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this just hide the issue? It's a good change, but only fixes the issue because copyto! currently always synchronizes. Ideally it shouldn't for certain copies, like CUDA.jl doesn't for CuArray->CuArray copies: https://github.com/JuliaGPU/CUDA.jl/blob/bb49887198f258ffcb186d81df4a787453428b38/src/array.jl#L622-L633

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. This should then probably all be handled by MTLBlitCommandEncoder

return A
else
error("Copy between different devices not implemented")
end
end

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

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

Expand Down
1 change: 0 additions & 1 deletion src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ end

function Base.unsafe_convert(::Type{MtlPointer{T}}, x::MtlArray) where {T}
buf = x.data[]
synchronize()
MtlPointer{T}(buf, x.offset*Base.elsize(x))
end

Expand Down