Skip to content

Commit ed9d202

Browse files
committed
Validate MtlArray storage mode
Check if 3rd argument of MtlArray (`S`) is a valid `MTL.MTLStorageMode` and throw ArgumentError for unsupported values.
1 parent 98a837b commit ed9d202

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/array.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ mutable struct MtlArray{T,N,S} <: AbstractGPUArray{T,N}
5252

5353
function MtlArray{T,N,S}(::UndefInitializer, dims::Dims{N}) where {T,N,S}
5454
check_eltype(T)
55+
56+
try
57+
convert(MTL.MTLStorageMode, S)
58+
catch
59+
throw(ArgumentError("Invalid MTL storage mode: $S. Must be one of Metal.PrivateStorage, Metal.SharedStorage or Metal.ManagedStorage."))
60+
end
61+
5562
maxsize = prod(dims) * sizeof(T)
5663

5764
bufsize = if Base.isbitsunion(T)

0 commit comments

Comments
 (0)