Skip to content
KernelIndex
Search⌘K

submission 730601

Chivier · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

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

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:50e4a758098852aad3b5cfb0eec345b7576f2ef6819b91173628939ded905e28
license declaredunknown
license concludedunknown
authorsChivier
imported2026-08-26

Techniques

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

fp4"""MoE MXFP4 V4 — Pre-allocated sorting buffers + direct moe_sorting call.
tile-m = 32_BLOCK_SIZE_M = 32

Kernel source

submission.py86 lines
#!POPCORN leaderboard amd-moe-mxfp4
#!POPCORN gpu MI355X
"""MoE MXFP4 V4 — Pre-allocated sorting buffers + direct moe_sorting call.
Eliminates per-call tensor allocation overhead."""
import os
import torch
from task import input_t, output_t
import aiter
from aiter import ActivationType, QuantType, dtypes
from aiter.fused_moe import fused_moe, moe_sorting, get_2stage_cfgs, get_padded_M, get_inter_dim, fused_moe_2stages

os.environ.setdefault("HIP_FORCE_DEV_KERNARG", "1")

_BLOCK_SIZE_M = 32

_cache = {}

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

    M = hidden_states.shape[0]
    topk = topk_ids.shape[1]
    E = gate_up_weight_shuffled.shape[0]
    model_dim = down_weight_shuffled.shape[1]
    hidden_pad = config["d_hidden_pad"] - config["d_hidden"]
    intermediate_pad = config["d_expert_pad"] - config["d_expert"]

    key = (M, topk, E, model_dim, config["d_expert"])
    if key not in _cache:
        # Pre-compute metadata (triggers CSV lookup + kernel selection)
        _, inter_dim_raw = gate_up_weight_shuffled.shape[1], gate_up_weight_shuffled.shape[2]
        E2, model_dim2, inter_dim2 = get_inter_dim(gate_up_weight_shuffled.shape, down_weight_shuffled.shape)

        metadata = get_2stage_cfgs(
            get_padded_M(M), model_dim2, inter_dim2, E2, topk,
            dtypes.bf16, dtypes.fp4x2, dtypes.fp4x2,
            QuantType.per_1x32, True, ActivationType.Silu,
            False, hidden_pad, intermediate_pad, True,
        )
        block_m = int(metadata.block_m)

        # Pre-allocate sorting buffers
        max_num_tokens_padded = int(M * topk + E * block_m - topk)
        max_num_m_blocks = int((max_num_tokens_padded + block_m - 1) // block_m)
        sorted_ids = torch.empty(max_num_tokens_padded, dtype=dtypes.i32, device="cuda")
        sorted_weights = torch.empty(max_num_tokens_padded, dtype=dtypes.fp32, device="cuda")
        sorted_expert_ids = torch.empty(max_num_m_blocks, dtype=dtypes.i32, device="cuda")
        num_valid_ids = torch.empty(2, dtype=dtypes.i32, device="cuda")
        moe_buf = torch.empty((M, model_dim2), dtype=dtypes.bf16, device="cuda")

        _cache[key] = (block_m, sorted_ids, sorted_weights, sorted_expert_ids,
                        num_valid_ids, moe_buf, E2, model_dim2)

    block_m, sorted_ids, sorted_weights, sorted_expert_ids, num_valid_ids, moe_buf, E2, model_dim2 = _cache[key]

    # Direct moe_sorting call with pre-allocated buffers
    aiter.moe_sorting_fwd(
        topk_ids, topk_weights,
        sorted_ids, sorted_weights, sorted_expert_ids, num_valid_ids, moe_buf,
        E, int(block_m), None, None, 0,
    )

    # Call fused_moe_2stages directly
    fused_moe_2stages(
        hidden_states,
        gate_up_weight_shuffled, down_weight_shuffled,
        topk, sorted_ids, sorted_weights, sorted_expert_ids, num_valid_ids,
        moe_buf, True, block_m,
        activation=ActivationType.Silu,
        quant_type=QuantType.per_1x32,
        doweight_stage1=False,
        q_dtype_a=dtypes.fp4x2,
        q_dtype_w=dtypes.fp4x2,
        w1_scale=gate_up_weight_scale_shuffled,
        w2_scale=down_weight_scale_shuffled,
        a1_scale=None, a2_scale=None,
        hidden_pad=hidden_pad,
        intermediate_pad=intermediate_pad,
    )

    return moe_buf
scrolls · 86 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