Skip to content

helios: trim trailing VMM reservation slack on CUDA_ERROR_INVALID_VALUE - #73

Draft
FujitsuPolycom wants to merge 1 commit into
mainfrom
jetson/pr-a-vmm-reservation-slack-trim
Draft

FujitsuPolycom wants to merge 1 commit into
mainfrom
jetson/pr-a-vmm-reservation-slack-trim

Conversation

@FujitsuPolycom

@FujitsuPolycom FujitsuPolycom commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Why

Prepared model cores align fixed virtual-memory reservations to coarse boundaries (typically GiB-rounded spans) that include unallocated trailing padding beyond the highest declared device allocation. On integrated GPUs whose kernel or firmware configuration exposes a slightly tighter CUDA VMM virtual-address ceiling than the host that exported the core (for example, stock QSPI boot firmware on JetPack 7.2.2 on Jetson Orin Nano 8 GB at ~95.83 GiB vs. a 96.0 GiB reservation end), cuMemAddressReserve fails with CUDA_ERROR_INVALID_VALUE even though every fixed and runtime-sized device allocation in the core fits inside the device's address space.

Trimming only the unallocated trailing slack—after the full reservation fails with CUDA_ERROR_INVALID_VALUE, rounded up to the device's live cuMemGetAllocationGranularity—lets existing signed cores load without re-exporting or relaxing any address-overlap, mapping, or teardown invariants.

What changed

Before this change, NativeResources::reserve issued a single cuMemAddressReserve for reservation.nbytes and failed immediately on CUDA_ERROR_INVALID_VALUE.

  • helios/src/runtime_core/driver.rs:
    • Before: CUDA_ERROR_INVALID_VALUE was not declared alongside CUDA_ERROR_NOT_READY and CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE.
    • After: Adds pub const CUDA_ERROR_INVALID_VALUE: c_int = 1.
  • helios/src/runtime_core/mod.rs & helios/src/runtime_core/model.rs:
    • Before: NativeResources::reserve(&mut self, core: &Core) always requested reservation.nbytes and only saw cores[0] during multi-rank loading in NativeModel::load.
    • After: Adds private unsafe fn reserve_for(&mut self, cores: &[Core]) (called by NativeModel::load with all ranks &cores, while NativeResources::reserve(&mut self, core: &Core) delegates to it for single-rank callers). When cuMemAddressReserve returns CUDA_ERROR_INVALID_VALUE, reserve_for queries cuMemGetAllocationGranularity (CU_MEM_ALLOC_GRANULARITY_MINIMUM) for the target device, computes trimmed_reservation_bytes across every rank's Memory::Device allocations inside [reservation.address, reservation.address + reservation.nbytes) using Allocation::extent() (covering both fixed and maximum runtime-sized extents) rounded up via usize::checked_next_multiple_of(granularity), and retries cuMemAddressReserve only when 0 < trimmed < reservation.nbytes.
    • Resource lifetime & safety: self.reservations.push((address, reserved_bytes)) records the actual reserved length before checking address != reservation.address, so release_reservations_and_context always passes the exact reserved size to cuMemAddressFree. No unsafe invariants change and no physical memory is allocated.
    • Cross-architecture portability: Querying live cuMemGetAllocationGranularity avoids assuming a hardcoded 2 MiB granule on 4 KiB or 64 KiB page hosts. On Windows (#[cfg(windows)]) and host_vmm Linux devices, address_space::check_fits continues to guard virtual-address width first and Memory::MappedHost remains managed separately by allocate_host.
    • Unit tests (helios/src/runtime_core/mod.rs): Adds CPU tests for trimmed_reservation_bytes covering trailing slack trimming, runtime-sized Sizing extents, multi-rank merged reservations where a secondary rank holds the highest device address, ignored MappedHost/Peer/unaddressed/before-window/at-window-end/external allocations, granularity == 0, no-slack boundary, reservation with no device allocations, and address overflow.
  • Compatibility & defaults: No core format, Protobuf, or default behavior change. On GPUs where the full reservation succeeds, the retry branch never runs. Existing signed cores load without re-export or re-signing.

Claimed benefit and result

  • Expected compatibility win (not yet GPU-verified on ccd6460b): Unblocks loading unmodified signed cores whose GiB-rounded trailing reservation slack overhangs a tighter integrated-GPU VMM ceiling (such as stock QSPI boot firmware on JetPack 7.2.2 on Jetson Orin Nano 8 GB) without re-exporting.
  • Performance impact: Expected zero steady-state runtime overhead; the fallback executes only once at startup if the initial cuMemAddressReserve fails. No serving throughput benchmark is claimed.

Supporting evidence and limitations

Tested on clean git archive ccd6460bf8088715c2026996d2498291dcbfb87b atop NVIDIA/hyperflare-inference main (7bbc6707792aa1cb8633794ee189b7592091cc45):

  • Layer 1 — CPU crate & boundary tests (passed on ccd6460bf8088715c2026996d2498291dcbfb87b):
    • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server (with FLARE_TEST_TEMPLATE_DIR prepared via tests/frontend/prepare_templates.py): 1,920 passed; 0 failed; 49 ignored (lib, including all 3 new runtime_core::tests::trimmed_reservation_bytes_* tests) and 62 passed; 0 failed; 36 ignored across integration tests (85 ignored tests require external model checkpoint snapshots or GPU hardware).
    • CUDA_VISIBLE_DEVICES="" pytest tests/preparation/test_core_boundary.py -v: 4 passed.
    • Layers 2 and 3 (scheduling simulator, TLA+, Kani) do not apply because scheduling, admission, speculation, cache ownership, and completion contracts are unchanged.
  • Unrun GPU checks & limitations (required before Ready / upstream):
    • Live GPU verification of the CUDA_ERROR_INVALID_VALUE retry and cuMemAddressFree teardown path on ccd6460bf8088715c2026996d2498291dcbfb87b has not yet been run (single-rank SM87 Jetson Orin Nano with stock QSPI boot firmware, multi-rank TP > 1, SM103/SM120/SM121, 64 KiB page systems, and Windows WDDM are covered by CPU unit tests and code audit rather than live GPU fault injection).

Discord: Dooner

Prepared model cores align fixed virtual-memory reservations to coarse
boundaries that can include unallocated trailing padding beyond the
highest declared device allocation. On integrated GPUs whose kernel or
firmware exposes a slightly tighter CUDA VMM ceiling than the exporting
host (for example, stock QSPI boot firmware on JetPack 7.2.2 on Jetson
Orin Nano 8 GB at ~95.83 GiB vs. a 96.0 GiB reservation end),
cuMemAddressReserve fails with CUDA_ERROR_INVALID_VALUE even though
every fixed and runtime-sized allocation fits.

- helios/src/runtime_core/driver.rs:
  - Before: CUDA_ERROR_INVALID_VALUE was not defined as a named constant.
  - After: adds pub const CUDA_ERROR_INVALID_VALUE: c_int = 1.
- helios/src/runtime_core/mod.rs & model.rs:
  - Before: NativeResources::reserve requested reservation.nbytes once
    and only received cores[0] in NativeModel::load.
  - After: adds private unsafe fn NativeResources::reserve_for(&mut self,
    cores: &[Core]) and trimmed_reservation_bytes (using
    usize::checked_next_multiple_of). On CUDA_ERROR_INVALID_VALUE, it
    queries cuMemGetAllocationGranularity (CU_MEM_ALLOC_GRANULARITY_MINIMUM),
    computes the granule-aligned span covering every rank's Memory::Device
    fixed and maximum runtime-sized extents inside the reservation, and
    retries cuMemAddressReserve only when 0 < trimmed < reservation.nbytes.
    self.reservations records the actual reserved length so teardown frees
    the exact span. Adds CPU unit tests for trimmed_reservation_bytes.
- Compatibility: zero behavior change when the full reservation succeeds;
  existing signed cores load without re-export or re-signing.

Result:
- Expected to unblock loading unmodified signed cores whose coarse
  trailing reservation slack overhangs a tighter integrated-GPU VMM
  ceiling, with zero steady-state runtime overhead.

Evidence:
- Verified on clean git archive via cargo test --locked --release
  --manifest-path helios/Cargo.toml --features runtime-core,server and
  CUDA_VISIBLE_DEVICES="" pytest tests/preparation/test_core_boundary.py.
- Limitations: live GPU verification of the retry and cuMemAddressFree
  teardown path on this candidate commit (single-rank SM87, multi-rank
  TP > 1, SM103/SM120/SM121, 64 KiB pages, and Windows WDDM) remains
  unrun.

Discord: Dooner

Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: Dooner <dooner@users.noreply.github.com>
@FujitsuPolycom
FujitsuPolycom force-pushed the jetson/pr-a-vmm-reservation-slack-trim branch from 5597325 to ccd6460 Compare December 4, 2026 21:57
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