Skip to content
KernelIndex
Search⌘K

submission 581885

abhitorch81 · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

No package. Vendor the mirrored source: 42 lines, June 9 Researcher Reciprocity License v1.0.

submission.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-amd-mxfp4-mm-581885?include=source"
interfacepython
Compatibility
measured onAMD Instinct MI355X
declared hardwareAMD Instinct MI355X
architecturesgfx950
dtypesbf16, mxfp4

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
AMD MXFP4 GEMMsuite of 6 cases
AMD Instinct MI355X
14.5µs
#506 of 1143
2026-03-17

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:ad592289be45bc52e52a8661126060f20494b5d752136209a972dcbe802d5f0a
license declaredunknown
license concludedunknown
authorsabhitorch81
imported2026-08-26

Techniques

Extracted from the mirrored source by pattern, never inferred. Each row cites its line.

fp4Optimized MXFP4 GEMM: bf16 A + preshuffled MXFP4 B -> fused fp4 quant A + gemm -> bf16 C.

Kernel source

submission.py42 lines
"""
Optimized MXFP4 GEMM: bf16 A + preshuffled MXFP4 B -> fused fp4 quant A + gemm -> bf16 C.

Key optimization: Use gemm_a16wfp4_preshuffle which takes bf16 A and quantizes it
on-the-fly inside the GEMM kernel, eliminating the separate dynamic_mxfp4_quant step.

B_shuffle and B_scale_sh are reshaped (zero-copy views) to the format expected by
the Triton preshuffle kernel. Both e8m0_shuffle (used to create B_scale_sh) and
shuffle_scales (expected by gemm_a16wfp4_preshuffle) apply the same permutation;
they differ only in the final view, so B_scale_sh.view(N_pad//32, K)[:N//32]
gives exactly the shuffle_scales-format tensor.
"""
from task import input_t, output_t
import torch


def custom_kernel(data: input_t) -> output_t:
    from aiter import dtypes
    from aiter.ops.triton.gemm.basic.gemm_a16wfp4 import gemm_a16wfp4_preshuffle

    A, B, B_q, B_shuffle, B_scale_sh = data
    A = A.contiguous()
    m, k = A.shape
    n = B_shuffle.shape[0]  # N (B_shuffle has shape (N, K//2) in fp4x2)

    # Reshape B_shuffle: (N, K//2) fp4x2 -> (N//16, K//2 * 16) uint8
    # This is a zero-copy view matching the preshuffled weight layout expected by the kernel.
    k_fp4x2 = k // 2
    B_w = B_shuffle.view(torch.uint8).view(n // 16, k_fp4x2 * 16)

    # Reshape B_scale_sh: (N_pad, K//32) e8m0 -> (N//32, K) uint8
    # e8m0_shuffle and shuffle_scales apply the same data permutation.
    # e8m0_shuffle views the result as (N_pad, K//32); shuffle_scales views it as (N//32, K).
    # Since K//32 is divisible by 8 for all benchmark shapes, K_pad = K//32, K_pad*32 = K.
    # N_pad is divisible by 32 (it's a multiple of 256), so view(N_pad//32, K) is exact.
    N_pad = B_scale_sh.shape[0]
    B_scale_w = B_scale_sh.view(torch.uint8).view(N_pad // 32, k)[:n // 32]

    # Fused: quantize A bf16->MXFP4 on-the-fly + GEMM with preshuffled B.
    # Uses tuned Triton configs (specialized for e.g. N=2112, K=7168 with NUM_KSPLIT=14).
    return gemm_a16wfp4_preshuffle(A, B_w, B_scale_w, dtype=dtypes.bf16)
scrolls · 42 lines total

Source code from GPU Mode and the KernelBot dataset · June 9 Researcher Reciprocity License v1.0

Best evidence level for this revision: reported

JSON