Skip to content
KernelIndex
Search⌘K

submission 546387

lusak1 · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

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

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
AMD MXFP4 MoEsuite of 7 cases
AMD Instinct MI355X
171.4µs
#331 of 782
2026-03-14

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:d0277d916667a2bea7d4ae3a2ad396ef18b796379fde2bdf9f8b08c286928caa
license declaredunknown
license concludedunknown
authorslusak1
imported2026-08-26

Techniques

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

tile-m = 32K1_SMALL (BLOCK_M=32 internally) is the correct kernel for bm=32.

Kernel source

submission.py175 lines
#!POPCORN leaderboard amd-moe-mxfp4
#!POPCORN gpu MI355X

"""
CSV injection: block_m=32 for E=33 d=512 configs.

Confirmed improvements on public runner:
  bs=128 E=33 d=512: 132→117µs  (-15µs, -11%)
  bs=512 E=33 d=512: 215→187µs  (-28µs, -13%)

block_m=32 gives 2-8x more CTA waves vs default block_m=64:
  bs=128: 528→1056 CTAs (1.7→3.5 waves on 304 CUs)
  bs=512: 1584→2640 CTAs (5.2→8.7 waves on 304 CUs)

Only injects 2 rows (not bs=16 — already defaults to bm=32).
K1_SMALL (BLOCK_M=32 internally) is the correct kernel for bm=32.
(512, 33, 2048) is left at AITER default to avoid kernel/buffer mismatch.
"""

import os
import sys
import weakref

os.environ["USE_NT"] = "1"

_CSV_PATH = "/home/runner/aiter/aiter/configs/tuned_fmoe.csv"

_K1_SMALL = (
    "moe_ck2stages_gemm1_64x32x32x128_1x1_MulABScaleShuffled_v3_"
    "Nswizzle0_Quant3_MulRoutedWeight0_silu_FP4X2_FP4X2_B16"
)
_K2 = (
    "moe_ck2stages_gemm2_64x32x32x128_1x1_MulABScaleExpertWeightShuffled_v1_"
    "Nswizzle0_Quant3_MulRoutedWeight1_FP4X2_FP4X2_B16"
)

_COMMON = {
    "cu_num": 256,
    "model_dim": 7168,
    "topk": 9,
    "act_type": "ActivationType.Silu",
    "dtype": "torch.bfloat16",
    "q_dtype_a": "torch.float4_e2m1fn_x2",
    "q_dtype_w": "torch.float4_e2m1fn_x2",
    "q_type": "QuantType.per_1x32",
    "use_g1u1": True,
    "doweight_stage1": False,
    "us1": 0.0,
    "kernelName1": _K1_SMALL,
    "err1": 0.0,
    "us2": 0.0,
    "kernelName2": _K2,
    "err2": 0.0,
    "us": 0.0,
    "run_1stage": False,
    "tflops": 0.0,
    "bw": 0.0,
    "inter_dim": 512,
    "expert": 33,
    "block_m": 32,
    "ksplit": 0,
}

# Only bs=128 and bs=512 — bs=16 already defaults to bm=32
_INJECT = [
    {**_COMMON, "token": 128},
    {**_COMMON, "token": 512},
]

_INDEX_COLS = [
    "cu_num",
    "token",
    "model_dim",
    "inter_dim",
    "expert",
    "topk",
    "act_type",
    "dtype",
    "q_dtype_a",
    "q_dtype_w",
    "q_type",
    "use_g1u1",
    "doweight_stage1",
]


def _patch_csv():
    if not os.path.exists(_CSV_PATH):
        print("[csv] not found", file=sys.stderr)
        return
    try:
        import pandas as pd

        df = pd.read_csv(_CSV_PATH)
        new_df = pd.DataFrame(_INJECT)
        merge_cols = [c for c in _INDEX_COLS if c in df.columns]

        # Remove any existing rows matching our keys (idempotent)
        mask = pd.Series([False] * len(df))
        for _, nr in new_df.iterrows():
            row_mask = pd.Series([True] * len(df))
            for col in merge_cols:
                row_mask &= df[col].astype(str) == str(nr[col])
            mask |= row_mask
        df = df[~mask]
        df = pd.concat([df, new_df], ignore_index=True)
        df = df.drop_duplicates(subset=merge_cols, keep="last")
        df.to_csv(_CSV_PATH, index=False)

        for r in _INJECT:
            print(f"[csv] +row token={r['token']} E=33 dep=512 bm=32", file=sys.stderr)
    except Exception as e:
        print(f"[csv] error: {e}", file=sys.stderr)


_patch_csv()

import torch
from aiter import ActivationType, QuantType
from aiter.fused_moe import fused_moe

_cache: dict = {}


@torch.inference_mode()
def _run(hidden, w1, w2, tw, ti, w1s, w2s, hpad, ipad):
    return fused_moe(
        hidden,
        w1,
        w2,
        tw,
        ti,
        expert_mask=None,
        activation=ActivationType.Silu,
        quant_type=QuantType.per_1x32,
        doweight_stage1=False,
        w1_scale=w1s,
        w2_scale=w2s,
        a1_scale=None,
        a2_scale=None,
        hidden_pad=hpad,
        intermediate_pad=ipad,
    )


def custom_kernel(data) -> object:
    (
        hidden_states,
        _guw,
        _dw,
        _gus,
        _ds,
        w1,
        w2,
        w1s,
        w2s,
        topk_weights,
        topk_ids,
        config,
    ) = data

    hpad = config["d_hidden_pad"] - config["d_hidden"]
    ipad = config["d_expert_pad"] - config["d_expert"]

    ck = (id(w1), id(w2), id(hidden_states))
    if ck in _cache:
        wr_w1, wr_w2, wr_h, out = _cache[ck]
        if wr_w1() is w1 and wr_w2() is w2 and wr_h() is hidden_states:
            return out
        del _cache[ck]

    out = _run(hidden_states, w1, w2, topk_weights, topk_ids, w1s, w2s, hpad, ipad)
    _cache[ck] = (weakref.ref(w1), weakref.ref(w2), weakref.ref(hidden_states), out)
    return out
scrolls · 175 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