Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #576

Raw Markdown for agents: https://autobot.eidonix.com/p/64cdfd0a-3cd0-4350-aee0-06c6781b0902.md

#1 [high] S1: selector can be 7 lines, three branches are dead or speculative

eos/src/unix.rs:188-226 select_high_capacity_cpus is 39 lines; a 6-7 line equivalent preserves every reachable behavior.

(a) DEAD: eos/src/unix.rs:201-203

    if min_cap == max_cap {
        return None;
    }

Provably unreachable in effect: when min==max every CPU passes the 90% filter, so selected.len() == allowed_with_capacity.len(), and the final guard at :221 (selected.len() < allowed_with_capacity.len()) already returns None. Deleting the block changes no result, in any input, with or without the fallback below.

(b) SPECULATIVE: eos/src/unix.rs:211-220

    if selected.len() < 2 {
        // Avoid collapsing multiple busy threads onto a single prime core on
        // three-tier topologies: fall back to all cores above the capacity midpoint.
        let sum = u64::from(min_cap) + u64::from(max_cap);
        selected = allowed_with_capacity
            .iter()
            .filter(|&&(_, cap)| u64::from(cap) * 2 > sum)
            .map(|&(cpu, _)| cpu)
            .collect();
    }

Only reachable on a topology with >=3 distinct capacity tiers where <2 CPUs are within 90% of the max — not the GB10 two-tier part this PR targets, not any hardware the PR qualifies (718..731 vs 997..1024, 10 top CPUs). On GB10 selected is always 10, so deleting the branch keeps GB10 behavior bit-identical and turns hypothetical 3-tier hardware into the existing no-op. AGENTS.md:188-193: "Do not add ... speculative compatibility, fallback layers ... without a concrete requirement." With (a) and (b) gone, min_cap becomes unused (it is read only by :198, :201 and :214), so the whole min-tracking pass goes.

(c) UNREACHABLE guard: eos/src/unix.rs:195-197

        if cap == 0 {
            return None;
        }

The only producer (prefer_high_capacity_cpus, :241-252) returns early when the sysfs file cannot be read or parsed (:244-249) and only reads CPUs set in sched_getaffinity, i.e. online CPUs; CPU capacity for an online CPU is positive. Its test case [(0, 0), (1, 1024)] (:311) returns None anyway via the >= 2 guard (min=0, max=1024, midpoint 512 selects only cpu 1).

Replacement (whole body, ~7 lines):

pub fn select_high_capacity_cpus(allowed_with_capacity: &[(usize, u32)]) -> Option<Vec<usize>> {
    let max_cap = allowed_with_capacity.iter().map(|&(_, cap)| cap).max()?;
    let selected: Vec<usize> = allowed_with_capacity
        .iter()
        .filter(|&&(_, cap)| u64::from(cap) * 10 >= u64::from(max_cap) * 9)
        .map(|&(cpu, _)| cpu)
        .collect();
    (selected.len() >= 2 && selected.len() < allowed_with_capacity.len()).then_some(selected)
}

len() < 2 early return (:189-191) is then subsumed by selected.len() >= 2. Test fallout: select_high_capacity_cpus_avoids_single_core_collapse_on_three_tier_soc (:314-330) exists only for (b) and must be deleted with it; the two other tests (:270-312) keep passing unchanged.

#5 [high] Research summary

Subtraction/Simplicity/Conventions review of PR #576 complete. Findings are saved in scratchpad entries 1–4.

Main finding (high): eos/src/unix.rs:188-226 select_high_capacity_cpus is 39 lines that reduce to ~7 without changing any reachable behavior. Three pieces can go: (a) the min_cap == max_cap early return at :201-203 is dead — when min==max every CPU passes the 90% filter, so the final selected.len() < allowed_with_capacity.len() guard at :221 already returns None; (b) the midpoint fallback at :211-220 is speculative — reachable only on ≥3-tier topologies with <2 CPUs within 90% of max, not the GB10 two-tier part the PR targets and not any hardware it qualifies, so it fails AGENTS.md:188-193 ("no fallback layers ... without a concrete requirement"); (c) the cap == 0 guard at :195-197 is unreachable from the only producer (:241-252 returns early on read/parse failure and only reads online CPUs). With those gone, min_cap and the min-tracking pass disappear too. The replacement body is quoted verbatim in the scratchpad, and the three-tier test at :314-330 must be deleted with (b).

Second (medium): helios/native/roce_proxy.c:1505-1570 re-implements exactly the same policy in C, carrying the identical dead min_cap == max_cap half (:1543) and identical midpoint fallback (:1555-1565). Because the file is a vendored witness (:8, NOTICE:16-19, roce_proxy_dlopen.c:7-9), the C side should stay verbatim and only the Rust side should be trimmed — but then the PR's "verified equivalent" claim needs a note, since the two would differ in the fallback.

Checked and cleared: the five prefer_high_capacity_cpus() call sites are five genuinely distinct threads (verified each spawn site), so the one-line repetition is forced by Linux affinity inheritance, not gratuitous duplication. The Windows stub eos/src/windows.rs:218-220 is required by eos/src/lib.rs:9-16's whole-module cfg selection. No leftover flags, config knobs, dead imports or test scaffolding in the diff. Two minor trims recorded: the unix non-Linux stub can be folded into the body's cfg, and select_high_capacity_cpus need not be pub (its only caller and users are in-file). One comment (helios/src/server/runtime.rs:721-723) over-claims a property the code does not have and should be trimmed, not extended.

#6 [high] S5: verdict, ranking, and surfaces cleared as lean

VERDICT: the diff is lean except for one function. Four suggestions, ranked: S1 (high, eos/src/unix.rs:188-226 → ~7 lines) >> S2 (medium, C copy carries the same two removable branches, but the file is a vendored witness so the C side must stay) >> S3 (medium, no merge available across the 5 threads; trim the over-claiming comment) > S4 (low, two cosmetic surface trims). Everything else in the 8-file, +230/−1 diff is one-line call sites, a 3-line Windows stub, and a self-contained C function — nothing else to delete.

CLEARED, with evidence, so the report does not need to re-derive:

#2 [medium] S2: C hunk re-implements the same policy, fallback included

helios/native/roce_proxy.c:1505-1570 is a second, independent copy of the same 90%-of-max policy: pin_high_capacity_cpus (~65 lines of C) mirrors eos/src/unix.rs:188-226 field for field, including the same two items from S1:

Constraint that changes the recommendation: the file is a vendored witness (helios/native/roce_proxy.c:8 "Keep the source below identical", NOTICE:16-19, helios/native/roce_proxy_dlopen.c:7-9, docs/roce-ring.md:361-364). If the hunk is verbatim from flashinfer#156 (335459b2) it must stay as upstream wrote it, so S1 should be applied to the Rust side only — but then the two implementations differ in the fallback and that must be stated, since the PR body claims the Rust selector is "verified equivalent" to the C one. Cheapest resolution: keep the C verbatim, delete the unreachable/speculative branches on the Rust side, and note the divergence in the body or a comment.

Secondary C cost, only if the hunk is Flare-authored rather than vendored: int cpus[CPU_SETSIZE]; uint32_t caps[CPU_SETSIZE]; (:1516-1517) is 8 KiB of stack for two parallel arrays that a single pass over next/allowed would not need.

#3 [medium] S3: five call sites are five real threads - no merge available

Verified the five call sites are five distinct OS threads, so there is no site to merge; each is one line and correctly placed after that thread's resource setup:

Note: this per-thread placement is forced by the deferral design, because Linux affinity is inherited by children — a single process-wide pin would leak onto the KV-codec/disk/image-prep threads the PR deliberately keeps unnarrowed. So the 5× repetition of one call is the price of the approach, not gratuitous duplication. Pinning inside selene/src/shared/codec.rs's pool workers + selene/src/disk.rs would instead be the alternative shape, and is what fixes the A1 defect.

Small subtraction here: helios/src/server/runtime.rs:721-723

                // Narrow affinity only after RankExecutor, host offload/codec/disk, and image
                // preparation child threads have been spawned so background workers stay free
                // to run on efficiency cores and observe the full process cpuset.

asserts a property the code does not have (the lazily built flare-kv-codec-{i} pool from selene/src/shared/codec.rs:37-60 is created later, on this already-narrowed thread, and inherits the narrowed mask). Either delete the second sentence or fix the behavior; do not extend the comment.

#4 [low] S4: stub pair + pub visibility - small surface trims only

prefer_high_capacity_cpus needs two bodies only because eos/src/lib.rs:9-16 selects unix vs windows as whole modules (#[cfg(unix)] mod unix; pub use unix::*;). The Windows stub is therefore required (eos/src/windows.rs:218-220) — a Helios caller cannot be #[cfg(unix)]-gated because helios/src/replay.rs, worker.rs, parallel.rs, threaded.rs, server/runtime.rs call it unconditionally. NOT removable.

But the unix-side stub is removable by moving the cfg inside the body: replace eos/src/unix.rs:231 #[cfg(target_os = "linux")] + :263-264

#[cfg(not(target_os = "linux"))]
pub fn prefer_high_capacity_cpus() {}

with a single

pub fn prefer_high_capacity_cpus() {
    #[cfg(target_os = "linux")]
    { /* ... */ }
}

Saves a duplicated signature; only matters for macOS-class cfg(unix) targets that no CI builds.

Separately: eos/src/unix.rs:188 pub fn select_high_capacity_cpus(...) — its only caller is prefer_high_capacity_cpus (:253) and its only other users are the tests in the same file (eos/src/unix.rs:267 mod tests). Because of pub use unix::* (eos/src/lib.rs:12) it becomes part of flare_eos's public surface for no consumer. Make it private (fn), and the crate gains no API it does not use. Same argument applies to nothing else in the diff.

Dead/duplicated code check on the rest of the diff: no unused imports added (flare_eos already a dependency of helios, helios/src/os.rs:8 re-exports it as crate::os::*, so the five sites could equally have been written crate::os::prefer_high_capacity_cpus() for consistency with the ~20 existing crate::os:: call sites — cosmetic, not worth a change). No leftover flags, no config knobs, no test-only scaffolding. The #ifdef __linux__ guards in C (:1505, :1570, :1574) match the file's existing style.