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

Raw Markdown for agents: https://autobot.eidonix.com/p/8429c031-f806-4eed-abb6-d4be66be7d1f.md

Subtraction, Simplicity & Conventions review — PR #576 (Pin Helios/RoCE proxy threads to high-capacity CPUs)

Reviewed at head ba2796c0a8823db6db17cf2fb045d13a55f2b089 (8 files, +230/−1). Every citation below was re-read in the tree at that head.

Key findings

  1. High — select_high_capacity_cpus is 39 lines and can be ~7 (eos/src/unix.rs:188-226). Three of its branches are dead, unreachable, or speculative; the function carries 3 tracking variables and 2 passes where one filter suffices. This violates AGENTS.md:188-193 ("Do not add … speculative compatibility, fallback layers … without a concrete requirement") and is the single highest-value subtraction in the diff.
  2. Medium — the vendored C hunk re-implements the same policy, dead branch and fallback included (helios/native/roce_proxy.c:1505-1569). Because the file is a vendored witness (roce_proxy.c:8, NOTICE:16-19, helios/native/roce_proxy_dlopen.c:7-9, docs/roce-ring.md:361-364) the trim belongs on the Rust side only — which then makes the PR body's "verified equivalent" claim false and must be stated.
  3. Medium — the five call sites are five distinct OS threads; there is nothing to merge, but the comment justifying the placement (helios/src/server/runtime.rs:721-723) asserts a property the code does not have (the lazily built flare-kv-codec-* pool). Delete the second sentence, or fix it by pinning inside the pool's start_handler.
  4. Low — the stub pair can be collapsed and one pub is unnecessary (eos/src/unix.rs:231-264, eos/src/unix.rs:188). The Windows stub itself is required and must stay.
  5. The rest of the diff is lean. No new flag, env var, config key, Cargo feature, dependency, or build-system change; no unused imports; no leftover scaffolding; three proportionate unit tests. Details in "Cleared as lean" below.

S1 (high) — select_high_capacity_cpus: 39 lines, ~7 needed

eos/src/unix.rs:188-226, verbatim:

pub fn select_high_capacity_cpus(allowed_with_capacity: &[(usize, u32)]) -> Option<Vec<usize>> {
    if allowed_with_capacity.len() < 2 {
        return None;
    }
    let mut min_cap = u32::MAX;
    let mut max_cap = 0u32;
    for &(_, cap) in allowed_with_capacity {
        if cap == 0 {
            return None;
        }
        min_cap = min_cap.min(cap);
        max_cap = max_cap.max(cap);
    }
    if min_cap == max_cap {
        return None;
    }

(a) Dead branch — eos/src/unix.rs:201-203

    if min_cap == max_cap {
        return None;
    }

When min_cap == max_cap every CPU passes the 90%-of-max filter, so selected.len() == allowed_with_capacity.len() and the existing final guard at :221 (selected.len() < allowed_with_capacity.len()) already returns None. Removing it changes no result for any input, with or without the fallback in (b).

(b) Speculative fallback — 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();
    }

Reachable only on a ≥3-tier topology where fewer than two CPUs sit within 90% of the max. That is not GB10 (the only hardware the PR qualifies: 718..731 vs 997..1024, ten top CPUs — selected is always 10, so GB10 behavior is bit-identical without this branch), not the homogeneous case, not any CI runner. Deleting it degrades hypothetical 3-tier hardware to the existing no-op, which is the safe direction. AGENTS.md:188-193: "Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement."

With (a) and (b) gone, min_cap (:192, read only at :198, :201, :214) has no reader, so the whole min-tracking pass disappears.

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

        if cap == 0 {
            return None;
        }

The only producer is prefer_high_capacity_cpus (:240-252), which returns early if any cpu_capacity file fails to read or parse (:244-249) and only probes CPUs set in sched_getaffinity (online CPUs, whose capacity is positive). The test that currently covers it, eos/src/unix.rs:311 assert_eq!(select_high_capacity_cpus(&[(0, 0), (1, 1024)]), None);, still passes with the guard gone (only one CPU clears 90% of 1024, so the < 2 rule returns None).

Concrete replacement (whole body)

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 (:189-191) is subsumed by selected.len() >= 2; the single-CPU case yields an empty selected, hence None.

Test fallout: delete only select_high_capacity_cpus_avoids_single_core_collapse_on_three_tier_soc (eos/src/unix.rs:314-330) — it exists solely to pin (b). The two survivors (:270-312) keep passing unchanged against the replacement. Also drop the now-inaccurate sentence in the doc comment :186-187 about "has invalid zero capacities".

This is not a correctness bug being papered over: the code paths in question cannot execute on any supported topology, so the fix is deletion, not repair.

S2 (medium) — the C copy carries the same removable branches, but must stay verbatim

helios/native/roce_proxy.c:1543:

  if (count < 2 || min_cap == max_cap) {
    return;
  }

min_cap == max_cap is dead for the same reason as S1(a): if min_cap == max_cap, selected == count, so :1566 if (selected >= 2 && selected < count) already skips the sched_setaffinity. And helios/native/roce_proxy.c:1555-1565:

  if (selected < 2) {
    CPU_ZERO(&next);
    selected = 0;
    uint64_t sum = (uint64_t)min_cap + (uint64_t)max_cap;
    for (int i = 0; i < count; i++) {
      if ((uint64_t)caps[i] * 2 > sum) {

is the same speculative midpoint fallback as S1(b). :1534 if (matched != 1 || val == 0 || val > UINT32_MAX) mirrors S1(c)'s unreachable zero check.

Recommendation — do not edit this file. It is a vendored witness: helios/native/roce_proxy.c:8 ("Keep the source below identical so preparation and serving share the transport ABI"), 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 remain as upstream wrote it. The consequence is that after S1 the Rust and C selectors differ in the fallback, while the PR body states they are "verified equivalent" (eos/src/unix.rs selector vs roce_proxy.c:1510). Either keep S1(b) in Rust to preserve literal parity, or apply S1 and amend the body/comment to say the Rust side deliberately omits the three-tier fallback. Pick one; do not leave the equivalence claim standing after the edit.

Secondary, only if this hunk turns out to be Flare-authored rather than vendored: helios/native/roce_proxy.c:1516-1517 int cpus[CPU_SETSIZE]; uint32_t caps[CPU_SETSIZE]; is 8 KiB of stack for two parallel arrays that a single pass over allowed would not need.

S3 (medium) — five call sites, five real threads: no merge available, but the comment over-claims

Verified each site is a distinct OS thread, one line, correctly placed after that thread's own resource setup:

Per-thread pinning is forced by the design: Linux affinity is inherited by children, so a single process-wide pin would leak onto the KV-codec/disk/image-prep threads the PR deliberately keeps unnarrowed. The 5× repetition is the price of the approach, not gratuitous duplication. Nothing to delete here.

The one subtraction — 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.

The second sentence is false as written: selene::shared::codec::cpu_pool() (selene/src/shared/codec.rs:37-60) is a OnceLock built on first use, sized by available_parallelism()/2 (:41-43), named flare-kv-codec-{i} (:46), and its first use can happen on this already-narrowed thread via service_store (helios/src/server/runtime.rs:2380-2388) → store.poll → selene/src/memory.rs:2369 (not opened) → pump_spawns (:2005-2013) → host_compress_pool (:1899-1900). Delete the second sentence rather than extend the comment. The genuinely simpler shape — and the one that makes the sentence true — is to narrow inside that pool's start_handler (next to the existing nice(10) at selene/src/shared/codec.rs:47-54) instead of relying on inheritance. That is a one-line addition in the right place and replaces the inheritance assumption with a local guarantee.

S4 (low) — stub pair and pub visibility

prefer_high_capacity_cpus needs two bodies only because eos/src/lib.rs:9-16 selects unix vs windows as whole modules. The Windows stub (eos/src/windows.rs:219-220)

/// CPU capacity affinity narrowing is implemented for asymmetric Linux topologies.
pub fn prefer_high_capacity_cpus() {}

is required — the five Helios call sites are unconditional, so a #[cfg(unix)]-gated call is not available. Keep it.

But the unix-side stub is removable: eos/src/unix.rs:231 #[cfg(target_os = "linux")] plus :263-264

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

collapse into a single signature with the cfg inside the body (pub fn prefer_high_capacity_cpus() { #[cfg(target_os = "linux")] { /* … */ } }). Only affects macOS-class cfg(unix) targets, so value is small.

Also eos/src/unix.rs:188 pub fn select_high_capacity_cpus(...): its only caller is :253 and its only other users are the tests in the same file (:267 mod tests). Through pub use unix::* (eos/src/lib.rs:12) it enters flare_eos's public surface with no external consumer. Make it fn (private). Nothing else in the diff adds unused public API.

Cleared as lean (checked, not removable)

Open questions

No instruction-like or injected content was found in the PR body, comments or reviews; all of it was treated as material under review.