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

Add more tests to api validation testing #447

Merged
merged 6 commits into from
Oct 18, 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
3 changes: 2 additions & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ steps:
- JuliaCI/julia#v1:
version: "1.10"
- JuliaCI/julia-test#v1:
test_args: "--quickfail metal"
test_args: "--quickfail"
# only enabled for select tests due to JuliaGPU/Metal.jl#34
- JuliaCI/julia-coverage#v1:
codecov: true
Expand All @@ -85,6 +85,7 @@ steps:
queue: "juliaecosystem"
os: "macos"
arch: "aarch64"
macos_version: "15.0"
if: |
build.message =~ /\[only tests\]/ ||
build.message =~ /\[only special\]/ ||
Expand Down
32 changes: 20 additions & 12 deletions src/memory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,30 @@ end
src::MtlPtr{T}, N::Integer;
queue::MTLCommandQueue=global_queue(dev),
async::Bool=false) where T
cmdbuf = MTLCommandBuffer(queue)
MTLBlitCommandEncoder(cmdbuf) do enc
MTL.append_copy!(enc, dst.buffer, dst.offset, src.buffer, src.offset, N * sizeof(T))
if N > 0
cmdbuf = MTLCommandBuffer(queue)
MTLBlitCommandEncoder(cmdbuf) do enc
MTL.append_copy!(enc, dst.buffer, dst.offset, src.buffer, src.offset, N * sizeof(T))
end
commit!(cmdbuf)
async || wait_completed(cmdbuf)
end
commit!(cmdbuf)
async || wait_completed(cmdbuf)
return dst
end

@autoreleasepool function unsafe_fill!(dev::MTLDevice, ptr::MtlPtr{T},
value::Union{UInt8,Int8}, N::Integer) where T
cmdbuf = MTLCommandBuffer(global_queue(dev))
MTLBlitCommandEncoder(cmdbuf) do enc
MTL.append_fillbuffer!(enc, ptr.buffer, value, N * sizeof(T), ptr.offset)
@autoreleasepool function unsafe_fill!(dev::MTLDevice, dst::MtlPtr{T},
value::Union{UInt8,Int8}, N::Integer;
queue::MTLCommandQueue=global_queue(dev),
async::Bool=false) where T
if N > 0
cmdbuf = MTLCommandBuffer(queue)
MTLBlitCommandEncoder(cmdbuf) do enc
MTL.append_fillbuffer!(enc, dst.buffer, value, N * sizeof(T), dst.offset)
end
commit!(cmdbuf)
async || wait_completed(cmdbuf)
end
commit!(cmdbuf)
wait_completed(cmdbuf)
return dst
end

# TODO: Implement generic fill since mtBlitCommandEncoderFillBuffer is limiting
5 changes: 5 additions & 0 deletions test/capturing.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using .MTL

if shader_validation
@warn "Skipping capturing tests; capturing is not supported with Metal Shader Validation enabled"
else

@testset "capturing" begin

mktempdir() do tmpdir
Expand Down Expand Up @@ -83,3 +87,4 @@ end
end

end
end
6 changes: 3 additions & 3 deletions test/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ end
Metal.code_warntype(devnull, dummy, Tuple{})
Metal.code_llvm(devnull, dummy, Tuple{})
if Metal.macos_version() >= v"13"
Metal.code_agx(devnull, dummy, Tuple{})
shader_validation || Metal.code_agx(devnull, dummy, Tuple{})
end

@device_code_lowered @metal dummy()
@device_code_typed @metal dummy()
@device_code_warntype io=devnull @metal dummy()
@device_code_llvm io=devnull @metal dummy()
if Metal.macos_version() >= v"13"
@device_code_agx io=devnull @metal dummy()
shader_validation || @device_code_agx io=devnull @metal dummy()
end

mktempdir() do dir
Expand All @@ -81,7 +81,7 @@ end
@test occursin("dummy", sprint(io->(@device_code_llvm io=io optimize=false @metal dummy())))
@test occursin("dummy", sprint(io->(@device_code_llvm io=io @metal dummy())))
if Metal.macos_version() >= v"13"
@test occursin("dummy", sprint(io->(@device_code_agx io=io @metal dummy())))
shader_validation || @test occursin("dummy", sprint(io->(@device_code_agx io=io @metal dummy())))
end

# make sure invalid kernels can be partially reflected upon
Expand Down
1 change: 1 addition & 0 deletions test/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const eltypes = [Int16, Int32, Int64,
TestSuite.supported_eltypes(::Type{<:MtlArray}) = eltypes

const runtime_validation = get(ENV, "MTL_DEBUG_LAYER", "0") != "0"
const shader_validation = get(ENV, "MTL_SHADER_VALIDATION", "0") != "0"

using Random

Expand Down