Final review report · NVIDIA/hyperflare-inference #659

Raw Markdown for agents: https://autobot.eidonix.com/p/da28119d-e9a4-4905-8bef-be3caabbcea4.md

Recommendation: Changes Requested

The core design and arithmetic are sound, model-agnostic, and well-scoped to shared cache-planning and VMM-allocation code (helios/src/runtime_core/cache_memory.rs, memory.rs). However, two concrete issues block merge: (1) the new CUDA VMM multi-aliasing and split-zeroing code in NativeResources::allocate_shared_cache has zero executed coverage on a GPU (including the modified GPU test) and no live-core verification, and (2) an existing in-repo GPU offload test writes and round-trips a distinct pattern through StateSlotId(0) and will fail on any continuation-state core where this optimization activates. Two clean subtractive refactors would also eliminate ~70 lines of duplicated logic.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. New CUDA VMM multi-aliasing and split-zeroing path is completely unexecuted on GPU (helios/src/runtime_core/cache_memory.rs:1106-1283, :1416-1488).

    • Verified behavior/impact: The only code that performs the multi-offset cuMemMap and split cuMemsetD8_v2 lives in NativeResources::allocate_shared_cache (:1416-1488). The new CPU unit tests only verify sentinel_saved_bytes, Layout::new, handle_charge, and capacities. The sole test covering allocate_shared_cache — cuda_aliases_preserve_rows_while_unowned_pages_are_rewritten (:1106-1283, which exercises both sentinel_granules == 0 at 3 * alignment / 2 and sentinel_granules == 3 at 7 * alignment / 2) — was modified and skipped ("all local GPUs were occupied"). Both docs/verification.md:14 (CUDA ordering / inactive rows / allocation stability require real GPU execution) and docs/design-review.md:106-115 (principle 12: validate the real path and back performance/memory claims with actual Helios measurements) apply directly here, especially given prior Blackwell driver cuMemMap aliasing constraints (cache_memory.rs:218-220).
    • Fix: Run cuda_aliases_preserve_rows_while_unowned_pages_are_rewritten on an assigned GPU against 16e2247 (and ideally verify in the equal_planes == true branch that row 0's leading granules stay zero while row 0's partial tail [sentinel_bytes, row_bytes) is independently backed from row 1), and report a before/after Plan cache / Allocate cache (or VRAM) reading from loading a real continuation-state core with row_bytes >= 2 * alignment.
  2. Existing GPU offload test writes and round-trips StateSlotId(0), breaking on affected cores (helios/src/offload/gpu_tests.rs:1476-1525, :1730-1804).

    • Verified behavior/impact: staged_store_round_trips_records_through_files_and_a_restart binds child_slot = StateSlotId(0) (:1478), uploads a distinct pseudo-random pattern across rank.row.unit_bytes into row 0 (:1519-1525), stores it to disk (:1730-1739), restores it into StateSlotId(2) (:1780-1790), and asserts byte-for-byte equality with the original pattern (:1798-1804). On any continuation-state core with row_bytes >= 2 * alignment, uploading to row 0 overwrites the single shared physical granule sentinel_granules times, so granules 0..sentinel_granules - 1 read back as copies of the last aliased granule and the test fails at :1800-1804.
    • Fix: Change child_slot at helios/src/offload/gpu_tests.rs:1478 to a nonzero slot (e.g. StateSlotId(4), adjusting the row_capacity assert at :1467 from >= 4 to >= 5).

Should Fix

  1. Enforce the non-zero row invariant in Helios's offload transfer layer (helios/src/offload/transfer.rs:156-163).

    • Verified behavior/impact: helios/src/offload/transfer.rs:156-163 only checks index >= geometry.row_capacity and accepts StateSlotId(0) for both inbound and outbound transfers. Now that row 0 is aliased onto one shared physical granule, an inbound transfer targeting slot 0 silently corrupts all sentinel_granules offsets simultaneously rather than affecting a single region. Production scheduling never allocates slot 0 (helios/src/scheduler.rs:946-948, 1753).
    • Fix: Reject index == 0 alongside index >= geometry.row_capacity at helios/src/offload/transfer.rs:156-163 (and update the two synthetic unit tests in helios/src/offload/transfer/codec.rs:1098, 1344 that pass StateSlotId(0) over standalone mapped host buffers to use StateSlotId(1) / a 3-row geometry).
  2. Guard Layout::grouped against execution == 0 and note the handle-margin trade-off in the PR description (helios/src/runtime_core/cache_memory.rs:259-262).

    • Verified behavior/impact: In Layout::grouped (:157, 259-262), sentinel_granules is computed solely from row_bytes / row_alignment without checking execution > 0 (or fixed_bytes >= n * row_alignment). While production capacities() guarantees execution >= 2 (memory.rs:459), Layout::new is callable directly and execution == 0 would leave fixed_bytes = 0 < sentinel_bytes. Separately, while the PR description mentions the 518,232 -> 518,504 test update, it omits explaining the handle-headroom cost (+17 handles/rank on DCP16, shrinking RM_HANDLE_RANGE headroom from 1.2% to 1.1%, and scaling by row_readers if state_pool ever has peer readers).
    • Fix: Compute sentinel_granules as if execution > 0 && row_bytes / row_alignment > 1 { row_bytes / row_alignment } else { 0 } (ensuring sentinel_bytes <= fixed_bytes by construction), and add one sentence to the PR description noting the RM-handle trade-off.

Subtract / Simplify

  1. Collapse row_backing_bytes onto bytes(core, 0, units) (helios/src/runtime_core/memory.rs:385-414 vs :357-381).

    • row_backing_bytes duplicates the exact capacity filter, units > s.maximum check, checked multiplication, alignment rounding, overflow errors, and try_fold from bytes. Calling let span = bytes(core, 0, units)?; first guarantees both validation and that sum(sentinel_saved_bytes) <= span (so neither summation overflow nor subtraction underflow is possible):
      fn row_backing_bytes(core: &Core, units: u64) -> Result<u64> {
          let span = bytes(core, 0, units)?;
          if units == 0 {
              return Ok(span);
          }
          let saved: u64 = core
              .allocations
              .iter()
              .filter_map(|a| a.sizing.as_ref().filter(|s| s.capacity == 0).map(|s| (a, s)))
              .map(|(a, s)| super::cache_memory::sentinel_saved_bytes(s.unit_bytes, a.alignment as u64))
              .sum();
          Ok(span - saved)
      }
      
    • Deletes ~20 lines of verbatim duplication and ensures virtual-span and physical-backing calculations share a single validation/rounding implementation.
  2. Describe the fixed-chunk split once on Layout (helios/src/runtime_core/cache_memory.rs:82-102, :1416-1447, :1468-1488).

    • handle_charge, allocate_shared_cache mapping, and allocate_shared_cache zeroing each repeat the same sentinel_granules > 1 / fixed_bytes > sentinel_bytes branching. A single helper on Layout:
      fn fixed_segments(&self) -> (u64, u64, u64) {
          let count = self.sentinel_granules.max(1);
          let granule = if count > 1 { self.alignment } else { self.fixed_bytes };
          (count, granule, self.fixed_bytes - granule * count)
      }
      
      eliminates both else branches in allocate_shared_cache (:1438-1447, :1483-1488) and collapses handle_charge (:82-102) into one checked expression (1u64.checked_add(count * row_readers) plus 1 + row_readers when tail > 0), removing ~50 lines of repeated branching and guaranteeing handle accounting, mapping, and zeroing cannot drift.

Nits

Dropped on verification