d3d12: LEONIDA_AB phases report CPU time and spikes; scripts/ab_cpu.py compares them #3486

Merged
leonida/mandy
MoonEyes merged 3 commits from diag/ab-cpu into main 2026-12-04 18:15:57 +00:00

Pull request successfully merged and closed

Member

A measuring tool, no change to the game. Each LEONIDA_AB end-of-phase line gains tail: p99 max over100 (frames over 100 ms) and cpu: list_calls tables search submit_user submit_kernel per frame, so an A/B can be judged on CPU time and on spikes, not only on frame time. Mandy is CPU-bound on the RTX 4060 measured today (card busy ~35-40 ms, idle ~27 ms of a ~58 ms frame), so frame time alone hides CPU wins.

scripts/ab_cpu.py <leonida.log> keeps world phases (≥ 1000 draws), pairs each phase with the one that differs only by that bit (N ^ 2^bit, disjoint pairs, works with several switches) and prints the median per arm and the paired difference with a 95 % Student interval, flagged OUTSIDE/INSIDE.

Counters reused (RecordNs, DynamicAsked, DynamicNs) with a cumulative total under a mutex (cold path); submitting threads' user+kernel time summed only while LEONIDA_AB is active. Nothing new off the A/B path.

Tested: cargo test -p leonida-gpu --features diagnostics: 876 passed (one known-flaky timeline test aside, passes alone); -- ab total_: 44 passed; without the feature 787 passed; clippy clean without diagnostics (the 11 diagnostics-feature errors are pre-existing, none on these lines); python -I tests/test_ab_cpu.py: 7 OK; check_no_game_data clean. A separate reviewer (Claude Opus 5.5) refused once (overlapping pairs, a race on the counter total), then ACCEPTED the fixes.

AI-assisted: written by Claude Opus 5.5 (Claude Code), reviewed by a separate Claude Opus 5.5 judge. Merged on Moon's written authorization (two maintainers).

🤖 Generated with Claude Code

A measuring tool, no change to the game. Each `LEONIDA_AB` end-of-phase line gains `tail: p99 max over100` (frames over 100 ms) and `cpu: list_calls tables search submit_user submit_kernel` per frame, so an A/B can be judged on CPU time and on spikes, not only on frame time. Mandy is CPU-bound on the RTX 4060 measured today (card busy ~35-40 ms, idle ~27 ms of a ~58 ms frame), so frame time alone hides CPU wins. `scripts/ab_cpu.py <leonida.log>` keeps world phases (≥ 1000 draws), pairs each phase with the one that differs only by that bit (`N ^ 2^bit`, disjoint pairs, works with several switches) and prints the median per arm and the paired difference with a 95 % Student interval, flagged OUTSIDE/INSIDE. Counters reused (RecordNs, DynamicAsked, DynamicNs) with a cumulative total under a mutex (cold path); submitting threads' user+kernel time summed only while `LEONIDA_AB` is active. Nothing new off the A/B path. Tested: `cargo test -p leonida-gpu --features diagnostics`: 876 passed (one known-flaky timeline test aside, passes alone); `-- ab total_`: 44 passed; without the feature 787 passed; clippy clean without diagnostics (the 11 diagnostics-feature errors are pre-existing, none on these lines); `python -I tests/test_ab_cpu.py`: 7 OK; check_no_game_data clean. A separate reviewer (Claude Opus 5.5) refused once (overlapping pairs, a race on the counter total), then ACCEPTED the fixes. AI-assisted: written by Claude Opus 5.5 (Claude Code), reviewed by a separate Claude Opus 5.5 judge. Merged on Moon's written authorization (two maintainers). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The phase line ends with `tail: p99=..ms max=..ms over100=N` and
`cpu: list_calls=..ms tables=.. search=..ms submit_user=..ms submit_kernel=..ms`,
per frame over the counted frames. The counters are copystat's own (list-call
ns, dynamic tables asked, searching ns, the submitting threads' user and kernel
time), made cumulative for the phase; the submitters' time only adds up when
LEONIDA_AB is on. scripts/ab_cpu.py gives, for phases with 1000+ draws a frame,
the median by bit and the paired N/N-1 gap with a 95 % interval and whether it
lies outside it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- scripts/ab_cpu.py: pair phase N with N ^ 2^bit (same cycle, that bit alone), each phase in
  at most one pair, so the differences share no measure and the 95 % interval is not too narrow;
  works with two or more switches.
- copystat: `taken` and `total` hold one mutex (cold paths), so a swap and its add to the
  cumulative counter are one step to a phase's reading.
- descriptor/host: the DynamicNs timer starts after the lock, so it counts the search alone.
- Tests: two switches, a missing partner, a line without the cpu block, total() after a take.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Member

Merged by Moon's agent on Moon's written authorization. Separate reviewer: ACCEPT (after one refusal). Measuring tool only.

Merged by Moon's agent on Moon's written authorization. Separate reviewer: ACCEPT (after one refusal). Measuring tool only.
Author
Member

Merged by Moon's agent on Moon's written authorization. Separate reviewer: ACCEPT (after one refusal). After the update merge with main, d3d12_switches.py --check and tests/test_ab_cpu.py pass on 6a9971b8f6. Measuring tool only, no change to the game.

Merged by Moon's agent on Moon's written authorization. Separate reviewer: ACCEPT (after one refusal). After the update merge with main, `d3d12_switches.py --check` and `tests/test_ab_cpu.py` pass on 6a9971b8f6. Measuring tool only, no change to the game.
Sign in to join this conversation.
No description provided.