UMA: used and sparse_used are running totals, alloc_in searches its window only #522

Open
github-bot wants to merge 1 commit from github-bot/gh-522 into main AGit
Owner

@⁠TG0000 on GitHub · 2026-11-24 01:15 UTC · original
TG0000:perf/xcl-perf3 → main · +86 −13 · 1 files · 1 commits · open

Uma::used() added up every live block on each call, and Uma::sparse_used() added up every sparse reservation. used() is asked before every coherent graphics VirtualAlloc (kernelx.rs:315), every committed placed resource (real.rs:1235) and every readback heap (real.rs:1263). So N title allocations cost O(N²) under the UMA lock. Both are now running totals, kept up to date where blocks and reservations are taken and returned.

alloc_in(k) also filtered the whole free map for window k. A free range never crosses a window boundary (each window is shorter than WINDOW), so it now walks only the keys in k's 4 GiB range. First-fit order and results are unchanged.

This doesn't change take_sparse_in's search; #483 bounds that one. The two PRs merge cleanly in either order (checked with git merge-tree).

What is in it

  • crates/xcl/src/gpu/uma.rs only:
    • Inner::used_bytes is updated in reserve_pool, alloc_where and free. used() and the XCL_TRACE_MEM trace read it.
    • Uma::sparse_bytes is updated through a new take_sparse wrapper (used by sparse_reserve, sparse_alloc_in and sparse_alloc) and in sparse_release. sparse_used() reads it.
    • alloc_where searches free.range(k·WINDOW..(k+1)·WINDOW) when it is given a window.
    • New test used_totals_follow_allocations_and_frees: the totals match the blocks and reservations through allocations, frees, coalescing, failed requests and unknown addresses.

Tested

  • RX 6800 (Adrenalin driver 32.0.21045.29003), Ryzen 9 5900X, Windows 11, rustc 1.100.0 stable-x86_64-pc-windows-msvc, release build.
  • cargo test -p xcl --lib: 634 passed, 3 failed, 21 ignored. The 3 failures are in title_textures::tests / vram::tests, and the same tests fail on origin/main (4 failures there on this machine). cargo test -p xcl --lib uma: 10 passed.
  • Throwaway microbenchmark (not committed), release build on the 5900X, for_runtime(1 GiB):
    • 4000 committed reserves, each preceded by a size() - used() check, plus 100k used() + sparse_used() reads: 592 ms → 0.97 ms (~600×).
    • 4000 sparse_alloc_in(0, 64 KiB) + sparse_used(): 12.2 ms → 0.43 ms (~28×).

Regression run

main:

xcl-smoke v1
commit: 7ebf1b8044bef8f0ef296eb36e85010cceb4633a
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 786 (PresentX 786)
presents per 2 s (last 3): 60 60 32
device removals: 0
crashes: 0
peak commit: 15147 MB

PR:

xcl-smoke v1
commit: 638c03951413279f24af06fbe3532f9732d67096
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 824 (PresentX 824)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15146 MB

Not tested

  • cargo test --workspace (only the xcl lib tests were run), other GPUs, MinGW builds.

AI use

  • Claude Code (Claude Opus 5.5) found the hot spot, wrote the change and the test, ran the benchmarks, tests and regression runs; reviewed by the submitter.

🤖 Generated with Claude Code

**@⁠TG0000** on GitHub · 2026-11-24 01:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/522) `TG0000:perf/xcl-perf3` → `main` · +86 −13 · 1 files · 1 commits · open `Uma::used()` added up every live block on each call, and `Uma::sparse_used()` added up every sparse reservation. `used()` is asked before every coherent graphics `VirtualAlloc` (`kernelx.rs:315`), every committed placed resource (`real.rs:1235`) and every readback heap (`real.rs:1263`). So N title allocations cost O(N²) under the UMA lock. Both are now running totals, kept up to date where blocks and reservations are taken and returned. `alloc_in(k)` also filtered the whole free map for window k. A free range never crosses a window boundary (each window is shorter than `WINDOW`), so it now walks only the keys in k's 4 GiB range. First-fit order and results are unchanged. This doesn't change `take_sparse_in`'s search; #483 bounds that one. The two PRs merge cleanly in either order (checked with `git merge-tree`). **What is in it** - `crates/xcl/src/gpu/uma.rs` only: - `Inner::used_bytes` is updated in `reserve_pool`, `alloc_where` and `free`. `used()` and the `XCL_TRACE_MEM` trace read it. - `Uma::sparse_bytes` is updated through a new `take_sparse` wrapper (used by `sparse_reserve`, `sparse_alloc_in` and `sparse_alloc`) and in `sparse_release`. `sparse_used()` reads it. - `alloc_where` searches `free.range(k·WINDOW..(k+1)·WINDOW)` when it is given a window. - New test `used_totals_follow_allocations_and_frees`: the totals match the blocks and reservations through allocations, frees, coalescing, failed requests and unknown addresses. **Tested** - RX 6800 (Adrenalin driver 32.0.21045.29003), Ryzen 9 5900X, Windows 11, rustc 1.100.0 stable-x86_64-pc-windows-msvc, release build. - `cargo test -p xcl --lib`: 634 passed, 3 failed, 21 ignored. The 3 failures are in `title_textures::tests` / `vram::tests`, and the same tests fail on `origin/main` (4 failures there on this machine). `cargo test -p xcl --lib uma`: 10 passed. - Throwaway microbenchmark (not committed), release build on the 5900X, `for_runtime(1 GiB)`: - 4000 committed `reserve`s, each preceded by a `size() - used()` check, plus 100k `used() + sparse_used()` reads: **592 ms → 0.97 ms** (~600×). - 4000 `sparse_alloc_in(0, 64 KiB)` + `sparse_used()`: **12.2 ms → 0.43 ms** (~28×). **Regression run** main: ``` xcl-smoke v1 commit: 7ebf1b8044bef8f0ef296eb36e85010cceb4633a gpu: AMD Radeon RX 6800 title: retail-title-1.0.2.1 seconds: 45 exit: 0x0 frames shown: 786 (PresentX 786) presents per 2 s (last 3): 60 60 32 device removals: 0 crashes: 0 peak commit: 15147 MB ``` PR: ``` xcl-smoke v1 commit: 638c03951413279f24af06fbe3532f9732d67096 gpu: AMD Radeon RX 6800 title: retail-title-1.0.2.1 seconds: 45 exit: 0x0 frames shown: 824 (PresentX 824) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15146 MB ``` **Not tested** - `cargo test --workspace` (only the `xcl` lib tests were run), other GPUs, MinGW builds. **AI use** - Claude Code (Claude Opus 5.5) found the hot spot, wrote the change and the test, ran the benchmarks, tests and regression runs; reviewed by the submitter. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`Uma::used()` summed every live block and `sparse_used()` every sparse
reservation on each call. kernelx asks `used()` before each coherent
graphics allocation and real.rs before each committed placed resource and
readback heap, so allocating N blocks cost O(N^2). Both are now totals
updated where blocks and reservations are taken and returned.

`alloc_in(k)` filtered the whole free map for window k. Free ranges never
straddle windows, so it now walks only the keys in k's 4 GiB range.
First fit order is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:24:28 +00:00
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-24 01:23 UTC · original

Tested

I built and tested the full synthetic workspace on the RTX 3080 Ti (driver 621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, debug. For both revisions I ran cargo build --offline --locked --workspace followed by cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4, with all XCL_SAMPLE_* variables unset.

Revision Cargo passed Failed Ignored GPU skips included in passes
Exact parent 7ebf1b8 677 0 41 2
PR head 638c039 678 0 41 2

The PR adds one UMA accounting test, and the texture and VRAM failures reported on the RX 6800 did not occur in either run here. Both revisions reported the same wave64 skips (gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware).

Not tested

Retail titles, release performance, or the PR integrated with newer main commits.

AI use

Codex with GPT-6.2 Sol ran the tests and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-24 01:23 UTC · [original](https://github.com/xcl-dev/xcl/pull/522#issuecomment-7119055015) **Tested** I built and tested the full synthetic workspace on the RTX 3080 Ti (driver 621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, debug. For both revisions I ran `cargo build --offline --locked --workspace` followed by `cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4`, with all `XCL_SAMPLE_*` variables unset. | Revision | Cargo passed | Failed | Ignored | GPU skips included in passes | | --- | ---: | ---: | ---: | ---: | | [Exact parent 7ebf1b8](https://github.com/ivall/xcl/commit/7ebf1b8044bef8f0ef296eb36e85010cceb4633a) | 677 | 0 | 41 | 2 | | [PR head 638c039](https://github.com/ivall/xcl/commit/638c03951413279f24af06fbe3532f9732d67096) | 678 | 0 | 41 | 2 | The PR adds one UMA accounting test, and the texture and VRAM failures reported on the RX 6800 did not occur in either run here. Both revisions reported the same wave64 skips (`gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware`). **Not tested** Retail titles, release performance, or the PR integrated with newer main commits. **AI use** Codex with GPT-6.2 Sol ran the tests and drafted this report.
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 03:04 UTC · original

Test run of 638c03951413279f24af06fbe3532f9732d67096 on AMD RDNA4. I merged it onto current main dd2ae9a locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 691 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 651 passed, 0 failed, 21 ignored
  • 0 SKIPPED; used_totals_follow_allocations_and_frees passes.

Review: I checked that the running totals cannot drift: in uma.rs at the PR head, both used.inserts add to used_bytes and the one used.remove subtracts the removed size; every reservation goes through take_sparse, which adds the same size take_sparse_in inserts, and sparse_release subtracts the size it removes from the map. alloc_in's range(k·WINDOW..(k+1)·WINDOW) relies on free ranges not crossing a window, which holds since each window is shorter than WINDOW. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

**@⁠MesshM** on GitHub · 2026-11-24 03:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/522#issuecomment-7120741715) Test run of `638c03951413279f24af06fbe3532f9732d67096` on AMD RDNA4. I merged it onto current `main` `dd2ae9a` locally (clean merge) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **691 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 651 passed, 0 failed, 21 ignored - **0 `SKIPPED`**; `used_totals_follow_allocations_and_frees` passes. **Review:** I checked that the running totals cannot drift: in `uma.rs` at the PR head, both `used.insert`s add to `used_bytes` and the one `used.remove` subtracts the removed size; every reservation goes through `take_sparse`, which adds the same `size` `take_sparse_in` inserts, and `sparse_release` subtracts the size it removes from the map. `alloc_in`'s `range(k·WINDOW..(k+1)·WINDOW)` relies on free ranges not crossing a window, which holds since each window is shorter than `WINDOW`. I found nothing to change. **Not tested:** no retail title or regression run (I have no unpacked game), no `XCL_SAMPLE_*` tests, release build; the PR's head on its old base was not run, only its merge onto `main`. Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Author
Owner

@⁠thaqiart139-alt on GitHub · 2026-11-24 22:48 UTC · original

Test report for this PR's head 638c039, merged into main 689f2db (no conflicts), on AMD RDNA2 with native 64-lane waves and on a 32-lane NVIDIA card.

Tested

  • GPUs: AMD Radeon(TM) Graphics, the RDNA2 iGPU of a Ryzen 7 7800X3D (native wave64, driver 32.0.21045.29003), and NVIDIA GeForce RTX 5070 (driver 32.0.16.2101), chosen with XCL_ADAPTER.
  • System: 32 GB, Windows 11 Home build 26300, Rust 1.100.0, debug, DXC 1.9.2602.17.
  • cargo test --workspace --no-fail-fast -- --test-threads=4:
main 689f2db with this PR
RTX 5070 971 passed, 4 failed, 45 ignored 972 passed, 4 failed, 45 ignored
Radeon iGPU 974 passed, 1 failed, 45 ignored 975 passed, 1 failed, 45 ignored
  • This PR adds no failure. The failures are the same on main, from #1679's new fuzz tests, and both are already reported on #1679:
    • RTX 5070: fuzz_validate_and_gpu_0 to _3 (CreateComputePipelineState: 0x8007000E)
    • iGPU: fuzz_validate_and_gpu_1 (seed 540: res[833] = 0x7, CPU 0x6)
  • This PR's new tests pass on both GPUs: used_totals_follow_allocations_and_frees.
  • This is the whole workspace, which the description lists as not tested (only the xcl lib tests were run there).
SKIPPED tests (the same on main and with this PR)
  • RTX 5070:
    • no wave64:
      • gpu::recomp::lower::tests: a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu
      • gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu, and the wave64 cases of its f16 / f32 / f64 / integer_programs_on_the_gpu
      • gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
    • the wave32 per-lane cases of lower_dxil's f16 arithmetic, f16 packed and f32 conversions: refused ("its #1426 semantics differ from the console's")
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode is off)
  • Radeon iGPU:
    • no mesh shaders: gpu::dxil::geometry_tests::gpu_geometry_direct_records, emitted_ms_primitive_attribute_reaches_the_pixel_shader, emitted_ms_ps_draw_a_triangle, gpu_geometry_mode_es_gs_strip, gpu_geometry_mode_es_gs_strip_with_branches, gpu_mesh_mode_two_passes
    • the wave32 and wave64 per-lane cases of lower_dxil's f16 arithmetic, f16 packed and f32 conversions: refused, as above
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • pso_measurement_compiles_an_exact_synthetic_record (Developer Mode is off)

Not tested

  • a title run, MinGW builds; other GPUs; Linux / Wine.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report.
**@⁠thaqiart139-alt** on GitHub · 2026-11-24 22:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/522#issuecomment-7146675434) Test report for this PR's head `638c039`, merged into `main` `689f2db` (no conflicts), on AMD RDNA2 with native 64-lane waves and on a 32-lane NVIDIA card. **Tested** - GPUs: AMD Radeon(TM) Graphics, the RDNA2 iGPU of a Ryzen 7 7800X3D (native wave64, driver 32.0.21045.29003), and NVIDIA GeForce RTX 5070 (driver 32.0.16.2101), chosen with `XCL_ADAPTER`. - System: 32 GB, Windows 11 Home build 26300, Rust 1.100.0, debug, DXC 1.9.2602.17. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: | | `main` `689f2db` | with this PR | |---|---|---| | RTX 5070 | 971 passed, 4 failed, 45 ignored | 972 passed, 4 failed, 45 ignored | | Radeon iGPU | 974 passed, 1 failed, 45 ignored | 975 passed, 1 failed, 45 ignored | - This PR adds no failure. The failures are the same on `main`, from #1679's new fuzz tests, and both are already reported on #1679: - RTX 5070: `fuzz_validate_and_gpu_0` to `_3` (`CreateComputePipelineState`: `0x8007000E`) - iGPU: `fuzz_validate_and_gpu_1` (`seed 540: res[833] = 0x7, CPU 0x6`) - This PR's new tests pass on both GPUs: `used_totals_follow_allocations_and_frees`. - This is the whole workspace, which the description lists as not tested (only the `xcl` lib tests were run there). <details><summary>SKIPPED tests (the same on <code>main</code> and with this PR)</summary> - **RTX 5070:** - no wave64: - `gpu::recomp::lower::tests`: `a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu`, `coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu`, `cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu`, `the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu` - `gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu`, and the wave64 cases of its `f16` / `f32` / `f64` / `integer_programs_on_the_gpu` - `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` - the wave32 per-lane cases of `lower_dxil`'s f16 arithmetic, f16 packed and f32 conversions: refused ("its #1426 semantics differ from the console's") - `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) - `pso_measurement_compiles_an_exact_synthetic_record` (Windows Developer Mode is off) - **Radeon iGPU:** - no mesh shaders: `gpu::dxil::geometry_tests::gpu_geometry_direct_records`, `emitted_ms_primitive_attribute_reaches_the_pixel_shader`, `emitted_ms_ps_draw_a_triangle`, `gpu_geometry_mode_es_gs_strip`, `gpu_geometry_mode_es_gs_strip_with_branches`, `gpu_mesh_mode_two_passes` - the wave32 and wave64 per-lane cases of `lower_dxil`'s f16 arithmetic, f16 packed and f32 conversions: refused, as above - `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) - `pso_measurement_compiles_an_exact_synthetic_record` (Developer Mode is off) </details> **Not tested** - a title run, MinGW builds; other GPUs; Linux / Wine. **AI use** - Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report.
Author
Owner

@⁠TG0000 on GitHub · 2026-11-25 12:28 UTC · original

Rebased onto main 1a0bbe3: head af0f5b8. The conflict was in the tests only. I also checked main's new window layouts: every place that takes or returns a block or a sparse range goes through the running totals.

Run on this head (Ryzen 9 5900X, Windows 11, MSVC): cargo test -p xcl --lib uma: 16 passed, 0 failed. Clippy stops on three TAU constants in files this PR does not touch, with this toolchain.

Not run on this head: the whole suite, the microbenchmark and the xcl-smoke pair. The blocks in the description are of 638c039, so the description check is expected to ask for a fresh one until it is run.

AI-assisted (Claude Code).

**@⁠TG0000** on GitHub · 2026-11-25 12:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/522#issuecomment-7162426635) Rebased onto main 1a0bbe3: head `af0f5b8`. The conflict was in the tests only. I also checked main's new window layouts: every place that takes or returns a block or a sparse range goes through the running totals. Run on this head (Ryzen 9 5900X, Windows 11, MSVC): `cargo test -p xcl --lib uma`: 16 passed, 0 failed. Clippy stops on three `TAU` constants in files this PR does not touch, with this toolchain. **Not run on this head:** the whole suite, the microbenchmark and the `xcl-smoke` pair. The blocks in the description are of `638c039`, so the description check is expected to ask for a fresh one until it is run. AI-assisted (Claude Code).
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 13:53 UTC · original

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 13:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/522#issuecomment-7164446023) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Author
Owner

@⁠TG0000 on GitHub · 2026-11-25 15:04 UTC · original

@⁠DavidM1911 Rebased onto latest main (head 1af0171) — thanks for testing!

**@⁠TG0000** on GitHub · 2026-11-25 15:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/522#issuecomment-7166263151) @⁠DavidM1911 Rebased onto latest `main` (head `1af0171`) — thanks for testing!
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 02:45 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 02:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/522#issuecomment-7181099545) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/522/head:github-bot/gh-522'
git switch 'github-bot/gh-522'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-522'
git switch 'github-bot/gh-522'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-522'
git switch 'github-bot/gh-522'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-522'
git switch 'main'
git merge --squash 'github-bot/gh-522'
git switch 'main'
git merge --ff-only 'github-bot/gh-522'
git switch 'main'
git merge 'github-bot/gh-522'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.