Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/KernelInterface/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KernelInterface"
uuid = "4ee993da-d684-4d17-a7dd-4e58e78d92bf"
authors = ["Valentin Churavy <v.churavy@gmail.com> and contributors"]
version = "0.4.7"
version = "0.4.8"

[compat]
julia = "1.10"
49 changes: 29 additions & 20 deletions lib/KernelInterface/test/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ function events_testsuite(b::KI.Backend)
# but waiting with a plain `synchronize`. Scaling a single launch would also count
# its launch and synchronization overhead once per launch, which can make up most of
# it (e.g. under compute-sanitizer), while the queue drains after paying it once.
expected = minimum(1:3) do _
function drain()
queue_launches()
start = time_ns()
KI.synchronize(b)
(time_ns() - start) / 1.0e9
return (time_ns() - start) / 1.0e9
end
expected = minimum(_ -> drain(), 1:3)

@testset "ordered across tasks" begin
# The child queues nothing but the wait, so its `synchronize` can only return
Expand All @@ -74,26 +75,34 @@ function events_testsuite(b::KI.Backend)
# not do: drivers that track hazards between command buffers (Metal, for its
# default buffers) order the readback after the fills without any wait.
#
# Collect beforehand so that a GC pause is unlikely to land inside the
# measurement and mask a missing wait.
GC.gc()
queue_launches()
start = time_ns()
ev = KI.record_event(b)
task = Threads.@spawn begin
# `wait_event` acts on the active device's queue, so select it first.
KI.device!(b, dev)
KI.wait_event(b, ev)
# The device may be shared with other work, e.g. the parallel workers of a test
# suite, so a drain can take several times as long as the next one. The wait is
# therefore timed a few times, and the longest of those compared with the
# shortest drain, timed before and after: a missing wait is short every time.
trials = map(1:3) do _
# Collect beforehand so that a GC pause is unlikely to land inside the
# measurement and mask a missing wait.
GC.gc()
queue_launches()
start = time_ns()
ev = KI.record_event(b)
task = Threads.@spawn begin
# `wait_event` acts on the active device's queue, so select it first.
KI.device!(b, dev)
KI.wait_event(b, ev)
KI.synchronize(b)
elapsed = (time_ns() - start) / 1.0e9
elapsed, Array(A)
end
trial = fetch(task)
KI.synchronize(b)
elapsed = (time_ns() - start) / 1.0e9
elapsed, Array(A)
trial
end
elapsed, result = fetch(task)
KI.synchronize(b)
# A third of the calibrated drain time leaves room for the device clocking up
# between calibration and this run; a missing wait is far below that.
@test elapsed >= expected / 3
@test all(==(Float32(launches)), result)
expected = min(expected, minimum(_ -> drain(), 1:3))
# A third of the drain time leaves room for the device clocking up between
# the drains and the waits; a missing wait is far below that.
@test maximum(first, trials) >= expected / 3
@test all(((_, result),) -> all(==(Float32(launches)), result), trials)
end

if KI.ndevices(b) > 1
Expand Down
Loading