Skip to content

Commit 0319803

Browse files
Fangzhou-Aiclaudebenenzhu
authored
[gfx950] DeepSeek-V4.1-Flash DEP8 kernel set (MI355X): sparse MLA, indexer, fused EP8 MoE, mHC, router, samplers, Engram (#12)
* gemm: DeepSeek-V4.1-Flash DEP8 GEMMs (decode-row MXFP8 shapes, wo_a, mHC post-mix epilogues, lm_head) New packages for the DEP8 (8 x MI355X, attention TP1) shapes: - mxfp8_decode_prequant: decode-row MXFP8 GEMM on pre-quantized rows, with a clamped SwiGLU + MXFP8 epilogue. - mxfp8_n1792_k5120 (wq_a | wkv), mxfp8_n32768_k1280 (wq_b), mxfp8_n4096_k1280 (indexer wq_b), mxfp8_n4608_k5120 (shared gate_up), mxfp8_n5120_k2304 (shared down), mxfp8_n5120_k8192 (wo_b): per-shape row tables over mxfp8_decode_prequant and mxfp8_common, falling back to AITER where it is faster. - mxfp8_n5120_k15360: the DSpark draft's input projection. - mxfp8_grouped_g8_n1024_k4096: grouped wo_a with bf16 or MXFP8 output. - mxfp8_postmix_hc4_n5120_k8192, mxfp8_postmix_add_hc4_n5120_k2304: wo_b / shared down with the mHC post-mix epilogue. - bf16_k5120_n1056_f32_n32: compressor kv|score (fp32) + indexer weights_proj (bf16) in one launch. - bf16_n129280_k5120: the full-vocabulary lm_head. - mxfp8_n25600_k6144: the Engram wkv rows, a shape folder registered in mxfp8_common's _SHAPE_HOSTS. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * norm, activation: RMSNorm + MXFP8, dual RMSNorm, mHC seams, clamped SiLU-mul + MXFP8 - norm/rmsnorm_mxfp8_h5120, norm/rmsnorm_dual_mxfp8_q1280_kv512: RMSNorm with the MXFP8 quant fused. - norm/mhc_post_pre_rmsnorm_h5120: the mHC seam (post-mix, gates, collapse, RMSNorm, optional MXFP8) in one launch. - norm/mhc_gate_finish_rmsnorm_h5120: the seam finisher on the post-mix GEMM's tile records. - norm/mhc_post_collapse_rmsnorm_h5120: the step-end post-mix + collapse + final RMSNorm. - activation/clamp_silu_mul_mxfp8_i2304: clamped SiLU-mul + MXFP8 quant for the shared expert's down GEMM. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * attention: sparse MLA decode, RoPE + fp8 KV insert, compressor insert (64 heads x d512) - sparse_mla_decode_fp8kv_h64_d512_rot64: sparse decode attention over the e4m3 KV cache with an inverse-RoPE + MXFP8 epilogue for wo_a. - rope_fp8_kv_insert_h64_d512_rot64: query RoPE + e4m3 quant and KV RoPE + e4m3 cache insert. - compressor_insert_d512_idx128_rot64: compressor pool + RMSNorm + RoPE and the latent / indexer key cache inserts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * indexer: MXFP4 top-512 indexer and the indexer query RoPE + MXFP4 quant - indexer_mxfp4_h32_d128_top512: top-512 over MXFP4 index keys for decode rows without writing the logits (dense, candidate-source and candidate-consumer layers, optional ragged slot lists), rows up to 1048576 entries. - q_rope_mxfp4_quant_h32_d128_rot64: indexer query RoPE + MXFP4 quant + weight scaling in one launch. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * moe: fused EP8 MoE, MXFP8 x MXFP4 routed experts, sqrt-softplus routers - fused_ep_mxfp4_h5120_i2304_e48_top6_ranks8: one launch per rank for a whole EP8 MoE layer (quant, dispatch, GEMM1 + clamped SwiGLU, GEMM2, combine) over IPC pools on one node; tests/multi_gpu8.py runs its 8-rank test. - mxfp4_h5120_i2304_e48_top6, mxfp4_h5120_i2304_e16_top3: one EP rank's routed experts (main and DSpark draft layers). - router_sqrtsoftplus_top6_h5120_e384, router_sqrtsoftplus_top3_h5120_e128: gate GEMM + biased sqrt-softplus top-k. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * sampling: one-launch Markov draft chain and standard rejection sampling (vocab 129280, 5 draft tokens) - markov_chain_gumbel_bf16_v129280_r256_s5: all 5 Markov draft steps of every request in one launch. - rejection_standard_v129280_s5: standard rejection sampling on the raw bf16 lm_head rows, two launches. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * engram: n-gram row pull over eight ranks and the gated Engram update - ngram_rows_mxfp8_d256_c24_ranks8: n-gram hash + MXFP8 row pull from the owner ranks' tables (IPC), written as the wkv GEMM's activation. - gated_post_bf16_h5120_hc4: the gated Engram update of the four residual streams. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * Index the new packages; 8-GPU CI rows for the Engram and fused EP tests amd_kernels/README.md: one line per new package (new section Engram). tools/ci/targets.tsv: the two 8-rank tests (engram/ngram_rows_mxfp8_d256_c24_ranks8/test_ngram_rows_ranks8.py, moe/fused_ep_..._ranks8/test_fused_ranks8.py) get 8 GPUs. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * One shape-agnostic entry per op for the new ops (#11) Callers (vLLM) no longer import shape packages for the DeepSeek-V4.1-Flash DEP8 ops. Each op gets one entry that reads the shape from its tensors and routes to the shape package; the packages are unchanged. - amd_kernels/routes.py: an op's registry (shape key -> shape package, imported on first use). - amd_kernels/<category>/__init__.py: per op, `<op>(...)` (the shape package's arguments), `<op>_blocker(...)` (None, or the reason a call is not covered, from host metadata only: the caller falls back) and `<op>_shapes()`. attention: sparse_mla_decode, rope_fp8_kv_insert, compressor_insert; indexer: mxfp4_indexer_topk / _candidate_topk, q_rope_mxfp4_quant; moe: router_topk, mxfp4_experts, expert_parallel (fused EP, a collective); norm: rmsnorm_mxfp8, rmsnorm_dual_mxfp8, mhc_post_pre_rmsnorm, mhc_post_collapse_rmsnorm, mhc_gate_finish; activation: clamp_silu_mul_mxfp8; sampling: markov_chain, rejection_sample; engram: ngram_rows, gated_post; gemm: mxfp8_gate_up_swiglu_mxfp8, mxfp8_postmix_gemm / _gates_gemm, mxfp8_grouped_gemm(_mxfp8), bf16_gemm, bf16_gemm_f32_bf16. - MXFP8 dense linears: no new entry. The DEP8 shape folders (1792 x 5120, 4096 x 1280, 4608 x 5120, 5120 x 2304, 5120 x 8192, 5120 x 15360, 32768 x 1280) are registered in gemm._SHAPE_HOSTS with their common-kernel ROWS; a folder with entries of its own adds `linear` / `gemm` (mxfp8_linear on bf16, mxfp8_gemm on row-major codes run the folder's entry where its table has a row), `covers` and `warmup`. New mxfp8_linear_blocker(m, n, k, out_dtype, prequant) answers per row count; tuned_shapes() lists the new shapes. Upstream shapes: unchanged. - tests/test_op_entries.py (CPU): every route names a package, uncovered keys and limits decline with a reason, every entry calls its package with the caller's arguments. tests/gemm/mxfp8_common/test_folder_entries.py (GPU): the common entries return the folder entries' results bit for bit. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * moe/fused_ep_mxfp4_h5120_i2304_e48_top6_ranks8: interleave an expert's route records over its row blocks Block b of an expert with n blocks takes records b, b + n, ... instead of a contiguous range. Records arrive grouped by source rank, so a contiguous split sent a hot expert's GEMM2 returns over one or two links at a time. Outputs are bitwise identical; zipf routing T 384-768 is 14 % faster, lognormal sigma 1.8 at T 710 12 %, uniform unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * Decode rows 769-1024: router, kv_score, wq_b and wo_b tuned rows Four row tables for the padded decode steps above 768 rows (c1024 runs 816-864): - moe/router_sqrtsoftplus_top6_h5120_e384: one tile row up to 1024 rows for the plain and the shuffled gate (20.5-20.7 us shuffled against 28.6-30.3 us served; the untuned large tile took 34-43 us). - gemm/bf16_k5120_n1056_f32_n32: MAX_M 1024, one tile row per column split above 768 rows (1.12-1.40x over the two torch launches). - gemm/mxfp8_n32768_k1280: mxfp8_linear_prequant, row-major codes and scales of the norm producer through the 4-wave kernel after one scale-layout launch (2.3-6.4 us under AITER on the same codes at 769-1024 rows, same bytes); preshuffle_weight_scale for the served linear's weight. - gemm/mxfp8_n5120_k8192: decode rows up to 1024 (96x80 / 112x80 / 128x80, 2 K-waves); serves_after_wo_a(m): wo_a's bf16 output + this entry beats wo_a's MXFP8 epilogue + AITER by 2.4-8.8 us a pair at 769-1024 rows. Tests, benchmarks (prequant scenario, wo_a + wo_b pair) and READMEs included. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * fused EP8 8-GPU test: 49 experts per rank vLLM's shipped DeepSeek-V4.1 expert plan holds one replica slot per rank (S = 49), the geometry the fused EP8 kernel runs under it. Cover it at decode rows up to 1024 per rank (skewed, uniform 848, one hot rank with 1024 rows and empty ranks) and under CUDA graph replay. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * READMEs and tests for decode rows 769-1024 and 49 experts per rank - gemm/mxfp8_n32768_k1280, gemm/mxfp8_n5120_k8192: one performance table each (the pre-quantized and wo_a + wo_b pair rows join the main table), one-line entry points. - moe/fused_ep_...ranks8: 48, 49, 56 and 63 experts per rank are tested. - gemm/bf16_k5120_n1056_f32_n32: the 769-1024-row range is the measured one. - tests/test_op_entries.py: blocker checks for the 769-1024-row codes path and the wo_b rows up to 1024. - test_mhc_seam::test_warmup_covers_every_size: turn the first-call warm-up on, as serving runs it; with it off only m = 16 compiled and the test passed only on a warm FlyDSL disk cache. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> * fused EP8: wrap-safe epoch waits, rows_hint clamped to the token bound, no trace switch from the environment - The arrival and finish waits compared `got < ep + 1` as signed int32. The epoch counts every call and is never reset, so at call 2^31 - 1 `ep + 1` wraps to INT_MIN, every rank skips both waits once and reads counts and the inbox before the peers wrote them. The waits compare the difference now (`(got - (ep + 1)) < 0`), as main's all_to_all_bf16_n100032_ranks2 does. - `sized_tokens` took `rows_hint` above 1024 as the tile size and `config_for` raised StopIteration on that rank before the launch, while the other ranks waited in the kernel. The hint is clamped to MAX_TOKENS. - AKR_EP_TRACE chose a kernel build from the environment; `kernel.TRACE` is a module constant now, which benchmark_timeline.py sets in each rank before the first compile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Taoyu Zhu <zhutaoyu97@gmail.com> * sparse_mla_decode: decline more keys per row than the kernel holds The kernel holds at most MAX_KEYS (1024) keys per row and drops the rest without an error; the entry's key (64 heads, 512 dims) does not show the per-row key count, so a model with the same heads and more keys per row passed the blocker and got a wrong result. `supports_sparse_mla_decode` and `sparse_mla_decode_blocker` take an optional `keys_per_row` (window plus top-k, known to the caller) and decline above MAX_KEYS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Taoyu Zhu <zhutaoyu97@gmail.com> --------- Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com> Signed-off-by: Taoyu Zhu <zhutaoyu97@gmail.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Taoyu Zhu <zhutaoyu97@gmail.com>
1 parent 9c6140c commit 0319803

323 files changed

Lines changed: 39742 additions & 4 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎amd_kernels/README.md‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
One line per kernel package. Each package's README has what it does, its entry points, performance and tests.
44

5+
## Op entries
6+
7+
Callers use one shape-agnostic entry per op ([`routes.py`](routes.py), issue #11): it reads the shape from its
8+
tensors and calls the shape package; `<op>_blocker(...)` returns None or the reason a call is not covered (the caller
9+
falls back), `<op>_shapes()` the covered shape keys.
10+
11+
- `gemm.mxfp8_common.gemm`: `mxfp8_linear`, `mxfp8_gemm` (+ `mxfp8_linear_blocker`, `tuned_shapes`) over the
12+
`gemm/mxfp8_n<N>_k<K>` folders in `gemm._SHAPE_HOSTS`.
13+
- `gemm`: `mxfp8_gate_up_swiglu_mxfp8[_prequant]` (gate_up + clamped SwiGLU + MXFP8).
14+
- `gemm`: `mxfp8_postmix_gemm`, `mxfp8_postmix_gates_gemm` (MXFP8 GEMM + mHC post-mix epilogue).
15+
- `gemm`: `mxfp8_grouped_gemm`, `mxfp8_grouped_gemm_mxfp8` (grouped MXFP8 GEMM, bf16 or MXFP8 out).
16+
- `gemm`: `bf16_gemm` (lm_head), `bf16_gemm_f32_bf16` (fp32 + bf16 columns in one GEMM).
17+
- `attention`: `sparse_mla_decode`, `rope_fp8_kv_insert`, `compressor_insert`.
18+
- `indexer`: `mxfp4_indexer_topk`, `mxfp4_indexer_candidate_topk`, `q_rope_mxfp4_quant`.
19+
- `moe`: `router_topk`, `mxfp4_experts` (+ `mxfp4_expert_weights`), `expert_parallel` (fused EP, a collective).
20+
- `norm`: `rmsnorm_mxfp8`, `rmsnorm_dual_mxfp8`, `mhc_post_pre_rmsnorm`, `mhc_post_collapse_rmsnorm`, `mhc_gate_finish`.
21+
- `activation`: `clamp_silu_mul_mxfp8`.
22+
- `sampling`: `markov_chain`, `rejection_sample`.
23+
- `engram`: `ngram_rows`, `gated_post`.
24+
525
## GEMM
626

727
- [`gemm/mxfp8_common`](gemm/mxfp8_common/README.md): MXFP8 dense GEMM entries (`mxfp8_linear`, `mxfp8_gemm`, ...),
@@ -24,6 +44,7 @@ One line per kernel package. Each package's README has what it does, its entry p
2444
- [`gemm/mxfp8_n6144_k8192`](gemm/mxfp8_n6144_k8192/README.md): the full output projection of the sequence-parallel
2545
prefill.
2646
- [`gemm/mxfp8_n12288_k6144`](gemm/mxfp8_n12288_k6144/README.md): the rows of the 12288 x 6144 GEMM.
47+
- [`gemm/mxfp8_n25600_k6144`](gemm/mxfp8_n25600_k6144/README.md): the rows of the 25600 x 6144 GEMM (Engram `wkv`).
2748
- [`gemm/mxfp8_gateup_swiglu_n6144_k6144_i3072`](gemm/mxfp8_gateup_swiglu_n6144_k6144_i3072/README.md): dense MLP
2849
gate_up + SwiGLU at 1-8 rows (TP4).
2950
- [`gemm/mxfp8_gateup_swiglu_n12288_k6144_i6144`](gemm/mxfp8_gateup_swiglu_n12288_k6144_i6144/README.md): dense MLP
@@ -39,6 +60,30 @@ One line per kernel package. Each package's README has what it does, its entry p
3960
five taps at TP4, and the four-rank gather.
4061
- [`gemm/bf16_concat_linear_n3072_k30720`](gemm/bf16_concat_linear_n3072_k30720/README.md): the draft's input fc over
4162
five taps at TP2, and the two-rank exchange.
63+
- [`gemm/mxfp8_n1792_k5120`](gemm/mxfp8_n1792_k5120/README.md): fused wq_a + wkv projection, N 1792 x K 5120, decode
64+
rows, quantization in the GEMM.
65+
- [`gemm/mxfp8_n32768_k1280`](gemm/mxfp8_n32768_k1280/README.md): the wq_b projection, N 32768 x K 1280, decode rows.
66+
- [`gemm/mxfp8_n4096_k1280`](gemm/mxfp8_n4096_k1280/README.md): the indexer wq_b projection, N 4096 x K 1280, decode
67+
rows.
68+
- [`gemm/mxfp8_n4608_k5120`](gemm/mxfp8_n4608_k5120/README.md): the shared-expert gate_up projection, N 4608 x K 5120,
69+
decode rows.
70+
- [`gemm/mxfp8_n5120_k2304`](gemm/mxfp8_n5120_k2304/README.md): the shared-expert down projection, N 5120 x K 2304,
71+
decode rows.
72+
- [`gemm/mxfp8_n5120_k8192`](gemm/mxfp8_n5120_k8192/README.md): the wo_b projection, N 5120 x K 8192, decode rows.
73+
- [`gemm/mxfp8_n5120_k15360`](gemm/mxfp8_n5120_k15360/README.md): the draft's input projection over three tapped
74+
hidden states, N 5120 x K 15360.
75+
- [`gemm/mxfp8_decode_prequant`](gemm/mxfp8_decode_prequant/README.md): decode-row MXFP8 GEMM on pre-quantized rows,
76+
with a clamped swiglu + MXFP8 epilogue.
77+
- [`gemm/mxfp8_grouped_g8_n1024_k4096`](gemm/mxfp8_grouped_g8_n1024_k4096/README.md): grouped MXFP8 GEMM, 8 groups x N
78+
1024 x K 4096 (the low-rank output projection's first GEMM), bf16 or MXFP8 out.
79+
- [`gemm/mxfp8_postmix_hc4_n5120_k8192`](gemm/mxfp8_postmix_hc4_n5120_k8192/README.md): MXFP8 GEMM N 5120 x K 8192
80+
with the four-stream mHC post-mix epilogue.
81+
- [`gemm/mxfp8_postmix_add_hc4_n5120_k2304`](gemm/mxfp8_postmix_add_hc4_n5120_k2304/README.md): MXFP8 GEMM N 5120 x K
82+
2304 with the routed add and the mHC post-mix epilogue.
83+
- [`gemm/bf16_k5120_n1056_f32_n32`](gemm/bf16_k5120_n1056_f32_n32/README.md): bf16 GEMM, K 5120: fp32 compressor
84+
columns plus 32 bf16 weight columns, one launch.
85+
- [`gemm/bf16_n129280_k5120`](gemm/bf16_n129280_k5120/README.md): the full-vocabulary lm_head, N 129280 x K 5120,
86+
bf16.
4287
- [`gemm/bf16_skinny_common`](gemm/bf16_skinny_common/README.md): the dense bf16 linears of a 1-192 row decode step
4388
(attention in/out projections, shared experts, latent down, lm_head, drafter context projection) on a load-time
4489
packed weight, one tuned tile table.
@@ -58,6 +103,16 @@ One line per kernel package. Each package's README has what it does, its entry p
58103
- [`moe/mxfp4_h6144_i1536_e128_top4`](moe/mxfp4_h6144_i1536_e128_top4/README.md): the TP2 MoE block (I 1536 per rank):
59104
routed MXFP4 experts (A4W4) with the MXFP8 shared expert (a TP shard, or the full copy: its shard read in place,
60105
the whole expert on a sequence-parallel rank's own rows).
106+
- [`moe/mxfp4_h5120_i2304_e48_top6`](moe/mxfp4_h5120_i2304_e48_top6/README.md): routed MXFP8 x MXFP4 experts, 48 local
107+
experts, top 6, H 5120 I 2304.
108+
- [`moe/mxfp4_h5120_i2304_e16_top3`](moe/mxfp4_h5120_i2304_e16_top3/README.md): routed MXFP8 x MXFP4 experts, 16 local
109+
experts, top 3, H 5120 I 2304.
110+
- [`moe/fused_ep_mxfp4_h5120_i2304_e48_top6_ranks8`](moe/fused_ep_mxfp4_h5120_i2304_e48_top6_ranks8/README.md):
111+
one-launch expert-parallel MoE on eight ranks: dispatch, experts, combine.
112+
- [`moe/router_sqrtsoftplus_top6_h5120_e384`](moe/router_sqrtsoftplus_top6_h5120_e384/README.md): router: gate GEMM
113+
and biased sqrt-softplus top-6 of 384 experts.
114+
- [`moe/router_sqrtsoftplus_top3_h5120_e128`](moe/router_sqrtsoftplus_top3_h5120_e128/README.md): router: gate GEMM
115+
and biased sqrt-softplus top-3 of 128 experts.
61116
- [`moe/latent_moe_common`](moe/latent_moe_common/README.md): latent MoE decode entries (`router_sigmoid_bias_topk`,
62117
`mxfp4_moe_experts`, `allreduce_latent_rmsnorm_up_proj`, `layer_tail_launch`, ...): the shape -> package routing and
63118
the reason a call has no kernel.
@@ -89,6 +144,12 @@ One line per kernel package. Each package's README has what it does, its entry p
89144
sliding-window decode attention over an fp8 KV cache, 1 or 2 KV heads per GPU (TP4 / TP2).
90145
- [`attention/norm_rope_fp8_insert_d128_rot64`](attention/norm_rope_fp8_insert_d128_rot64/README.md): the draft's
91146
norm + RoPE + fp8 KV insert, 1 or 2 KV heads per GPU (TP4 / TP2).
147+
- [`attention/rope_fp8_kv_insert_h64_d512_rot64`](attention/rope_fp8_kv_insert_h64_d512_rot64/README.md): query RoPE +
148+
e4m3 quant and KV RoPE + e4m3 cache insert, 64 heads of 512.
149+
- [`attention/compressor_insert_d512_idx128_rot64`](attention/compressor_insert_d512_idx128_rot64/README.md):
150+
compressor pool + RMSNorm + RoPE and the latent / indexer key cache inserts.
151+
- [`attention/sparse_mla_decode_fp8kv_h64_d512_rot64`](attention/sparse_mla_decode_fp8kv_h64_d512_rot64/README.md):
152+
sparse decode attention, 64 heads x d512, e4m3 KV, inverse-RoPE MXFP8 output.
92153
- [`attention/norm_rope_insert_common`](attention/norm_rope_insert_common/README.md): RMS norm + RoPE + KV insert
93154
entries (`qkv_norm_rope_insert`, `kv_norm_rope_insert_multilayer`): the shape -> package routing and the reason a
94155
call has no kernel.
@@ -127,6 +188,17 @@ One line per kernel package. Each package's README has what it does, its entry p
127188
- [`indexer/indexer_nvfp4_d128_p128_top16`](indexer/indexer_nvfp4_d128_p128_top16/README.md): the sparse-attention
128189
indexer: block scores over NVFP4 index pages and the top-16 blocks, decode and prefill, one GPU at 1 / 2 index heads
129190
(TP4 / TP2), or two or four GPUs at decode.
191+
- [`indexer/indexer_mxfp4_h32_d128_top512`](indexer/indexer_mxfp4_h32_d128_top512/README.md): MXFP4 indexer top-512
192+
over decode rows without writing the logits.
193+
- [`indexer/q_rope_mxfp4_quant_h32_d128_rot64`](indexer/q_rope_mxfp4_quant_h32_d128_rot64/README.md): indexer query
194+
RoPE + MXFP4 quant, 32 heads of 128.
195+
196+
## Engram
197+
198+
- [`engram/ngram_rows_mxfp8_d256_c24_ranks8`](engram/ngram_rows_mxfp8_d256_c24_ranks8/README.md): n-gram hash and
199+
MXFP8 row pull from the owner ranks' tables, eight ranks.
200+
- [`engram/gated_post_bf16_h5120_hc4`](engram/gated_post_bf16_h5120_hc4/README.md): gated Engram update of the four
201+
residual streams, bf16.
130202
- [`indexer/mxfp4_indexer_common`](indexer/mxfp4_indexer_common/README.md): MXFP4 DSA indexer entries
131203
(`mxfp4_paged_score_topk`, `mxfp4_prefill_score`, `mxfp4_prefill_topk`): the shape -> package routing and the reason a
132204
call has no kernel.
@@ -152,6 +224,8 @@ One line per kernel package. Each package's README has what it does, its entry p
152224
TP4 down GEMM (I 3072).
153225
- [`activation/swiglu_oai_mxfp8_i6144`](activation/swiglu_oai_mxfp8_i6144/README.md): SwiGLU + MXFP8 quant for the
154226
TP2 down GEMM (I 6144).
227+
- [`activation/clamp_silu_mul_mxfp8_i2304`](activation/clamp_silu_mul_mxfp8_i2304/README.md): clamped SiLU-mul + MXFP8
228+
quant for the shared expert's down GEMM.
155229

156230
## Norms
157231

@@ -164,6 +238,15 @@ One line per kernel package. Each package's README has what it does, its entry p
164238
all-reduce + Gemma norm with bf16-rounded MXFP8.
165239
- [`norm/gemma_rmsnorm_bf16_mxfp8_h6144`](norm/gemma_rmsnorm_bf16_mxfp8_h6144/README.md): Gemma RMSNorm to
166240
bf16-rounded MXFP8.
241+
- [`norm/rmsnorm_mxfp8_h5120`](norm/rmsnorm_mxfp8_h5120/README.md): RMSNorm + MXFP8 quant, H 5120.
242+
- [`norm/rmsnorm_dual_mxfp8_q1280_kv512`](norm/rmsnorm_dual_mxfp8_q1280_kv512/README.md): dual RMSNorm: q row to
243+
MXFP8, kv row to bf16.
244+
- [`norm/mhc_post_pre_rmsnorm_h5120`](norm/mhc_post_pre_rmsnorm_h5120/README.md): mHC seam in one launch: post-mix,
245+
gates, collapse, RMSNorm (+ MXFP8).
246+
- [`norm/mhc_gate_finish_rmsnorm_h5120`](norm/mhc_gate_finish_rmsnorm_h5120/README.md): mHC seam finisher: GEMM tile
247+
records to gates, collapse and RMSNorm (+ MXFP8).
248+
- [`norm/mhc_post_collapse_rmsnorm_h5120`](norm/mhc_post_collapse_rmsnorm_h5120/README.md): mHC step-end tail:
249+
post-mix, collapse and final RMSNorm.
167250
- [`norm/attnres_rmsnorm_common`](norm/attnres_rmsnorm_common/README.md): the all-reduce + AttnRes + RMSNorm entry
168251
(`attnres_comm`): (hidden, world size) -> package and the reason a call has no kernel.
169252
- [`norm/allreduce_attnres_rmsnorm_h7168_ranks8`](norm/allreduce_attnres_rmsnorm_h7168_ranks8/README.md): eight-rank
@@ -233,6 +316,10 @@ One line per kernel package. Each package's README has what it does, its entry p
233316
vocabulary (163840, 200064) -> package and the reason a call has no kernel.
234317
- [`sampling/top_p_mask_f32_v200064`](sampling/top_p_mask_f32_v200064/README.md): vLLM's top-p without top-k on fp32
235318
logits rows, bit for bit: the split chain (<= 64 rows) in one launch, the one-program-per-row kernel above.
319+
- [`sampling/markov_chain_gumbel_bf16_v129280_r256_s5`](sampling/markov_chain_gumbel_bf16_v129280_r256_s5/README.md):
320+
5-step Markov draft chain for every request of the batch in one launch.
321+
- [`sampling/rejection_standard_v129280_s5`](sampling/rejection_standard_v129280_s5/README.md): standard rejection
322+
sampling of 5 draft tokens, two launches.
236323
- [`sampling/top_p_mask_f32_v163840`](sampling/top_p_mask_f32_v163840/README.md): top-p mask of <= 64 fp32 logits rows,
237324
vocabulary 163840: vLLM's split top-p chain in one launch.
238325

‎amd_kernels/activation/__init__.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# SPDX-FileCopyrightText: Copyright contributors to the amd-kernels project
3+
"""Activation op entries (``amd_kernels.routes``): clamped SiLU-mul + MXFP8."""
4+
5+
from amd_kernels.routes import Routes, check, first
6+
7+
_CLAMP_SILU = Routes("clamp_silu_mul_mxfp8", {2304: "amd_kernels.activation.clamp_silu_mul_mxfp8_i2304"})
8+
9+
10+
def clamp_silu_mul_mxfp8_shapes() -> frozenset:
11+
"""Intermediate sizes (half the gate_up width)."""
12+
return _CLAMP_SILU.shapes()
13+
14+
15+
def clamp_silu_mul_mxfp8_blocker(gate_up) -> str | None:
16+
"""None when a package serves ``silu(min(g, limit)) * clamp(u, -limit, limit)`` + MXFP8 of ``gate_up``
17+
[rows, 2 * inter] bf16."""
18+
if gate_up.dim() != 2 or gate_up.shape[1] % 2:
19+
return "clamp_silu_mul_mxfp8: gate_up must be [rows, 2 * inter]"
20+
return first(
21+
_CLAMP_SILU.blocker(gate_up.shape[1] // 2),
22+
None if str(gate_up.dtype).endswith("bfloat16") else "clamp_silu_mul_mxfp8: needs bf16 gate_up",
23+
)
24+
25+
26+
def clamp_silu_mul_mxfp8(gate_up, limit: float = 10.0, **kwargs):
27+
"""``(codes, scales)``; ``codes=`` / ``scale=`` as the shape package's ``clamp_silu_mul_mxfp8``."""
28+
check(clamp_silu_mul_mxfp8_blocker(gate_up))
29+
return _CLAMP_SILU.package(gate_up.shape[1] // 2).clamp_silu_mul_mxfp8(gate_up, limit, **kwargs)
30+
31+
32+
def warmup_clamp_silu_mul_mxfp8(inter: int, device=None) -> None:
33+
_CLAMP_SILU.package(inter).warmup_clamp_silu_mul_mxfp8(device)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Clamped SiLU-mul + MXFP8, I 2304 (gfx950)
2+
3+
## What it does
4+
5+
One launch for the activation between the shared-expert gate_up and down GEMMs of a SwiGLU MLP with a clamp, and the
6+
MXFP8 quant of its result for the down GEMM. Input: gate_up bf16 `[M, 4608]` (gate columns 0-2303, up columns 2304-4607,
7+
unit column stride, any row stride), M >= 0 (decode rows 1-768, any larger M works), fp32 limit (10 in the served
8+
model). Outputs: e4m3 codes `[M, 2304]` and E8M0 scale bytes `[M, 72]`, both row-major (the layout the vLLM MXFP8 linear
9+
takes as a pre-quantized `QuantizedActivation`).
10+
11+
Contract (`reference.py`): vLLM's `SiluAndMulWithClamp` at alpha 1, beta 0 (its HIP op): `g = min(gate, limit)`,
12+
`u = clamp(up, -limit, limit) + 0`, `act = bf16(bf16(silu(g)) * u)` with `silu(g) = g / (1 + exp(-g))` in fp32 (the
13+
intermediate bf16 rounding is the op's); then Triton's `mxfp8_e4m3_quantize` of the bf16 `act`: per 32 columns
14+
`clamp(ceil(log2(amax / 448)) + 127, 0, 254)` and e4m3 codes of `act * 2^(127 - byte)`. Codes and scales equal the
15+
served op + quantizer bit for bit (tests, 19 row counts).
16+
17+
## Entry points
18+
19+
- `clamp_silu_mul_mxfp8`: the down GEMM's codes and scales of a gate_up block; outputs may be the caller's static
20+
buffers; graph-capture safe, bitwise repeatable.
21+
- `warmup_clamp_silu_mul_mxfp8`: compiles the one variant before graph capture (also the first call's warm-up).
22+
23+
The kernel has one variant at every M (`kernel.py`: 576 lanes per row, four columns each).
24+
25+
## Performance
26+
27+
One MI355X, graph replay of 100 distinct inputs, median of 5 x 5 replays, rounds A B B A, us per call. Baseline: vLLM's
28+
`silu_and_mul_with_clamp` HIP op + Triton `mxfp8_e4m3_quantize` (two launches).
29+
30+
| rows | 16 | 32 | 64 | 96 | 128 | 192 | 256 | 384 | 512 | 768 |
31+
|---|---|---|---|---|---|---|---|---|---|---|
32+
| served op + quant | 4.56 | 4.82 | 5.06 | 5.06 | 5.10 | 5.22 | 5.53 | 6.46 | 7.00 | 8.02 |
33+
| this entry | 2.23 | 2.38 | 2.47 | 2.53 | 2.55 | 2.67 | 2.89 | 3.43 | 3.61 | 4.58 |
34+
35+
## Tests
36+
37+
```bash
38+
python3 -m pytest tests/activation/clamp_silu_mul_mxfp8_i2304 -q
39+
python3 benchmarks/activation/clamp_silu_mul_mxfp8_i2304/benchmark_clamp_silu_mul.py
40+
```
41+
42+
One GPU: every decode row count against the reference and the served ops (bitwise), clamp and sign-of-zero edge values,
43+
row strides, caller buffers, graph replay with poisoned outputs, determinism, no compile after the warm-up.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# SPDX-FileCopyrightText: Copyright contributors to the amd-kernels project
3+
"""Clamped SiLU-mul of a gate_up row (2 x 2304) and its MXFP8 quant in one launch, FlyDSL (gfx950)."""
4+
5+
from .host import clamp_silu_mul_mxfp8, warmup_clamp_silu_mul_mxfp8
6+
from .reference import clamp_silu_mul_mxfp8_reference, clamp_silu_mul_reference, dequantize_mxfp8
7+
8+
__all__ = ["clamp_silu_mul_mxfp8", "clamp_silu_mul_mxfp8_reference", "clamp_silu_mul_reference", "dequantize_mxfp8",
9+
"warmup_clamp_silu_mul_mxfp8"]
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# SPDX-FileCopyrightText: Copyright contributors to the amd-kernels project
3+
"""Compile cache and entry of the clamped SiLU-mul + MXFP8 quant."""
4+
5+
import functools
6+
import struct
7+
8+
import torch
9+
from amd_kernels.warm_up import entry
10+
11+
from . import kernel as _kernel
12+
13+
I = _kernel.I
14+
15+
16+
@functools.cache
17+
def _kernel_exe():
18+
return _kernel.compile_clamp_silu_mul_mxfp8()
19+
20+
21+
def _run_compiled(exe, *args):
22+
"""First call compiles and runs (``flyc.compile``); later calls dispatch the cached CompiledFunction."""
23+
import flydsl.compiler as flyc
24+
25+
cf = getattr(exe, "_cf", None)
26+
if cf is None:
27+
exe._cf = flyc.compile(exe, *args)
28+
else:
29+
cf(*args)
30+
31+
32+
def _clamp_silu_mul_mxfp8(gate_up, limit=10.0, *, codes=None, scale=None):
33+
m = gate_up.shape[0]
34+
assert gate_up.dtype == torch.bfloat16 and gate_up.ndim == 2 and gate_up.shape[1] == 2 * I
35+
assert gate_up.stride(1) == 1
36+
dev = gate_up.device
37+
codes = torch.empty((m, I), dtype=torch.float8_e4m3fn, device=dev) if codes is None else codes
38+
scale = torch.empty((m, I // 32), dtype=torch.uint8, device=dev) if scale is None else scale
39+
assert codes.shape == (m, I) and codes.dtype == torch.float8_e4m3fn and codes.is_contiguous()
40+
assert scale.shape == (m, I // 32) and scale.dtype == torch.uint8 and scale.is_contiguous()
41+
if m:
42+
_run_compiled(
43+
_kernel_exe(),
44+
gate_up.data_ptr(),
45+
codes.data_ptr(),
46+
scale.data_ptr(),
47+
m,
48+
gate_up.stride(0),
49+
struct.unpack("<i", struct.pack("<f", limit))[0],
50+
torch.cuda.current_stream(),
51+
)
52+
return codes, scale
53+
54+
55+
def _mode(gate_up, limit=10.0, **kw):
56+
return ()
57+
58+
59+
def _sizes(mode):
60+
return (16,)
61+
62+
63+
def _inputs(mode, n, gate_up, limit=10.0, **kw):
64+
return (torch.zeros(n, 2 * I, dtype=torch.bfloat16, device=gate_up.device), limit), {}
65+
66+
67+
clamp_silu_mul_mxfp8 = entry("activation/clamp_silu_mul_mxfp8_i2304", mode=_mode, sizes=_sizes, inputs=_inputs)(
68+
_clamp_silu_mul_mxfp8
69+
)
70+
clamp_silu_mul_mxfp8.__doc__ = """Clamped SiLU-mul of ``gate_up`` [m, 4608] bf16 (gate | up, unit column stride, any
71+
row stride) and its MXFP8 quant in one launch (``reference.py``). Returns (codes e4m3 [m, 2304], scales E8M0 u8
72+
[m, 72] row-major); ``codes`` / ``scale`` may be the caller's buffers. CUDA-graph safe."""
73+
74+
75+
def warmup_clamp_silu_mul_mxfp8(device: torch.device | None = None) -> None:
76+
"""Compile the kernel before graph capture."""
77+
clamp_silu_mul_mxfp8(torch.zeros(16, 2 * I, dtype=torch.bfloat16, device=device or "cuda"))

0 commit comments

Comments
 (0)