ReadingResearchRadarInvestment framework
Sign in / Sign up
← Back to reading
NewsMaterial5 min readDisconfirmAI Editorial

AMD Engineers Profile a VALU-Bound MoE Kernel on MI300X and Replace Its Arithmetic Decode with a Bit Lookup

AMD's FlyDSL team documents how they traced a 2.2×–2.4× MoE GEMM slowdown on MI300X to software E2M1→bf16 weight decoding, then replaced it with a v_perm_b32 byte lookup table. The article walks through a four-step profiling pipeline—GPU kernel time, SQ hardware counters, advanced thread trace, and FlyDSL source-line tables—and shows that the decode is a fixed bit pattern, not arithmetic, because all 16 E2M1 values are exactly representable in bf16.

2026-11-26 08:00 GMT+8

The AMD Instinct MI300X (gfx942, CDNA 3) has no hardware instruction to convert MXFP4 weights to bf16. That conversion arrives with CDNA 4 in the MI350 series. Serving a mixture-of-experts model like gpt-oss with MXFP4 (E2M1) weights on MI300X therefore requires every 4-bit weight to be decoded in software before it can feed a matrix core. Four AMD engineers—Menghsuan Yang, Felix Li, Clement Lin, and Chunhung Wang—documented what that software decode costs and how to eliminate it.

Their profiling pipeline proceeds in four narrowing layers. First, GPU kernel time from rocprofv3 --kernel-trace identifies which stage dominates and how it scales with token count, avoiding host-side timer noise at small batches. Second, SQ hardware counters collected in separate passes reveal what the waves spend their cycles on: the ratio of non-MFMA VALU instructions per MFMA, the VALU share of issue cycles, and three wave-time ratios (executing, ready-but-waiting-to-issue, waiting-on-a-dependency). Third, advanced thread trace (ATT) on a single CU records every instruction executed, its hit count, and its cycle contribution. Fourth, rebuilding the kernels with FLYDSL_DEBUG_ENABLE_DEBUG_INFO=1 produces a DWARF line table that maps each instruction address back to the Python source line that emitted it.

The counters showed the bottleneck clearly. In the software-decode path, every MFMA is accompanied by 36 to 80 other vector instructions. VALU takes 93–98% of the cycles in which waves issue anything; memory and LDS instructions together account for at most 2.7%. Waves spend 77–90% of their lifetime either issuing or ready to issue, and only 10–23% waiting on a dependency. The profile is VALU-issue-bound, not memory-bound. The ATT instruction mix confirmed it: at 2048 tokens, VALU instructions other than MFMA constitute 91% of GEMM1 instructions and 86% of its cycles, while MFMA itself is 2–3% of instructions and about 1% of cycles. Seven instructions—shifts, compares, packed multiplies, bit-field extracts, and/or, NaN checks, and three-way adds—account for 60% of all GEMM1 cycles.

Sign in / Sign up
ReadingResearchRadarInvestment framework

The source-line mapping then tied those instructions to a single FlyDSL helper: _fp4_nibble_to_bf16x8_sw. This function issues 85–93% of the executed instructions and takes 67–81% of the cycles across both GEMMs and both token counts. Of the 72.0 non-MFMA VALU instructions per MFMA in GEMM1 at 8 tokens, 69.3 come from this helper—about 17 instructions per weight. The matrix work itself, MFMA plus operand packing, is only 3.5–5.0% of instructions.

The root cause is that gfx942 lacks the hardware convert, so the software path rebuilds each nibble as an f32 bit pattern, multiplies by the group scale, and converts to bf16 with a five-instruction round-to-nearest-even sequence that includes a NaN check. The ISA listing shows 38 VALU instructions for two weights. But the authors realized none of that arithmetic is needed. E2M1 has only 16 values (8 magnitudes × 2 signs), and with a 2-bit exponent and 1-bit mantissa, every one of them is exactly representable in bf16. The 16 output bit patterns are known in advance. Turning FP4 into bf16 is a table lookup, not a computation.

The fix exploits v_perm_b32, which treats two 32-bit sources as an 8-byte table and each selector byte from 0 to 7 picks one table entry. The high bytes of the eight magnitudes take only three distinct values {0x00, 0x3F, 0x40} and the low bytes four {0x00, 0x40, 0x80, 0xC0}, so each half fits an 8-entry byte table. The 3-bit magnitude (nibble & 7) is a valid selector. One v_perm_b32 returns the four high bytes, another the four low bytes, for four nibbles with no compare chain. The sign is bit 3 of each nibble, folded in with a single v_and_or_b32. The e8m0 scale, being a power of two, is applied by shifting into f32, multiplying, and truncating back—exact in bf16, so truncation equals round-to-nearest.

The result: the LUT decode issues about 5 instructions per weight instead of 17, reducing VALU per MFMA from 72.0 to 20.5 in GEMM1 at 8 tokens. Kernel time drops 2.2×–2.4× for GEMM1 and 1.7×–2.5× for GEMM2 across token counts from 1 to 8192. A hardware verification reads back 22,020,096 decoded weights through GEMM2 with random packed bytes and e8m0 scales from 0x00 to 0xFC, covering all 64,768 pairs of packed byte value and scale. Every nonzero weight is bit-identical between the software and LUT outputs.

After the fix, new limits become visible: s_waitcnt rises from 5.5% to 11% of GEMM1 cycles, and v_pk_mul_f32 (the scale multiply) accounts for 33% of LUT GEMM1 cycles at 2048 tokens, with 94% of those cycles spent waiting before issue. The decode is no longer the sole bottleneck, but VALU still dominates issue. Two follow-up pull requests (#6144 and #8184) further reduce the decode from 28 to 21 VALU instructions per 8 weights by looking up E4M3FNUZ fp8 codes instead of bf16 bytes.

The transferable lesson is the profiling loop itself: time kernels on the GPU, use counter ratios to see what the waves are busy with, use thread trace to tie cycles to specific instructions, use compiler line tables to tie instructions to source, and fix the code those lines point at. And the specific principle that emerged: when a conversion always produces the same output bits for the same input, it is a lookup table, not arithmetic. The authors' measurements are first-party on a single MI300X with synthetic inputs and one model shape; other architectures, shapes, and real checkpoints remain unmeasured.

Sources

  • rocm.blogs.amd.comROCm Blogs↗
Continue researching →