Skip to content

gemm: a warp's code copy of the native NVFP4 walk reads eight rows' whole steps - #1005

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-next-prefill-moe
Oct 30, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-next-prefill-moe

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 FP4-Local의 긴 프롬프트 prefill에서 routed expert의 NVFP4 gemm을 DGX Spark에서 빠르게 하는 속도 PR입니다.

What and why

The routed FC1 (gate/up) and FC2 (down) kernels of the native NVFP4 walk in crates/gpu/src/gemm/nvfp4mma.rs spent their time waiting on shared-memory copies. Each thread copied half a row's 16-byte chunk, so a warp's cp.async writes landed on 16-way shared-memory bank conflicts.

  • The native activation planes now hold a 16-value block's values i and i + 8 in byte i, the order the weight uses, so the walk reads both operands' codes as stored and the per-step repack is gone.
  • A thread copies one 16-byte chunk of two weight rows and of one activation column, so a warp reads eight rows' whole 64-byte steps and writes them across all 32 banks.
  • tools/unsafe-ratchet.txt: the gpu unsafe block count goes from 2841 to 2839, the count the file now reaches.

Prefill on Qwen3.8 FP4-Local at a 4096-token prompt is 10.469% faster with the same greedy output. Decode is unchanged.

Release notes: Changed: Qwen3.8 FP4-Local prefill and time to first token are about 10% faster on a DGX Spark, with the same greedy output.

Code shape

  • No second copy. The column mapping the two kernels share is one tile_column beside live_rows in nvfp4mma.rs; both callers use it.
  • Model code holds only architecture facts. The change is in the shared NVFP4 gemm and gained no per-model branch, flag or trait method.
  • Dead code is gone. The per-step weight repack (packed_pair) is deleted with its last use.
  • No silent failure. The change adds no input path; the existing refusals are unchanged.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint moved. The unsafe ratchet count for gpu went down, from 2841 to 2839.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

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

What I ran

Speed

Model nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300, draft off. Each request is a 4096-id prompt and 128 greedy tokens from eight corpus windows 50,000 ids apart, after one lead-in. Base is upstream main 02238d00df9b9c9ae6cc70b271d95b769150d8d8; head is this branch, each built from its own tree and run alternately for six rounds, three a side. Each cell is the median of three rounds. Greedy output is identical on every request.

git checkout 02238d00df9b9c9ae6cc70b271d95b769150d8d8   # main
cargo build -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve
BLOOMERY_DRAFT=off BLOOMERY_HOST_ROOM=96G ./target/release/bloomery-serve -m "$MODEL_FP4L" --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896

Build the head the same way, serve it with the same flags, and send the requests above, alternating the two trees. Ranges are "separate" when the three head rounds and the three base rounds do not overlap.

Metric main head Change Ranges
Prefill tok/s 2512.85 2775.91 +10.469% separate
TTFT p95 ms 1637.19 1482.53 -9.447% separate
Decode tok/s 31.5614 31.5433 -0.057% overlap

Prefill and TTFT p95 are resolved (resolution 0.500%). Decode is not changed by this PR; its row is inside the 0.500% the run can resolve.

Gates and tests

cargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features gpu --release --bin gate_gemm
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemm --case nvfp4_native
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemm --case nvfp4_gate_up
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemm --case nvfp4_swiglu
BLOOMERY_BOX_LOCAL=1 ./tools/box.sh 'bash tools/gate.sh --gpu --oxide --release -p bloomery-gpu --lib -- --ignored --exact gemm::nvfp4mma::tests::hw_native_activation_planes --nocapture'
GATE nvfp4_native PASS-lines=51
GATE nvfp4_gate_up PASS-lines=14
GATE nvfp4_swiglu PASS-lines=21
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 467 filtered out

None of the three gate outputs has a FAIL line.

Hardware (if the change is for a machine)

The change targets the GB10 (sm_121a). The timed runs and the gates ran on a DGX Spark.

NVIDIA GB10, 595.84
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

…he walk reads both operands' codes as stored
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 30, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: One new asynchronous copy uses a safety justification explicitly forbidden by R1.

Must fix

1. State the second copy's safety invariant locally

crates/gpu/src/gemm/nvfp4mma.rs:505 Kind B: R1's addendum explicitly rejects “as above” as a safety justification. This block delegates its source-bound and publication proof to another operation.
Write the proof while introducing the layout, so later edits can be checked at this copy.
Replace the comment with:

// SAFETY: wr1's aligned chunk is within its checked plane; st < STAGES, cr < 64 and
// cq < 4 select unique words in row cr + 64, read only after the copy wait and barrier.

Non-blocking

⚠ Supply the numerical proof: crates/gpu/src/gemm/nvfp4mma.rs:117 permutes K positions within each scale block for both MMA operands. The “float sum order or precision” class requires an error model and gate-gpu-e2e count-pin output. Add those results; the reported kernel bands and equal greedy tokens do not establish that pin.

⚠ Identify the tested head and request command: crates/gpu/src/gemm/nvfp4mma.rs:1372 changes the timed kernel, but the PR body identifies the tested head only as “this branch” and omits the benchmark request-driver command. Record the full tested head SHA and that command with output so the GB10 results are reproducible and tied to the reviewed code.

Checked

Duplicates: tile_column replaces both local column mappings; no second owner found in gemm.
Complexity: tile_column has one conditional; the kernel bodies remain together.
Silent failure: changed row/column clamps pad tiles; live stores retain their bounds.
Tests: no gate tests changed. The bank-layout const assertion checks the revised copy mapping.
Gates: no tolerance relaxed; the unsafe ceiling decreases from 2841 to 2838.
Escape catalog: C1–C4 matched none.

Notes

Validation was static; GPU gates were not run by the validator.

Card check: needs-gpu. This pull request changes crates/gpu/src/gemm/nvfp4mma.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Comment thread crates/gpu/src/gemm/nvfp4mma.rs Outdated
$wq0.as_ptr().add($wr0 * $steps * 8 + at),
)
};
// SAFETY: as above, for the second weight row into row cr + 64 < TILE_ROWS.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R1's addendum forbids “as above”; state this copy's bounds, ownership and publication invariant here.

Suggested change
// SAFETY: as above, for the second weight row into row cr + 64 < TILE_ROWS.
// SAFETY: wr1's aligned chunk is within its checked plane; st < STAGES, cr < 64 and
// cq < 4 select unique words in row cr + 64, read only after the copy wait and barrier.

@juliankang4
juliankang4 force-pushed the dgx-spark-q38-next-prefill-moe branch from 708b6f6 to 4ab8c96 Compare October 30, 2026 08:32

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review: must-fix 1 is fixed at crates/gpu/src/gemm/nvfp4mma.rs:505. The second copy now states its bounds, ownership and publication invariant locally.

Verdict: CLEAN: The interdiff resolves the safety-comment finding and introduces no executable change.

Non-blocking

⚠ Numerical proof remains open: crates/gpu/src/gemm/nvfp4mma.rs:117 permutes K positions within each scale block for both operands. Supply the error model and gate-gpu-e2e count-pin output required by the “float sum order or precision” class. Kernel bands and equal greedy tokens do not establish that pin.

⚠ Tested-head and request-command evidence remains open: crates/gpu/src/gemm/nvfp4mma.rs:1374 participates in the timed kernel. The body identifies the tested head as “this branch” and omits the benchmark request-driver command. Add the full tested head SHA and the command with output to make the GB10 results reproducible.

Checked

Duplicates: 0 new items in the interdiff; dryer reported 0 candidate pairs.
Complexity: crapper flagged no functions; the interdiff changes only a comment.
Silent failure: 0 new sites; checked copy bounds, unique destinations and wait/barrier publication.
Tests: no tests changed; mutation check is not applicable. Static copy arithmetic covered all 256 threads and final half-steps.
Gates: no pins, thresholds or cases changed in the interdiff.
Escape catalog: C1–C4 matched none.

Notes

Validation was static; GPU gates were not run during this review. GPU evidence remains incomplete because the PR text lacks the tested head SHA.

Card check: needs-gpu. This pull request changes crates/gpu/src/gemm/nvfp4mma.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit fb43427 into midagedev:main Oct 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant