Skip to content

Memory: bound sparse UMA first-fit searches by address - #483

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
TG0000:perf/sparse-uma-range-search
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
TG0000:perf/sparse-uma-range-search

Conversation

@TG0000

@TG0000 TG0000 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Sparse UMA reservations specify address bounds. The allocator now uses B-tree range queries to skip holes outside those bounds, reducing work under the mutex. It tries the first entry directly and checks the immediate predecessor of the lower bound when seeking.

What is in it

  • Bounded first-fit search in gpu/uma.rs, with tests for a free range crossing the lower bound, alignment, and allocations across a 4 GiB window boundary.

Tested

  • Ryzen 9 5900X, Radeon RX 6800 (32.0.21045.29003), Windows build 26300, Rust 1.100.0 MSVC.
  • cargo +stable-x86_64-pc-windows-msvc build --workspace and cargo +stable-x86_64-pc-windows-msvc build --release -p xcl passed.
  • cargo +stable-x86_64-pc-windows-msvc test --workspace --no-fail-fast -- --test-threads=4 returned 675 passed, 3 failed, 41 ignored, and 0 emitted GPU SKIPPED lines. All 9 UMA tests passed. The 3D mip readback mismatch in placed_title_textures_share_vram_and_preserve_pixels also reproduced as an isolated MSVC test on 2997c9a. The two other failures followed poisoned locks in the head suite.
  • 200,000 synthetic first-fit requests produced the same addresses and free and used maps as the original allocator.
  • Standalone MSVC benchmark compiled with rustc +stable-x86_64-pc-windows-msvc --edition=2021 -O. Each request was 64 KiB with 64 KiB alignment in one 4 GiB window. All synthetic holes were 64 KiB, spaced 128 KiB apart. Successful allocations restored the exact fit between iterations. Median of 15 paired samples with 20,000 requests per variant in alternating order.
Free ranges Before (ns/op) After (ns/op) Speedup
One exact fit 62.60 60.55 1.03x
Fit after 128 holes below the window 267.85 102.16 2.62x
Empty window, 128 holes above 207.38 17.79 11.66x
Fit after 512 holes below the window 926.78 104.17 8.90x
Empty window, 512 holes above 846.43 22.28 37.99x
Fit after 2,048 holes below the window 3,454.49 111.89 30.88x
Empty window, 2,048 holes above 3,331.11 26.74 124.57x

Regression run

The first pair showed 590 frames on main and 413 on head. The repeat below held the same lock across both 45-second runs. Both pairs used a 3.5 GiB free physical memory watchdog.

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 838 (PresentX 838)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15158 MB
xcl-smoke v1
commit: 3462d4045d20c597ce4952d0f843fe5e6ae9a76a
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 853 (PresentX 853)
presents per 2 s (last 3): 58 60 60
device removals: 0
crashes: 0
peak commit: 15136 MB

Not tested

  • Allocator speedup during retail gameplay, other GPU models and operating systems.

AI use

  • Codex in T3 Code (GPT 6.2 Sol) wrote the change, synthetic tests, benchmark and PR description, and ran verification.

Seek to the requested address range before scanning for a fit, while still checking the one free range that can begin before the lower bound and overlap it. This keeps fragmented windows outside the request from extending the time spent under the sparse allocator lock.

Co-Authored-By: GPT 6.2 Sol <noreply@openai.com>
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run and review of 3462d4045d20c597ce4952d0f843fe5e6ae9a76a on AMD RDNA4 (the PR has an RX 6800 run with 3 failures). The branch is based on 2997c9a, so I merged it onto current main 9ce2070 locally (clean merge, only uma.rs) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), 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
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4) on the merge: 686 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 646 passed, 0 failed, 21 ignored
  • 0 SKIPPED; all 9 gpu::uma::tests pass, including the two new ones
  • the three failures in the description do not show up here: placed_title_textures_share_vram_and_preserve_pixels passes on this RDNA4 card (its 3D mip readback mismatch on RDNA1/RDNA2 is what D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them #470 is about), and no test failed on a poisoned lock
  • with only the predecessor lookup (g.0.range(..lo_bound).next_back()) replaced by None (not committed), both new tests fail: sparse_first_fit_keeps_the_range_crossing_the_lower_bound gets lo + 4 * GRAIN instead of lo, and sparse_first_fit_skips_a_window_boundary_only_when_requested gets None instead of WINDOW. So they pin the case the change is about.

Review: I checked that the bounded search returns what the old iter().find_map did. The free ranges in the map are disjoint, so of the ranges that start below lo_bound only the immediate predecessor can reach into [lo_bound, hi_bound), and none that starts at or after hi_bound can. The candidates are therefore the same, and they are tried in the same address order (predecessor first, then the starts inside the bounds), so the first fit is the same range. Trying first_key_value() before them changes nothing: if it lies outside the bounds first_fit returns None, and if it is the predecessor it is looked at twice, with no side effects. An empty map still gives None. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no timing of the lock hold (the benchmark in the description was not rerun); 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; each point was checked against the code.

@H0UNDZER0

H0UNDZER0 commented Nov 24, 2026 •

Copy link
Copy Markdown

Tested on an RTX 5080: pass, 678 passed, 0 failed. As far as I can see, this is the first run of this PR on NVIDIA.

  • Commit 3462d4045d20c597ce4952d0f843fe5e6ae9a76a, this PR's head as is (on its base 2997c9a), release build.
  • NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9700X; Windows 11 Pro 24H2 (26100.9711); Rust 1.100.0 MSVC; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0). No XCL_* variables set.
  • cargo build --release --workspace --locked: OK, the same single fetch_update warning as main.
  • cargo test --workspace --release --no-fail-fast --locked -- --test-threads=4, run twice (the second with --show-output): 678 passed, 0 failed, 41 ignored both times. main 2997c9a gives 676 / 0 / 41 on this PC: the difference is this PR's 2 new tests.
  • SKIPPED: the usual 2, gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64).
  • All 9 uma tests pass, the 2 new sparse_first_fit_* ones included. The 3 failures of the RX 6800 run in the description do not happen here: placed_title_textures_share_vram_and_preserve_pixels passes, as it does on main on this GPU.

Not tested

  • The allocator's speed.
  • This PR merged onto a newer main. At the time of the run that was 508a0c7; git merge-tree showed no conflict.
  • Debug build, retail titles, scripts/smoke.ps1.

AI use: Claude Code (Claude Opus 5.5, Claude Fable 5.2)

@raylitebull
raylitebull merged commit da6174d into xcl-dev:main Nov 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants