{"id":57623,"date":"2026-06-22T10:33:00","date_gmt":"2026-06-22T14:33:00","guid":{"rendered":"https:\/\/overcentral.com\/en\/?p=57623"},"modified":"2026-06-22T10:33:00","modified_gmt":"2026-06-22T14:33:00","slug":"moonmath-hip-kernel-mi300x-aiter-benchmark","status":"publish","type":"post","link":"https:\/\/overcentral.com\/en\/moonmath-hip-kernel-mi300x-aiter-benchmark\/","title":{"rendered":"MoonMath AI Open-Sources HIP Kernel That Beats AITER v3 on MI300X"},"content":{"rendered":"<p>The <a href=\"https:\/\/github.com\/moonmath\/hip-attention\" target=\"_blank\" rel=\"noopener noreferrer\" data-iacss-external=\"1\">MoonMath AI<\/a> team has open-sourced a bf16 forward attention kernel for AMD&#8217;s MI300X GPU, achieving significant performance gains over AMD&#8217;s own optimized AITER v3 kernel across all tested configurations. Written entirely in HIP rather than hand-tuned assembly, the kernel is available under the MIT license and represents a notable advance in open-source GPU kernel development for AMD&#8217;s CDNA3 architecture. Bare-metal access for development and testing was provided by HotAisle, an <a href=\"https:\/\/overcentral.com\/en\/amd-removes-tsme-cpu-security\/\" title=\"AMD Removes TSME Memory Encryption from Consumer CPUs\" data-iacss-internal=\"1\">AMD<\/a> cloud provider.<\/p>\n<h2>What the MoonMath AI Kernel Does and Why It Matters<\/h2>\n<p>Attention is the fused softmax(QK<sup>T<\/sup>\/\u221ad)\u00b7V operation at the heart of every transformer model. The MI300X is AMD&#8217;s CDNA3 data-center GPU targeting the gfx942 instruction set, and this kernel runs exclusively on that hardware. It computes forward attention in bf16 with a fixed head dimension of 128, accepting inputs in either BSHD or BHSD layout without requiring a transpose. Any sequence length is supported, including cross-attention.<\/p>\n<p>The kernel has real limitations: no causal mask, no grouped-query attention, and no varlen batching. Outputs are in bf16, and it runs only on gfx942 hardware. Numerics are tightly controlled \u2014 all three rounding modes (RTNE, RTNA, RTZ) match AITER&#8217;s per-mode rules, every finite output sits within 1 bf16 ULP of AITER, and NaN and Inf handling is bit-identical and deterministic.<\/p>\n<h2>The Core Technique: One-Instruction Assembly Wrappers<\/h2>\n<p>The central innovation avoids a familiar dilemma in GPU kernel development. Compiler intrinsics keep code tidy but let the compiler reorder or rename operands. Raw inline assembly gives full control but forces manual register and address management. MoonMath wraps exactly one instruction in a __device__ __forceinline__ function, using extended asm constraints to describe operands. The team picks the opcode; the compiler still allocates registers and tracks data flow.<\/p>\n<p>The key pattern uses a &#8220;+v&#8221;(c) constraint that ties the accumulator input and output to the same VGPR, eliminating copy instructions. This keeps the kernel close to ordinary HIP while still steering the machine one instruction at a time. The approach demonstrates that precise control over instruction selection does not require abandoning compiler register allocation.<\/p>\n<h2>Architecture: Eight Waves, Two Groups, Two Barriers<\/h2>\n<p>A CDNA3 compute unit has four SIMD units, but MoonMath runs eight waves per block in two groups of four. Both groups execute the same Q\u00b7K, softmax, O += P\u00b7V sequence but are offset by a phase. While one group saturates the matrix core, the other runs softmax and issues loads. They then swap, keeping the matrix core continuously busy. Two s_barrier instructions bound each iteration \u2014 one at the phase handoff and one at the iteration boundary \u2014 with per-counter waits handling the rest of the synchronization.<\/p>\n<p>This approach echoes FlashAttention-3&#8217;s matmul and softmax alternation but without a dedicated producer warp. On CDNA3 every memory move is already asynchronous, so a separate producer wave is unnecessary.<\/p>\n<h2>Memory Placement Strategy: Where Data Lives and Why<\/h2>\n<p>Most of the speedup comes from deliberate memory placement. K streams from HBM into LDS in a double-buffered 32 KiB buffer shared by all eight waves. V is kept hot in L1, reread on every PV matmul. Q and accumulators reside in registers, read every iteration and never reloaded.<\/p>\n<p>The team chose the 16\u00d716\u00d716 MFMA over the 32\u00d732\u00d78 variant. Both offer identical throughput, but the smaller tile accumulates into only 4 fp32 elements per lane instead of 16. Lower accumulator pressure leaves room for deeper prefetch and a third Q tile (3Q), which raises data reuse per loaded K and V tile. A Flash-Decoding-style tail <a href=\"https:\/\/overcentral.com\/en\/kv-cache-compression-methods\/\" title=\"TurboQuant, OSCAR, EpiCache Vie for KV Cache Compression Lead\" data-iacss-internal=\"1\">KV<\/a> split rescues the stranded fractional round across MI300X&#8217;s 304 compute units. Moving V to L1 freed the LDS that the third Q tile then fills \u2014 each decision cascades into the next.<\/p>\n<h2>Benchmark Results: Beating AITER v3 Across the Board<\/h2>\n<p>Tests ran on MI300X in bf16 with head dimension 128. Each shape was measured at three rounding modes: RTNE (round to nearest even), RTNA (round to nearest, ties away from zero, AITER&#8217;s default), and RTZ (truncate toward zero, AITER&#8217;s fastest mode).<\/p>\n<p>Selected results:<\/p>\n<ul>\n<li>(2, 24, 8192, 128), RTNE: MoonMath 3.083 ms vs AITER 3.792 ms \u2014 1.23\u00d7 faster<\/li>\n<li>(2, 24, 16384, 128), RTNE: 11.670 ms vs 14.691 ms \u2014 1.26\u00d7 faster<\/li>\n<li>(2, 24, 32768, 128), RTNA: 44.440 ms vs 52.363 ms \u2014 1.18\u00d7 faster<\/li>\n<li>(1, 16, 131072, 128), RTNE: 232.517 ms vs 269.278 ms \u2014 1.16\u00d7 faster<\/li>\n<\/ul>\n<p>Geometric means across the full sweep favor MoonMath by 1.18\u00d7 (RTNE), 1.15\u00d7 (RTNA), and 1.08\u00d7 (RTZ) versus AITER v3. Against Modular MAX, geomeans range from 1.44\u00d7 to 1.49\u00d7, with per-shape speedups reaching 1.59\u00d7. The RTZ mode is the tightest race; the (4, 16, 16384) RTZ shape improved from 0.95\u00d7 to 1.07\u00d7 after the tail KV split was implemented.<\/p>\n<h2>Real-World Validation: Wan2.1 Video Diffusion<\/h2>\n<p>The kernel has already been tested in production. A real SGLang pull request used it to speed up Wan2.1 video diffusion by 1.23\u00d7 with no quality regression. This demonstrates that the performance gains translate beyond synthetic benchmarks into actual model workloads.<\/p>\n<h2>What This Means for Developers<\/h2>\n<p>For developers working with <a href=\"https:\/\/www.amd.com\/en\/products\/accelerators\/instinct\/mi300x.html\" target=\"_blank\" rel=\"sponsored noopener noreferrer\" data-iacss-external=\"1\">AMD MI300X<\/a> hardware, this kernel offers an immediate performance uplift for bf16 attention with head dimension 128, available now under a permissive MIT license. The code demonstrates that HIP-based kernels can outperform hand-tuned assembly when combined with careful memory placement and pipeline design. The one-instruction asm wrapper technique is a practical pattern that other kernel developers can adopt to gain instruction-level control without sacrificing compiler register management. Anyone running transformer inference or training on MI300X hardware should evaluate this kernel against their existing attention implementation, particularly for long-sequence workloads where the memory placement advantages compound most significantly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The MoonMath AI team has open-sourced a bf16 forward attention kernel for AMD&#8217;s MI300X GPU, achieving significant performance gains over AMD&#8217;s own optimized AITER v3 kernel across all tested configurations. Written entirely in HIP rather than hand-tuned assembly, the kernel is available under the MIT license and represents a notable advance in open-source GPU kernel [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":84504,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/cards.overcentral.com\/cards\/en\/57623.png","fifu_image_alt":"MoonMath AI Open-Sources HIP Kernel That Beats AITER v3 on MI300X","footnotes":""},"categories":[349],"tags":[],"class_list":["post-57623","post","type-post","status-publish","format-standard","has-post-thumbnail","category-articles"],"fifu_image_url":"https:\/\/cards.overcentral.com\/cards\/en\/57623.png","fifu_image_alt":"MoonMath AI Open-Sources HIP Kernel That Beats AITER v3 on MI300X","_links":{"self":[{"href":"https:\/\/overcentral.com\/en\/wp-json\/wp\/v2\/posts\/57623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/overcentral.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/overcentral.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/overcentral.com\/en\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/overcentral.com\/en\/wp-json\/wp\/v2\/comments?post=57623"}],"version-history":[{"count":0,"href":"https:\/\/overcentral.com\/en\/wp-json\/wp\/v2\/posts\/57623\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/overcentral.com\/en\/wp-json\/wp\/v2\/media\/84504"}],"wp:attachment":[{"href":"https:\/\/overcentral.com\/en\/wp-json\/wp\/v2\/media?parent=57623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/overcentral.com\/en\/wp-json\/wp\/v2\/categories?post=57623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/overcentral.com\/en\/wp-json\/wp\/v2\/tags?post=57623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}