diff --git a/lib/KernelInterface/Project.toml b/lib/KernelInterface/Project.toml index ae059408d..582b30caa 100644 --- a/lib/KernelInterface/Project.toml +++ b/lib/KernelInterface/Project.toml @@ -1,7 +1,7 @@ name = "KernelInterface" uuid = "4ee993da-d684-4d17-a7dd-4e58e78d92bf" authors = ["Valentin Churavy and contributors"] -version = "0.4.7" +version = "0.4.8" [compat] julia = "1.10" diff --git a/lib/KernelInterface/test/events.jl b/lib/KernelInterface/test/events.jl index 8de5481fe..ffa412670 100644 --- a/lib/KernelInterface/test/events.jl +++ b/lib/KernelInterface/test/events.jl @@ -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 @@ -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