Skip to content

Commit c953739

Browse files
Remove old code and clean-up tests (#464)
1 parent 246bd77 commit c953739

File tree

10 files changed

+131
-164
lines changed

10 files changed

+131
-164
lines changed

.buildkite/pipeline.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ steps:
3838
# soft_fail: true
3939

4040
# special tests
41-
- group: ":eyes: Special"
41+
- group: ":floppy_disk: Storage Modes"
4242
depends_on: "julia"
4343
steps:
4444
- label: "{{matrix.storage}} array storage"
@@ -53,10 +53,10 @@ steps:
5353
arch: "aarch64"
5454
if: |
5555
build.message =~ /\[only tests\]/ ||
56-
build.message =~ /\[only special\]/ ||
56+
build.message =~ /\[only storage\]/ ||
5757
build.message !~ /\[only/ && !build.pull_request.draft &&
5858
build.message !~ /\[skip tests\]/ &&
59-
build.message !~ /\[skip special\]/
59+
build.message !~ /\[skip storage\]/
6060
timeout_in_minutes: 60
6161
matrix:
6262
setup:
@@ -65,13 +65,20 @@ steps:
6565
- "managed"
6666
commands: |
6767
echo -e "[Metal]\ndefault_storage = \"{{matrix.storage}}\"" >LocalPreferences.toml
68+
69+
# special tests
70+
- group: ":eyes: Special"
71+
depends_on: "julia"
72+
steps:
6873
- label: "API validation"
74+
soft_fail: true
6975
plugins:
7076
- JuliaCI/julia#v1:
7177
version: "1.10"
7278
- JuliaCI/julia-test#v1:
73-
test_args: "--quickfail"
74-
# only enabled for select tests due to JuliaGPU/Metal.jl#34
79+
# test_args: "--quickfail"
80+
test_args: ""
81+
# Don't quickfail to see which ones fail
7582
- JuliaCI/julia-coverage#v1:
7683
codecov: true
7784
dirs:
@@ -88,9 +95,11 @@ steps:
8895
macos_version: "15.0"
8996
if: |
9097
build.message =~ /\[only tests\]/ ||
98+
build.message =~ /\[only validation\]/ ||
9199
build.message =~ /\[only special\]/ ||
92100
build.message !~ /\[only/ && !build.pull_request.draft &&
93101
build.message !~ /\[skip tests\]/ &&
102+
build.message !~ /\[skip validation\]/ &&
94103
build.message !~ /\[skip special\]/
95104
timeout_in_minutes: 60
96105
- label: "Opaque pointers"

lib/mtl/library.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ end
2323

2424
function MTLLibraryFromFile(dev::MTLDevice, path::String)
2525
err = Ref{id{NSError}}(nil)
26-
handle = if Metal.macos_version() >= v"13"
26+
handle = let
2727
url = NSFileURL(path)
2828
@objc [dev::id{MTLDevice} newLibraryWithURL:url::id{NSURL}
2929
error:err::Ptr{id{NSError}}]::id{MTLLibrary}
30-
else
31-
@objc [dev::id{MTLDevice} newLibraryWithFile:path::id{NSString}
32-
error:err::Ptr{id{NSError}}]::id{MTLLibrary}
3330
end
3431
err[] == nil || throw(NSError(err[]))
3532

src/array.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,8 @@ fill(v::T, dims...; storage=DefaultStorageMode) where T = fill!(MtlArray{T,lengt
532532

533533
# optimized implementation of `fill!` for types that are directly supported by fillbuffer
534534
function Base.fill!(A::MtlArray{T}, val) where T <: Union{UInt8,Int8}
535-
if length(A) > 0
536-
B = convert(T, val)
537-
unsafe_fill!(device(A), pointer(A), B, length(A))
538-
end
535+
B = convert(T, val)
536+
unsafe_fill!(device(A), pointer(A), B, length(A))
539537
A
540538
end
541539

src/compiler/reflection.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ end
4040
if !job.config.kernel
4141
error("Can only generate AGX code for kernel functions")
4242
end
43-
if macos_version() < v"13"
44-
error("Native code reflection is only supported on OSX 13 or higher")
45-
end
4643

4744
# compile the kernel
4845
compiled = compile(job)
@@ -99,7 +96,7 @@ function extract_gpu_code(f, binary)
9996
arch = findfirst(fat_handle) do arch
10097
arch.header isa MachO.MachOHeader64 && GPUMachineType(arch.header.cputype) == AppleGPU
10198
end
102-
arch == nothing && error("Could not find GPU architecture in universal binary")
99+
arch === nothing && error("Could not find GPU architecture in universal binary")
103100

104101
# the GPU binary contains several sections...
105102
## ... extract the compute section, which is another Mach-O binary

src/device/intrinsics/memory.jl

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,12 @@ export MtlThreadGroupArray
55
66
Create an array local to each threadgroup launched during kernel execution.
77
"""
8-
MtlThreadGroupArray
9-
10-
@static if Sys.isapple() && macos_version() >= v"13.0"
11-
@inline function MtlThreadGroupArray(::Type{T}, dims) where {T}
12-
len = prod(dims)
13-
# NOTE: this relies on const-prop to forward the literal length to the generator.
14-
# maybe we should include the size in the type, like StaticArrays does?
15-
ptr = emit_threadgroup_memory(T, Val(len))
16-
MtlDeviceArray(dims, ptr)
17-
end
18-
else
19-
# on older macOS, shared memory with small types results in miscompilation (Metal.jl#26),
20-
# so we use an array wrapper extending the element size to the minimum known to work.
21-
# this was fixed in macOS 13 beta 4 (22A5311f).
22-
23-
@inline function MtlThreadGroupArray(::Type{T}, dims) where {T}
24-
len = prod(dims)
25-
if sizeof(T) >= 4
26-
ptr = emit_threadgroup_memory(T, Val(len))
27-
MtlDeviceArray(dims, ptr)
28-
else
29-
ptr = emit_threadgroup_memory(UInt32, Val(len))
30-
arr = MtlDeviceArray(dims, ptr)
31-
MtlLargerDeviceArray{T,ndims(arr),AS.ThreadGroup}(arr)
32-
end
33-
end
8+
@inline function MtlThreadGroupArray(::Type{T}, dims) where {T}
9+
len = prod(dims)
10+
# NOTE: this relies on const-prop to forward the literal length to the generator.
11+
# maybe we should include the size in the type, like StaticArrays does?
12+
ptr = emit_threadgroup_memory(T, Val(len))
13+
MtlDeviceArray(dims, ptr)
3414
end
3515

3616
# get a pointer to threadgroup memory, with known (static) or zero length (dynamic)

src/initialization.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ function __init__()
4040
ENV["MTL_DEBUG_LAYER_ERROR_MODE"] = "nslog"
4141
ENV["MTL_DEBUG_LAYER_WARNING_MODE"] = "nslog"
4242

43-
if macos_version() >= v"13"
44-
# enable Metal shader validation
45-
ENV["MTL_SHADER_VALIDATION"] = "4"
46-
end
43+
# enable Metal shader validation
44+
ENV["MTL_SHADER_VALIDATION"] = "4"
4745
end
4846

4947
@autoreleasepool try

test/array.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,19 @@ end
229229

230230
@testset "fill($T)" for T in [Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64,
231231
Float16, Float32]
232+
broken466a = T [Int8,UInt8]
233+
broken466b = (Base.JLOptions().check_bounds != 1 || shader_validation)
232234

233235
b = rand(T)
234236

235237
# Dims in tuple
236238
let A = Metal.fill(b, (10, 10, 10, 1000))
237239
B = fill(b, (10, 10, 10, 1000))
238-
@test Array(A) == B
240+
@test Array(A) == B broken=(broken466a && broken466b)
239241
end
240242

241-
let M = Metal.fill(b, (10, 10, 10, 1000))
242-
B = fill(b, (10, 10, 10, 1000))
243+
let M = Metal.fill(b, (10, 10))
244+
B = fill(b, (10, 10))
243245
@test Array(M) == B
244246
end
245247

@@ -249,9 +251,9 @@ end
249251
end
250252

251253
#Dims already unpacked
252-
let A = Metal.fill(b, 10, 10, 10, 1000)
253-
B = fill(b, 10, 10, 10, 1000)
254-
@test Array(A) == B
254+
let A = Metal.fill(b, 10, 1000, 1000)
255+
B = fill(b, 10, 1000, 1000)
256+
@test Array(A) == B broken=broken466a
255257
end
256258

257259
let M = Metal.fill(b, 10, 10)
@@ -267,13 +269,15 @@ end
267269

268270
@testset "fill!($T)" for T in [Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64,
269271
Float16, Float32]
272+
broken466a = T [Int8,UInt8]
273+
broken466b = (Base.JLOptions().check_bounds != 1 || shader_validation)
270274

271275
b = rand(T)
272276

273277
# Dims in tuple
274-
let A = MtlArray{T,3}(undef, (10, 10, 10))
278+
let A = MtlArray{T,3}(undef, (10, 1000, 1000))
275279
fill!(A, b)
276-
@test all(Array(A) .== b)
280+
@test all(Array(A) .== b) broken=broken466a
277281
end
278282

279283
let M = MtlMatrix{T}(undef, (10, 10))
@@ -287,9 +291,9 @@ end
287291
end
288292

289293
# Dims already unpacked
290-
let A = MtlArray{T,3}(undef, 10, 10, 10)
294+
let A = MtlArray{T,4}(undef, 10, 10, 10, 1000)
291295
fill!(A, b)
292-
@test all(Array(A) .== b)
296+
@test all(Array(A) .== b) broken=(broken466a && broken466b)
293297
end
294298

295299
let M = MtlMatrix{T}(undef, 10, 10)

test/capturing.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ manager = MTLCaptureManager()
2626
# Capture Descriptor
2727
desc = MTLCaptureDescriptor()
2828
# Capture Object
29-
@test desc.captureObject == nothing
29+
@test desc.captureObject === nothing
3030
cmdq = global_queue(device())
3131
desc.captureObject = cmdq
3232
@test desc.captureObject == cmdq
@@ -40,19 +40,19 @@ desc.destination = MTL.MTLCaptureDestinationGPUTraceDocument
4040
@test desc.destination == MTL.MTLCaptureDestinationGPUTraceDocument
4141

4242
# Output URL
43-
@test desc.outputURL == nothing
43+
@test desc.outputURL === nothing
4444
path = joinpath(tmpdir, "test.gputrace")
4545
desc.outputURL = NSFileURL(path)
4646
@test desc.outputURL == NSFileURL(path)
4747

4848
# Capture Scope
4949
queue = MTLCommandQueue(device())
5050
default_scope = manager.defaultCaptureScope
51-
@test default_scope == nothing
51+
@test default_scope === nothing
5252
new_scope = MTLCaptureScope(@objc [manager::id{MTLCaptureManager} newCaptureScopeWithCommandQueue:queue::id{MTLCommandQueue}]::id{MTLCaptureScope})
5353
@test new_scope.commandQueue == queue
5454
@test new_scope.device == device()
55-
@test new_scope.label == nothing
55+
@test new_scope.label === nothing
5656
new_label = "Metal.jl capturing test"
5757
new_scope.label = new_label
5858
@test new_scope.label == new_label

test/execution.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,13 @@ end
5959
Metal.code_typed(dummy, Tuple{})
6060
Metal.code_warntype(devnull, dummy, Tuple{})
6161
Metal.code_llvm(devnull, dummy, Tuple{})
62-
if Metal.macos_version() >= v"13"
63-
shader_validation || Metal.code_agx(devnull, dummy, Tuple{})
64-
end
62+
shader_validation || Metal.code_agx(devnull, dummy, Tuple{})
6563

6664
@device_code_lowered @metal dummy()
6765
@device_code_typed @metal dummy()
6866
@device_code_warntype io=devnull @metal dummy()
6967
@device_code_llvm io=devnull @metal dummy()
70-
if Metal.macos_version() >= v"13"
71-
shader_validation || @device_code_agx io=devnull @metal dummy()
72-
end
68+
shader_validation || @device_code_agx io=devnull @metal dummy()
7369

7470
mktempdir() do dir
7571
@device_code dir=dir @metal dummy()
@@ -80,9 +76,7 @@ end
8076
# make sure kernel name aliases are preserved in the generated code
8177
@test occursin("dummy", sprint(io->(@device_code_llvm io=io optimize=false @metal dummy())))
8278
@test occursin("dummy", sprint(io->(@device_code_llvm io=io @metal dummy())))
83-
if Metal.macos_version() >= v"13"
84-
shader_validation || @test occursin("dummy", sprint(io->(@device_code_agx io=io @metal dummy())))
85-
end
79+
shader_validation || @test occursin("dummy", sprint(io->(@device_code_agx io=io @metal dummy())))
8680

8781
# make sure invalid kernels can be partially reflected upon
8882
let

0 commit comments

Comments
 (0)