Skip to content

cargo, tools: host CPU flags per target triple (S2, pin 87bc9518) - #36

Merged
midagedev merged 13 commits into
midagedev:mainfrom
avlp12:cargo-per-target-rustflags
Oct 11, 2026
Merged

midagedev merged 13 commits into
midagedev:mainfrom
avlp12:cargo-per-target-rustflags

Conversation

@avlp12

@avlp12 avlp12 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Requested by Alis

What and why

On aarch64 (DGX Spark) the flat extra-rustflags = ["-C", "target-cpu=znver3", ...] reached every cargo oxide build. There rustc warns on every crate that znver3 is not a processor, and on some crates it crashes inside LLVM, so a Spark owner had to edit the local .cargo/cuda-oxide.toml. The fork's cargo-oxide now reads [target.<triple>] extra-rustflags (midagedev/cuda-oxide#1, merged as 87bc9518). This PR moves the [patch] pin there and splits the flags by triple:

  • x86_64-unknown-linux-gnu keeps znver3 and -sse4a;
  • aarch64-unknown-linux-gnu gets target-cpu=native.

This is S2 of docs/contrib/dgx-spark.md, as asked in #13.

Code shape

  • No second copy. Each triple's list is held equal between .cargo/config.toml (plain cargo) and .cargo/cuda-oxide.toml (cargo oxide) by tools/check-rustflags.sh, as the flat list was.

  • Model code holds only architecture facts. No Rust code changes.

  • Dead code is gone.

  • No silent failure. check-rustflags.sh reads the codegen options in every spelling rustc takes (-C x, -Cx, --codegen x, --codegen=x, and target_cpu for target-cpu). It refuses:

    • a top-level CPU flag;
    • on aarch64, a target-cpu outside an allowlist (native, generic, or a cortex-, neoverse- or apple- prefix; the prefix is not checked further), and any target-feature;
    • a missing side for either triple;
    • a third triple named on one side only.

    It runs its twelve red-and-green cases on every call (--self-test prints them).

  • Comments state what is true now.

  • No relaxed gate. The x86_64 list is unchanged.

  • cargo fmt and cargo clippy: no Rust touched.

Duplication found or removed (path:line): none.

Changed:

  • Pin. Cargo.toml and Cargo.lock move the [patch] rev from 4da6c138 to 87bc9518 (pin/4da6c138 is tagged on the fork). 87bc9518 differs from 4da6c138 only in cuda-oxide/crates/cargo-oxide, so I expect the backend crates' closure to be unchanged and the previous backend to be reusable. That reuse is your call under the pin-move rule.
  • Reinstall needed. The installed cargo-oxide must be rebuilt from 87bc9518 (the cargo install ... --rev line in docs/BUILD.md) before the next oxide build. A cargo-oxide from 4da6c138 ignores [target.*] tables without an error, and the new .cargo/cuda-oxide.toml has no top-level list. So an old binary would build the x86 host code without znver3 and -sse4a, and nothing would say so. Nothing in the tree checks the installed cargo-oxide's rev today; I can add that guard in a follow-up if you want it.
  • Flags. .cargo/cuda-oxide.toml and .cargo/config.toml hold the per-triple tables.
  • Check. tools/check-rustflags.sh is rewritten as described above.
  • Docs. docs/BUILD.md ("The CPU flag" and the cargo install ... --rev line), docs/cuda-oxide.md, AGENTS.md, the S2 rows of docs/contrib/dgx-spark.md, row 32 of docs/upstream/nvlabs-ledger.md, row 8 of docs/contrib/local-check.md and THIRD_PARTY_NOTICES.md. docs/BUILD.md also says the installed cargo-oxide must be the pinned rev.

What I ran

On a Mac:

$ cargo metadata --locked --format-version 1 > /dev/null    # the lock resolves 87bc9518
$ bash tools/check-rustflags.sh
check-rustflags: ok — aarch64-unknown-linux-gnu: both owners carry ['-C', 'target-cpu=native']
check-rustflags: ok — x86_64-unknown-linux-gnu: both owners carry ['-C', 'target-cpu=znver3', '-C', 'target-feature=-sse4a']
$ bash tools/check-rustflags.sh --self-test
check-rustflags self-test: ok  good: clean
check-rustflags self-test: ok  flat oxide list (the old shape): ...
check-rustflags self-test: ok  aarch64 inherits znver3: ...
... (12 cases, all ok)
$ bash tools/check-comments.sh
check-comments: ok (771 files, ...)

The branch is on main at dc49ae45; the one conflict, the S2/S3 rows of docs/contrib/dgx-spark.md, keeps main's S3 row and this PR's S2 row.

On two DGX Sparks: GB10, DGX OS 7.6.0, driver 580.178.04, nightly-2026-08-28. These runs were with the fork's first commit for this change; 87bc9518 adds the host-tuple and compiler-probe follow-up on top of it. Build only, no model:

  • Fork tests. cargo test -p cargo-oxide passed with 0 failures: 252 tests on the first commit on both Sparks, and 255 with the follow-up on one of them. 87bc9518 differs from the follow-up that ran only in comments and README text.
  • Plain cargo. With target-cpu=znver3, glob and regex-syntax crash rustc with SIGSEGV. With native, the same crates build clean.
  • Bloomery build. It ran on one Spark inside nvidia/cuda:13.3.1-devel-ubuntu24.04, with the [patch] rev kept at the public 4da6c138 and the patched cargo-oxide installed. cargo oxide build --arch sm_86 -- -p bloomery-gpu-gates --features gpu --release --bin generate_qwen3moe built the binary. All 124 rustc invocations carried -C target-cpu=native (the log's other Running lines are 20 build-script runs and the cargo command itself), none carried znver3, and nothing crashed.

Not run: the x86 identity check (the flag list and just ptx-scan of generate_ds41 and gate_e2e) and any box gate. You said on #13 that you would run those.

Hardware (if the change is for a machine)

DGX Spark (GB10, aarch64, 128 GB, driver 580.178.04, DGX OS 7.6.0), two units, build only. The x86_64 side is unchanged.

🤖 Generated with Claude Code

@midagedev

Copy link
Copy Markdown
Owner

@avlp12 감사합니다. 확인하고 있습니다. 이 PR은 cuda-oxide pin을 옮기기 때문에, 박스의 backend를 그대로 다시 쓸 수 있는지부터 저희 쪽에서 확인합니다. 그다음 착지 train에서 gate를 돌리겠습니다.

@midagedev

Copy link
Copy Markdown
Owner

Review done: the pin move is one fork commit in cargo-oxide only, so the box can reuse its current backend. One trap we found: a cargo-oxide older than 87bc9518 reads only extra-rustflags and ignores a [target.*] table with no warning (fork context.rs inspect_oxide_config). A box with the old binary would build host code without znver3, and every check would stay green. Could the build refuse a cargo-oxide older than the pin, by name? I will reinstall the box's binary at 87bc9518 before this lands either way.

avlp12 added a commit to avlp12/bloomery that referenced this pull request Oct 11, 2026
…t the pinned rev (midagedev#36 review) — a cargo-oxide older than 87bc9518 reads only the top-level extra-rustflags and ignores the [target.<triple>] tables without a word, so with this branch's .cargo/cuda-oxide.toml it would build the host code without znver3 and -sse4a while every check stays green. A command that builds with cargo-oxide (one that names `cargo oxide`, `gate.sh --oxide` or `release/build.sh`, once any `release/build.sh --check`, which only reads built binaries, is taken out of it, so a build chained after a --check is still checked) now reads `cargo install --list` on the box, after the BLOOMERY_BOX_ENV exports so a CARGO_HOME or PATH set there is the one checked, and goes on only when its cargo-oxide line names the pin's rev (`...?rev=<rev>#<short>`); any other rev, or an install with no rev (a path install), stops with rc 70 naming the installed rev, the pin and the reinstall line in docs/BUILD.md. Other commands are unchanged. card-tests: the remote command of each of the three forms carries the check, after a BLOOMERY_BOX_ENV CARGO_HOME, and so does a --check chained with a build; a plain cargo call and a lone `release/build.sh --check` do not; the check run against a stub `cargo install --list` passes the pin and refuses 4da6c138 and a path install. FAIL-first: with the old box.sh the presence check and both refusals were red (the pin case passed)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@avlp12

avlp12 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Thank you. I added the check in e4049ec.

  • Which commands. The check covers every command through tools/box.sh that builds with cargo-oxide: one that names cargo oxide, gate.sh --oxide or release/build.sh. release/build.sh --check only reads built binaries, so it is left out, but a build chained after it in the same command is still checked.
  • What it does. Such a command now reads cargo install --list on the box first. This runs after the BLOOMERY_BOX_ENV exports, so a CARGO_HOME or PATH set there is the one checked. It goes on only when the cargo-oxide line names the pin's rev. Otherwise it stops with rc 70 and names the installed rev, the pin, and the reinstall line in docs/BUILD.md.
  • Exact match. Any rev other than the pin is refused, newer ones too, and so is a path install, which has no rev. So the reinstall should be the cargo install --git ... --rev 87bc9518... line from docs/BUILD.md, not --path.
  • Tests. card-tests: 545 passed.
    • The remote command of each of the three forms carries the check, and so does one with a BLOOMERY_BOX_ENV CARGO_HOME. So does a --check chained with a build. A plain cargo call and a lone release/build.sh --check do not.
    • Against a stub cargo install --list, the check passes the pin and refuses 4da6c138 and a path install.
    • With the old box.sh, the presence check and both refusals were red.
  • Limits. It reads the install record, so a different cargo-oxide binary copied onto PATH by hand would not be seen. A cargo oxide run outside box.sh is not covered.

@midagedev

Copy link
Copy Markdown
Owner

Thank you. I am checking e4049ec now. It lands after the box's cargo-oxide is reinstalled at 87bc9518.

midagedev and others added 9 commits October 11, 2026 21:39
… and decision share one expansion

serve::media::expand_spans (each placeholder run of the prompt ids expanded to its image's
token count, a placeholder carried in text refused by name) moves with Expanded and ExpandError
to crates/vision/src/media.rs, the model-generic owner beside MediaModel, so the decision crate
can call it without a serve dependency. serve calls it and maps ExpandError into MediaError.
A move: serve's gates unchanged and green.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… as the release does (vision R4c-b)

- request: images in llama.cpp's order (the request's `images`, then the state's image_url
  parts), each a data URL, at most 8; the state comes back without those parts. videos stays
  501, a non-data URL and a ninth image stay 400. The request is valid with images; encode and
  the label model refuse them by name (NotSupported, llama.cpp's hint), so today's seats answer
  as before.
- encode_media(tok, req, &dyn MediaModel, counts, max): the media piece is the placeholders and
  a "\n" tokenized in one call, each pad run expanded to its image's count through
  vision::media::expand_spans; Encoded.image_spans names them; fixed counts the media ids; a
  placeholder in text and media ids past the context are refused by name.
- gate-decision-clef: hw_clef_image_ids_equal_the_release — every set D request's input_ids equal
  the release's, list for list (6 of 6). Set D (images.jsonl) states no identity, so this clause
  reads it raw beside the same run's reference.jsonl (its revision equals clefvis.sh's, its ids
  equal) — a substitute for a family check until the writer states one.
FAIL-first: D3 (no "\n" after the last image) red on the box at c1 234, c2 1108, c3 234, i640
338, i1024 806; D1 and D2 red in host tests (set D has no state image part to catch them).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ile, from the listing or the verified cache

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eat flags and projector, the encoder reserve in the whole-fit verdict (qwen35_open::open_seated), Body35's media hidden call, the image refusals by name

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s with the encoder, 501 with llama.cpp's hint without it, the image 400s, the --hf projector pick

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… open_tower open a seat's projector and tower for any serve seat, merged_cells and Flags::wanted beside them (span_rows loses its rows_of parameter); image_plan holds the plan's side of an image input free of the encoder crates (the tower's reserve on the stage card, the refusal that names it, the rotation table's bytes per position) so every build's placement can take it; ds41's seat opens through them

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd prefill_media in serve_seats/qwen3, the tower's reserve and the rotation tables in qwen3moe's placed plan and whole fit (each named in the ctx and whole-fit lines), the &VISION record; gate_qwen3_serve's --images clauses: set E prompt ids, set F chat inside the CUDA/CPU agreeing prefix with a first divergence only at a near tie (PIN F_NEAR_TIE 0.1), an image slot beside a text slot, the refusals and the plan's reserve, each FAIL-first by its own mutant

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion_seat::open_seat takes the file the seat resolved (the decide seat's --hf pick), open_tower, merged_cells; the whole-fit line's encoder note has one owner, image_plan::note

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the gates that reach it, the Qwen3.6 image clause's plan budget has its defaults twin, rustfmt

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@midagedev

Copy link
Copy Markdown
Owner

This goes into tonight's 0.3.0 train with #38. e4049ec conflicts with #38's local mode in tools/box.sh, so I resolved it in the train: both blocks stay, and the cargo-oxide check runs in local mode too ($OXIDE$ARCHX$ENVS$OXCHECK$LOCALX). #38's local-mode card test then needs a cargo-oxide at the pin on its PATH, so I added a stub for that one case (card tests 610/0). Before merging I will push the rebased two commits to this branch, so it lands as Merged. Tell me if you see a problem with that resolution.

juliankang4 and others added 4 commits October 11, 2026 22:04
…is tree on a contributor's machine with a card of its own

- docs/contrib/local-check.md rows 1, 3, 4, 5 and 7. No ssh and no rsync: bash runs the same command line in this tree,
  guard and profile and exports included. The environment file is BLOOMERY_ENV_FILE (default ~/bloomery-env.sh; missing: 69).
  Refused (64) on a host that is not Linux, with BLOOMERY_BOX_QUEUE=1, and where /root/bloomery-cpu.lock exists.
- BLOOMERY_LOCK_DIR (tools/ref/lease-probe.sh's LOCK_DIR, /root when unset) holds the timing lease, the holds, the gate
  locks, the V4.1 load lock and queue and the batch hold. Local mode defaults it to ~/.cache/bloomery/locks and makes it.
  It refuses (64) a relative path, which two trees would read apart, and /root however it is spelled, where its guard
  would make the box's lease file; an environment file or BLOOMERY_BOX_ENV that moves it after the guard is refused (64),
  and so is an environment file's BLOOMERY_ARCH other than the one the recipe expanded. lease-probe.sh's holds glob and
  give-way check and gpu-gate.sh's lock descriptors take the path whole, so a path with a space or a ; works.
- lease-probe.sh owns the box's mark: on_box (/root/bloomery-cpu.lock exists) and box_lock_dir (a directory that is
  /root). box.sh, gpu-gate.sh and lease_take read them.
- gpu-gate.sh: BLOOMERY_BOX_CARD=local takes one lock, bloomery-gate-local.lock, for what the machine shows, and leaves
  CUDA_VISIBLE_DEVICES as it finds it; its lock directory is never /root (64). `both` in BLOOMERY_CARD or
  BLOOMERY_GATE_CARD is refused (64); a held lease is waited for as the lock is. On the box, BLOOMERY_BOX_CARD=local and
  a BLOOMERY_LOCK_DIR other than /root are refused (64), as lease_take refuses another lease file there.
- CUDA_OXIDE_BACKEND is unset after the environment file (row 7), so cargo oxide builds and keeps its own backend (no
  rc 70 check). BLOOMERY_REMOTE adds no CARGO_BUILD_JOBS.
- The command runs without the variables box.sh reads on this side (BLOOMERY_MODEL above all: the model crate's tests read
  it as a model path), without box.sh's own outputs (BLOOMERY_REF_MODEL_PROFILE, the fixture tier's BLOOMERY_CARD_BUDGET
  and BLOOMERY_FIXTURE_MODEL) and without the lease's file names, as over ssh.
- box-gc.sh refuses (64) local mode: its root is then the contributor's tree, whose binaries are their own runs.
- Unset or 0 leaves the ssh, rsync and queue arguments box.sh builds byte-identical, direct and queued.
- card-tests: the local mode cases, the lock directory (two holds' give-way under a path with a space among them), the
  refusals, LOCAL=0 against unset, and on the box gpu-gate.sh's box refusals; the helpers drop the new variables a caller
  in local mode would pass. gpu-gate.sh --self-test: the local lock, the V4.1 load lock, a held lease.
FAIL-first: against main's box.sh, gpu-gate.sh, lease-probe.sh, lease.sh and box-gc.sh, 27 card tests are red. With
gpu-gate.sh's local arm removed the self-test's six local cases are red, and with take_local not reading the lease its
lease case is red. On a stand-in for the box (a root container where /root/bloomery-cpu.lock exists), removing
gpu-gate.sh's box refusal turns its two card tests red.
…ERY_BOX_CARD=local): timing-card.sh times the one card nvidia-smi lists by UUID, the lease and its trace sit in BLOOMERY_LOCK_DIR, the witness prints the card, its Xid count, the shared memory pool and the machine, and depth-qwen3moe.sh fails an arm on an Xid or a lost card

FAIL-first: against the local mode commit's timing-card.sh, lease.sh, arm-place.sh, depth-qwen3moe.sh and lcpp-warm.sh,
18 card tests are red on a Mac (the same 18 of 583 on Linux): 17 of the 18 local mode cases (the 18th, an arm on a card
that answers, is a control) and lease_take's machine lease under BLOOMERY_LOCK_DIR. With lease.sh's local label and its
trace path in the lock directory removed, the lease self-test's tag-local-busy and trace-file-lock-dir are red. Against
the local mode commit's runner the stub suite's local, local-xid and local-twocard cases are red (3 of 69, on Linux).
With the journal check reading its stderr with its stdout, the case of a journal that only warns on stderr is red; with
the local refusal tagged [timing-cards], its tag case is red. The pool line's fields are pinned by the stub suite's
local case alone (with the earlier pool line, 1 of 69 is red on Linux); the bound on the UUID query and the journal
check's skip for root have no test that can see them.
…ork's cargo-oxide (87bc9518, merged on bloomery) reads `[target.<triple>] extra-rustflags`, so .cargo/cuda-oxide.toml carries znver3 (with -sse4a) for x86_64-unknown-linux-gnu only and target-cpu=native for aarch64-unknown-linux-gnu, and .cargo/config.toml takes the same aarch64 table; the flat znver3 reached aarch64 builds, where rustc warned on every crate and crashed in LLVM on glob and regex-syntax. check-rustflags reads each list's codegen options in every spelling rustc takes (-C x, -Cx, --codegen, target_cpu for target-cpu), holds each triple's two lists equal, x86_64 to znver3 and -sse4a, aarch64 to an aarch64 CPU name (native, generic, cortex-*, neoverse-*, apple-*) and no target-feature, and refuses a top-level CPU flag; its twelve cases (the old flat list and its joined spelling, znver3 or haswell or an x86 feature or the target_cpu spelling on aarch64, a missing side, ...) run red on every call. The x86_64 flags an oxide build gets with --target x86_64-unknown-linux-gnu are byte-identical to the flat list's. The [patch] pin moves 4da6c138 -> 87bc9518 (pin/4da6c138 is tagged); 87bc9518 differs from 4da6c138 only in crates/cargo-oxide, so the backend crates are untouched

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…t the pinned rev (midagedev#36 review) — a cargo-oxide older than 87bc9518 reads only the top-level extra-rustflags and ignores the [target.<triple>] tables without a word, so with this branch's .cargo/cuda-oxide.toml it would build the host code without znver3 and -sse4a while every check stays green. A command that builds with cargo-oxide (one that names `cargo oxide`, `gate.sh --oxide` or `release/build.sh`, once any `release/build.sh --check`, which only reads built binaries, is taken out of it, so a build chained after a --check is still checked) now reads `cargo install --list` on the box, after the BLOOMERY_BOX_ENV exports so a CARGO_HOME or PATH set there is the one checked, and goes on only when its cargo-oxide line names the pin's rev (`...?rev=<rev>#<short>`); any other rev, or an install with no rev (a path install), stops with rc 70 naming the installed rev, the pin and the reinstall line in docs/BUILD.md. Other commands are unchanged. card-tests: the remote command of each of the three forms carries the check, after a BLOOMERY_BOX_ENV CARGO_HOME, and so does a --check chained with a build; a plain cargo call and a lone `release/build.sh --check` do not; the check run against a stub `cargo install --list` passes the pin and refuses 4da6c138 and a path install. FAIL-first: with the old box.sh the presence check and both refusals were red (the pin case passed)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@midagedev
midagedev force-pushed the cargo-per-target-rustflags branch from e4049ec to 9fa36f5 Compare October 11, 2026 13:46
@midagedev

Copy link
Copy Markdown
Owner

This branch now points at its commit in the 0.3.0 release train. One conflict with #38 in tools/box.sh (the remote command line) is resolved there, and the card-tests local-mode case uses a stub cargo-oxide at the pin. It lands with the release tonight.

@midagedev
midagedev merged commit 9fa36f5 into midagedev:main Oct 11, 2026
1 check passed
juliankang4 added a commit that referenced this pull request Oct 13, 2026
…s what its earlier commits earned

A merged pull request is labelled from its merge commit against that commit's first parent. A rebase merge, the only
kind this repository's merge button allows, has no merge commit: merge_commit_sha is the pull request's last commit,
so the diff covers that commit alone, and the labels its open runs put on for the earlier commits came off at the
merge. A merge now adds labels and removes none. Walking back the pull request's commits does not fix the diff: a
stack pushed at once (#27, #36, #38, #39) lists every commit below it, so each would take the whole stack's labels.
@juliankang4 juliankang4 added the tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo label Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants