GPU: a pipeline library save the host has no memory for waits, not aborts (1.7 GB library on NVIDIA) #2005

Merged
KevinPratap merged 1 commit from upstream-pr/2007 into main 2026-11-25 21:53:05 +00:00
KevinPratap commented 2026-11-25 02:48:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KevinPratap on 2026-11-25T02:48:41Z.


Problem

library::save serialises the pipeline library with vec![0u8; GetSerializedSize()]. On NVIDIA the library holds each pipeline's machine code: after translate --cache --pipelines it is about 1.7 GB on an RTX 4050 Laptop, where the README mentions about 4 MB on AMD. A save in the world then aborted the whole process:

memory allocation of 2650101862 bytes failed

(32 GB RAM, about 21 GB committed by the process at that point.)

Fix

The buffer is reserved with try_reserve_exact. Without memory, the save logs a warning and returns. The pipelines stay counted as added, so the next save tries again.

Verified

  • New test a_save_buffer_the_host_cannot_give_is_refused; the pipeline::library tests pass (9).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings is clean.

Related: the size itself (one blob rewritten whole every 20 s) is worth splitting on NVIDIA, but that is a larger change.

Only crates/victory-gpu/src/pipeline/library.rs changes.

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6596050627 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2007). Originally posted by [KevinPratap](https://github.com/KevinPratap) on 2026-11-25T02:48:41Z. --- ## Problem `library::save` serialises the pipeline library with `vec![0u8; GetSerializedSize()]`. On NVIDIA the library holds each pipeline's machine code: after `translate --cache --pipelines` it is about **1.7 GB** on an RTX 4050 Laptop, where the README mentions about 4 MB on AMD. A save in the world then aborted the whole process: ``` memory allocation of 2650101862 bytes failed ``` (32 GB RAM, about 21 GB committed by the process at that point.) ## Fix The buffer is reserved with `try_reserve_exact`. Without memory, the save logs a warning and returns. The pipelines stay counted as added, so the next save tries again. ## Verified - New test `a_save_buffer_the_host_cannot_give_is_refused`; the `pipeline::library` tests pass (9). - `cargo clippy -p victory-gpu --all-targets -- -D warnings` is clean. Related: the size itself (one blob rewritten whole every 20 s) is worth splitting on NVIDIA, but that is a larger change. Only `crates/victory-gpu/src/pipeline/library.rs` changes. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-25 04:06:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:33:10Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Pipeline-library save with insufficient host memory waits instead of aborting — OOM-path hardening; correct fail-slow behavior for an emulator.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051461156 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2007#pullrequestreview-6051461156). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:33:10Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Pipeline-library save with insufficient host memory waits instead of aborting — OOM-path hardening; correct fail-slow behavior for an emulator.
jeremygold02 commented 2026-11-25 04:06:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:35:51Z.


Triage verdict — Keep the fallible allocation; preserve early-list retries (54b994d)

Evidence

  • The reservation failure now returns without aborting. There is one save path where leaving l.added intact is insufficient. When l.added == 0, prebuilt_changed is false, and the early list alone is dirty, the entry check consumes USED_CHANGED with swap(false, …) before calling zeroed. The new failure return leaves no dirty flag for a later retry. The existing serializer-error path has the same bookkeeping gap.

Checks and limits

  • The allocation helper test covers rejecting an unallocatable size and producing zero bytes for a small size. It does not go through save with only the early list dirty. The exact-head Windows check passed. I reviewed the source and CI without inducing host memory pressure.

Next step

  • Retain or restore the early-list dirty state when an allocation or serialization failure interrupts a save, without overwriting concurrent usage updates. A synthetic failed allocation with no new pipelines, followed by a successful retry, would pin the behavior. #72’s retry bookkeeping is a useful comparator for the broader save path.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152062533 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2007#issuecomment-7152062533). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T03:35:51Z. --- **Triage verdict — Keep the fallible allocation; preserve early-list retries** (`54b994d`) **Evidence** - The reservation failure now returns without aborting. There is one save path where leaving `l.added` intact is insufficient. When `l.added == 0`, `prebuilt_changed` is false, and the early list alone is dirty, the entry check consumes `USED_CHANGED` with `swap(false, …)` before calling `zeroed`. The new failure return leaves no dirty flag for a later retry. The existing serializer-error path has the same bookkeeping gap. **Checks and limits** - The allocation helper test covers rejecting an unallocatable size and producing zero bytes for a small size. It does not go through `save` with only the early list dirty. The [exact-head Windows check](https://github.com/Marvisak/VIctory/actions/runs/45535587136/job/138941267116) passed. I reviewed the source and CI without inducing host memory pressure. **Next step** - Retain or restore the early-list dirty state when an allocation or serialization failure interrupts a save, without overwriting concurrent usage updates. A synthetic failed allocation with no new pipelines, followed by a successful retry, would pin the behavior. #72’s retry bookkeeping is a useful comparator for the broader save path. This verification was AI-assisted.
Marvisak commented 2026-11-25 10:07:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:16:55Z.


Automated triage for the maintainers.

Merge candidate.

crates/victory-gpu/src/pipeline/library.rs::save now allocates the serialisation buffer with try_reserve_exact (new helper zeroed) instead of vec[0u8; GetSerializedSize()], so a library too large for the host's free memory logs a warning and is retried on a later save instead of aborting the process. l.added/prebuilt_changed are left untouched on that path, so the retry does happen; on Windows the allocator reports failure rather than overcommitting, so try_reserve_exact is the right tool here. Small, focused, merges cleanly.

Optional follow-up, also raised in the earlier review comment: when only the early list is dirty, USED_CHANGED has already been swapped to false before the allocation, so a failed allocation (like the existing serialiser-error path) drops that pending early-list save until something else changes; restoring the flag on both failure returns would close that. #2129 contains the same fallible helper inside a much larger rework of the library file; this PR is the smaller way to land just the abort fix. Recommending a look, not approving.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158119598 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2007#issuecomment-7158119598). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:16:55Z. --- <!-- victory-triage v1 head=54b994d172fbce85cb2e76fb10e4b901051efb4b verdict=merge-candidate at=2026-11-25T09:16:48Z --> Automated triage for the maintainers. **Merge candidate.** `crates/victory-gpu/src/pipeline/library.rs::save` now allocates the serialisation buffer with `try_reserve_exact` (new helper `zeroed`) instead of `vec[0u8; GetSerializedSize()]`, so a library too large for the host's free memory logs a warning and is retried on a later save instead of aborting the process. `l.added`/`prebuilt_changed` are left untouched on that path, so the retry does happen; on Windows the allocator reports failure rather than overcommitting, so `try_reserve_exact` is the right tool here. Small, focused, merges cleanly. Optional follow-up, also raised in the earlier review comment: when only the early list is dirty, `USED_CHANGED` has already been swapped to `false` before the allocation, so a failed allocation (like the existing serialiser-error path) drops that pending early-list save until something else changes; restoring the flag on both failure returns would close that. #2129 contains the same fallible helper inside a much larger rework of the library file; this PR is the smaller way to land just the abort fix. Recommending a look, not approving. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 22:03:19 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2005
No description provided.