-
Notifications
You must be signed in to change notification settings - Fork 38
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
Test all storage modes #314
Changes from all commits
f513c7f
b01003d
8feaa08
988290c
03a262d
c950282
4bf5979
2886b8f
a3f3377
c919da8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
Manifest.toml | ||
LocalPreferences.toml | ||
*.DS_Store | ||
*.gputrace | ||
*.trace | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[Metal] | ||
# which storage mode unspecified allocations should default to. | ||
# possible values: "Private", "Shared", "Managed" | ||
#default_storage = "Private" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,18 @@ const MtlMatrix{T,S} = MtlArray{T,2,S} | |
const MtlVecOrMat{T,S} = Union{MtlVector{T,S},MtlMatrix{T,S}} | ||
|
||
# default to private memory | ||
const DefaultStorageMode = Private | ||
const DefaultStorageMode = let str = @load_preference("default_storage", "Private") | ||
if str == "Private" | ||
Private | ||
elseif str == "Shared" | ||
Shared | ||
elseif str == "Managed" | ||
Managed | ||
else | ||
error("unknown default storage mode: $default_storage") | ||
end | ||
end | ||
|
||
MtlArray{T,N}(::UndefInitializer, dims::Dims{N}) where {T,N} = | ||
MtlArray{T,N,DefaultStorageMode}(undef, dims) | ||
|
||
|
@@ -170,14 +181,16 @@ 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 | ||
|
||
function Base.unsafe_convert(::Type{Ptr{S}}, x::MtlArray{T}) where {S, T} | ||
buf = x.data[] | ||
if is_private(x) | ||
throw(ArgumentError("cannot take the CPU address of a $(typeof(x))")) | ||
end | ||
synchronize() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would probably be good to port the opportunistic synchronization from CUDA.jl There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can that be a separate PR? I don't have time at the moment to look into that and this PR in its current state seems to fix #312 and make CI more robust. |
||
buf = x.data[] | ||
convert(Ptr{T}, buf) + x.offset*Base.elsize(x) | ||
end | ||
|
||
|
@@ -237,7 +250,7 @@ Base.convert(::Type{T}, x::T) where T <: MtlArray = x | |
Base.unsafe_convert(::Type{<:Ptr}, x::MtlArray) = | ||
throw(ArgumentError("cannot take the host address of a $(typeof(x))")) | ||
|
||
Base.unsafe_convert(t::Type{MTL.MTLBuffer}, x::MtlArray) = x.data[] | ||
Base.unsafe_convert(::Type{MTL.MTLBuffer}, x::MtlArray) = x.data[] | ||
|
||
|
||
## interop with ObjC libraries | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think we need to synchronize here. MtlPointers will only be used on device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this the kernelabstractions
copyto
test fails.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before #305 it worked without a sync.
Metal.jl/src/array.jl
Line 147 in 91d72d0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the problem is, that pointer(A) might mean device or host pointer. #316 might fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is what CUDA.jl does https://github.com/JuliaGPU/CUDA.jl/blob/bb49887198f258ffcb186d81df4a787453428b38/src/CUDAKernels.jl#L41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this PR passes all tests, I suggest we merge this and then you can finish up the fix in #316.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, it's really not acceptable to sync on every pointer conversion, as that would remove almost all opportunity for asynchronous execution (as most GPU operations involve a conversion to a pointer).