Skip to content

Memory: keep single-window sparse_reserve allocations inside one window - #2886

Open
Decodere wants to merge 1 commit into
xcl-dev:nvidia-devfrom
Decodere:fix-sparse-reserve-single-window
Open

Decodere wants to merge 1 commit into
xcl-dev:nvidia-devfrom
Decodere:fix-sparse-reserve-single-window

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

Targets nvidia-dev (eae01502). Related to #2867.

After 3292b096 moved physical page homes out of window 0 into windows 1+ via Uma::sparse_alloc_above, Series S sparse-heap layouts place 664+ MiB of physical homes at the start of window 1 (0x11_0000_0000), leaving under 3.35 GiB in window 1 while window 2 (0x12_0000_0000) has a full 4 GiB free. Because Uma::sparse_reserve always passed single_window = false, a title reservation of at most one window (for example ~3.4 GiB) straddled the window 1 / window 2 boundary (0x12_0000_0000) instead of landing wholly inside window 2. Multiple sparse-window paths (title_buffer_window, uma_window_buffer, and view_bytes) reject or truncate ranges that cross a 4 GiB window boundary.

What is in it

  • crates/xcl/src/gpu/uma.rs (Uma::sparse_reserve):
    • Round size with checked arithmetic (size.max(1).checked_next_multiple_of(GRAIN)?), matching sparse_alloc and sparse_alloc_above.
    • When size <= WINDOW, first attempt take_sparse_in(&mut g, above_0, end, size, GRAIN, true) so single-window title reservations stay inside one window in windows 1+ whenever one has room (placing a ~3.4 GiB Series S arena wholly in window 2 after 664+ MiB of window 1 physical homes).
    • Fall back cleanly to take_sparse_in(&mut g, above_0, end, size, GRAIN, false) and then take_sparse_in(&mut g, lo, end, size, GRAIN, false) so window 0 stays uncluttered for 32-bit descriptor heaps and fragmented or multi-window (> WINDOW) reservations keep working unchanged.
  • crates/xcl/src/gpu/uma.rs (gpu::uma::tests::sparse_reserve_keeps_single_window_reservations_inside_one_window):
    • Reproduces the 3292b096 Series S startup layout (2892 MiB GPU heaps + 38 MiB view heap in window 0, 664 MiB physical homes in window 1) and asserts a 3500 MiB sparse_reserve lands wholly in window 2 (b + 2 * WINDOW) instead of straddling 0x12_0000_0000, smaller 256 MiB reservations reuse window 1's remaining tail, fragmented windows 1+ (2 GiB + 2 GiB across the boundary) still satisfy a 3 GiB reservation via cross-window fallback without touching window 0, and usize::MAX returns None.

Tested

  • Hardware & toolchain: Windows 11 Home (build 26200), Intel Core i5-11400F (6C/12T), 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (32-lane waves, driver 621.14), rustc 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug and release on origin/nvidia-dev (eae01502).
  • Baseline-fail proof on unmodified eae01502 sparse_reserve with only the new test added:
    • cargo test -p xcl --lib -- sparse_reserve_keeps_single_window_reservations_inside_one_window --nocapture --test-threads=1: 0 passed, 1 failed (left: 73710698496 = 0x11_2980_0000 straddling 0x12_0000_0000, right: 77309411328 = 0x12_0000_0000).
  • Fixed (237b7181):
    • cargo clippy --all-targets -- -A clippy::approx_constant: 0 new warnings and 0 errors in crates/xcl/src/gpu/uma.rs (1 pre-existing nvidia-dev clippy error remains in untouched crates/xcl/src/hle/d3d12x/sparse.rs:6393).
    • Debug: 3x cargo test -p xcl --lib -- gpu::uma::tests:: --test-threads=1: 19 passed, 0 failed, 0 ignored (0 skipped); cargo test -p xcl --lib -- physical_homes_leave_window_0_to_the_title --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored (0 skipped).
    • Release: 3x cargo test --release -p xcl --lib -- gpu::uma::tests:: --test-threads=1: 19 passed, 0 failed, 0 ignored (0 skipped); hle::kernelx::tests::: 59 passed, 0 failed, 1 ignored (0 skipped); hle::d3d12x::console_heap::tests::: 19 passed, 0 failed, 0 ignored (0 skipped).
    • cargo build --release --workspace && cargo test --release --workspace --no-fail-fast -- --test-threads=4: 1819 passed, 5 failed, 48 ignored across 39 top-level test targets (30 expected SKIPPED notices: 21 wave64, 3 per-lane refusals, 3 D3D12 debug layer, 2 opt-in/heap-window skips, 1 Windows driver-cache toggle). All 5 failures are pre-existing on origin/nvidia-dev (eae01502) and unrelated to uma.rs: gpu_compute_thread_limits_leave_the_lanes_past_them_out (Tests: the thread limit tests of f9bcafd run on a wave32-only GPU #2854), split_compute_prefers_the_offline_whole_pipeline (Tests: the thread limit tests of f9bcafd run on a wave32-only GPU #2854), console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly (Tests: a console MS in the AS slot is refused by its MS translation #2788), async_compute_pso_registers_real_pso_and_not_standin (Tests: wait for late release before checking released pipelines are gone #2770), and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs.

Regression run
Quiet 60 s release runs (scripts/smoke.ps1 -Seconds 60, XCL_NETWORK=0, default flags, RTX 4060 8 GB, driver 621.14). Includes same-day main ancestor (e120925e) for pr_check.py, freshly measured nvidia-dev target base (eae01502), and PR head (237b7181):

main ancestor (e120925e, same-day baseline for pr_check.py):

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1629 (PresentX 1629)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14025 MB

nvidia-dev target base (eae01502):

xcl-smoke v1
commit: eae015021c639866ab061cdff2e9daf8ba9daac5
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15268 MB

PR (237b7181):

xcl-smoke v1
commit: 237b7181b9b973a781dad8825101f03506237858
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1530 (PresentX 1530)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16362 MB

Not tested

AI use

  • Google Antigravity (Gemini 4 Neon) audited Uma::sparse_reserve and 3292b096 on origin/nvidia-dev (eae01502), implemented the single-window-first placement and unit test, ran the baseline-fail check, clippy, unit/workspace tests, and paired 60 s retail smokes on the hardware above, and drafted this PR description.

After 3292b09 placed physical page homes in windows 1+ first via
`Uma::sparse_alloc_above`, the start of window 1 holds 664+ MiB of
homes on Series S sparse-heap layouts, leaving under 3.35 GiB in
window 1 while window 2 has a full 4 GiB free. Because
`Uma::sparse_reserve` always passed `single_window = false`, a title
reservation of at most one window (for example ~3.4 GiB) straddled the
window 1 / window 2 boundary (0x12_0000_0000) instead of landing
wholly in window 2.

Round `size` with checked arithmetic (`checked_next_multiple_of(GRAIN)?`),
try `take_sparse_in(..., above_0, end, size, GRAIN, true)` first when
`size <= WINDOW`, and fall back to cross-window placement in windows 1+
and then `lo..end` so window 0 stays uncluttered for 32-bit descriptor
heaps and fragmented or multi-window reservations keep working.

Related to xcl-dev#2867.

Assisted-by: Google Antigravity (Gemini 4 Neon)
@joeypercia

Copy link
Copy Markdown
Contributor

@Decodere thanks for the fix. I ran it on the 12 GB card from #2867, where eae01502 crashed 3 of 3 times. With #2886 it still ended in the same window, 2 of 2 runs, so it does not cover what happens here.

Tree: #2867's (nvidia-dev eae01502 + #2794 + two local logging/input commits) with #2886 237b7181 merged, same settings as in #2867 (Series S profile, XCL_UMA_WINDOWS=16, XCL_COHERENT_HEAPS=sparse:1024, XCL_TWO_PASS_MB=3072), RTX 4070 Ti 12 GB, driver 621.40, warm caches.

run end
1 device removed 0x887a0006 at 203.8 s; DRED device state 7 (page fault, no breadcrumbs); the NVIDIA driver logged event 153 and 24 × event 13 at that moment
2 0xc0000005 at 167.5 s in game_scarlett_master.exe+0x4dd64da, read at 0xffffffffffffffff (rcx=0x3f8000003f800000, two floats of 1.0 where a pointer was expected); crash 2 in #2867 was the same read at +0x4dd64ec

So with #2886 the crash in the title still comes, and the other run faults on the GPU instead, at the same stage of the world load. The one run with 3292b096 reverted went to the 900 s cap. That fits your second point (the map_pages home check that only looks at the first and last page) more than the reservation crossing the window boundary, but I have not tested that.

AI use: Claude Code (Claude Opus 5.5) ran the runs on the hardware above, read the logs and wrote this.

@Decodere

Copy link
Copy Markdown
Contributor Author

Thank you @joeypercia for testing #2886 on the 12 GB #2867 setup — really helpful data.

Understood and agreed: #2886 alone does not stop the #2867 crashes, especially with @grahamster2's hardware measurement on #2867 showing Window 2 left only 3,911 MB contiguous vs the title's 3,977 MB MEM_64K_PAGES pool spilling into plain memory.

Keeping #2886 scoped strictly to Uma::sparse_reserve preventing <= 4 GiB reservations from straddling window boundaries when a clean single window exists (Related to #2867, not closing #2867), while leaving the Window 0 / top-down home placement fix to @grahamster2's #2867 PR.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…m, pure std)

Upstream single-commit 7575f67 on 8b957be: 1 file shaders.rs +38/-2.
Helper + 2 direct_sweep call-site swaps + regression test, hunk bodies
identical (only line offset from linux-only helpers). xcl-dev#2909/xcl-dev#2910 SKIP
(hle/d3d12x/real.rs, Windows-only); xcl-dev#2906 SKIP (dev-stack tip, same
shape as xcl-dev#2886); xcl-dev#2889 re-pinned f334cc9 (force-push, still SKIP).
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.

2 participants