Skip to content

Commit 4906e89

Browse files
Remove support for s backed by managed storage. (#649)
1 parent 973b0b9 commit 4906e89

File tree

6 files changed

+24
-48
lines changed

6 files changed

+24
-48
lines changed

.buildkite/pipeline.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ steps:
3737
soft_fail: true
3838

3939
# special tests
40-
- group: ":floppy_disk: Storage Modes"
40+
- group: ":floppy_disk: Shared (unified) Storage"
4141
depends_on: "julia"
4242
steps:
43-
- label: "{{matrix.storage}} array storage"
43+
- label: "shared array storage"
4444
plugins:
4545
- JuliaCI/julia#v1:
4646
version: "1.11"
@@ -57,13 +57,8 @@ steps:
5757
build.message !~ /\[skip tests\]/ &&
5858
build.message !~ /\[skip storage\]/
5959
timeout_in_minutes: 60
60-
matrix:
61-
setup:
62-
storage:
63-
- "shared"
64-
- "managed"
6560
commands: |
66-
echo -e "[Metal]\ndefault_storage = \"{{matrix.storage}}\"" >LocalPreferences.toml
61+
echo -e "[Metal]\ndefault_storage = \"shared\"" >LocalPreferences.toml
6762
6863
# special tests
6964
- group: ":eyes: Special"

lib/mtl/storage_type.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export ReadUsage, WriteUsage, ReadWriteUsage
55
# SharedStorage -> Buffer in Host memory, accessed by the GPU. Requires no sync
66
# ManagedStorage -> Mirrored memory buffers in host and GPU. Requires syncing
77
# PrivateStorage -> Memory in Device, not accessible by Host.
8-
# Memoryless -> iOS stuff. ignore it
8+
# Memoryless -> render pipeline stuff. ignore it (for now)
99

1010
abstract type StorageMode end
1111

@@ -16,7 +16,7 @@ Used to indicate that the resource is stored using `MTLStorageModeShared` in mem
1616
1717
For more information on Metal storage modes, refer to the official Metal documentation.
1818
19-
See also [`Metal.PrivateStorage`](@ref) and [`Metal.ManagedStorage`](@ref).
19+
See also [`Metal.PrivateStorage`](@ref).
2020
"""
2121
struct SharedStorage <: StorageMode end
2222

@@ -27,6 +27,9 @@ Used to indicate that the resource is stored using `MTLStorageModeManaged` in me
2727
2828
For more information on Metal storage modes, refer to the official Metal documentation.
2929
30+
!!! warning
31+
`ManagedStorage` is no longer supported with `MtlArray`s. Instead, use `SharedStorage` or use the Metal api directly from `Metal.MTL`.
32+
3033
See also [`Metal.SharedStorage`](@ref) and [`Metal.PrivateStorage`](@ref).
3134
"""
3235
struct ManagedStorage <: StorageMode end
@@ -38,15 +41,14 @@ Used to indicate that the resource is stored using `MTLStorageModePrivate` in me
3841
3942
For more information on Metal storage modes, refer to the official Metal documentation.
4043
41-
See also [`Metal.SharedStorage`](@ref) and [`Metal.ManagedStorage`](@ref).
44+
See also [`Metal.SharedStorage`](@ref).
4245
"""
4346
struct PrivateStorage <: StorageMode end
4447
struct Memoryless <: StorageMode end
4548

4649
# Remove the ".MTL" when printing
4750
Base.show(io::IO, ::Type{<:PrivateStorage}) = print(io, "Metal.PrivateStorage")
4851
Base.show(io::IO, ::Type{<:SharedStorage}) = print(io, "Metal.SharedStorage")
49-
Base.show(io::IO, ::Type{<:ManagedStorage}) = print(io, "Metal.ManagedStorage")
5052

5153
"""
5254
MTL.CPUStorage

src/array.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ end
3939
4040
`N`-dimensional Metal array with storage mode `S` and elements of type `T`.
4141
42-
`S` can be `Metal.PrivateStorage` (default), `Metal.SharedStorage`, or `Metal.ManagedStorage`.
42+
`S` can be `Metal.PrivateStorage` (default), `Metal.SharedStorage`.
4343
4444
See the Array Programming section of the Metal.jl docs for more details.
4545
"""
@@ -96,6 +96,7 @@ mutable struct MtlArray{T,N,S} <: AbstractGPUArray{T,N}
9696
obj = if storagemode == MTL.MTLStorageModeShared
9797
new{T,N,SharedStorage}(copy(data), maxsize, offset, dims)
9898
elseif storagemode == MTL.MTLStorageModeManaged
99+
@warn "`ManagedStorage` is no longer supported with `MtlArray`s. Instead, use `SharedStorage` or use the Metal api directly from `Metal.MTL`."
99100
new{T,N,ManagedStorage}(copy(data), maxsize, offset, dims)
100101
elseif storagemode == MTL.MTLStorageModePrivate
101102
new{T,N,PrivateStorage}(copy(data), maxsize, offset, dims)
@@ -140,6 +141,9 @@ is_shared(A::MtlArray) = storagemode(A) == SharedStorage
140141
141142
Returns true if `A` has storage mode [`Metal.ManagedStorage`](@ref).
142143
144+
!!! warning
145+
`ManagedStorage` is no longer supported with `MtlArray`s. Instead, use `SharedStorage` or use the Metal api directly from `Metal.MTL`.
146+
143147
See also [`is_shared`](@ref) and [`is_private`](@ref).
144148
"""
145149
is_managed(A::MtlArray) = storagemode(A) == ManagedStorage
@@ -149,7 +153,7 @@ is_managed(A::MtlArray) = storagemode(A) == ManagedStorage
149153
150154
Returns true if `A` has storage mode [`Metal.PrivateStorage`](@ref).
151155
152-
See also [`is_shared`](@ref) and [`is_managed`](@ref).
156+
See also [`is_shared`](@ref).
153157
"""
154158
is_private(A::MtlArray) = storagemode(A) == PrivateStorage
155159

@@ -192,8 +196,6 @@ const DefaultStorageMode = let str = @load_preference("default_storage", "privat
192196
PrivateStorage
193197
elseif str == "shared"
194198
SharedStorage
195-
elseif str == "managed"
196-
ManagedStorage
197199
else
198200
error("unknown default storage mode: $default_storage")
199201
end
@@ -247,7 +249,7 @@ Base.sizeof(x::MtlArray) = Base.elsize(x) * length(x)
247249
@inline function Base.pointer(x::MtlArray{T}, i::Integer=1; storage=PrivateStorage) where {T}
248250
PT = if storage == PrivateStorage
249251
MtlPtr{T}
250-
elseif storage == SharedStorage || storage == ManagedStorage
252+
elseif storage == SharedStorage
251253
Ptr{T}
252254
else
253255
error("unknown memory type")
@@ -272,12 +274,12 @@ end
272274

273275

274276
## indexing
275-
function Base.getindex(x::MtlArray{T,N,S}, I::Int) where {T,N,S<:Union{SharedStorage,ManagedStorage}}
277+
function Base.getindex(x::MtlArray{T,N,S}, I::Int) where {T,N,S<:SharedStorage}
276278
@boundscheck checkbounds(x, I)
277279
unsafe_load(pointer(x, I; storage=S))
278280
end
279281

280-
function Base.setindex!(x::MtlArray{T,N,S}, v, I::Int) where {T,N,S<:Union{SharedStorage,ManagedStorage}}
282+
function Base.setindex!(x::MtlArray{T,N,S}, v, I::Int) where {T,N,S<:SharedStorage}
281283
@boundscheck checkbounds(x, I)
282284
unsafe_store!(pointer(x, I; storage=S), v)
283285
end
@@ -481,7 +483,7 @@ Adapt.adapt_storage(::MtlArrayAdaptor{S}, xs::AbstractArray{T,N}) where {T<:Comp
481483
"""
482484
mtl(A; storage=Metal.PrivateStorage)
483485
484-
`storage` can be `Metal.PrivateStorage` (default), `Metal.SharedStorage`, or `Metal.ManagedStorage`.
486+
`storage` can be `Metal.PrivateStorage` (default) or `Metal.SharedStorage`.
485487
486488
Opinionated GPU array adaptor, which may alter the element type `T` of arrays:
487489
* For `T<:AbstractFloat`, it makes a `MtlArray{Float32}` for performance and compatibility

src/memory.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ function Base.unsafe_copyto!(dev::MTLDevice, dst::MtlPtr{T}, src::Ptr{T}, N::Int
4444
free(tmp_buf)
4545
elseif storage_type == MTL.MTLStorageModeShared
4646
unsafe_copyto!(convert(Ptr{T}, dst), src, N)
47-
elseif storage_type == MTL.MTLStorageModeManaged
48-
unsafe_copyto!(convert(Ptr{T}, dst), src, N)
49-
MTL.DidModifyRange!(dst.buffer, 1:N)
5047
end
5148
return dst
5249
end
@@ -73,14 +70,6 @@ function Base.unsafe_copyto!(dev::MTLDevice, dst::Ptr{T}, src::MtlPtr{T}, N::Int
7370
free(tmp_buf)
7471
elseif storage_type == MTL.MTLStorageModeShared
7572
unsafe_copyto!(dst, convert(Ptr{T}, src), N)
76-
elseif storage_type == MTL.MTLStorageModeManaged
77-
cmdbuf = MTLCommandBuffer(queue) do cmdbuf
78-
MTLBlitCommandEncoder(cmdbuf) do enc
79-
append_sync!(enc, src.buffer)
80-
end
81-
end
82-
wait_completed(cmdbuf)
83-
unsafe_copyto!(dst, convert(Ptr{T}, src), N)
8473
end
8574
return dst
8675
end

src/pool.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const alloc_stats = AllocStats()
3535
alloc(device, bytesize, [ptr=nothing];
3636
storage=Default, hazard_tracking=Default, cache_mode=Default)
3737
38-
Allocates a Metal buffer on `device` of`bytesize` bytes. If a CPU-pointer is passed as last
38+
Allocates a Metal buffer on `device` of `bytesize` bytes. If a CPU-pointer is passed as last
3939
argument, then the buffer is initialized with the content of the memory starting at `ptr`,
4040
otherwise it's zero-initialized.
4141
@@ -44,9 +44,7 @@ otherwise it's zero-initialized.
4444
The storage kwarg controls where the buffer is stored. Possible values are:
4545
- PrivateStorage : Residing on the device
4646
- SharedStorage : Residing on the host
47-
- ManagedStorage : Keeps two copies of the buffer, on device and on host. Explicit calls must be
48-
given to syncronize the two
49-
- Memoryless : an iOS specific thing that won't work on Mac.
47+
- Memoryless : A render pipeline exclusive mode. Render pipelines are not yet supported on Metal.jl.
5048
5149
Note that `PrivateStorage` buffers can't be directly accessed from the CPU, therefore you cannot
5250
use this option if you pass a ptr to initialize the memory.

test/array.jl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
STORAGEMODES = [Metal.PrivateStorage, Metal.SharedStorage, Metal.ManagedStorage]
1+
STORAGEMODES = [Metal.PrivateStorage, Metal.SharedStorage]
22

33
@testset "array" begin
44

@@ -158,7 +158,7 @@ check_storagemode(arr, smode) = Metal.storagemode(arr) == smode
158158
# private storage errors.
159159
if SM == Metal.PrivateStorage
160160
let arr_mtl = Metal.zeros(Float32, dim...; storage=Metal.PrivateStorage)
161-
@test is_private(arr_mtl) && !is_shared(arr_mtl) && !is_managed(arr_mtl)
161+
@test is_private(arr_mtl) && !is_shared(arr_mtl)
162162
@test_throws "Cannot access the contents of a private buffer" arr_cpu = unsafe_wrap(Array{Float32}, arr_mtl, dim)
163163
end
164164

@@ -169,24 +169,14 @@ check_storagemode(arr, smode) = Metal.storagemode(arr) == smode
169169
end
170170
elseif SM == Metal.SharedStorage
171171
let arr_mtl = Metal.zeros(Float32, dim...; storage=Metal.SharedStorage)
172-
@test !is_private(arr_mtl) && is_shared(arr_mtl) && !is_managed(arr_mtl)
172+
@test !is_private(arr_mtl) && is_shared(arr_mtl)
173173
@test unsafe_wrap(Array{Float32}, arr_mtl) isa Array{Float32}
174174
end
175175

176176
let b = rand(Float32, 10)
177177
arr_mtl = mtl(b; storage=Metal.SharedStorage)
178178
@test arr_mtl[1] == b[1]
179179
end
180-
elseif SM == Metal.ManagedStorage
181-
let arr_mtl = Metal.zeros(Float32, dim...; storage=Metal.ManagedStorage)
182-
@test !is_private(arr_mtl) && !is_shared(arr_mtl) && is_managed(arr_mtl)
183-
@test unsafe_wrap(Array{Float32}, arr_mtl) isa Array{Float32}
184-
end
185-
186-
let b = rand(Float32, 10)
187-
arr_mtl = mtl(b; storage=Metal.ManagedStorage)
188-
@test arr_mtl[1] == b[1]
189-
end
190180
end
191181
end
192182

0 commit comments

Comments
 (0)