Subtractive report · NVIDIA/hyperflare-inference #576

Raw Markdown for agents: https://autobot.eidonix.com/p/c9efd042-8f9f-4c1a-9665-2df8444b7e6a.md

Review of PR #576 (Subtraction lens) — Pin Helios execution and RoCE proxy threads to high-capacity CPUs

Key findings

The PR is well evidenced and the idea is sound, but it is roughly twice the size it needs to be: 4 of its 7 changed files carry ~107 of the +226 added lines that can go without losing either placement result the PR reports.

  1. ~66 lines — the C affinity helper is a line-for-line duplicate of the Rust one, and it never needs to run at all. pin_high_capacity_cpus (helios/native/roce_proxy.c:1505-1570) repeats eos/src/unix.rs:172-248 (same sched_getaffinity, same per-CPU cpu_capacity reads, same cap*10 >= max*9, same <2 fallbacks, same sched_setaffinity). The proxy thread is a pthread_create from roce_start (roce_proxy.c:1674), whose only caller is RoceTransport::connect (helios/src/execution/roce.rs:295); a new thread inherits its creator's mask, so one Rust call before roce_start gives the proxy exactly the mask the C helper installs. It also edits the body of a file that must stay identical to the pinned FlashInfer proxy (roce_proxy.c:6-8, docs/roce-ring.md:360-364).
  2. ~36 lines — the three-tier "single-core collapse" fallback and its test protect a branch that is already safe. unix.rs:195-204 + test unix.rs:298-314. The final guard at unix.rs:205 already turns a sub-2 selection into a no-op; the fallback only changes which set a prime-core SoC gets, a topology outside the charter's scope. Removing it also empties min_cap, collapsing the min/max loop (176-184) and the provably redundant min_cap == max_cap return (185-187).
  3. ~4 lines — helios/src/replay.rs:171-176 wraps run(...) in a closure only to pin flare-cuda, a worker the native server never spawns.
  4. ~1 line — helios/src/execution/worker.rs:71 pins ExecutionWorker, which its own doc comment (worker.rs:36-37) calls the bootstrap/qualification control surface.

Files found already minimal: eos/src/windows.rs (the stub is load-bearing), helios/src/execution/parallel.rs:539 and helios/src/server/runtime.rs:568 (real serving threads).

Verdict: make it smaller first.


Scope and rules applied

Change size from the diff: 7 files, +226 / −1. Confirmed removable: ≈107 lines (≈47 %), in 4 places.


Findings, ranked by lines saved

1. Should fix — delete the 66-line C copy; pin from Rust before roce_start (~66 lines)

Where: helios/native/roce_proxy.c:1505-1570 (the whole #ifdef __linux__ block containing pin_high_capacity_cpus, plus the call at :1576).

What it is: a C transcription of eos/src/unix.rs:172-248. Side-by-side the two are the same algorithm: sched_getaffinity(0, …); a loop over the mask reading /sys/devices/system/cpu/cpu%d/cpu_capacity; an early return on any missing/zero/unparsable capacity (unix.rs:182-184, roce_proxy.c:1537-1539); count < 2 || min_cap == max_cap → return (unix.rs:185-187, roce_proxy.c:1548); the 90 % filter cap*10 >= max*9; the <2 midpoint retry; and selected >= 2 && selected < count → sched_setaffinity. Nothing in it is C-specific beyond syntax.

Why nothing is lost: the proxy thread does not need to pin itself. roce_start creates it with pthread_create(&c->thread, NULL, proxy_main, c) (roce_proxy.c:1674), its sole caller is RoceTransport::connect (helios/src/execution/roce.rs:295; declaration at roce.rs:71; no other call site in the tree), and a new pthread inherits the creating thread's affinity mask and CPU set. Pinning the creating thread one line earlier gives flare-roce precisely the mask the C helper would install for itself — the same result the PR measures (48/48 critical threads on X925 5-9,15-19).

Smaller version:

/* roce_proxy.c: delete 1505-1570 entirely; proxy_main keeps only: */
#ifdef __linux__
  (void)pthread_setname_np(pthread_self(), "flare-roce");
#endif
// helios/src/execution/roce.rs, immediately before line 295
flare_eos::prefer_high_capacity_cpus();
if unsafe { roce_start(self.context) } != 0 {

Keeps the 2-line pthread_setname_np (the PR's evidence uses the flare-roce name). Net: −66 in C, +1 in Rust, one copy of the policy instead of two, and the vendored file's provenance contract (roce_proxy.c:6-8) stays intact.


2. Should fix — drop the three-tier fallback and its test; the existing <2 guard already no-ops it (~36 lines)

Where: eos/src/unix.rs:195-204 (fallback, 10 lines incl. its 2-line comment) and the test eos/src/unix.rs:298-314 (select_high_capacity_cpus_avoids_single_core_collapse_on_three_tier_soc, 17 lines).

Why nothing is lost: the guard immediately below at unix.rs:205 — selected.len() >= 2 && selected.len() < allowed_with_capacity.len() — already returns None whenever the first pass selects fewer than 2 CPUs, which is the safe "leave affinity alone" behaviour the fallback claims to protect. The fallback therefore only changes which set is chosen on a topology where exactly one CPU clears 90 % of the maximum: a prime-core SoC, which the charter excludes ("DGX Spark" / "SM120/SM121") and which the PR's own caveats admit was not tested. On the stated target (10× A725 at 718-731 + 10× X925 at 997-1024) the 90 % pass always selects 10 CPUs — the PR's own gb10 test asserts that.

Second-order savings inside the same function: with the fallback gone, min_cap has no reader, so the min/max accumulation loop (unix.rs:176-184, ~9 lines) collapses to a single max(), and if min_cap == max_cap { return None } (185-187, 3 lines) is provably redundant — when every capacity is equal, every CPU passes the 90 % filter, so selected.len() == allowed.len() and line 205 already returns None.

Smaller version (~14 lines replacing 44 at unix.rs:167-210):

/// Select the high-capacity CPU subset of `allowed` when its capacities span
/// more than one tier. `None` means "leave this thread's affinity alone".
fn select_high_capacity_cpus(allowed: &[(usize, u32)]) -> Option<Vec<usize>> {
    let max_cap = allowed.iter().map(|&(_, cap)| cap).max()?;
    if allowed.len() < 2 || allowed.iter().any(|&(_, cap)| cap == 0) {
        return None;
    }
    let selected: Vec<usize> = allowed
        .iter()
        .filter(|&&(_, cap)| u64::from(cap) * 10 >= u64::from(max_cap) * 9)
        .map(|&(cpu, _)| cpu)
        .collect();
    (selected.len() >= 2 && selected.len() < allowed.len()).then_some(selected)
}

Every surviving assertion still passes unchanged: homogeneous → all selected → None; efficiency-only and performance-only cpusets → None; [(19, 1024)] → len < 2 → None; [(0, 0), (1, 1024)] → zero capacity → None; the GB10 split → the 10 X925 CPUs. The same 11-line fallback in the C copy disappears with finding 1.

(Nit within this finding, 0 lines but smaller surface: select_high_capacity_cpus is pub (unix.rs:172) yet its only caller is prefer_high_capacity_cpus in the same file (unix.rs:237); fn keeps the tests working and stops a policy detail from becoming exported API.)


3. Nit — drop the pin from the flare-cuda replay worker (~4 lines)

Where: helios/src/replay.rs:171-176. The closure exists only to add the call:

.spawn(move || {
    flare_eos::prefer_high_capacity_cpus();
    run(receiver, completion_sender, ready_sender)
})

ReplayWorker is not spawned by the native server: searching ReplayWorker across helios/src/server and helios/src/execution returns nothing (the server uses RankExecutor, see helios/src/server/runtime.rs:585); its users are heliopause/src/python.rs:45-46 (not opened) and the CUDA integration/tool tests under helios/src/runtime_core/*_tests.rs (not opened) and helios/tests/tools/*. None of the four critical threads the PR measures is a replay worker.

Smaller version — restore the single line at replay.rs:173:

.spawn(move || run(receiver, completion_sender, ready_sender))

Saves the 4-line closure (net −3 after the −1 removal). Caveat: if maintainers regard heliopause's GraphReplayWorker as a latency-critical serving thread, this stays — I read the PR's measurements as naming only the execution/WFET thread and the RoCE proxy.


4. Nit — drop the pin from the bootstrap/qualification worker (1 line)

Where: helios/src/execution/worker.rs:71.

ExecutionWorker's own doc comment (worker.rs:36-37) says: "Synchronous control surface for bootstrap/qualification callers on other threads. The native scheduler owns its rank executor directly without this channel boundary." Its only users are helios/tests/tools/tp4_collective.rs:122 (not opened),134,156 and heliopause/src/python.rs:410-411 (not opened), so this pins a thread that never serves a request. Nothing in the PR's evidence depends on it.

The description's phrase "execution … worker threads" is satisfied by the flare-model thread (runtime.rs:568) and serve_rank (parallel.rs:539), both kept.

(Related observation, not a proposed addition: the in-process per-rank executor threads — flare-rank-N at helios/src/execution/threaded.rs:652-654 — receive no pin at all. That is pre-existing, not caused by this PR, and adding one is outside the subtraction lens; flagging it so a reviewer does not read worker.rs:71 as covering that path.)


Examined and deliberately kept (no finding)


Open questions / what I could not verify

  1. Is there a no-new-code fix? The charter asks for "a way to solve it without new code at all". A static cpuset (CPUAffinity=/taskset to 5-9,15-19) would reproduce the placement, and a narrower systemd cpuset per rank could even give per-thread divergence. I could not show from the code that this suffices: the PR pins only two threads while leaving HTTP, frontend, offload and copy threads on the shared core budget, and a whole-process cpuset cannot make that distinction. Report as a question for maintainers, not a finding.
    • Note for whoever checks: nothing in the repo sets process affinity today (selene-manager/deploy/seccomp-io-uring.json:309 (not opened),317 already allows sched_getaffinity/sched_setaffinity), so no accompanying seccomp/policy change is needed.
  2. threaded.rs:652-654 (above) — is the in-process flare-rank-N executor the thread the PR actually wanted? If so, worker.rs:71 is in the wrong place and the right place is still missing; I am not proposing that addition.
  3. Windows coverage: the PR states the windows.rs stub was not compiled on Windows. That is a test-coverage gap, not a subtraction, and proposing a test is outside this lens.

Totals

Change Lines
PR as submitted +226 / −1 (7 files)
Finding 1 — C helper deleted, Rust pin added −66 / +1 and 1 file
Finding 2 — fallback, min/max loop, min==max guard, three-tier test −36
Finding 3 — replay.rs closure −4 (+1 restored)
Finding 4 — worker.rs pin −1
After all four ≈ +119 / −1 across 6 files (≈47 % smaller)

The reduced change still delivers both headline results: flare-model pinned by runtime.rs:568, serve_rank pinned by parallel.rs:539, and flare-roce inheriting the creating thread's mask from the one new call in roce.rs — no duplicated policy, no edited vendored C body, no code for topologies the project does not target.