fix(wgpu): close a device profile on its last compute pass - #1592
Merged
Conversation
A profiled region gets timestamp writes only on the pass that drains its token, so `stop_profile_setup` resolved the end from the same query set the start came from and reported the first pass alone. Every later pass of the region carries no timestamp at all. Each pass of a live profile now rewrites the end slot of the profile's own query set, so the last one to run marks the end. One set per profile either way: the query-set budget and its round-robin are untouched. The launch-overhead throughput probe is what this surfaced on. Its window stayed pinned near 24 us whatever the loop length, and the benchmarker's warmup, seeing a duration that never grows, drove the count to hundreds of thousands; the constant divided by that count underflowed `Duration` to exactly zero, which autotune read as launches being free on every wgpu backend. Closes #1421
ThierryCantin-Demers
marked this pull request as ready for review
September 2, 2026 18:32
louisfd
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1421.
A profiled region gets timestamp writes only on the pass that drains its token, so
stop_profile_setupresolves the end from the set the start came from and the window is the first compute pass alone.WgpuStreamcloses a pass every 32 dispatches, so any longer region reports a constant.That constant becomes zero in
launch_overhead, which derives its loop length from the measurement: a window that never grows drives warmup to ~670k iterations, and 23.9 µs over that count underflowsDurationto zero. It printsN/A, androofline_boundshas been costing a launch at zero on every wgpu backend.The fix. A profile keeps one query set for its whole span. The pass that opens it writes both slots; every later pass while it is live rewrites only the end slot, so the last pass marks the end. No extra query sets, and the allocator is untouched.
Not the per-pass sets #1421 suggests: that is ~233k
create_query_setcalls per sample at these counts, and under Metal's 28-set budget the round-robin hands back the set a live profile started in and clobbers that start, giving zero again.Measured, RTX 4070 Ti SUPER, profiling N launches:
Pinned within 2 % while the work grows 64×. One and eight launches are unchanged; the single-pass regime was already right. 3.5 µs per launch matches what CUDA measures on the same card. WGSL is the same shape.
cubecl-wgpuwas not instantiatingtestgen_profiling!, which is why this survived; it is wired in here, andtest_window_spans_every_pass_in_itreports a growth ratio of 0.76 on the unfixed code while both pre-existing profiling tests pass.Green on
cubecl-wgpu --features spirv(746 + 17), on lavapipe as a CI stand-in, and on CUDA againstorigin/main(same 17 pre-existing failures both sides, one-test delta is the new test).Known, not fixed here
roofline_boundsstill charges an unmeasurable launch as free; that wantsBounds::launch_overheadto become optional.QuerySetAllocatordoc is corrected to say so; fixing it needs the allocator to know which sets are live.Validate your PR with burn.
It is important that you make sure that you don't introduce any bugs in burn.
Instructions