Repository navigation
gpu: gemm_q8_0p_slab reads the Q8_0 planes a row's step at a time for a full card of tiles that share their slabs - #549
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: The new slab path accepts a code plane that violates its asynchronous copy alignment.
Must fix
1. Check the code plane's alignment before dispatch
gemm32.rs:297 copies 16 bytes from qs, with every source offset a multiple of 16 bytes. The safe tensor window constructor checks only the element's alignment, so DeviceTensor::<u32>::window_of(&parent, 4, 4112, 640) succeeds for a sufficiently large aligned parent.
Use that window with an aligned scale plane, K=2560, and a filled dense route of 1100 slots. The shape checks accept it; the derived grid is 594 blocks and selects the slab entry when the loaded wave is at most 594. The launcher check validates only d. Every code source address remains 4 modulo 16, reaching undefined device memory operations instead of a named shape error (kind A, R19).
One shared check protects both Q8_0-plane entries and avoids diagnosing an asynchronous device failure later. Inside the Q8_0Plane match arm, insert this before the selector:
crate::tensor::check_alignment::<cuda_device::vector::U32x4, _>(
"Gemm32Kernels::enqueue_gemm32",
"Q8_0 code plane",
qs.buf(),
)?;Extend the existing alignment gate with an aligned scale plane and a code-plane window at byte offset 4. Assert a shape error naming Q8_0 code plane and untouched output; removing this check must turn the clause red.
Checked
Traced the tensor window, shape validation, selector, launch contract and new slab copy. The current alignment gate offsets only the scale plane. No escape-catalog pattern or ledger lesson applies.
Notes
Validation was static; GPU gates were not run. The PR reports GB10 and RTX 5090 gate output.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu/src/gemm/gemm32.rs, crates/gpu/src/gemm/kernels32.rs and carries a gate run on the author's card, which counts as verified.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
… a full card of tiles that share their slabs The Q8_0-plane GEMM was bound by L2 requests, not by the tensor pipe: on GB10 its L2 tag stage ran at 86 % of peak while the IMMA pipe ran at 21 %. Each 64-value step sent two code requests a row (16-byte chunks 32 bytes apart, each reading half of two sectors) and one 2-byte scale request a row, and a stack larger than L2 (qkv, q) came from DRAM once per tile. gemm_q8_0p_slab reads the same planes with the same products, order and bits: four threads copy a row's 64 bytes in one instruction, each pair keeps a 16-byte window of eight scales, read once per four steps and decoded at the store, and an expert of 8 MiB of planes or more goes in groups of 16 tiles, slab by slab, so the resident blocks share their weight slabs. Those reads cost a few instructions a step. They pay where several tiles read each slab across a full card, and lose up to 8 % on GB10 where each slab is read once (16 or 64 columns) or the grid fits in one wave. So the launcher takes the new entry for a grid of one wave or more (the card's SMs times the entry's resident blocks an SM, read at load) whose slots pass one tile an expert (Gemm32Kernels::q8_0p_slab), and gemm_q8_0p, unchanged, otherwise. The other five 32-value entries keep their code. gate_gemm's g32_slab runs one stack past the raster's bytes at one tile and at two tiles under a wave (gemm_q8_0p) and at a full card (gemm_q8_0p_slab), checks the entry q8_0p_slab names for each, and holds every output bit for bit to the contract's transcription.
…cales At K 2560 every row of the stack starts on a group of eight scales, so the slab entry's first step always moves the window and the window @prep binds is never read. K 2592 is 81 blocks a row: most rows start inside a group, and their first scales come from that window.
eae630b to
05e0fbf
Compare
There was a problem hiding this comment.
Since the last review: finding 1 is fixed at gemm32.rs:1417. Both Q8_0-plane entries check code alignment before launch. The gate checks named refusal and untouched output for both entries.
Verdict: CLEAN: The interdiff closes the alignment defect and preserves bounds for the revised scale loads.
Checked
Duplicates: 0 new definitions in the interdiff. Both dryer pairs use the existing gemm32_block! core; their weight-layout arms differ.
Complexity: slab_case (55) adds graph inspection, refusal checks and a second K. q8p_gemm_arms (19) is unchanged benchmark enumeration.
Silent failure: 1 zero-default site followed. Only inactive row pairs reach it; live scale windows fit within the checked stack.
Tests: removing the alignment checks fails the refusal assertions; forcing the old entry at gemm32.rs:1428 fails entry_ok; zeroing the initial window at gemm32.rs:339 fails the K=2592 numerical assertions. The PR reports red runs for these mutants.
Bounds: standalone arithmetic checks passed for every supported K, scale-window transitions, partial raster groups and the empty-tile mapping.
Gates: numerical bands unchanged. The unsafe ratchet and replaced gate clauses have dated PIN reasons.
Performance: the changed production path adds no launches, copies, allocations or synchronization. The PR supplies gate output and timed prefill A/B evidence.
Escape catalog: no matching pattern.
Notes
Validation here was static plus arithmetic checks; no CUDA build or GPU gate was run. The PR supplies GB10 and RTX 5090 gate output.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu/src/gemm/gemm32.rs, crates/gpu/src/gemm/kernels32.rs and carries a gate run on the author's card, which counts as verified.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8의 dense 프롬프트 projection에서 Q8_0 GEMM이 카드를 한 wave 이상 채우면 tile들이 weight slab을 함께 읽는 새 커널로 계산하게 해서, DGX Spark 한 대의 prefill을 빠르게 하는 작업입니다.
Part of #493.
What and why
This PR adds
gemm_q8_0p_slab, a second entry for the Q8_0-plane prompt GEMM. The launcher takes it when the grid fills at least one wave of the card (as many blocks as all its SMs hold at once) and the slots fill more than one 64-column tile an expert. Every other launch keepsgemm_q8_0p, whose kernel does not change. On one DGX Spark, Qwen3.8-Flash-Next UD-Q4_K_XL prefills 2,048 tokens at 1296.56 tok/s against 1188.63 tok/s on main (+9.1%), and 512 tokens 7.7% faster. On an RTX 5090, UD-Q3_K_XL prefill is 2.3% faster at 2,048 tokens and 2.4% faster at 512. Decode speed is the same on both cards. On both, the newg32_slabcase observes which entry each launch runs, andgate_gemmmatches every checked output bit for bit to the contract's transcription.Main's
gemm_q8_0pis bound by L2 requests. An ncu profile of it on GB10, at thezprojection (6144 x 2560) with 2,048 columns, shows the L2 tag stage at 86.3% of peak while the IMMA pipe is active 20.7% of the time. Each 64-value step sends two code requests a row (16-byte chunks 32 bytes apart, each reading half of two sectors) and one 2-byte scale request a row. Blocks go tile by tile, so a stack larger than L2 (qkvat 27.8 MB andqat 33 MB, against GB10's 24 MiB) comes from DRAM once per tile.gpu/gemm/gemm32.rs:gemm_q8_0p_slabreads the same planes with the same products, order and bits. Four threads copy a slab row's 64 bytes of a step in one request (w32!(@stage slab)). Each thread pair keeps a 16-byte window of eight scales, read once every four steps, and decodes its scale at the store (@window,@load,@store). An expert of 8 MiB of planes or more (GEMM32_RASTER_BYTES) runs its blocks in groups of 16 tiles, slab by slab (raster32), so the blocks resident at once share each weight slab. A smaller stack stays in L2 and runs tile by tile, as before.Gemm32Kernels::q8_0p_slab(grid, n_slots, n_experts)picks the entry:gemm_q8_0p_slabwhen the grid is at least one wave and the slots fill more than one tile an expert, elsegemm_q8_0p. The extra reads cost a few instructions a step. They pay back when several tiles read each slab across a full card, but not when each slab is read once (16 or 64 columns) or the grid fits in one wave. One wave is the card's SM count times the entry's resident blocks an SM, whichGemm32Kernels::loadreads from the card: 48 x 2 = 96 blocks on GB10 and 170 x 2 = 340 on an RTX 5090.gemm32.rs: both entries copy the code plane in 16-byte chunks, andgemm_q8_0p_slabalso reads a thread pair's eight scales as one 16-byte load. A window into the code plane is only 4-byte aligned, and one into the scale plane only 2-byte aligned. Before either entry launches,enqueue_gemm32checks the code plane withtensor::check_alignment, and before a slab launch it checks the scale plane too. A misaligned plane gets aGpuError::Shapethat names it (Q8_0 code planeorQ8_0 scale plane), and nothing launches.gpu/gemm/kernels32.rs: thegemm_q8_0p_slabkernel entry and its launch contract.gate_gemm.rs: the newg32_slabcase runs one 4112-row stack at K 2560 and at K 2592 (81 blocks a row, so rows start inside a group of eight scales; 11.2 and 11.3 MB of planes, past the raster threshold) at 16 columns (one tile, 33 blocks), 65 columns (two tiles, 66 blocks) and 1100 columns (594 blocks). It captures each launch in a graph, reads the kernel node's entry name and grid, and expectsgemm_q8_0p_slabwhere the slots pass one tile and the grid reaches the wave thatGemm32Kernels::q8_0p_wave()reports for the card. Numerical checks cover all outputs at 16/65 columns and a rotating quarter at 1100; checked outputs match the f64 band and the contract's transcription bit for bit. Every output is checked for writes and contributes toy_fnv. Itsg32_slab_selectorclause checksq8_0p_slabone block under the wave, at the wave and at one tile.g32_slab_scale_unalignedlaunches the slab entry with the scales at byte offset 2, andg32_slab_code_unalignedlaunches each entry (1100 and 16 columns) with the codes at byte offset 4, at each K. Both expect the named refusal with the output untouched. The first commit adds bench arms forgemm_q8_0pat Qwen3.8's dense prompt projections and around the loaded wave.tools/ref/ptx-shapes*.tsvgain agemm_q8_0p_slabrow, andtools/unsafe-ratchet.txtmoves fromgpu 1986togpu 1991with aPIN(2026-10-20)line.Release notes: Changed: Qwen3.8's dense Q8_0 prompt projections take a faster GEMM entry,
gemm_q8_0p_slab, when a launch fills the card, with the same output bits.Code shape
gemm_q8_0p_slabis a new weight arm of the existingw32!andgemm32_block!macros, so it shares the K walk, the MMA and the epilogue with the other six 32-value entries, which keep their code.gemm_q8_0pstill runs every launch under one wave or at one tile an expert.u32is a namedGpuError::shapeat load. A code plane that is not 16-byte aligned, or a scale plane that is not at a slab launch, is a namedGpuError::Shapebefore the launch, which leaves the output untouched. A block past the live tiles returns at once.gpu 1986togpu 1991: four blocks in the neww32!arms and one in the raster prologue, each with a SAFETY line, under aPIN(2026-10-20)line that names them.rustfmt --checkpasses ongate_gemm.rs, and clippy reports no warning on a line this PR adds.Duplication found or removed: none.
What I ran
The head of this PR is
05e0fbfbon upstreame3ce40fd. Theg32gate ran on both cards at this head, and so did the GB10 prefill A/B. The kernel bench, the RTX 5090 prefill A/B and theq5_0pandg38gate cases were measured ata3f0dde9on upstream7c7a3e94, except the RTX 5090 kernel bench, which ran ata32ca4af, whose kernel, launcher and bench code are the same.The kernel bench and the RTX 5090 A/B predate the current slab body, which has no scalar scale fallback: a thread pair always reads its window of eight scales with one 16-byte load.
kernels32.rsis the same as ata3f0dde9, andgemm_q8_0phas the same PTX as main.gemm_q8_0p_slabuses 118 registers on GB10 and 120 on the RTX 5090, with no spill on either (ptxas 13.3.73). The other changes ingemm32.rsare host code: the code-plane alignment check before either Q8_0-plane entry, the scale-plane check before a slab launch, theq8_0p_wave()accessor that the gate and the bench read, and an unused import that upstream removed. The bench arms keep their sizes on both cards, because half of the loaded wave is the SM count on each.Correctness
I ran
just gate-gpu-gemm --case g32at05e0fbfbon GB10 (BLOOMERY_ARCH=sm_121) and on the RTX 5090 (sm_120). The oracle is the f64 reference band and the contract's transcription, which every checked output must match bit for bit. Theq5_0pandg38cases run entries other than the two Q8_0-plane ones, whose code this head does not change, so their results come froma3f0dde9.05e0fbfba3f0dde9a3f0dde9The 177
y_fnvoutput hashes that theg32run prints are the same on both cards. A hash covers every output of its row; the band and bit comparison covers the outputs a row reports aschecked.g32_slab_selectorpasses at the loaded wave (wave=96on GB10,wave=340on the RTX 5090). Ing32_slabat K 2560, m 16 (grid 33,checked=65792) and m 65 (grid 66,checked=267280) reportentry=gemm_q8_0p entry_ok=true, and m 1100 (grid 594,checked=1130800) reportsentry=gemm_q8_0p_slab entry_ok=true. All three reportband_off=0 contract_bits_differ=0with the same output hashes on both cards (y_fnv=256df6760857058e,8af9d8d4c394d283and9521145de741e977). At K 2592 the same three rows pass with the same entries, the samecheckedcounts and the same hashes on both cards (y_fnv=886af2dc789c238c,9c8f676e2af435aaand1beb2efa95ae3d60). The refusal rows reportnamed_shape=true output_untouched=trueon both cards at each K:g32_slab_scale_unalignedat byte offset 2 with the detailQ8_0 scale plane, andg32_slab_code_unalignedat byte offset 4 for m 1100 and m 16 with the detailQ8_0 code plane, eachis not 16-byte aligned.Each new clause fails first on the defect it guards. All of these runs were on GB10 except the first. At
05e0fbfb, on the RTX 5090:@prepwindow replaced by zeros, K 2592 at m 1100 reportsband_off=989051 contract_bits_differ=989443and FAIL, K 2560 at m 1100 still passes, and the gate exits with rc 1.At
b3f9bcbd:enqueue_gemm32changed to launchgemm_q8_0p, the m 1100 row reportsentry=gemm_q8_0p entry_ok=falseand FAIL while its numbers still match (band_off=0 contract_bits_differ=0 y_fnv=9521145de741e977), and the gate exits with rc 1.g32_slab_code_unalignedgetsresult=Ok(())and reportsnamed_shape=false output_untouched=falseFAIL with rc 1, at m 1100 on the slab entry and, in a separate run, at m 16 ongemm_q8_0p.At
2ef4554f:g32_slab_scale_unalignedgetsresult=Ok(())and reportsnamed_shape=false output_untouched=falseFAIL, and the gate exits with rc 1.grid=66 slab=true,contract_bits_differ=0) with rc 1. The loaded-wave expectation passes the same input with rc 0.grid >= self.q8_0p_wave() &&removed fromq8_0p_slab,g32_slab_selectorreports FAIL and the gate exits with rc 1.Kernel bench
gate_gemm --bench-kernels --bench-arm <arm>at Qwen3.8's dense prompt shapes. Head and main were built from the same tree with each side's kernel files and run alternately (head, main, main, head) for each arm: one round on GB10 (two runs a side) and two rounds on the RTX 5090 (four a side). Each run reports its rate in TOPS (2 x T x rows x K over the minimum graph time), and the table gives each side's median at 2,048 columns.qkvzoutqkvAt the wave boundary with two tiles, the arm one wave wide runs
gemm_q8_0p_slaband gains 4.0% on GB10 (96 blocks) and 14.1% on the RTX 5090 (340 blocks). The arm two blocks under the wave runsgemm_q8_0pand reads the same as main (GB10 -0.1%, RTX 5090 +0.0%).The one-tile arms at the wave boundary (
wavem1_t16,wave_t16,wavep1_t16) read -0.7%, -0.5% and -0.9% on GB10 and 0.0% on the RTX 5090. They run main'sgemm_q8_0pon the head too, because one tile an expert keeps that entry. The sm_121 builds of head and main differ only by the rows of the newgemm_q8_0p_slabentry, andgemm_q8_0phas the same PTX and the same ptxas row (ptxas 13.3.73) in both, so it is the same machine code. The difference comes from how the two builds lay out the binary.Prefill A/B on one DGX Spark
generate_qwen3moewith Qwen3.8-Flash-Next UD-Q4_K_XL, the first P ids of an English prose corpus as the prompt,BLOOMERY_DRAFT=off, 32 generated tokens,--time, one process a row:Two untimed runs (main, then head, at P 2048) came first. Then P 2048 ran head, main, main, head twice, and P 512 once, all in one sitting. Head is
05e0fbfb, and main is upstreame3ce40fdbuilt from its own tree.Delta (head against main, medians): pp2048 +9.1%, pp512 +7.7%; decode unchanged.
Every head row is above every main row. The card's 1 GiB device-memory stream read measured 241.8 GB/s before the sitting and 239.6 GB/s after it, and the kernel log showed no Xid.
Prefill A/B on an RTX 5090
The same command and order with Qwen3.8-Flash-Next UD-Q3_K_XL, measured at head
a3f0dde9after one untimed run, with main built from upstream7c7a3e94's tree forsm_120:Delta (head against main, medians): pp2048 +2.3%, pp512 +2.4%; decode unchanged.
An nsys profile of the head at P 2048 confirms that both entries run in this prefill:
gemm_q8_0p_slab279 launches for 16.1% of GPU time andgemm_q8_0p217 launches for 5.3%.Hardware
Three machines: one DGX Spark ran the gate and the kernel bench, a second DGX Spark ran the prefill A/B, and an RTX 5090 machine ran the gate, the kernel bench and its A/B.
nvidia-smion each card in the gate run at05e0fbfb:GB10 is compute capability 12.1 (
BLOOMERY_ARCH=sm_121), and the RTX 5090 is 12.0 (sm_120). The DGX Spark that ran the A/B reports the sameNVIDIA GB10, 595.84.just gate-gpu-gemm --case g32buildsgate_gemmfor the card and runs it. Its last lines on GB10, then on the RTX 5090:The
q5_0pandg38summary lines from the GB10 run ata3f0dde9:Models:
unsloth/Qwen3.8-Flash-Next-GGUFat revision766911a6, UD-Q4_K_XL, on the DGX Spark, and Qwen3.8-Flash-Next UD-Q3_K_XL (first shard sha256f2ef4328) on the RTX 5090.What I ran into
None of this blocks the PR. Nothing came up that needs a maintainer's attention.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.