Skip to content

dgx-spark: P1, qdot runs the host tier off x86_64 through its scalar mirrors (design S) - #15

Closed
juliankang4 wants to merge 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-p1
Closed

juliankang4 wants to merge 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-p1

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

The qdot part of P1 in docs/contrib/dgx-spark.md, with answer 1 of §5 (design S in P1). Part of #13. #14 is in
main now, and this branch is rebased on it: the change is the one commit. Design R (#14)
refuses the host tier off x86_64, but the fixture tier offloads to it (§3.4), so the fixture gates need it to run there.
The rest of P1, and how I plan to go on with the port, are in a comment on #13.

  • Off x86_64, qdot::supports is has_kernel: every type with a kernel takes the fused path through its scalar
    mirror, which carries the AVX2 kernels' bits. fuses follows, so the host union admits its stacks and the matmul
    dispatch fuses its rows. has_features stays false there, so dot_row_cols, dot_q3k_r8_cols and the row lanes
    keep the paths they already take without the ISA: one column at a time through dot_row, the r8 scalar mirror, and
    NoLanes, which the union's lane choice asks first. The union's r8 cost (r8_tile_cost) now asks has_tile(Q3_K)
    like its siblings, so a scalar r8 group is costed at its bytes once a column instead of the AVX2 tile's units.
  • Two kernels had no bit-identical fallback, and both are fixed:
    • swiglu and swiglu_clamp without AVX2+FMA computed silu with libm's exp, one ulp off ik's v_expf on some
      inputs (swiglu_clamp_matches_ik_rule failed on aarch64 in the dgx-spark: P0, the host crates and the engine build on aarch64 (design R) #14 run). They now take expf_ik_scalar(0.0 - g),
      v_expf's bits, as the card rule's swiglu already does.
    • dot_f32 without AVX2+FMA returned None, and its callers summed left to right: 3.8e-6 off the router's exact pin
      in crates/model/tests/moe.rs:81-84. It now runs the kernel's eight lanes one value at a time (mul_add for each
      fused add, then hsum_float_8's pairs), which dot_f32_is_the_reference_lane_order holds to the reference order.
  • Tests. quantize_col_random_bit_identical, hw_v_expf_equals_expf_ik_over_f32_range and
    hw_card_swiglu_clamp_scalar_matches_avx2 only compare an AVX2 path with its mirror, so they are x86_64-only.
    hw_union_q6_k_down_matches_per_column met dgx-spark: P0, the host crates and the engine build on aarch64 (design R) #14's refusal of the host layer off x86_64; it now compares its values
    there and then fails by name on the row-lane clause, as the tile and lane gates already do, instead of passing
    without lanes.

On x86_64 the source change is a cfg line on supports, the fallback lines, the r8_tile_cost predicate (the same
value there) and the tests. With the repo's target-cpu=znver3, is_x86_feature_detected!("avx2") and ("fma") are
true at compile time, so the fallbacks are dead code there and the generated code does not change.

Left out on purpose. Some gates keep an AVX2-against-mirror clause beside hand or ik oracles (the quantize_col gates,
hw_q82_codes_at_bf16_round_down, hw_q8k_codes_at_subnormal_scales, the dot_row gates' kernel-against-emulator
step). Off x86_64 that clause compares the mirror with itself; the oracle clauses next to it are the evidence there, so
I left the tests whole. swiglu_clamp's fallback and card_swiglu_clamp_1 now have the same body, but they transcribe
two rules (ik's and the card's), so I kept them apart.

Code shape

  • No second copy. The fallbacks call the existing expf_ik_scalar; the dot_f32 lanes are the kernel's
    order and the test's oracle is its independent transcription.
  • Model code holds only architecture facts.
  • Dead code is gone.
  • No silent failure. A type with no kernel is still refused by name (UnsupportedType), and a gate whose
    clause has nothing to compare off x86_64 fails by name instead of passing.
  • Comments state what is true now.
  • No relaxed gate. The three tests that become x86_64-only still run there; off x86_64 they would compare a
    mirror with itself.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed: none.

What I ran

On a Mac with the pinned nightly and the CUDA 13.3 headers:

just mac-static upstream/main
mac-static: fmt-check rc 0 in 10 s — rustfmt diff blocks: 0
mac-static: lint rc 0 in 63 s — mac-check: lint ^warning: 41 = the ratchet 41 in tools/lint-ratchet.txt; target <tree>/target, 25 bloomery crates checked or compiled
mac-static: combos rc 0 in 63 s — mac-check: combos rc 0; 17 shapes run, 0 red, 27 skipped (scoped), in 63 s (recipes.py combos: 17 of 37 commands to run, 202 distinct (package, target, mode, features) tuples, 0 green in the ledger, 20 with no input changed since 506b4ba35, 7 left out by name)
mac-static: check-arch rc 0 in 18 s
mac-static: check-comments rc 0 in 18 s
mac-static: check-defaults rc 0 in 1 s
mac-static: check-levers rc 0 in 13 s
mac-static: check-loads rc 0 in 77 s
mac-static: check-recipes rc 0 in 492 s
mac-static: check-rustflags rc 0 in 0 s
mac-static: check-unsafe rc 0 in 2 s
mac-static: check-waits rc 0 in 1 s
mac-static: total 493 s, base upstream/main, ledger ~/.cache/bloomery/mac-static-ledger.tsv
mac-static: ok
BLOOMERY_CHECK_TARGET=aarch64-unknown-linux-gnu tools/mac-check.sh check
mac-check: check rc 0; target <tree>/target, 25 bloomery crates checked or compiled

The x86_64 assembly of bloomery-qdot and bloomery-model (--emit=asm, one codegen unit) equals #14's apart from
the line numbers in panic locations.

On a DGX Spark, in the container #14 describes, the tools/recipes.py host-nightly units pass in all 19 crates; the 25
tests #14 lists as P1's starting list pass, and dot_f32_is_the_reference_lane_order now checks the fallback there
instead of returning early:

bloomery-model rc=0 10s passed=249 failed=0 ignored=104
bloomery-qdot rc=0 2s passed=20 failed=0 ignored=37

The ignored tests of qdot, union and attn, run with plain cargo test as their recipes run them (--release for
the first two). Every red is a missing input or a named refusal:

  • No model file or harness dump on this machine: every gate that reads /models/... or $BLOOMERY_DATA/ref.
  • Named refusals of a clause with nothing to compare off x86_64: the tile gates ("has no tile kernel on this CPU"),
    hw_q3k_r8_tile_matches_dot_row, hw_lanes_match_dot_row_synthetic, hw_union_q6_k_down_matches_per_column after
    its values, and hw_flash_simd_bands_against_scalar (kq_dot_simd's panic). hw_lanes_refuse_bad_shapes fails on
    its first refusal (NoLanes comes first), as its ignore reason says.
  • Green: the union r8 and Q8_0 down gates, hw_flash_split_k_bands_against_one_segment, the encoder edge gates and the
    card gates with oracles.

Hardware

The DGX Spark of #14 (NVIDIA GB10, DGX OS 7.6.0, driver 595.84), in its CUDA 13.3.1 container. No speed numbers here.

AI help

An AI coding agent wrote the code changes and this description, ran the commands above on my machines, and compared
the x86_64 assembly. I did the code review of the diff and the review of this pull request myself.

…rror (design S); swiglu and dot_f32 without AVX2 keep the kernels' bits

supports is has_kernel off x86_64, so fuses admits the host union's stacks and the matmul dispatch's rows there. Tile,
r8 and row-lane calls keep has_features, false off x86_64, and take the scalar paths they already have; the union's r8
cost asks has_tile(Q3_K), as its siblings do, so a scalar r8 group costs its bytes once a column.

swiglu and swiglu_clamp without AVX2+FMA ran silu through libm's exp, one ulp off ik's v_expf on some inputs
(swiglu_clamp_matches_ik_rule); they take expf_ik_scalar, v_expf's bits, as the card rule's swiglu does. dot_f32
without AVX2+FMA returned None and its callers summed left to right, 3.8e-6 off the router pin in tests/moe.rs; it runs
the kernel's eight lanes one value at a time.

quantize_col_random_bit_identical, hw_v_expf_equals_expf_ik_over_f32_range and
hw_card_swiglu_clamp_scalar_matches_avx2 only compare an AVX2 path with its mirror, so they are x86_64-only.
hw_union_q6_k_down_matches_per_column names the row lanes a CPU lacks after its values instead of passing.
@midagedev

Copy link
Copy Markdown
Owner

Thank you very much, Julian. This landed on main as 021dab6, with you as the author. The fixture gate batch was green (132 items, 0 red).

This is the first step that lets the engine build and run off x86_64, and the scalar mirrors keep the kernels' bits. We are truly grateful for this work. I am closing this PR because the commit is on main through our landing train. Your name will be in the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants