Steps on the card: their planning on the submitting thread cut by a fifth (a third with more places) #2005

Closed
github-bot wants to merge 5 commits from github-bot/gh-2005 into main AGit
Owner

@⁠binarycleric on GitHub · 2026-11-29 07:07 UTC · original
up/card-steps-planning → main · +747 −169 · 1 files · 5 commits · closed without merging

What it changes

With VICTORY_CARD_STEPS on and the relay's second stage, every submission held up by flights in the air is planned on the submitting thread before it goes: the steps the card can do in front of it are chosen, the host copy that holds each one's bytes is found, our list is recorded, and the fills' descriptor slots are pointed at the result. A play log broke the submitting thread's time down only as far as "card steps", about 4 ms a frame. This PR measures the four parts and cuts the three that cost the most.

How it was measured

The first commit splits take_steps into four functions, named after the timeline spans it already had: choose, ops_of, record_ops and point_slots. Behaviour doesn't change. It also adds planning_bench, an ignored test that runs those functions on a frame like a street's:

  • 3,200 fills in 6 submissions;
  • 300 distinct places in a ring of constants, 8 to a page;
  • 512 writers in the air;
  • 4 of our lists in the air, so each slot let go of another buffer.
cargo test -p victory-gpu --release --lib planning_bench -- --ignored --nocapture --test-threads=1

BENCH_FRAMES/SUBMISSIONS/FILLS/PLACES/WRITERS/RING_KB/IN_THE_AIR change the load. Every comparison below ran the two settings in alternating rounds (6 to 10 rounds) and takes medians per frame. Noise was about ±8%: once, two identical settings came out 111 µs apart while other builds were running.

At the start, per frame on a quiet machine: steps chosen ~340 µs, holders ~230, the list ~270, slots ~550. In total ~1.4 ms. With other builds running, the slots on 8 threads took 1,200 µs and slowed the other parts, for a total of ~2.1 ms.

What changes

Commit Change Switch (=0 restores the old path) planning_bench, per frame
1 Four functions and the bench none, no behaviour change
2 Slots made on the submitting thread alone, not on 8 parts. The parts queued on the one lock of the retire queue and on the shared buffer's refcount. VICTORY_CARD_SLOTS_ONE_THREAD with builds running: slots 1,200 → 545 µs, total 2.09 → 1.03 ms. Quiet machine: even (1.13 vs 1.16 ms).
3 plan no longer boxes an iterator for every step (3,200 allocations a frame). none, the plan is the same steps chosen 332 → 191 µs
4 The holder of each place is found in one pass over the writers per submission, not a scan of all writers per place. Writers added during planning, and places not asked for at first, are looked at as before. VICTORY_CARD_WRITERS_SWEEP holders 242 → 208 µs (512 writers), 497 → 334 (1,500), 1,170 → 759 (4,096)
5 Places of the same host copy and level that lie within 4 KiB of each other and a multiple of 256 apart are brought into our buffer by one copy. If that layout wouldn't fit the buffer, each place gets its own copy, as before. VICTORY_CARD_READS_JOINED the list 231 → 101 µs (300 places), 1,676 → 82 (3,000)

Overall, first commit against last, 10 rounds on a quiet machine: 1,423 → 1,141 µs a frame (~237 → ~190 µs a submission). In a heavier frame (3,000 places, 1,500 writers): 5.96 → 1.92 ms.

The bench numbers were taken on our integration branch; on main the commits conflicted only where take_steps was split up. VICTORY_PLACED_FILLS (#740) now goes through choose: its served fills come back with the chosen steps, and their slots are pointed after point_slots, on the same thread. The bench runs with it off.

Tried and not kept

  • Passing blocked_by's answer on to late_blocked: a whole blocked_by that finds nothing blocked costs 5 to 7 µs a frame.
  • Keeping what mapped learned of pages across submissions: it costs ~25 µs a frame, and a stale entry is a correctness risk.
  • Making the slots on 8 threads with the retirements taken out: the slots were 20% faster, but the frame was slower overall.
  • Resetting our landed lists on a thread of their own: −31 µs one time, +8 µs the next.

How it was tested

  • GPU and profile: RTX 5070 Ti 16 GB, Ryzen 9 7900X; Series X profile, 1440p native, DLSS off, frame generation off; ray-tracing passes left out (no structure builder) (play numbers), plus planning_bench (above)
  • Before: bench 1,423 µs a frame; in play on our integration branch before these commits, "planning steps done on the card" was about 4.1 ms a frame
  • After: bench 1,141 µs a frame (5.96 → 1.92 ms in a heavier frame); in play with them (VICTORY_CARD_STEPS=2, 26–28 fps, about 3,500–4,700 draws) 3.2–3.3 ms a frame. The two play numbers come from different builds of a busy branch, so they show a direction, not this PR alone
  • cargo test passed for the crates it touches: yes. Rebased onto main e1f2eb60: cargo test --release -p victory-gpu --lib, 592 passed, 0 failed, 45 ignored

Tests

  • one_pass_over_the_writers_says_what_each_in_turn_does: the one pass gives the same answer, refusals included, as looking at each writer for each place. 300 random rounds of overlapping, empty and side-by-side writers and places, with writers added while it's under way.
  • the_holder_is_the_same_after_one_pass: holder gives the same host copy or refusal both ways, with three real host copies and a writer pushed during planning.
  • places_read_are_where_their_copies_put_them: with joining on and off, every place's bytes are where its op reads them. Places start 256-aligned, copies don't overlap, and the layout fits our buffer (400 random rounds).
  • The card-steps tests already there pass. The ignored end-to-end flight test passes with joined reads on and off.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1279 (also removes the boxed iterators in plan and replaces the linear writer scan, with a sorted search), #1298 (card_steps among other submitting-thread changes). Slots on one thread, the one-pass writer sweep and joined reads are separate switches here, so whichever lands first, the rest can be rebased onto it.
**@⁠binarycleric** on GitHub · 2026-11-29 07:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2005) `up/card-steps-planning` → `main` · +747 −169 · 1 files · 5 commits · closed without merging ## What it changes With `VICTORY_CARD_STEPS` on and the relay's second stage, every submission held up by flights in the air is planned on the submitting thread before it goes: the steps the card can do in front of it are chosen, the host copy that holds each one's bytes is found, our list is recorded, and the fills' descriptor slots are pointed at the result. A play log broke the submitting thread's time down only as far as "card steps", about 4 ms a frame. This PR measures the four parts and cuts the three that cost the most. ### How it was measured The first commit splits `take_steps` into four functions, named after the timeline spans it already had: `choose`, `ops_of`, `record_ops` and `point_slots`. Behaviour doesn't change. It also adds `planning_bench`, an ignored test that runs those functions on a frame like a street's: - 3,200 fills in 6 submissions; - 300 distinct places in a ring of constants, 8 to a page; - 512 writers in the air; - 4 of our lists in the air, so each slot let go of another buffer. ``` cargo test -p victory-gpu --release --lib planning_bench -- --ignored --nocapture --test-threads=1 ``` `BENCH_FRAMES/SUBMISSIONS/FILLS/PLACES/WRITERS/RING_KB/IN_THE_AIR` change the load. Every comparison below ran the two settings in alternating rounds (6 to 10 rounds) and takes medians per frame. Noise was about ±8%: once, two identical settings came out 111 µs apart while other builds were running. At the start, per frame on a quiet machine: steps chosen ~340 µs, holders ~230, the list ~270, slots ~550. In total ~1.4 ms. With other builds running, the slots on 8 threads took 1,200 µs and slowed the other parts, for a total of ~2.1 ms. ### What changes | Commit | Change | Switch (`=0` restores the old path) | planning_bench, per frame | |---|---|---|---| | 1 | Four functions and the bench | none, no behaviour change | | | 2 | Slots made on the submitting thread alone, not on 8 parts. The parts queued on the one lock of the retire queue and on the shared buffer's refcount. | `VICTORY_CARD_SLOTS_ONE_THREAD` | with builds running: slots 1,200 → 545 µs, total 2.09 → 1.03 ms. Quiet machine: even (1.13 vs 1.16 ms). | | 3 | `plan` no longer boxes an iterator for every step (3,200 allocations a frame). | none, the plan is the same | steps chosen 332 → 191 µs | | 4 | The holder of each place is found in one pass over the writers per submission, not a scan of all writers per place. Writers added during planning, and places not asked for at first, are looked at as before. | `VICTORY_CARD_WRITERS_SWEEP` | holders 242 → 208 µs (512 writers), 497 → 334 (1,500), 1,170 → 759 (4,096) | | 5 | Places of the same host copy and level that lie within 4 KiB of each other and a multiple of 256 apart are brought into our buffer by one copy. If that layout wouldn't fit the buffer, each place gets its own copy, as before. | `VICTORY_CARD_READS_JOINED` | the list 231 → 101 µs (300 places), 1,676 → 82 (3,000) | Overall, first commit against last, 10 rounds on a quiet machine: 1,423 → 1,141 µs a frame (~237 → ~190 µs a submission). In a heavier frame (3,000 places, 1,500 writers): 5.96 → 1.92 ms. The bench numbers were taken on our integration branch; on main the commits conflicted only where `take_steps` was split up. `VICTORY_PLACED_FILLS` (#740) now goes through `choose`: its served fills come back with the chosen steps, and their slots are pointed after `point_slots`, on the same thread. The bench runs with it off. ### Tried and not kept - Passing `blocked_by`'s answer on to `late_blocked`: a whole `blocked_by` that finds nothing blocked costs 5 to 7 µs a frame. - Keeping what `mapped` learned of pages across submissions: it costs ~25 µs a frame, and a stale entry is a correctness risk. - Making the slots on 8 threads with the retirements taken out: the slots were 20% faster, but the frame was slower overall. - Resetting our landed lists on a thread of their own: −31 µs one time, +8 µs the next. ## How it was tested - GPU and profile: RTX 5070 Ti 16 GB, Ryzen 9 7900X; Series X profile, 1440p native, DLSS off, frame generation off; ray-tracing passes left out (no structure builder) (play numbers), plus `planning_bench` (above) - Before: bench 1,423 µs a frame; in play on our integration branch before these commits, "planning steps done on the card" was about 4.1 ms a frame - After: bench 1,141 µs a frame (5.96 → 1.92 ms in a heavier frame); in play with them (`VICTORY_CARD_STEPS=2`, 26–28 fps, about 3,500–4,700 draws) 3.2–3.3 ms a frame. The two play numbers come from different builds of a busy branch, so they show a direction, not this PR alone - `cargo test` passed for the crates it touches: yes. Rebased onto main e1f2eb60: `cargo test --release -p victory-gpu --lib`, 592 passed, 0 failed, 45 ignored ### Tests - `one_pass_over_the_writers_says_what_each_in_turn_does`: the one pass gives the same answer, refusals included, as looking at each writer for each place. 300 random rounds of overlapping, empty and side-by-side writers and places, with writers added while it's under way. - `the_holder_is_the_same_after_one_pass`: `holder` gives the same host copy or refusal both ways, with three real host copies and a writer pushed during planning. - `places_read_are_where_their_copies_put_them`: with joining on and off, every place's bytes are where its op reads them. Places start 256-aligned, copies don't overlap, and the layout fits our buffer (400 random rounds). - The card-steps tests already there pass. The ignored end-to-end flight test passes with joined reads on and off. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1279 (also removes the boxed iterators in `plan` and replaces the linear writer scan, with a sorted search), #1298 (card_steps among other submitting-thread changes). Slots on one thread, the one-pass writer sweep and joined reads are separate switches here, so whichever lands first, the rest can be rebased onto it.
What `take_steps` did in one body is four functions, as its timeline
spans already named them: the steps chosen (`choose`), what holds their
bytes (`ops_of`), the list (`record_ops`) and the slots (`point_slots`,
given the call that makes a slot). Nothing it does changes.

`planning_bench` (ignored; a release build, a process of its own) plans a
street's frame part by part: 3,200 fills in six submissions, a few
hundred places of a ring of constants eight to a page, read through the
host copy of a heap declared written whole beside 512 other writers, and
four of our lists in the air, so that a slot showed another buffer before.
Every slot the card's steps point lets go of the buffer it showed before
(another of our lists' buffers between, most often) into the one queue of
what is let go, under its lock, and holds the one it shows now: on six
threads the slots stood in line for both. planning_bench, runs each way
in turns, medians per frame, with other builds running on the machine:
the slots 1,200 us on eight parts, 545 on one thread; the whole planning
2.09 ms against 1.03. With the machine quieter the two were even (1.13
ms against 1.16).

VICTORY_CARD_SLOTS_ONE_THREAD=0: on eight parts, as before.
For each step done on the card the plan boxed the iterator over those
ahead of it: 3,200 allocations a frame in a street, half of the plan.
planning_bench, eight runs each way in turns, medians per frame: the
steps chosen in 191 us against 332. The plan is the same.
What holds the bytes a step reads or writes was found by looking at every
writer of the flights in the air (every range a flight declares written,
by host copy) for each new place, and anew behind each copy. Now the
places a submission's steps read and write are sorted once and the
writers are gone over once, in their order, each telling the places it
meets what it says of them: the answer `holder` gave, refusals and their
reasons included. Writers added behind the pass (copies done here) and a
place not asked for at first are looked at as before.

planning_bench, runs each way in turns, medians per frame of that part:
208 us against 242 with 512 writers, 334 against 497 with 1,500, 759
against 1,170 with 4,096. Sorting the writers for each submission to find
them by place lost with 512.

VICTORY_CARD_WRITERS_SWEEP=0: each writer looked at for each place.
Our list copied each place a submission's steps read into the buffer
between with a copy of its own, some 0.3 us each to record. Places of the
same host copy, on the same level, that lie within 4 KiB of one another
and a multiple of 256 apart (each still begins where a constant buffer
may) are now copied as they lie, with what is between them; a layout that
would not fit the buffer that way is made one by one, as before.

planning_bench, runs each way in turns, medians per frame of the list:
101 us against 231 with 300 places a frame, 82 against 1,676 with 3,000.

VICTORY_CARD_READS_JOINED=0: a copy for each place.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 07:10:38 +00:00
github-bot closed this pull request 2026-11-29 07:16:12 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2005
No description provided.