Skip to content
KernelIndex
Search⌘K

submission 708836

ihansel · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

submission.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-amd-moe-mxfp4-708836?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
168.5µs
#299 of 782
2026-04-03

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:a5e240348f845849d12ab02431323a8a60dba9ea51a34db3749eb857a94f912b
license declaredunknown
license concludedunknown
authorsihansel
imported2026-08-15

Techniques

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

fp4"""MoE MXFP4 v82: Force CKTile via KSPLIT=2.

Kernel source

submission.py54 lines
"""MoE MXFP4 v82: Force CKTile via KSPLIT=2.
KSPLIT>1 triggers CKTile backend (faster than CK2stages for SiLU+per_1x32).
Shape-conditional: avoid KSPLIT for E33/d2048 (catastrophic regression with KSPLIT=4).
"""
import os
import torch  # noqa: F401
from aiter import ActivationType, QuantType
from aiter.fused_moe import fused_moe

from task import input_t, output_t
from reference import ref_kernel  # noqa: F401


def custom_kernel(data: input_t) -> output_t:
    (
        hidden_states, gate_up_weight, down_weight,
        gate_up_weight_scale, down_weight_scale,
        gate_up_weight_shuffled, down_weight_shuffled,
        gate_up_weight_scale_shuffled, down_weight_scale_shuffled,
        topk_weights, topk_ids, config,
    ) = data

    hidden_pad = config["d_hidden_pad"] - config["d_hidden"]
    intermediate_pad = config["d_expert_pad"] - config["d_expert"]

    n_experts = config.get("n_routed_experts", 0) + config.get("n_shared_experts", 0)
    M = hidden_states.shape[0]

    # CKTile (triggered by KSPLIT>1) is faster than CK2stages for most shapes.
    # But E33/bs512/d512 regresses +38% with KSPLIT=2 → skip for that regime.
    top_k = topk_ids.shape[1]
    tokens_per_expert = M * top_k / max(n_experts, 1)

    if n_experts > 100:
        # E257: many experts, few tokens each → KSPLIT=4 helps CU fill
        os.environ["AITER_KSPLIT"] = "4"
    elif tokens_per_expert > 100:
        # Large batch + few experts → CK2stages auto is better (e.g. E33/bs512)
        os.environ.pop("AITER_KSPLIT", None)
    else:
        # Medium shapes (E33/bs16, E33/bs128) → KSPLIT=2 triggers CKTile
        os.environ["AITER_KSPLIT"] = "2"

    result = fused_moe(
        hidden_states, gate_up_weight_shuffled, down_weight_shuffled,
        topk_weights, topk_ids,
        activation=ActivationType.Silu, quant_type=QuantType.per_1x32,
        doweight_stage1=False,
        w1_scale=gate_up_weight_scale_shuffled,
        w2_scale=down_weight_scale_shuffled,
        hidden_pad=hidden_pad, intermediate_pad=intermediate_pad,
    )
    return result
scrolls · 54 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