Subtraction, Simplicity & Conventions review — PR #669
Key findings
Verdict first. This diff introduces no new flags, environment switches, config knobs, or extension points — nothing of the "speculative generality" kind. The new named attribute constants (helios/src/runtime_core/driver.rs:14-19) are a net simplification over the magic integers that previously appeared inline; adding 91/99/134/141 to that set is the right move and should not be reverted. The cost is elsewhere: roughly 120 of the +417 net lines are removable duplication, one dead fallback branch, and unreachable re-validation, and the single capability decision is spread across four places (Rust allocator, Rust runtime, Python snapshot, Python region) where one would do. Five findings, all non-blocking in the strict "simplicity" sense, ordered by size.
- (high)
host::use_host_vmmshould own its attribute queries — two call sites duplicate the same 20-line query to feed it; the unit test restates the function body. ~45 lines. - (high) Delete the
HOST_NUMA_VMM == 0fallback instead of re-checking attribute 141 in Python — the allocator has two identicalelsearms and a divergent state (host_vmm=truewith no VMM support), which forces a third check per region in Python plus its test. ~25 lines. - (medium)
vmm_host_windowis a parallel copy ofwindow_host_layout's placement logic — two functions, two tests, one contract. ~57 lines collapsible. - (medium) Unreachable re-validation and a duplicated
EXTERNAL_FLOORin Rust — a power-of-two granule check that cannot fire, two redundantusizeguards, and a second copy of a Python constant inferred by a hardcoded address heuristic. ~15 lines. - (low) Prose budget went to the wrong file, and the rename kept no alias — the design doc grew attribute-level implementation detail while four places that now state the opposite of the new behaviour were left untouched.
Where a workaround exists only because of an unreachable or divergent branch (findings 2 and 4), the recommendation below is to delete the branch, not patch it.
1. (high) Fold the 99/91 queries into host::use_host_vmm; delete the tautological test
helios/src/runtime_core/host.rs:12-18:
pub fn use_host_vmm(
windows: bool,
host_register_supported: bool,
can_use_host_pointer: bool,
) -> bool {
windows || !host_register_supported || !can_use_host_pointer
}
The helper is a three-argument boolean expression, but neither caller has those booleans: both run the same two cuDeviceGetAttribute blocks first.
Caller A — helios/src/runtime_core/mod.rs:364-386 (~23 lines):
let mut host_register_supported = 1;
driver.check(
"cuDeviceGetAttribute(HOST_REGISTER_SUPPORTED)",
(driver.device_attribute)(
&mut host_register_supported,
driver::CU_DEVICE_ATTRIBUTE_HOST_REGISTER_SUPPORTED,
device,
),
)?;
...
let host_vmm = host::use_host_vmm(
cfg!(windows),
host_register_supported != 0,
can_use_host_pointer != 0,
);
Caller B — heliopause/src/allocator.rs:465-480 repeats the identical two checks, and they force the init tuple to grow from four elements to six (allocator.rs:448-455):
let (
mut address,
mut granularity,
mut gpudirect,
mut integrated,
mut host_register,
mut can_use_host_pointer,
) = (0, 0, 0, 0, 1, 1);
host.rs already owns host_numa_properties(driver, device) (host.rs:57-98), which does exactly this kind of query, so it is the natural home for the sibling. Replace with pub unsafe fn use_host_vmm(driver: &driver::Driver, device: i32) -> Result<bool> that performs the two queries itself and returns cfg!(windows) || host_register == 0 || can_use_host_pointer == 0. Then:
mod.rs:364-386collapses tolet host_vmm = host::use_host_vmm(&driver, device)?;- the
allocator.rstuple returns to(address, granularity, gpudirect, integrated) = (0, 0, 0, 0)and lines:465-480disappear, leaving:511-515as one call.
~45 lines net removed, and cfg!(windows) stops being a runtime parameter threaded through a library API — the platform check belongs inside the module that documents the WDDM rule. That also fixes the inconsistency where helios and heliopause each decide independently whether they are on Windows.
Also delete helios/src/runtime_core/host.rs:202-221:
#[test]
fn host_vmm_dispatch_requires_both_host_register_and_host_pointer() {
use super::super::driver;
assert_eq!(driver::CU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM, 91);
assert_eq!(driver::CU_DEVICE_ATTRIBUTE_HOST_REGISTER_SUPPORTED, 99);
...
assert_eq!(
use_host_vmm(windows, host_reg, host_ptr),
windows || !host_reg || !host_ptr,
The loop asserts that the function equals a copy of its own body — it cannot fail unless the same edit is made twice — and the four assert_eq! lines merely restate the constant definitions in driver.rs:14-19. With the query folded in there is nothing left to unit-test here without a driver; the behaviour is covered end-to-end. (Note this is distinct from the good unit tests in the same module, host.rs:180-200, which exercise non-trivial rounding/merging logic — those should stay.)
2. (high) Delete the HOST_NUMA_VMM == 0 fallback instead of re-checking 141 per region in Python
heliopause/src/allocator.rs:518-561 has two structurally identical else arms; the inner one is dead weight that also leaves the arena in a state that is false:
let (host_base, host_extent) = if !cfg!(windows) && host_vmm {
if let Some((_, host_granularity)) = host::host_numa_properties(&driver, device)? {
...
} else {
(default_host_base, default_host_extent)
}
} else {
(default_host_base, default_host_extent)
};
When a device reports 99 == 0 or 91 == 0 and 141 == 0, the code keeps "host_vmm": true in the snapshot (allocator.rs:863) with an ordinary non-VMM host window, and the failure only surfaces later in Python. That divergent state is what forces the third capability check on the Python side, ignition/preparation/core_storage.py:499-502:
supported = C.c_int()
cuda.call("cuDeviceGetAttribute", C.byref(supported), C.c_int(141), C.c_int(device))
if not supported.value:
raise RuntimeError("mapped core storage requires host-backed CUDA VMM")
Replace the two arms with one error path (this is the "delete the workaround, don't patch it" case — the Correctness lens owns the capability-hole framing; from the simplicity lens the point is that the branch has no valid outcome):
let properties = (!cfg!(windows) && host_vmm)
.then(|| host::host_numa_properties(&driver, device))
.transpose()?
.flatten();
…errored when host_vmm is true on Unix and properties is None, and using (default_host_base, default_host_extent) otherwise. That removes one branch and one reachable-but-useless arena state; then the Python re-query at core_storage.py:499-502 is dead and should be deleted, together with tests/preparation/test_core_storage.py:130-139 (test_host_vmm_region_requires_host_numa_vmm), and the two imports the PR pushed below the new check (core_storage.py:503-504) can move back to the top of __init__ beside HostRegion.__init__ (core_storage.py:438-439):
import torch
from b12x.sequence import tensor_from_pointer as _tensor_from_pointer
The decision then lives in exactly one place — the native allocator — which is the PR's own stated aim ("single source of truth"). The duplicated error string "mapped core storage requires host-backed CUDA VMM" currently appears in two languages (helios/src/runtime_core/host.rs:115-116 and core_storage.py:502); deleting the Python one leaves one.
3. (medium) vmm_host_window is a second copy of window_host_layout's placement algorithm
allocator.rs:320-347 already places a host window immediately after the device windows, granule-aligned and inside the aperture:
let aligned_start = if granule > 1 {
device_end
.checked_add(granule - 1)
.map(|n| n & !(granule - 1))
} else {
Some(device_end)
};
vmm_host_window (allocator.rs:361-418) repeats that same "aligned after the device span" computation almost verbatim (allocator.rs:405-413):
if let Some(after) = base
.checked_add(device_span)
.and_then(|end| end.checked_add(window_align - 1))
.map(|n| n & !(window_align - 1))
&& after.checked_add(total).is_some()
&& can_reserve(after, total)?
{
return Ok((after, per_rank));
}
It also repeats the "prefer the default, otherwise fall back" skeleton. Two functions now own overlapping contracts, and two tests assert overlapping invariants: window_host_layout_narrows_wddm_host_window (allocator.rs:~1570-1587) and the new vmm_host_window_respects_aperture_floor_and_rank_count (allocator.rs:1589-1637).
Suggested collapse: give window_host_layout the two ingredients vmm_host_window actually adds — a can_reserve: impl FnMut(u64, u64) -> Result<bool> candidate probe and a min_host_base low floor — and let it run the single ordered search: validate the aperture → try the default span → try before base at/above the floor → try after device_end → error. For the WDDM and non-VMM callers, pass |_, _| Ok(true) and the existing floor, which preserves today's behaviour exactly. That deletes vmm_host_window (~57 lines), its #[allow(clippy::too_many_arguments)] (allocator.rs:366) and the eight-positional-argument call site at allocator.rs:531-555, and leaves one test that must cover the whole "where does host storage go" contract.
If a full merge is judged too invasive for review, at minimum remove the attribute at :366 by passing (base, extent, world) alongside a small Defaults { base, extent } struct and the closure — eight bare u64/u32 positional arguments at :531-555 are not reviewable.
4. (medium) Unreachable re-validation, and a Python constant restated in Rust
(a) allocator.rs:377-381 cannot fire:
if !granule.is_power_of_two() {
return Err(invalid(format!(
"invalid host allocation granularity {granule:#x}"
)));
}
Its argument is granule.max(host_granularity as u64) (allocator.rs:520). host_numa_properties already rejects a non-power-of-two host granularity (helios/src/runtime_core/host.rs:91-95), and allocator.rs:495-502 already rejects a non-power-of-two device granule (this PR tightened it from granule != 0 to granule.is_power_of_two()). The only caller that can reach it is the unit test feeding 0 and 3 << 20 (allocator.rs:1633-1634) — impossible inputs. Delete the check and those two asserts; keep the validation in host.rs, where the value originates.
(b) Two redundant width guards over the same value — allocator.rs:521-525 and :540-542:
let host_align = usize::try_from(host_granule).map_err(|_| {
invalid(format!(
"invalid host CUDA allocation granularity {host_granule:#x}"
))
})?;
let Ok(len) = usize::try_from(bytes) else {
return Ok(false);
};
host_granularity is already a usize coming out of host_numa_properties, so host_granule: u64 cannot exceed usize; the usize::try_from(bytes) guard sits inside a closure on a length this same code just bounded by the aperture. Both can go, along with the plumbing the closure needs to convert back.
(c) EXTERNAL_FLOOR duplicated in Rust with a heuristic to guess which value applies — allocator.rs:526-530:
let min_host_base = if integrated != 0 && base < 0x40_0000_0000 {
0x3_0000_0000
} else {
0x40_0000_0000
};
These are ignition's EXTERNAL_FLOOR values restated: 0x4000000000 at ignition/preparation/core_storage.py:42, overridden to 0x300000000 for SM87 at :69. The Rust side infers which one applies from the address itself (base < 0x40_0000_0000) rather than being told. Two copies of a security-relevant floor, one of them guessed, is precisely what the charter's "Be explicit and pin everything. No magic defaults" rules out. Since the caller already knows the floor, pass it: flare_core_initialize_window(rank, world, device, *window) is the only entry point (core_storage.py:94-96), so a min_host_base argument (or reading it off the shipped window contract) keeps one definition.
5. (low) Prose budget and the rename
The WindowsHostRegion → HostVmmRegion rename (core_storage.py:492) kept no alias. Only in-repo reference was core_storage.py:356 (now region_type = HostVmmRegion if self._host_vmm else HostRegion), so it is self-consistent and a one-line WindowsHostRegion = HostVmmRegion is not needed in-repo — flag as an out-of-tree risk only, not a blocker.
The larger prose point: docs/runtime-core-design.md:104-113 gained attribute-level implementation detail (which attributes are queried, in what order), while four places that now say the opposite of the new behaviour were left untouched:
docs/windows.md:212-217— "Linux registers host pages for mapped graph storage. Windows uses host-backed CUDA VMM …"docs/prefix-cache-offload.md:588-590— "On hosts whereHOST_NUMAvirtual memory allocation is unsupported (such as Windows WDDM and integrated Tegra/GA10B GPUs)…"helios/src/cuda.rs:552-557—is_host_numa_unsupportedcomment naming "Windows WDDM and integrated Tegra/GA10B GPUs"selene/src/offload.rs:693-695— same claim ("such as GA10B or Windows")
Per AGENTS.md:57-58, stale-versus-code statements are recorded defects, not something to leave contradicted in design docs. These are three one-line edits; the design doc should state the contract ("the native allocator selects and reports the host backing mode"), not the attribute numbers.
Also worth one sentence (mention, not a blocker)
helios/src/runtime_core/mod.rs:22 widens #[cfg(any(windows, test))] mod host to pub mod host, making pub unsafe fn host_numa_properties and pub fn use_host_vmm permanent public runtime API — needed so heliopause can share the helper, but undeclared in the PR description. pub(crate) plus a deliberate re-export, or a module named for sharing, would keep the surface honest.
Open questions / not found
- Whether
#658's "128 GiB GA10B VMM window" and this PR's measured96.56 GiBceiling on Orin Nano are the same board dimension (8 GiB Nano vs 64 GiB AGX). Not resolvable from the repo; relevant because both PRs rewritecore_storage.py:66-71in opposite directions. - Whether any out-of-tree recipe or test imports
WindowsHostRegion; the rename has no alias and no in-repo consumer beyondcore_storage.py:356. - Whether the
pub mod hostwidening is intended as supported public API or should bepub(crate). - No run logs back the Orin/Thor end-to-end claims; the replay path used (
helios/tests/fixed_core_fixture.py:111(not opened) →event_tests.rs(not opened)) is#[ignore]d and requiresFLARE_EVENT_TEST_CORE, so CI cannot reproduce them (evidence question, not a simplicity one).