Skip to content
KernelIndex
Search⌘K

submission 691129

Sami · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

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

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
AMD Instinct MI355X
56.5µs
#199 of 766
2026-04-01

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:24a09e61fb92e24a245318be9ce7d17aee26806b4c545c09907157f52bd60038
license declaredunknown
license concludedunknown
authorsSami
imported2026-08-15

Techniques

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

persistent-kernelMLA decode — all persistent mode with tuned splits, pre-cached, no torch.compile.

Kernel source

submission.py78 lines
"""
MLA decode — all persistent mode with tuned splits, pre-cached, no torch.compile.

Proven split values from grid-search. All 8 shapes pre-cached at import.
Direct-cast Q: q.to(fp8) with scale=1.0 (single kernel launch).
Flat array indexing for minimal overhead.
"""
import os
os.environ["HIP_FORCE_DEV_KERNARG"] = "1"
os.environ["PYTORCH_TUNABLEOP_ENABLED"] = "0"

import torch
import aiter
from task import input_t, output_t
from aiter.mla import mla_decode_fwd as _trigger_build
from aiter import dtypes as aiter_dtypes
from aiter import get_mla_metadata_info_v1, get_mla_metadata_v1

NUM_HEADS = 16; NUM_KV_HEADS = 1; QK_HEAD_DIM = 576; V_HEAD_DIM = 512
SM_SCALE = 1.0 / (QK_HEAD_DIM ** 0.5); PAGE_SIZE = 1; FP8_DTYPE = aiter_dtypes.fp8
_unit_scale = torch.ones(1, dtype=torch.float32, device="cuda")

_SPLIT_TABLE = {
    (4, 1024): 32, (4, 8192): 16,
    (32, 1024): 16, (32, 8192): 32,
    (64, 1024): 2, (64, 8192): 32,
    (256, 1024): 4, (256, 8192): 4,
}

_SHAPES = [(4,1024),(4,8192),(32,1024),(32,8192),(64,1024),(64,8192),(256,1024),(256,8192)]
_S2I = {s: i for i, s in enumerate(_SHAPES)}

# Per-shape flat arrays
_ki = [None]*8; _kl = [None]*8; _o = [None]*8
_wm = [None]*8; _wi = [None]*8; _wis = [None]*8
_ri = [None]*8; _rfm = [None]*8; _rpm = [None]*8
_lg = [None]*8; _al = [None]*8

def _init(idx, bs, kv_len):
    total_kv = bs * kv_len; nks = _SPLIT_TABLE[(bs, kv_len)]
    _ki[idx] = torch.arange(total_kv, dtype=torch.int32, device="cuda")
    _kl[idx] = torch.full((bs,), kv_len, dtype=torch.int32, device="cuda")
    _o[idx] = torch.empty((bs, NUM_HEADS, V_HEAD_DIM), dtype=torch.bfloat16, device="cuda")
    qo = torch.arange(0, bs+1, dtype=torch.int32, device="cuda")
    kvi = torch.arange(0, bs+1, dtype=torch.int32, device="cuda") * kv_len
    info = get_mla_metadata_info_v1(bs,1,NUM_HEADS,FP8_DTYPE,FP8_DTYPE,is_sparse=False,fast_mode=False,num_kv_splits=nks,intra_batch_mode=True)
    wm,wi,wis,ri,rfm,rpm = [torch.empty(s,dtype=t,device="cuda") for s,t in info]
    get_mla_metadata_v1(qo,kvi,_kl[idx],NUM_HEADS//NUM_KV_HEADS,NUM_KV_HEADS,True,wm,wis,wi,ri,rfm,rpm,page_size=PAGE_SIZE,kv_granularity=64,max_seqlen_qo=1,uni_seqlen_qo=1,fast_mode=False,max_split_per_batch=nks,intra_batch_mode=True,dtype_q=FP8_DTYPE,dtype_kv=FP8_DTYPE)
    sd = rpm.size(0)
    _wm[idx]=wm; _wi[idx]=wi; _wis[idx]=wis
    _ri[idx]=ri; _rfm[idx]=rfm; _rpm[idx]=rpm
    _lg[idx] = torch.empty((sd,1,NUM_HEADS,V_HEAD_DIM),dtype=torch.float32,device="cuda")
    _al[idx] = torch.empty((sd,1,NUM_HEADS,1),dtype=torch.float32,device="cuda")

for _bs, _kv in _SHAPES:
    _init(_S2I[(_bs, _kv)], _bs, _kv)

def custom_kernel(data: input_t) -> output_t:
    q, kd, qo, kvi, cfg = data
    kf, ks = kd["fp8"]
    i = _S2I[(cfg["batch_size"], cfg["kv_seq_len"])]
    kv_4d = kf.view(kf.shape[0], PAGE_SIZE, NUM_KV_HEADS, kf.shape[-1])
    q_fp8 = q.to(FP8_DTYPE)
    aiter.mla_decode_stage1_asm_fwd(
        q_fp8, kv_4d, qo, kvi,
        _ki[i], _kl[i], None,
        _wm[i], _wi[i], _wis[i],
        1, PAGE_SIZE, NUM_KV_HEADS, SM_SCALE,
        _lg[i], _al[i], _o[i],
        _unit_scale, ks,
    )
    aiter.mla_reduce_v1(
        _lg[i], _al[i],
        _ri[i], _rfm[i], _rpm[i],
        1, _o[i], None,
    )
    return _o[i]
scrolls · 78 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