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

Raw Markdown for agents: https://autobot.eidonix.com/p/29e3d3d1-3227-416b-a495-67f4f7b3a548.md

#1 [high] S1: c->gid_index in roce_ctx_t is now write-only dead state

helios/native/roce_proxy.c:268 int gid_index; inside the roce_ctx_t typedef (fields 262-300). Written once at :558 c->gid_index = gid_indices[0];. Grep of the whole file for gid_index returns only: 259 (roce_hca_t field, needed), 461 (hca read in open_hca, needed), 558 (ctx write), 577 (hca write, needed), 587/597 (roce_create wrapper), 680 (hca read in connect_qp, the actual fix). So ctx->gid_index is write-only: connect_qp was changed from c->gid_index to hca->gid_index (:680). roce_ctx_t is opaque to Rust (FFI holds a *mut context; roce_blob_t at :240-243 carries only mtu/qp_num/lanes), so deleting the field changes no ABI.

Simplification: delete line 268 from the typedef and delete line 558. Two fewer lines of fork from the vendored FlashInfer source (header at roce_proxy.c:6-8 demands the body stay identical), and removes a second, divergent source of truth for the GID index (ctx value = gid_indices[0] while QPs use per-HCA values -> a latent trap = pure subtraction.

#2 [high] S2: roce_create wrapper is dead code with duplicated validation

helios/native/roce_proxy.c:587-601 is the whole roce_create wrapper: it re-checks n_hca < 1 || n_hca > ROCE_MAX_HCAS (needed only so the gids[] fill cannot overflow), fills int gids[ROCE_MAX_HCAS] with the single index, and tail-calls roce_create_with_gids.

Callers: grep roce_create across the repo = roce_proxy.c:531 (with_gids def), :587 (wrapper def), :599 (its tail call), helios/src/execution/roce.rs:46 (FFI decl of with_gids), roce.rs:205 (single call site). Nothing declares or calls roce_create any more; the Rust FFI was switched wholesale to roce_create_with_gids. roce_proxy_dlopen.c:236 #include "roce_proxy.c" compiles it into the same object, so there is no dynamic-symbol indirection either.

Simplification: delete lines 587-601 (and with them the duplicate bounds check and the ROCE_MAX_HCAS stack array). If it is meant for out-of-tree FlashInfer callers, that is exactly the vendored-parity claim in docs/roce-ring.md:360-364 which the file header (roce_proxy.c:6-8) asserts and nothing tests.

#3 [high] S3: gid_index duplicated alongside gid_indices, plus 3 redundant fallbacks

One fact (the GID index per device) is stored twice and recovered by three fallbacks, all of which exist only for test fixtures.

(a) helios/src/execution/roce_fabric.rs:430-431

    let gid_index = devices[0].1;
    let gid_indices: Vec<u32> = devices.iter().map(|(_, gid, _)| *gid).collect();

gid_index is, by construction, gid_indices[0] — derived state stored separately.

(b) roce_fabric.rs:1027-1031 in Fabric::topology:

        let gid_indices = if self.gid_indices.len() == self.endpoints.len() {
            self.gid_indices.clone()
        } else {
            vec![self.gid_index; self.endpoints.len()]
        };

In discover_in (the only producer) gid_indices.len() == endpoints.len() always, because both are built from the same devices vector. The else branch is reachable only from the three hand-built test fixtures that set gid_indices: Vec::new() (roce_fabric.rs:1567, :1682, :1834; roce.rs:397).

(c) roce_fabric.rs:1006-1011 gid_index_for repeats the same fallback:

    pub fn gid_index_for(&self, index: usize) -> u32 {
        self.gid_indices.get(index).copied().unwrap_or(self.gid_index)
    }

Because gid_indices is exactly parallel to endpoints, self.gid_indices[index] is the honest expression; the .get(..).unwrap_or(..) masks a producer bug rather than covering a real case.

(d) helios/src/execution/roce.rs:199-203 a third copy of the same fallback:

        let gid_indices: Vec<c_int> = if topology.gid_indices.len() == pointers.len() {
            topology.gid_indices.iter().map(|&g| g as c_int).collect()
        } else {
            vec![topology.gid_index as c_int; pointers.len()]
        };

pointers.len() is topology.hcas.len(), and Topology::gid_indices is produced with self.endpoints.len() == hcas.len() in that same function. So all three branches are dead in production and none has a test (roce.rs is #[cfg(feature = "roce")], so CI only compiles it).

Simplification: keep gid_indices: Vec<u32> as the single stored fact on Fabric and Topology; expose pub fn gid_index(&self) -> u32 { self.gid_indices[0] } for the one outside consumer (heliopause/src/python.rs:698-699 fabric.gid_index, prep path) and for the doctor's warn text (spark.rs:254); make gid_index_for a plain index; delete the two if len == len { clone } else { vec![..] } blocks and the .unwrap_or. Fix the four fixtures to carry real indices (gid_indices: vec![3; 2]) instead of Vec::new(). Net: ~20 lines gone, one invariant expressed once instead of four times.

#5 [high] Research summary

Subtraction/simplicity review of #672 complete. The Rust discovery fix itself is lean and idiomatic (the pick_gid_index closure and the filter_map/take/is_empty restructure are strictly simpler than main's two-pass global-index selection); the removable code is concentrated in the native proxy and in the redundant plumbing of the new per-HCA index.

Four findings, all in the scratchpad with verbatim quotes and line numbers:

  1. roce_ctx_t.gid_index is now write-only (helios/native/roce_proxy.c:268, written at :558). Since connect_qp switched to hca->gid_index (:680), nothing reads the ctx-level copy. roce_ctx_t is opaque to the Rust FFI and absent from roce_blob_t, so deleting the field and its assignment is ABI-neutral — two fewer lines of fork from the vendored source, and one fewer divergent source of truth.
  2. roce_create (roce_proxy.c:587-601) is dead code with a duplicated bounds check. Every in-tree caller now goes to roce_create_with_gids; the 15-line wrapper exists only to fill a ROCE_MAX_HCAS array and re-validate n_hca. Delete it (or keep it only if an out-of-tree FlashInfer caller is demonstrated — which is exactly the untested parity claim in docs/roce-ring.md:360-364).
  3. The per-HCA index is stored twice and recovered by three fallback branches, all dead in production and none tested. gid_index is by construction gid_indices[0] (roce_fabric.rs:430-431); Fabric::topology re-derives a same-length vec with an else branch reachable only from Vec::new() test fixtures (:1027-1031); gid_index_for repeats the fallback (:1006-1011); roce.rs:199-203 repeats it a third time. Collapse to one stored Vec<u32> plus a gid_index() accessor and fix the four fixtures; ~20 lines gone.
  4. (Low) flare-cli/src/doctor/spark.rs:150/179/181-198 builds a parallel ready_gids vec only to format a mixed/single label; folding the index into Interface or always printing indices [...] removes the array and the branch, and also removes the inconsistency with the terminal Warn text at :250-256, which still uses singular fabric.gid_index.

Also noted: doc updates that AGENTS.md:234 requires for transport changes (docs/multi-host.md (not opened), docs/roce-ring.md) are absent, and the header of the edited vendored file still claims byte parity with FlashInfer — both are convention-level rather than code-shape issues.

#6 [medium] S0: what is already lean in this diff (no action needed)

Verified by reading helios/src/execution/roce_fabric.rs:404-476 at head: the new shape is strictly simpler than main's rule, not more convoluted.

Conclusion for the report: the Rust half of the diff is lean and idiomatic; the subtraction findings are (a) dead/duplicated state in the vendored C and (b) triple-redundant fallbacks around a single invariant.

#7 [medium] S5: convention items — stale docs and vendored-parity header (not code shape)

These are structural-convention issues, adjacent to the subtraction lens; keep them short in the report.

VERIFIED BY ME at head:

FROM THE DOSSIER, NOT RE-VERIFIED BY ME (phrase as "reported", not "verified"): docs/multi-host.md:42-43 ("Active RoCEv2 ports with IPv4 GIDs"), docs/multi-host.md:102-130, docs/roce-ring.md:405, docs/cli-design.md:1695-1698 (doctor wording, singular index) and :1707-1714 ("RoCEv2 GID index 3") all still describe the old single host-wide index rule.

Also from my own read: the doctor's terminal Warn fallback at flare-cli/src/doctor/spark.rs:250-256 still formats the singular "at RoCEv2 GID index {}" from fabric.gid_index, inconsistent with the new "indices [a, b]" wording at :187-198 — folded into note #4.

#4 [low] S4: doctor ready_gids parallel vec + mixed-label branch

flare-cli/src/doctor/spark.rs:150 introduces let mut ready_gids = Vec::new(); — a second vector parallel to ready (built at :149) and pushed in lockstep at :179 ready_gids.push(gid_index);. Then :181-198 spends 12 lines minting a label:

            let gid_label = if ready_gids.iter().all(|&g| g == ready_gids[0]) {
                format!("index {}", ready_gids[0])
            } else {
                format!(
                    "indices [{}]",
                    ready_gids
                        .iter()
                        .map(u32::to_string)
                        .collect::<Vec<_>>()
                        .join(", ")
                )
            };

Two cheaper options, both removing a parallel array and the branch:

  1. Add gid_index: u32 to Interface (spark.rs:267-273) next to device/interface; the label becomes ready.iter().map(|i| i.gid_index).collect::<Vec<_>>() rendered once, and configuration_warnings does not care about the extra field.
  2. Or drop the special case and always print indices [3, 3] / indices [3, 5] (one format!, no branch), which also fixes the inconsistency that the terminal Warn path at :250-256 still says "at RoCEv2 GID index {}" singular from fabric.gid_index. Either way ~10 lines go.

Low importance: this is the least of the four; the duplicate-array pattern is the structural point, and the single-vs-mixed wording is presentation.