Subtractive scratchpad · NVIDIA/hyperflare-inference #576

Raw Markdown for agents: https://autobot.eidonix.com/p/00e8733e-a34e-4831-88b0-bbacff67ce8b.md

#1 [high] Should fix: roce_proxy.c's pin_high_capacity_cpus duplicates eos::prefer_high_capacity_cpus; call the Rust helper before roce_start instead (~66 lines)

helios/native/roce_proxy.c:1505-1570 (#ifdef __linux__ … #endif, pin_high_capacity_cpus) is a line-for-line C transcription of eos/src/unix.rs:172-248: same sched_getaffinity, same per-CPU /sys/devices/system/cpu/cpuN/cpu_capacity read, same 90% filter (cap*10 >= max*9), same <2 fallbacks, same setaffinity. Nothing in it is C-specific.

It is also unnecessary: helmos/native/roce_proxy.c:1661 roce_start() builds the proxy thread with pthread_create (line 1674) from RoceTransport::connect() (helios/src/execution/roce.rs:264-300, roce_start called at roce.rs:295). A new pthread inherits its creator's affinity mask and CPU set, so pinning the creating thread immediately before roce_start gives the proxy thread exactly the same mask the C helper would install for itself.

Smaller version — delete roce_proxy.c:1505-1570 entirely and keep only the one-line rename; then in helios/src/execution/roce.rs, before line 295:

flare_eos::prefer_high_capacity_cpus();
if unsafe { roce_start(self.context) } != 0 { … }

Saves ~66 added lines of C and leaves no duplicated policy (single threshold, single fallback rule). Also required by docs/roce-ring.md:360-364 and the file's own provenance header (roce_proxy.c:6-8: "Keep the source below identical so preparation and serving share the transport ABI"), which the added Flare-specific block violates. Keep pthread_setname_np(…, "flare-roce") (2 lines) — the PR's evidence uses the name.

Verified: roce_start is the only pthread_create of proxy_main (roce_proxy.c:1674) and has one caller (roce.rs:295); RoceTransport::connect is called at flare-cli/src/cluster.rs:203 and :250, both before serving starts.

#2 [high] Should fix: drop the three-tier "avoid single-core collapse" fallback and its test; the existing <2 guard already makes it a no-op (~44 lines)

eos/src/unix.rs:195-204 (the if selected.len() < 2 { … midpoint fallback … } block), the comment at 196-197, and the test eos/src/unix.rs:298-314 (select_high_capacity_cpus_avoids_single_core_collapse_on_three_tier_soc).

Why nothing is lost: the final guard at unix.rs:205 (selected.len() >= 2 && selected.len() < allowed.len()) already turns a sub-2 selection into None, i.e. "leave affinity alone", which is the safe behaviour the fallback claims to protect. The fallback only changes which set is chosen on a topology where exactly one CPU is within 90% of the maximum — a prime-core SoC. The charter scopes Flare to SM120/SM121 workstations and DGX Spark and says the project is "not interested in … broad hardware support" (charter Goals/How We Work). On the stated target (GB10, 10 X925 at 997-1024 + 10 A725 at 718-731) the 90% pass always selects 10 CPUs; the PR's own test data shows the fallback branch unreachable there.

Once the fallback goes, min_cap has no reader, so the whole min/max loop at unix.rs:176-184 collapses too, and the min_cap == max_cap early return at 185-187 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 39 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)
}

Surviving tests still pass unchanged: homogeneous (all selected → None), efficiency-only and performance-only single-tier cpusets (all selected → None), [(19,1024)] (len < 2 → None), [(0,0),(1,1024)] (zero capacity → None), and the GB10 split.

Saves ~10 (fallback) + 6 (min_cap loop) + 3 (min==max) + 17 (test) ≈ 36 lines; with the C copy removed per the other finding, the same 11-line fallback disappears from C too.

#7 [high] Summary: change is +226/−1; ≈107 lines removable (47%); the minimal form keeps parallel.rs + runtime.rs pins

Change size (from the diff): 7 files, +226/−1.

Confirmed subtractions, ranked by lines saved:

  1. ~66 lines — delete roce_proxy.c:1505-1570 (C duplicate of the Rust helper) and pin before roce_start in helios/src/execution/roce.rs:295. Keep the pthread_setname_np line.
  2. ~36 lines — delete the three-tier midpoint fallback (unix.rs:195-204) and its test (unix.rs:298-314); min/max loop and min_cap == max_cap guard fall out with it (unix.rs:176-187). 14-line replacement given.
  3. ~4 lines — drop the pin from helios/src/replay.rs:171-176 (test/heliopause replay worker only).
  4. ~1 line — drop the pin from helios/src/execution/worker.rs:71 (bootstrap/qualification surface only).

Total ≈ 107 lines of the +226 (≈47%), with no behaviour the PR's own measurements depend on lost: the remaining pin on the flare-model thread (runtime.rs:568) plus the same mask inherited by the RoCE proxy thread reproduces the two placement results the PR reports. The peer-rank pin (parallel.rs:539) stays.

Files examined and found minimal: eos/src/windows.rs (stub is required), helios/src/execution/parallel.rs:539 (multi-host rank serving path, needed), helios/src/server/runtime.rs:568 (the flare-model serving thread, needed).

Potential pre-existing duplication not caused by this PR: helios/src/execution/threaded.rs:652-654 spawns the actual in-process per-rank executor threads (flare-rank-N) with no pin, so on a single-host TP core the WFET-serving threads still follow the unsigned scheduler. Mentioning as a gap, not a subtraction (I do not propose adding the call).

#8 [high] Research summary

Reviewed PR #576 (7 files, +226/−1) through the subtraction lens, against the charter (SM120/SM121 + DGX Spark scope, "smallest footprint in shared code", "not interested in broad hardware support") and docs/roce-ring.md's rule that the vendored proxy stay identical to the pinned dependency.

Four confirmed subtractions, ≈107 of the +226 lines (≈47%), recorded in the scratchpad with exact lines and replacement code:

  1. ~66 lines — the C helper is a copy of the Rust one and does not need to exist. pin_high_capacity_cpus (roce_proxy.c:1505-1570) is a line-for-line transcription of eos/src/unix.rs:172-248 — same getaffinity, same sysfs reads, same 90% filter, same fallbacks. It is also redundant: the proxy thread is a pthread_create (roce_proxy.c:1674) from roce_start, whose only caller is RoceTransport::connect (helios/src/execution/roce.rs:295), so a pin on the creating thread gives the proxy the same mask — one call in roce.rs, and the C block goes. It additionally breaks the file's own provenance header (roce_proxy.c:6-8) and docs/roce-ring.md:360-364. Keep only the pthread_setname_np line, which the PR's evidence uses.

  2. ~36 lines — the three-tier "avoid single-core collapse" fallback protects a branch that is already safe (unix.rs:195-204 + its test at 298-314). The final selected.len() >= 2 guard (line 205) already turns a sub-2 selection into a no-op, so the fallback only changes which set is picked on a prime-core SoC outside the project's targets; on GB10 it never fires. Removing it also empties min_cap, collapsing the min/max loop and the provably redundant min_cap == max_cap early return. I gave a 14-line replacement whose behaviour still satisfies every surviving test.

  3. ~4 lines — replay.rs:171-176 wraps run(...) in a closure only to add a pin on the flare-cuda replay worker, which the native server never spawns (it is heliopause's GraphReplayWorker and the CUDA integration tests).

  4. ~1 line — worker.rs:71 pins ExecutionWorker, which its own doc comment calls the bootstrap/qualification control surface; its only users are tp4_collective and heliopause. Meanwhile the real in-process per-rank threads (threaded.rs:652) get no pin — noted as a gap, not something I propose adding.

Checked and deliberately not proposed: the eos/src/windows.rs stub is load-bearing (lib.rs re-exports windows::* on Windows, and gating four call sites instead would be longer); the 90% multiply, the cpu_set_t scan, and the per-thread allocations have no shorter correct equivalent. The one open question is the charter-level "solve it in the right place": a deployment-only affinity fix is plausible, but the code cannot show that a static cpuset reaches the placement the PR measures.

Net: the change should not merge at 226 lines; the same reported placement follows from the flare-model pin plus the proxy inheriting that mask, at roughly half the size.

#9 [high] Charter quotes to cite in the report (smallest footprint, no broad hardware support, provenance, judged on merits)

Quotes the report should attach to the findings:

Code rule (not the charter, but the repo's own documented standard):

#10 [high] Reduced-change shape and verification evidence (what I checked by search, so the report can state it plainly)

Minimal form of the change after the four subtractions:

Verification performed (all by reading code / search at the PR head):

#3 [medium] Nit: worker.rs:71 pins a bootstrap/qualification thread that never serves, while the real per-rank threads (threaded.rs:652) stay unpinned (1 line)

helios/src/execution/worker.rs:71 (flare_eos::prefer_high_capacity_cpus(); inside ExecutionWorker::start).

ExecutionWorker (worker.rs:36-40, doc comment: "Synchronous control surface for bootstrap/qualification callers on other threads. The native scheduler owns its rank executor directly without this channel boundary") is not the serving thread. The serving paths are:

Its only users are test/qualification tools: helios/tests/tools/tp4_collective.rs:122,134,156 and heliopause/src/python.rs:410-411 (ExecutionWorker::new / new_parallel). So the call pins a thread that never serves a request, and the PR still leaves the actual in-process per-rank executor threads (threaded.rs:652) unpinned — the placement the PR measures is flare-model's.

Removing worker.rs:71 saves 1 line and keeps the description's own list of "model, peer-rank, execution, and replay worker threads" consistent only if the execution thread is read as serve_rank/flare-model.

Jump: this one line is defensible as "keep the library entry point consistent"; it is a nit on lines, but worth flagging because it hides the threaded.rs gap.

#4 [medium] Nit: replay.rs:171-176 adds a 4-line closure only to pin the heliopause/test replay worker, which the native server never spawns (3 lines)

helios/src/replay.rs:171-176 — the closure is only to add the pin.

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

ReplayWorker is published for Python (heliopause/src/python.rs:45-46) and used by CUDA integration tests (helios/src/runtime_core/{cooperative,event,programmatic_edge,shared_memory}_tests.rs, helios/tests/tools/*). It is not spawned by the native server: grep ReplayWorker in helios/src/server and helios/src/execution returns nothing, and helios/src/server/runtime.rs uses RankExecutor.

Removing the call restores the one-line .spawn(move || run(receiver, completion_sender, ready_sender)) at replay.rs:173 and saves the 4-line closure (net −3 lines). Nothing the description claims is served is lost: none of the four measured critical threads (flare-model, flare-roce, plus the threaded rank threads) is a flare-cuda replay worker.

Caveat to note in the report: if maintainers consider heliopause's GraphReplayWorker a latency-critical serving thread, this stays. I read the PR's own measurements as naming only the execution/WFET thread and the RoCE proxy.

#6 [medium] Rejected candidates and open question: deployment-only CPUAffinity alternative; magic numbers; heap use; cpu_set_t loop

Deliberately rejected candidates, so the report does not re-litigate them:

  1. "The change is unnecessary; operators should set CPUAffinity / taskset." Rejected as a subtraction finding. The charter says to look for "a way to solve it without new code at all", but the PR's measured A/B on one live server (144.88 vs 123.66 tok/s) is about placement, which a static systemd cpuset (the default 0-19 quoted in the PR) does not fix, and pinning the whole process to 5-9,15-19 would also move HTTP/frontend/offload threads off the shared core budget. Cannot show from the code that a deployment-only fix suffices. Report it as an open question only.

  2. Threshold 90% and midpoint as two magic numbers. Kept as a clamp only: the fallback removal (see the fallback finding) removes the second number entirely; the remaining *10 >= *9 is used by three tests and removing it would leave nothing to select.

  3. u64::from(cap) * 10 >= u64::from(max_cap) * 9. Could be cap >= max_cap / 10 * 9? No — that truncates differently and changes behaviour at boundaries; the widening to u64 costs nothing and is correct.

  4. let _ = unsafe { libc::sched_setaffinity(…) }; ignoring the result. Correct for a best-effort hint (no I/O error can be surfaced usefully from a thread entry point); not a subtraction.

  5. max_cpus = std::mem::size_of::<libc::cpu_set_t>() * 8 and CPU_ISSET loop. This is the only portable way with libc's fixed-size cpu_set_t; sched_getaffinity returns the mask size but Rust's libc exposes CPU_COUNT/CPU_ISSET only against the fixed struct. No shorter equivalent.

  6. heap allocations in prefer_high_capacity_cpus (a Vec and a String per allowed CPU). Runs once per thread at startup, ~20 sysfs reads. Not worth an optimisation; not a subtraction.

  7. Anything needing a new test, comment, doc or option — out of lens.

#5 [low] No finding: windows.rs no-op stub is required by eos/src/lib.rs's cfg re-export; gating four call sites instead would be longer

eos/src/windows.rs:219-220 adds pub fn prefer_high_capacity_cpus() {} (2 lines incl. doc).

The stub is required as written: eos/src/lib.rs:9-16 re-exports unix::* on #[cfg(unix)] and windows::* on #[cfg(windows)], and prefer_high_capacity_cpus is called unconditionally from helios. Without a Windows definition the Windows build fails. So the tutorial alternative is to not call it from four places and instead gate the four call sites:

#[cfg(unix)]
flare_eos::prefer_high_capacity_cpus();

That deletes the Windows stub (2 lines) but adds #[cfg(unix)] four times (4 lines) — net worse, and it spreads a platform condition into helios. Recommend keeping the stub. Also check eos/src/unix.rs:215/247: the function has one prefer_high_capacity_cpus body selected by #[cfg(target_os = "linux")] / #[cfg(not(target_os = "linux"))] inside the unix module, so BSD/macOS get the empty body without a second stub — that is already the minimal form.

Conclusion: no finding here; the PR note "the eos/src/windows.rs no-op stub was not compiled on a Windows host" is a coverage gap, not a subtraction, and I should not propose adding a test.