Skip to content

vllm.models.minimax_m3.nvidia.specialized_decode.kernels.moe.kernel

The fused MiniMax-M3 MoE engine for 1..8 decode tokens on one TP rank, one CuTe DSL kernel (m3_moe_kernel).

Routing (MiniMax2 top-4, or routes polled from the post), FC1 (NVFP4 x NVFP4, SwiGLU-OAI, NVFP4 requantization), FC2, the MXFP8 shared expert on extra CTAs, the combine and the push into the next layer's all-reduce slots, in one launch. The routed part follows the TRTLLM-Gen fused MoE's math. The build is configured by M3_CONFIG (see _cfg below); fc1_per_token selects the per-token FC1 scale (mode Q).

_adv(stage, phase)

The next ring position's (stage, phase).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _adv(stage, phase):
    """The next ring position's (stage, phase)."""
    stage = stage + cutlass.Int32(1)
    wrap = stage == cutlass.Int32(STAGES)
    return cutlass.select_(wrap, cutlass.Int32(0), stage), cutlass.select_(
        wrap, phase ^ cutlass.Int32(1), phase
    )

_adv1(stage, phase)

FC1 ring cursor: [0, S1R) (= _adv unless PW2F).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _adv1(stage, phase):
    """FC1 ring cursor: [0, S1R) (= _adv unless PW2F)."""
    stage = stage + cutlass.Int32(1)
    wrap = stage == cutlass.Int32(S1R)
    return cutlass.select_(wrap, cutlass.Int32(0), stage), cutlass.select_(
        wrap, phase ^ cutlass.Int32(1), phase
    )

_adv2(stage, phase)

FC2 ring cursor: [S1R if PW2F else 0, STAGES) (= _adv unless PW2F).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _adv2(stage, phase):
    """FC2 ring cursor: [S1R if PW2F else 0, STAGES) (= _adv unless PW2F)."""
    stage = stage + cutlass.Int32(1)
    wrap = stage == cutlass.Int32(STAGES)
    return cutlass.select_(
        wrap, cutlass.Int32(S1R if PW2F else 0), stage
    ), cutlass.select_(wrap, phase ^ cutlass.Int32(1), phase)

_ar_in_rearm(tidx, bx, desc, s_par)

AR_IN teardown: re-arm this CTA's share of the consumed slots (every CTA has read them: counter).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _ar_in_rearm(tidx, bx, desc, s_par: cutlass.Array):
    """AR_IN teardown: re-arm this CTA's share of the consumed slots (every CTA has read them: counter)."""
    buf = cutlass.Int64(_ld_relaxed_u64(desc))
    maxt = cutlass.Int64(_ld_relaxed_u64(desc + cutlass.Int64(24)))
    half = maxt * cutlass.Int64(AR_IN_W * (H // 2))
    total = cutlass.Int32(M_MAX * AR_IN_W * ARIN_NCC)
    q = bx * cutlass.Int32(THREADS) + tidx
    E = cutlass.Int32(ARIN_EMPTY)
    while q < total:
        t = q // cutlass.Int32(AR_IN_W * ARIN_NCC)
        rem = q - t * cutlass.Int32(AR_IN_W * ARIN_NCC)
        r = rem // cutlass.Int32(ARIN_NCC)
        cc = rem - r * cutlass.Int32(ARIN_NCC)
        sl = cc // cutlass.Int32(ARIN_NCC // AR_IN_CL)
        par = cutlass.Int64(s_par.load(idx=t * cutlass.Int32(AR_IN_CL) + sl))
        a0 = buf + (
            par * half
            + (cutlass.Int64(t) * cutlass.Int64(AR_IN_W) + cutlass.Int64(r))
            * cutlass.Int64(H // 2)
            + cutlass.Int64(cc) * cutlass.Int64(4)
        ) * cutlass.Int64(4)
        for z in cutlass.range_constexpr(4):
            _st_relaxed_u32(a0 + cutlass.Int64(4 * z), E)
        q = q + cutlass.Int32(NCTA * THREADS)

_ar_in_reduce(tidx, warp, lane, bx, desc, s_big, s_par, xb32, s_misc, tdbg, ar_bar)

AR_IN prologue (all THREADS threads of a routed CTA), distributed like the prx boundary: CTA c owns ARIN_PER 16-byte chunks of the [M, H] rows (each slot word is polled by one thread of the grid, then re-armed by it), sums the ranks, adds the residual, writes residual_out and its rows' sum-of-squares partials; one grid-wide counter; then every CTA normalizes the full rows (read back from residual_out) into its x staging. CTA 0 also writes the normed x to global (xb32) for the shared CTAs.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _ar_in_reduce(
    tidx,
    warp,
    lane,
    bx,
    desc,
    s_big: cutlass.Array,
    s_par: cutlass.Array,
    xb32: cutlass.Array,
    s_misc: cutlass.Array,
    tdbg: cutlass.Array,
    ar_bar: cutlass.Array,
):
    """AR_IN prologue (all THREADS threads of a routed CTA), distributed like the prx boundary: CTA c owns ARIN_PER
    16-byte chunks of the [M, H] rows (each slot word is polled by one thread of the grid, then re-armed by it), sums
    the ranks, adds the residual, writes residual_out and its rows' sum-of-squares partials; one grid-wide counter;
    then every CTA normalizes the full rows (read back from residual_out) into its x staging. CTA 0 also writes the
    normed x to global (xb32) for the shared CTAs."""
    buf = cutlass.Int64(_ld_relaxed_u64(desc))
    flg = cutlass.Int64(_ld_relaxed_u64(desc + cutlass.Int64(8)))
    maxt = cutlass.Int64(_ld_relaxed_u64(desc + cutlass.Int64(24)))
    res_in = cutlass.Int64(_ld_relaxed_u64(desc + cutlass.Int64(32)))
    rout = cutlass.Int64(_ld_relaxed_u64(desc + cutlass.Int64(40)))
    gamma_ptr = cutlass.Int64(_ld_relaxed_u64(desc + cutlass.Int64(48)))
    eps = _ld_relaxed_u32(desc + cutlass.Int64(56)).bitcast(cutlass.Float32)
    cnt = cutlass.Int64(_ld_relaxed_u64(desc + cutlass.Int64(64)))
    psq = cutlass.Int64(_ld_relaxed_u64(desc + cutlass.Int64(80)))
    half = maxt * cutlass.Int64(AR_IN_W * (H // 2))
    xs32 = cutlass.Array(
        s_big.data_ptr(0), shape=(M_MAX * H // 2,), dtype=cutlass.Int32, alignment=16
    )
    scr = cutlass.Array(
        s_big.data_ptr(_OFF_B2),
        shape=((THREADS // 32) * M_MAX,),
        dtype=cutlass.Float32,
        alignment=16,
    )
    if tidx < cutlass.Int32(M_MAX * AR_IN_CL):
        s_par.store(
            _ld_volatile_s32(flg + cutlass.Int64(4) * cutlass.Int64(tidx))
            & cutlass.Int32(1),
            idx=tidx,
        )
    prims.barrier_cta_sync(0)
    # ---- phase A: this CTA's chunks
    E = cutlass.Int32(ARIN_EMPTY)
    q0 = bx * cutlass.Int32(ARIN_PER) + tidx
    act = (tidx < cutlass.Int32(ARIN_PER)) & (q0 < cutlass.Int32(ARIN_TC))
    q = cutlass.select_(act, q0, cutlass.Int32(0))
    t = q // cutlass.Int32(ARIN_NCC)
    cc = q - t * cutlass.Int32(ARIN_NCC)
    sl = cc // cutlass.Int32(ARIN_NCC // AR_IN_CL)
    par = cutlass.Int64(s_par.load(idx=t * cutlass.Int32(AR_IN_CL) + sl))
    wb = (
        par * half
        + cutlass.Int64(t) * cutlass.Int64(AR_IN_W * (H // 2))
        + cutlass.Int64(cc) * cutlass.Int64(4)
    )
    sqt = cutlass.Float32(0.0)
    if act:
        acc = [cutlass.Float32(0.0) for _ in range(8)]
        addrs = [
            buf + (wb + cutlass.Int64(r * (H // 2))) * cutlass.Int64(4)
            for r in range(AR_IN_W)
        ]
        first = [_ld_v4_u32(addrs[r], True) for r in range(AR_IN_W)]
        rres = _ld_v4_u32(
            res_in
            + (
                cutlass.Int64(t) * cutlass.Int64(H)
                + cutlass.Int64(cc) * cutlass.Int64(8)
            )
            * cutlass.Int64(2)
        )
        for r in cutlass.range_constexpr(AR_IN_W):
            v0, v1, v2, v3 = first[r][0], first[r][1], first[r][2], first[r][3]
            while (v0 == E) | (v1 == E) | (v2 == E) | (v3 == E):
                vr = _ld_v4_u32(addrs[r], True)
                v0, v1, v2, v3 = vr[0], vr[1], vr[2], vr[3]
            _st_v4_u32(
                addrs[r], E, E, E, E
            )  # re-arm (prx: the reader re-arms what it read)
            vv = [v0, v1, v2, v3]
            for z in cutlass.range_constexpr(4):
                lo = (vv[z] << cutlass.Int32(16)).bitcast(cutlass.Float32)
                hi = (vv[z] & cutlass.Int32(-65536)).bitcast(cutlass.Float32)
                if cutlass.const_expr(r == 0):
                    acc[2 * z] = lo
                    acc[2 * z + 1] = hi
                else:
                    acc[2 * z] = _add_rn(acc[2 * z], lo)
                    acc[2 * z + 1] = _add_rn(acc[2 * z + 1], hi)
        words = []
        for z in cutlass.range_constexpr(4):
            rw = rres[z]
            ulo = _bf16_round(
                _add_rn(
                    _bf16_round(acc[2 * z]),
                    (rw << cutlass.Int32(16)).bitcast(cutlass.Float32),
                )
            )
            uhi = _bf16_round(
                _add_rn(
                    _bf16_round(acc[2 * z + 1]),
                    (rw & cutlass.Int32(-65536)).bitcast(cutlass.Float32),
                )
            )
            sqt = _fma_rn(uhi, uhi, _fma_rn(ulo, ulo, sqt))
            words.append(
                (
                    (ulo.bitcast(cutlass.Int32) >> cutlass.Int32(16))
                    & cutlass.Int32(0xFFFF)
                )
                | (uhi.bitcast(cutlass.Int32) & cutlass.Int32(-65536))
            )
        _st_v4_u32(
            rout + cutlass.Int64(q) * cutlass.Int64(16),
            words[0],
            words[1],
            words[2],
            words[3],
        )
    for tt in cutlass.range_constexpr(M_MAX):
        v = cutlass.select_(act & (t == cutlass.Int32(tt)), sqt, cutlass.Float32(0.0))
        for off in cutlass.range_constexpr(5):
            v = _add_rn(v, cute.arch.shuffle_sync_bfly(v, 16 >> off))
        if lane == 0:
            scr.store(v, idx=warp * cutlass.Int32(M_MAX) + cutlass.Int32(tt))
    prims.barrier_cta_sync(0)
    if tidx < cutlass.Int32(M_MAX):
        tot = cutlass.Float32(scr.load(idx=tidx))
        for w_ in cutlass.range_constexpr(1, THREADS // 32):
            tot = _add_rn(
                tot, cutlass.Float32(scr.load(idx=cutlass.Int32(w_ * M_MAX) + tidx))
            )
        _st_relaxed_u32(
            psq + cutlass.Int64(bx * cutlass.Int32(M_MAX) + tidx) * cutlass.Int64(4),
            tot.bitcast(cutlass.Int32),
        )
    prims.barrier_cta_sync(0)
    # ---- grid-wide: every CTA's chunks and partials are out
    if tidx == 0:
        _fence_proxy_async_global()  # residual_out rows are read back by TMA in other CTAs
        old_cnt = _atom_add_release(cnt, 1)
        s_misc.store(old_cnt, idx=1)
        tgt = (old_cnt // cutlass.Int32(NCTA) + cutlass.Int32(1)) * cutlass.Int32(NCTA)
        cv = _ld_acquire_u32(cnt)
        while cv - tgt < cutlass.Int32(0):
            _nanosleep(40)
            cv = _ld_acquire_u32(cnt)
        _fence_proxy_async_global()
        prims.mbarrier_arrive_expect_tx(ar_bar.subview(0), M_MAX * H * 2)
        for tt in cutlass.range_constexpr(M_MAX):
            _bulk_g2s(
                xs32.subview(cutlass.Int32(tt * (H // 2))).data_ptr().toint(),
                rout + cutlass.Int64(tt * H * 2),
                H * 2,
                ar_bar.subview(0).data_ptr().toint(),
            )
    prims.barrier_cta_sync(0)
    # ---- phase B: row sums of squares, then the full normed rows into the x staging
    # (every load of a phase is issued before its first use: the loads are volatile asm,
    # one round trip per phase, not per value)
    PV = (M_MAX + 3) // 4
    pls = []
    for k in cutlass.range_constexpr((NCTA + THREADS - 1) // THREADS):
        ci = tidx + cutlass.Int32(k * THREADS)
        cs = cutlass.select_(ci < cutlass.Int32(NCTA), ci, cutlass.Int32(0))
        for h in cutlass.range_constexpr(PV):
            pls.append(
                _ld_v4_u32(
                    psq
                    + (cutlass.Int64(cs) * cutlass.Int64(M_MAX) + cutlass.Int64(4 * h))
                    * cutlass.Int64(4),
                    False,
                    True,
                )
            )
    gvs = []
    for j in cutlass.range_constexpr(ARIN_J):
        cq = cutlass.select_(
            tidx + cutlass.Int32(j * THREADS) < cutlass.Int32(ARIN_NCC),
            tidx + cutlass.Int32(j * THREADS),
            cutlass.Int32(ARIN_NCC - 1),
        )
        gvs.append(_ld_v4_u32(gamma_ptr + cutlass.Int64(cq) * cutlass.Int64(16)))
    for tt in cutlass.range_constexpr(M_MAX):
        v = cutlass.Float32(0.0)
        for k in cutlass.range_constexpr((NCTA + THREADS - 1) // THREADS):
            ok = tidx + cutlass.Int32(k * THREADS) < cutlass.Int32(NCTA)
            pv = pls[k * PV + tt // 4][tt % 4]
            v = _add_rn(
                v,
                cutlass.select_(ok, pv.bitcast(cutlass.Float32), cutlass.Float32(0.0)),
            )
        for off in cutlass.range_constexpr(5):
            v = _add_rn(v, cute.arch.shuffle_sync_bfly(v, 16 >> off))
        if lane == 0:
            scr.store(v, idx=warp * cutlass.Int32(M_MAX) + cutlass.Int32(tt))
    _wait(ar_bar.subview(0), 0)  # the u rows landed in the x staging
    prims.barrier_cta_sync(0)
    for tt in cutlass.range_constexpr(M_MAX):
        tot = cutlass.Float32(scr.load(idx=cutlass.Int32(tt)))
        for w_ in cutlass.range_constexpr(1, THREADS // 32):
            tot = _add_rn(
                tot, cutlass.Float32(scr.load(idx=cutlass.Int32(w_ * M_MAX + tt)))
            )
        inv = _rsqrt_approx(_add_rn(_div_full(tot, cutlass.Float32(float(H))), eps))
        for j in cutlass.range_constexpr(ARIN_J):
            cc0 = tidx + cutlass.Int32(j * THREADS)
            valid = cc0 < cutlass.Int32(ARIN_NCC)
            cq = cutlass.select_(valid, cc0, cutlass.Int32(ARIN_NCC - 1))
            uv = [
                xs32.load(
                    idx=cutlass.Int32(tt * (H // 2))
                    + cq * cutlass.Int32(4)
                    + cutlass.Int32(z)
                )
                for z in range(4)
            ]
            gv = gvs[j]
            nw = []
            for z in cutlass.range_constexpr(4):
                u = uv[z]
                gw = gv[z]
                glo = _add_rn(
                    cutlass.Float32(1.0),
                    (gw << cutlass.Int32(16)).bitcast(cutlass.Float32),
                )
                ghi = _add_rn(
                    cutlass.Float32(1.0),
                    (gw & cutlass.Int32(-65536)).bitcast(cutlass.Float32),
                )
                nlo = _bf16_round(
                    _mul_rn(
                        _mul_rn((u << cutlass.Int32(16)).bitcast(cutlass.Float32), inv),
                        glo,
                    )
                )
                nhi = _bf16_round(
                    _mul_rn(
                        _mul_rn(
                            (u & cutlass.Int32(-65536)).bitcast(cutlass.Float32), inv
                        ),
                        ghi,
                    )
                )
                nw.append(
                    (
                        (nlo.bitcast(cutlass.Int32) >> cutlass.Int32(16))
                        & cutlass.Int32(0xFFFF)
                    )
                    | (nhi.bitcast(cutlass.Int32) & cutlass.Int32(-65536))
                )
            if valid:
                w0i = cutlass.Int32(tt * (H // 2)) + cq * cutlass.Int32(4)
                for z in cutlass.range_constexpr(4):
                    xs32.store(nw[z], idx=w0i + cutlass.Int32(z))
                if bx == 0:
                    _st_v4_u32(
                        cutlass.Int64(xb32.data_ptr().toint())
                        + cutlass.Int64(w0i) * cutlass.Int64(4),
                        nw[0],
                        nw[1],
                        nw[2],
                        nw[3],
                    )

_ar_parity(arp, t, cl)

The call parity _ar_push reads for token t's channel cl (fixed between this kernel's grid dependency and the next all-reduce, which this kernel releases at teardown): loaded ahead of the finalize (AR_PRE).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
def _ar_parity(arp, t, cl):
    """The call parity _ar_push reads for token t's channel cl (fixed between this kernel's grid dependency and the
    next all-reduce, which this kernel releases at teardown): loaded ahead of the finalize (AR_PRE)."""
    return _ld_volatile_s32(
        arp.load(idx=2)
        + cutlass.Int64(4)
        * cutlass.Int64(t * cutlass.Int32(AR_CL) + cl // cutlass.Int32(H // AR_CL))
    )

_ar_push(arp, v, low, t, cl)

Push bf16 channel pair (cl, cl + 1) of token t (v = channel cl's bf16 value on this lane, its neighbour's on lane ^ 8) into this rank's set-A slot of the exchange; the slot half is the all-reduce CTA (t, cl // 768)'s call parity. Only lanes with low store; every lane of the warp must call it (shuffle).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
def _ar_push(arp, v, low, t, cl):
    """Push bf16 channel pair (cl, cl + 1) of token t (v = channel cl's bf16 value on this lane, its neighbour's on
    lane ^ 8) into this rank's set-A slot of the exchange; the slot half is the all-reduce CTA (t, cl // 768)'s call
    parity. Only lanes with `low` store; every lane of the warp must call it (shuffle)."""
    hi = cute.arch.shuffle_sync_bfly(v, 8)
    pred = cutlass.select_(low, cutlass.Int32(1), cutlass.Int32(0))
    cs = cutlass.select_(low, cl, cutlass.Int32(0))
    world = arp.load(idx=4)
    parity = cutlass.Int64(
        _ld_volatile_s32(
            arp.load(idx=2)
            + cutlass.Int64(4)
            * cutlass.Int64(t * cutlass.Int32(8) + cs // cutlass.Int32(H // 8))
        )
        & cutlass.Int32(1)
    )
    off = (
        parity * arp.load(idx=5) * world * cutlass.Int64(H // 2)
        + (cutlass.Int64(t) * world + arp.load(idx=3)) * (cutlass.Int64(H // 2))
        + cutlass.Int64(cs // cutlass.Int32(2))
    )
    _st_global_b32_if(
        arp.load(idx=1) + off * cutlass.Int64(4), _bf16x2_word(v, hi), pred
    )

_ar_push_g3(ard, v, low, t, cl)

Push bf16 channel pair (cl, cl + 1) of token t into boundary-exchange's slot (buf, rank, t) on every rank's buffer; ard = (bufs[0], .., bufs[W - 1], rank, buf) preloaded after the grid dependency (AR_PRE).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
def _ar_push_g3(ard, v, low, t, cl):
    """Push bf16 channel pair (cl, cl + 1) of token t into boundary-exchange's slot (buf, rank, t) on every rank's buffer;
    ard = (bufs[0], .., bufs[W - 1], rank, buf) preloaded after the grid dependency (AR_PRE)."""
    hi = cute.arch.shuffle_sync_bfly(v, 8)
    pred = cutlass.select_(low, cutlass.Int32(1), cutlass.Int32(0))
    cs = cutlass.select_(low, cl, cutlass.Int32(0))
    w = _bf16x2_word(v, hi)
    rk = ard[AR_W]
    bufi = ard[AR_W + 1]
    off = (
        (bufi * cutlass.Int64(AR_W) + rk) * cutlass.Int64(AR_ROWS) + cutlass.Int64(t)
    ) * cutlass.Int64(H) + cutlass.Int64(cs)
    for r in range(AR_W):
        _st_global_b32_if(ard[r] + off * cutlass.Int64(2), w, pred)

_ar_push_pre(ard, parity32, v, low, t, cl)

_ar_push with the parity (_ar_parity) and the descriptor fields ard = (mc, rank, world, maxt) preloaded.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
def _ar_push_pre(ard, parity32, v, low, t, cl):
    """_ar_push with the parity (_ar_parity) and the descriptor fields ard = (mc, rank, world, maxt) preloaded."""
    hi = cute.arch.shuffle_sync_bfly(v, 8)
    pred = cutlass.select_(low, cutlass.Int32(1), cutlass.Int32(0))
    cs = cutlass.select_(low, cl, cutlass.Int32(0))
    rk, world, maxt = ard[-3], ard[-2], ard[-1]
    parity = cutlass.Int64(parity32 & cutlass.Int32(1))
    off = (
        parity * maxt * world * cutlass.Int64(H // 2)
        + (cutlass.Int64(t) * world + rk) * (cutlass.Int64(H // 2))
        + cutlass.Int64(cs // cutlass.Int32(2))
    )
    w = _bf16x2_word(v, hi)
    for r_ in range(len(ard) - 3):
        _st_global_b32_if(ard[r_] + off * cutlass.Int64(4), w, pred)

_b1_addr(t, kb16)

Word index in the resident B tiles of the 8 FP4 bytes of token t's 16-value block kb16.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _b1_addr(t, kb16):
    """Word index in the resident B tiles of the 8 FP4 bytes of token t's 16-value block kb16."""
    kt = kb16 >> cutlass.Int32(4)
    j = kt >> cutlass.Int32(2)
    n = (kt & cutlass.Int32(3)) * cutlass.Int32(QS) + t
    cc = (kb16 >> cutlass.Int32(1)) & cutlass.Int32(7)
    return (
        j * cutlass.Int32(NUM_BYTES_B1)
        + n * cutlass.Int32(KT_BYTES)
        + (cc ^ (n & cutlass.Int32(7))) * cutlass.Int32(16)
        + (kb16 & cutlass.Int32(1)) * cutlass.Int32(8)
    ) // cutlass.Int32(4)

_bar_arrive(bar_id, threads, *, loc=None, ip=None)

bar.arrive: signal a named barrier without waiting (its memory ordering is bar.sync's).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _bar_arrive(bar_id: int, threads: int, *, loc=None, ip=None):
    """bar.arrive: signal a named barrier without waiting (its memory ordering is bar.sync's)."""
    _llvm.inline_asm(
        None,
        [],
        f"bar.arrive {bar_id}, {threads};",
        "",
        has_side_effects=True,
        is_align_stack=False,
        asm_dialect=_llvm.AsmDialect.AD_ATT,
        loc=loc,
        ip=ip,
    )

_bf16_bits(x, *, loc=None, ip=None)

bf16 (nearest even) bits of x in the low 16 bits.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _bf16_bits(x, *, loc=None, ip=None):
    """bf16 (nearest even) bits of x in the low 16 bits."""
    return cutlass.Int32(
        _asm(
            _T.i32(),
            [cutlass.Float32(x)],
            "{\n.reg .b16 t;\ncvt.rn.bf16.f32 t, $1;\ncvt.u32.u16 $0, t;\n}",
            "=r,f",
            False,
            loc,
            ip,
        )
    )

_bf16_round(x, *, loc=None, ip=None)

X rounded to bf16 (nearest even), as f32.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _bf16_round(x, *, loc=None, ip=None):
    """X rounded to bf16 (nearest even), as f32."""
    return cutlass.Float32(
        _asm(
            _T.f32(),
            [cutlass.Float32(x)],
            "{\n.reg .b16 t;\ncvt.rn.bf16.f32 t, $1;\nmov.b32 $0, {0, t};\n}",
            "=f,f",
            False,
            loc,
            ip,
        )
    )

_bf16x2_word(lo, hi, *, loc=None, ip=None)

bf16(lo) | bf16(hi) << 16 (RN), with -0.0 halves turned into +0.0 (0x80000000 marks an empty exchange word).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _bf16x2_word(lo, hi, *, loc=None, ip=None):
    """bf16(lo) | bf16(hi) << 16 (RN), with -0.0 halves turned into +0.0 (0x80000000 marks an empty exchange word)."""
    return cutlass.Int32(
        _llvm.inline_asm(
            _T.i32(), [cutlass.Float32(hi).ir_value(loc=loc, ip=ip), cutlass.Float32(lo).ir_value(loc=loc, ip=ip)],
            "{\n\t.reg .b32 w, l, h;\n\t.reg .pred pl, ph;\n\tcvt.rn.bf16x2.f32 w, $1, $2;\n\t"
            "and.b32 l, w, 0xFFFF;\n\tsetp.eq.u32 pl, l, 0x8000;\n\t@pl and.b32 w, w, 0xFFFF0000;\n\t"
            "shr.u32 h, w, 16;\n\tsetp.eq.u32 ph, h, 0x8000;\n\t@ph and.b32 w, w, 0x0000FFFF;\n\t"
            "mov.b32 $0, w;\n\t}", "=r,f,f",
            has_side_effects=False, is_align_stack=False, asm_dialect=_llvm.AsmDialect.AD_ATT, loc=loc, ip=ip,
        )
    )  # fmt: skip

_build_b1(tidx, warp, lane, base_row, base_col, x32, xsf32, sB1, b1_ready)

B (the M tokens' whole K) into the resident tiles from the NVFP4 activation, its scales to TMEM.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _build_b1(
    tidx,
    warp,
    lane,
    base_row,
    base_col,
    x32: cutlass.Array,
    xsf32: cutlass.Array,
    sB1: cutlass.Array,
    b1_ready: cutlass.Array,
):
    """B (the M tokens' whole K) into the resident tiles from the NVFP4 activation, its scales to TMEM."""
    sB1_32 = cutlass.Array(
        sB1.data_ptr(0),
        shape=(S1 * NUM_BYTES_B1 // 4,),
        dtype=cutlass.Int32,
        alignment=16,
    )
    for r in cutlass.range_constexpr(
        (M_MAX * (H // 16) + EPI_THREADS - 1) // EPI_THREADS
    ):
        b = tidx + cutlass.Int32(r * EPI_THREADS)
        if b < cutlass.Int32(M_MAX * (H // 16)):
            t = b // cutlass.Int32(H // 16)
            kb = b - t * cutlass.Int32(H // 16)
            v2 = x32.load(idx=b * cutlass.Int32(2), vector_size=2, alignment=8)
            sB1_32.store(
                (cutlass.Int32(v2[0]), cutlass.Int32(v2[1])),
                idx=_b1_addr(t, kb),
                alignment=8,
            )
    _sfb1_to_tmem(warp, lane, base_row, base_col, xsf32, b1_ready)

_build_b1_fused(tidx, warp, lane, base_row, base_col, xb32, sfsc, sB1, s_xsf, b1_ready)

_build_b1 from the bf16 hidden states, quantized exactly as fp4_quantize(x, sf_scale, 16).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _build_b1_fused(
    tidx,
    warp,
    lane,
    base_row,
    base_col,
    xb32: cutlass.Array,
    sfsc: cutlass.Array,
    sB1: cutlass.Array,
    s_xsf: cutlass.Array,
    b1_ready: cutlass.Array,
):
    """_build_b1 from the bf16 hidden states, quantized exactly as fp4_quantize(x, sf_scale, 16)."""
    sB1_32 = cutlass.Array(
        sB1.data_ptr(0),
        shape=(S1 * NUM_BYTES_B1 // 4,),
        dtype=cutlass.Int32,
        alignment=16,
    )
    s_xsf8 = cutlass.Array(
        s_xsf.data_ptr(0), shape=(M_MAX * (H // 16),), dtype=cutlass.Int8, alignment=16
    )
    sc = cutlass.Float32(sfsc.load(idx=0))
    rsc = _rcp(sc)
    rsix = _rcp(cutlass.Float32(6.0))
    NBLK = M_MAX * (H // 16) // EPI_THREADS
    QB = B1_QB_EFF  # blocks whose loads are in flight together (cfg b1_qb)
    # a rolled loop over groups of QB blocks (a fully unrolled one is ~50 KB of SASS at M = 8: instruction fetch bound)
    for rg in cutlass.range(NBLK // QB, unroll=1):
        wall = []
        for rr in cutlass.range_constexpr(QB):
            bq = tidx + (rg * cutlass.Int32(QB) + cutlass.Int32(rr)) * cutlass.Int32(
                EPI_THREADS
            )
            for h in cutlass.range_constexpr(2):
                wall.append(
                    xb32.load(
                        idx=bq * cutlass.Int32(8) + cutlass.Int32(4 * h),
                        vector_size=4,
                        alignment=16,
                    )
                )
        for rr in cutlass.range_constexpr(QB):
            b = tidx + (rg * cutlass.Int32(QB) + cutlass.Int32(rr)) * cutlass.Int32(
                EPI_THREADS
            )
            t = b // cutlass.Int32(H // 16)
            kb = b - t * cutlass.Int32(H // 16)
            w = []
            for h in cutlass.range_constexpr(2):
                v4 = wall[rr * 2 + h]
                for z in cutlass.range_constexpr(4):
                    w.append(cutlass.Int32(v4[z]))
            xs = []
            for z in cutlass.range_constexpr(8):
                xs.append((w[z] << cutlass.Int32(16)).bitcast(cutlass.Float32))
                xs.append((w[z] & cutlass.Int32(-65536)).bitcast(cutlass.Float32))
            vmax = cute.math.abs(xs[0])
            for z in cutlass.range_constexpr(1, 16):
                vmax = cute.arch.fmax(vmax, cute.math.abs(xs[z]))
            sfb = _e4m3_bits(_mul_rn(sc, _mul_rn(vmax, rsix)))
            osc = cutlass.select_(
                vmax != cutlass.Float32(0.0),
                _rcp(_mul_rn(_e4m3_to_f32(sfb), rsc)),
                cutlass.Float32(0.0),
            )
            by = [
                _e2m1x2(_mul_rn(xs[2 * z + 1], osc), _mul_rn(xs[2 * z], osc))
                & cutlass.Int32(0xFF)
                for z in range(8)
            ]
            lo = (
                by[0]
                | (by[1] << cutlass.Int32(8))
                | (by[2] << cutlass.Int32(16))
                | (by[3] << cutlass.Int32(24))
            )
            hi = (
                by[4]
                | (by[5] << cutlass.Int32(8))
                | (by[6] << cutlass.Int32(16))
                | (by[7] << cutlass.Int32(24))
            )
            sB1_32.store((lo, hi), idx=_b1_addr(t, kb), alignment=8)
            s_xsf8.store(cutlass.Int8(sfb), idx=b)
    cute.arch.sync_warp()
    cute.arch.barrier(barrier_id=EPI_BAR, number_of_threads=EPI_THREADS)
    _sfb1_to_tmem(warp, lane, base_row, base_col, s_xsf, b1_ready)

_bulk_g2s(dst_smem, src_gaddr, nbytes, mbar_smem, *, loc=None, ip=None)

cp.async.bulk of nbytes from a raw global address into shared memory, completing mbar (shared addresses).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _bulk_g2s(dst_smem, src_gaddr, nbytes, mbar_smem, *, loc=None, ip=None):
    """cp.async.bulk of nbytes from a raw global address into shared memory, completing mbar (shared addresses)."""
    _llvm.inline_asm(
        None,
        [cutlass.Int32(dst_smem).ir_value(loc=loc, ip=ip), cutlass.Int64(src_gaddr).ir_value(loc=loc, ip=ip),
         cutlass.Int32(nbytes).ir_value(loc=loc, ip=ip), cutlass.Int32(mbar_smem).ir_value(loc=loc, ip=ip)],
        "cp.async.bulk.shared::cluster.global.mbarrier::complete_tx::bytes [$0], [$1], $2, [$3];", "r,l,r,r",
        has_side_effects=True, is_align_stack=False, asm_dialect=_llvm.AsmDialect.AD_ATT, loc=loc, ip=ip,
    )  # fmt: skip

_div_rn(a, b, *, loc=None, ip=None)

IEEE division (div.rn.f32).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _div_rn(a, b, *, loc=None, ip=None):
    """IEEE division (div.rn.f32)."""
    return cutlass.Float32(
        _asm(
            _T.f32(),
            [cutlass.Float32(a), cutlass.Float32(b)],
            "div.rn.f32 $0, $1, $2;",
            "=f,f,f",
            False,
            loc,
            ip,
        )
    )

_e2m1x2(hi, lo, *, loc=None, ip=None)

One byte of two E2M1 values (lo in the low nibble), round to nearest even, saturating.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _e2m1x2(hi, lo, *, loc=None, ip=None):
    """One byte of two E2M1 values (lo in the low nibble), round to nearest even, saturating."""
    return cutlass.Int32(
        _asm(
            _T.i32(),
            [cutlass.Float32(hi), cutlass.Float32(lo)],
            "{\n.reg .b8 t;\ncvt.rn.satfinite.e2m1x2.f32 t, $1, $2;\ncvt.u32.u8 $0, t;\n}",
            "=r,f,f",
            False,
            loc,
            ip,
        )
    )

_e4m3_bits(x, *, loc=None, ip=None)

e4m3 (round to nearest even, saturating) of x as an int 0..255.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _e4m3_bits(x, *, loc=None, ip=None):
    """e4m3 (round to nearest even, saturating) of x as an int 0..255."""
    return cutlass.Int32(
        _asm(
            _T.i32(),
            [cutlass.Float32(x)],
            "{\n.reg .b16 t;\ncvt.rn.satfinite.e4m3x2.f32 t, 0f00000000, $1;\ncvt.u32.u16 $0, t;\n}",
            "=r,f",
            False,
            loc,
            ip,
        )
    ) & cutlass.Int32(0xFF)

_e4m3x2(hi, lo, *, loc=None, ip=None)

Two e4m3 (nearest even, saturating) in 16 bits, lo in the low byte.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _e4m3x2(hi, lo, *, loc=None, ip=None):
    """Two e4m3 (nearest even, saturating) in 16 bits, lo in the low byte."""
    return cutlass.Int32(
        _asm(
            _T.i32(),
            [cutlass.Float32(hi), cutlass.Float32(lo)],
            "{\n.reg .b16 t;\ncvt.rn.satfinite.e4m3x2.f32 t, $1, $2;\ncvt.u32.u16 $0, t;\n}",
            "=r,f,f",
            False,
            loc,
            ip,
        )
    )

_ex2_full(x, *, loc=None, ip=None)

ex2.approx.f32 (no flush to zero), Triton's tl.exp.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _ex2_full(x, *, loc=None, ip=None):
    """ex2.approx.f32 (no flush to zero), Triton's tl.exp."""
    return cutlass.Float32(
        _asm(
            _T.f32(),
            [cutlass.Float32(x)],
            "ex2.approx.f32 $0, $1;",
            "=f,f",
            False,
            loc,
            ip,
        )
    )

_l2_prefetch(addr, nbytes, *, loc=None, ip=None)

cp.async.bulk.prefetch.L2 of nbytes (a multiple of 16) at global address addr (16-byte aligned).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _l2_prefetch(addr, nbytes, *, loc=None, ip=None):
    """cp.async.bulk.prefetch.L2 of nbytes (a multiple of 16) at global address addr (16-byte aligned)."""
    _llvm.inline_asm(
        None,
        [
            cutlass.Int64(addr).ir_value(loc=loc, ip=ip),
            cutlass.Int32(nbytes).ir_value(loc=loc, ip=ip),
        ],
        "cp.async.bulk.prefetch.L2.global [$0], $1;",
        "l,r",
        has_side_effects=True,
        is_align_stack=False,
        asm_dialect=_llvm.AsmDialect.AD_ATT,
        loc=loc,
        ip=ip,
    )

_ld_v4_u32(addr, volatile=False, cg=False, *, loc=None, ip=None)

Four int32 words at a 16-byte-aligned global address (ld.volatile for the polled exchange slots, .cg for data other CTAs of this grid wrote).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _ld_v4_u32(addr, volatile: bool = False, cg: bool = False, *, loc=None, ip=None):
    """Four int32 words at a 16-byte-aligned global address (ld.volatile for the polled exchange slots, .cg for data
    other CTAs of this grid wrote)."""
    op = (
        "ld.volatile.global.v4.u32"
        if volatile
        else ("ld.global.cg.v4.u32" if cg else "ld.global.v4.u32")
    )
    out = _llvm.inline_asm(
        _llvm.StructType.get_literal([_T.i32()] * 4), [cutlass.Int64(addr).ir_value(loc=loc, ip=ip)],
        op + " {$0, $1, $2, $3}, [$4];", "=r,=r,=r,=r,l", has_side_effects=True,
        is_align_stack=False, asm_dialect=_llvm.AsmDialect.AD_ATT, loc=loc, ip=ip,
    )  # fmt: skip
    return [
        cutlass.Int32(_llvm.extractvalue(_T.i32(), out, [i], loc=loc, ip=ip))
        for i in range(4)
    ]

_match_any(value, *, loc=None, ip=None)

The mask of the warp's lanes holding the same 32-bit value.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _match_any(value, *, loc=None, ip=None):
    """The mask of the warp's lanes holding the same 32-bit value."""
    return cutlass.Int32(
        _asm(
            _T.i32(),
            [cutlass.Int32(value)],
            "match.any.sync.b32 $0, $1, 0xffffffff;",
            "=r,r",
            False,
            loc,
            ip,
        )
    )

_mbar_arrive_n(mbar_smem, n, *, loc=None, ip=None)

mbarrier.arrive with count n on a shared-memory barrier (release, CTA scope).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _mbar_arrive_n(mbar_smem, n, *, loc=None, ip=None):
    """mbarrier.arrive with count n on a shared-memory barrier (release, CTA scope)."""
    _llvm.inline_asm(
        None,
        [cutlass.Int32(mbar_smem).ir_value(loc=loc, ip=ip), cutlass.Int32(n).ir_value(loc=loc, ip=ip)],
        "{ .reg .b64 st; mbarrier.arrive.release.cta.shared::cta.b64 st, [$0], $1; }", "r,r",
        has_side_effects=True, is_align_stack=False, asm_dialect=_llvm.AsmDialect.AD_ATT, loc=loc, ip=ip,
    )  # fmt: skip

_mx_osc(amax)

mxfp8 quantization of a block with absolute max amax: (UE8M0 code, the element multiplier).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
def _mx_osc(amax):
    """mxfp8 quantization of a block with absolute max amax: (UE8M0 code, the element multiplier)."""
    code = _ue8m0_rp(_mul_rn(amax, _rcp(cutlass.Float32(448.0))))
    cf = cutlass.Int32(
        cutlass.select_(
            code == cutlass.Int32(255),
            cutlass.Int32(0x7FFFFFFF),
            cutlass.select_(
                code == cutlass.Int32(0),
                cutlass.Int32(0x00400000),
                code << cutlass.Int32(23),
            ),
        )
    ).bitcast(cutlass.Float32)
    return code, cutlass.select_(
        amax != cutlass.Float32(0.0), _rcp(cf), cutlass.Float32(0.0)
    )

_mx_words(v, osc)

e4m3 words of len(v) (a multiple of 4) values times osc, in element order.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
def _mx_words(v, osc):
    """e4m3 words of len(v) (a multiple of 4) values times osc, in element order."""
    words = []
    for t in range(len(v) // 4):
        lo = _e4m3x2(_mul_rn(v[4 * t + 1], osc), _mul_rn(v[4 * t], osc))
        hi = _e4m3x2(_mul_rn(v[4 * t + 3], osc), _mul_rn(v[4 * t + 2], osc))
        words.append(lo | (hi << cutlass.Int32(16)))
    return words

_nkb2(t2)

K-64 MMA instructions (= scale atoms) of FC2 k-tile t2.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
def _nkb2(t2: int) -> int:
    """K-64 MMA instructions (= scale atoms) of FC2 k-tile t2."""
    return NUM_KB if t2 < KT2 - 1 else KB2_LAST

_pf_next(arp, cid, lane, nthr_ctas)

PF_NEXT: this lane's share of the arp[6] table's L2 prefetches (PF_CHUNK-byte bulk prefetches).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _pf_next(arp: cutlass.Array, cid, lane, nthr_ctas: cutlass.Constexpr):
    """PF_NEXT: this lane's share of the arp[6] table's L2 prefetches (PF_CHUNK-byte bulk prefetches)."""
    npf = cutlass.Int32(arp.load(idx=7))
    tbl = arp.load(idx=6)
    gid = cutlass.Int64(cid) * cutlass.Int64(32) + cutlass.Int64(lane)
    for si in cutlass.range(0, npf, unroll=1):
        pbase = _ld_relaxed_u64(tbl + cutlass.Int64(si) * cutlass.Int64(16))
        pbytes = _ld_relaxed_u64(
            tbl + cutlass.Int64(si) * cutlass.Int64(16) + cutlass.Int64(8)
        )
        pf_nch = (pbytes + cutlass.Int64(PF_CHUNK - 1)) // cutlass.Int64(PF_CHUNK)
        pf_ci = gid
        while pf_ci < pf_nch:
            pf_rem = pbytes - pf_ci * cutlass.Int64(PF_CHUNK)
            pf_nb = cutlass.Int32(
                cutlass.select_(
                    pf_rem > cutlass.Int64(PF_CHUNK), cutlass.Int64(PF_CHUNK), pf_rem
                )
            )
            _l2_prefetch(pbase + pf_ci * cutlass.Int64(PF_CHUNK), pf_nb)
            pf_ci = pf_ci + cutlass.Int64(nthr_ctas * 32)

_rcp(a, *, loc=None, ip=None)

rcp.approx.ftz.f32 (the reciprocal TRT-LLM's FP4 quantization uses).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _rcp(a, *, loc=None, ip=None):
    """rcp.approx.ftz.f32 (the reciprocal TRT-LLM's FP4 quantization uses)."""
    return cutlass.Float32(
        _asm(
            _T.f32(),
            [cutlass.Float32(a)],
            "rcp.approx.ftz.f32 $0, $1;",
            "=f,f",
            False,
            loc,
            ip,
        )
    )

_seg(i0, i1, k)

Segment k of the FC1 item range [i0, i1) (items = unit-major stages): (unit, first stage, end stage). Order: the last unit (its head, the part a split unit's next CTA does not cover), then the first unit, then the rest.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _seg(i0, i1, k):
    """Segment k of the FC1 item range [i0, i1) (items = unit-major stages): (unit, first stage, end stage). Order:
    the last unit (its head, the part a split unit's next CTA does not cover), then the first unit, then the rest."""
    uf = i0 // cutlass.Int32(S1)
    ul = (i1 - cutlass.Int32(1)) // cutlass.Int32(S1)
    unit = uf + k - cutlass.Int32(1)
    unit = cutlass.select_(k == cutlass.Int32(0), ul, unit)
    unit = cutlass.select_(ul == uf, uf, unit)
    j0 = i0 - unit * cutlass.Int32(S1)
    j0 = cutlass.select_(j0 < cutlass.Int32(0), cutlass.Int32(0), j0)
    j1 = i1 - unit * cutlass.Int32(S1)
    j1 = cutlass.select_(j1 > cutlass.Int32(S1), cutlass.Int32(S1), j1)
    return unit, j0, j1

_sf1_cp(lane, stage, sf_line, c, sSFA, s1w, ab_full)

(SFA_CP) FC1 stage scale atoms: word [r][q] of atom kb <- raw atom 4 q + kb (raw line sf_line = 4 x atom) word [r][c % 4] (what the splicer copies out of the raw box), 4-byte cp.async by the warp's 32 lanes; their arrivals (noinc) complete the stage's full barrier together with the A boxes' bytes.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _sf1_cp(
    lane,
    stage,
    sf_line,
    c,
    sSFA: cutlass.Array,
    s1w: cutlass.Array,
    ab_full: cutlass.Array,
):
    """(SFA_CP) FC1 stage scale atoms: word `[r][q]` of atom kb <- raw atom 4 q + kb (raw line sf_line = 4 x atom)
    word `[r][c % 4]` (what the splicer copies out of the raw box), 4-byte cp.async by the warp's 32 lanes; their
    arrivals (noinc) complete the stage's full barrier together with the A boxes' bytes."""
    src0 = (
        (sf_line >> cutlass.Int32(2)) * cutlass.Int32(128)
        + lane * cutlass.Int32(4)
        + (c & cutlass.Int32(3))
    )
    dst0 = stage * cutlass.Int32(NUM_WORDS_SFA) + lane * cutlass.Int32(4)
    if cutlass.const_expr(SFA_BULK):
        if lane == 0:
            blk_ = ((sf_line >> cutlass.Int32(2)) >> cutlass.Int32(4)) * cutlass.Int32(
                4
            ) + (c & cutlass.Int32(3))
            _bulk_g2s(
                sSFA.subview(stage * cutlass.Int32(NUM_WORDS_SFA)).data_ptr().toint(),
                cutlass.Int64(s1w.data_ptr().toint())
                + cutlass.Int64(blk_) * cutlass.Int64(NUM_BYTES_SFA),
                NUM_BYTES_SFA,
                ab_full.subview(stage).data_ptr().toint(),
            )
            if cutlass.const_expr(
                SFA_ARR1
            ):  # the 32 lanes' arrivals the barrier counts (no cp.async is pending)
                _mbar_arrive_n(ab_full.subview(stage).data_ptr().toint(), 32)
        if cutlass.const_expr(not SFA_ARR1):
            cute.arch.sync_warp()
    else:
        for q in cutlass.range_constexpr(C1):
            for kb in cutlass.range_constexpr(NUM_KB):
                prims.cp_async_shared_global(
                    sSFA.subview(dst0 + cutlass.Int32(kb * 128 + q)),
                    s1w.subview(src0 + cutlass.Int32((4 * q + kb) * 128)),
                    4,
                    "ca",
                )
    if cutlass.const_expr(not (SFA_BULK and SFA_ARR1)):
        prims.cp_async_mbarrier_arrive(
            ab_full.subview(stage), noinc=True
        )  # (SFA_BULK: no cp.async, arrives now)
    cute.arch.sync_warp()

_sf2_cp(lane, stage, g, blk, t2, n_here, s_el, sSFA, s2w, ab_full)

(SFA_CP) FC2 k-tile t2 scale atoms: word [r][jj] of atom kb <- raw atom (rows / 128, K block 4 t2 + kb) of slot jj's expert, word [r][blk % 4].

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _sf2_cp(
    lane,
    stage,
    g,
    blk,
    t2,
    n_here,
    s_el: cutlass.Array,
    sSFA: cutlass.Array,
    s2w: cutlass.Array,
    ab_full: cutlass.Array,
):
    """(SFA_CP) FC2 k-tile t2 scale atoms: word `[r][jj]` of atom kb <- raw atom (rows / 128, K block 4 t2 + kb) of slot
    jj's expert, word `[r][blk % 4]`."""
    dst0 = stage * cutlass.Int32(NUM_WORDS_SFA) + lane * cutlass.Int32(4)
    for jj in cutlass.range_constexpr(4):
        if cutlass.Int32(jj) < n_here:
            e = s_el.load(idx=g * cutlass.Int32(4) + cutlass.Int32(jj))
            src0 = (
                (
                    (e * cutlass.Int32(SF2_RB) + (blk >> cutlass.Int32(2)))
                    * cutlass.Int32(SF2_KA)
                    + cutlass.Int32(4 * t2)
                )
                * cutlass.Int32(128)
                + lane * cutlass.Int32(4)
                + (blk & cutlass.Int32(3))
            )
            # (a partial last k-tile has no atoms past I_TP)
            for kb in cutlass.range_constexpr(NUM_KB):
                prims.cp_async_shared_global(
                    sSFA.subview(dst0 + cutlass.Int32(kb * 128 + jj)),
                    s2w.subview(src0 + cutlass.Int32(kb * 128)),
                    4,
                    "ca",
                )
    prims.cp_async_mbarrier_arrive(ab_full.subview(stage), noinc=True)
    cute.arch.sync_warp()

_sfa_to_tmem(sSFA, stage, base_row, base_col)

(SFA_CP, elected MMA thread) the stage's 4 scale atoms smem -> TMEM (what the splicer warp does otherwise).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _sfa_to_tmem(sSFA: cutlass.Array, stage, base_row, base_col):
    """(SFA_CP, elected MMA thread) the stage's 4 scale atoms smem -> TMEM (what the splicer warp does otherwise)."""
    s2t_shape, s2t_mc = prims.S2TCopyMode.S2T_32x128b_WARPX4
    sd0 = prims.Tcgen05SmemDesc.build(
        sSFA.subview(stage * cutlass.Int32(NUM_WORDS_SFA)),
        leading_byte_offset=16,
        stride_byte_offset=128,
        base_offset=0,
        layout=0,
    )
    for kb in cutlass.range_constexpr(NUM_KB):
        prims.tcgen05_cp(
            s2t_shape,
            _tptr(base_row, base_col + SFA1_COL + stage * cutlass.Int32(16) + kb * 4),
            sd0 + (kb * 512 >> 4),
            multicast=s2t_mc,
        )

_sfb1_to_tmem(warp, lane, base_row, base_col, src, b1_ready)

B1 scales to TMEM: instruction (j, kb)'s column holds, at lane n = QS q + t, token t's 4 scales of k-tile 4 j + q, K 64 kb .. (src: int32 words [M, 96] of the token scales); each warp writes its sub-partition.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _sfb1_to_tmem(
    warp, lane, base_row, base_col, src: cutlass.Array, b1_ready: cutlass.Array
):
    """B1 scales to TMEM: instruction (j, kb)'s column holds, at lane n = QS q + t, token t's 4 scales of k-tile
    4 j + q, K 64 kb .. (src: int32 words [M, 96] of the token scales); each warp writes its sub-partition."""
    q = lane // cutlass.Int32(QS)
    tl = lane - q * cutlass.Int32(QS)
    sf_ok = (lane < cutlass.Int32(N1)) & (tl < cutlass.Int32(M_MAX))
    sfv = []
    for a in cutlass.range_constexpr(NUM_SFB1_ATOMS):
        j = a // NUM_KB
        kb = a % NUM_KB
        wsf = src.load(
            idx=cutlass.select_(
                sf_ok,
                tl * cutlass.Int32(H // 64)
                + (cutlass.Int32(4 * j) + q) * cutlass.Int32(4)
                + cutlass.Int32(kb),
                cutlass.Int32(0),
            )
        )
        sfv.append(cutlass.select_(sf_ok, cutlass.Int32(wsf), cutlass.Int32(0)))
    for a in cutlass.range_constexpr(NUM_SFB1_ATOMS):
        prims.tcgen05_st(
            "32x32b",
            _tptr(base_row + warp * cutlass.Int32(32), base_col + SFB1_COL + a * 4),
            sfv[a],
        )
    prims.tcgen05_wait(prims.Tcgen05Wait.STORE)
    prims.fence_proxy("async_shared", space=prims.SharedSpace.shared_cta)
    prims.tcgen05_fence(prims.Tcgen05Fence.BEFORE_THREAD_SYNC)
    prims.mbarrier_arrive(b1_ready)

_sh_issue(lane, sid, g, s_big, sh_full, tma_gu, tma_dn, gusf, dnsf)

Stage g of the shared CTA's stream into ring slot g % SH_NST (warp 0). g < SH_GT: gate_up k-tile g of both slices: quadrant Q = 2 q + u (q slice, u 0 gate / 1 up) = rows 32 sid .. (+ 768 for up) at k-tile SH_GT q + g, its raw scale atom at raw slot Q. Else down tile j = (g - SH_GT) / 6 (rows 256 sid + 128 j ..), k-tile (g - SH_GT) % 6.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _sh_issue(
    lane,
    sid,
    g,
    s_big: cutlass.Array,
    sh_full: cutlass.Array,
    tma_gu,
    tma_dn,
    gusf: cutlass.Array,
    dnsf: cutlass.Array,
):
    """Stage g of the shared CTA's stream into ring slot g % SH_NST (warp 0). g < SH_GT: gate_up k-tile g of both
    slices: quadrant Q = 2 q + u (q slice, u 0 gate / 1 up) = rows 32 sid .. (+ 768 for up) at k-tile SH_GT q + g, its
    raw scale atom at raw slot Q. Else down tile j = (g - SH_GT) / 6 (rows 256 sid + 128 j ..), k-tile
    (g - SH_GT) % 6."""
    st = g % cutlass.Int32(SH_NST)
    bar = sh_full.subview(st)
    if cutlass.const_expr(SH_PRETILE):
        if lane == 0:
            src = (sid * cutlass.Int32(SH_STAGES) + g) * cutlass.Int32(SH_STAGE_BYTES)
            prims.mbarrier_arrive_expect_tx(bar, SH_STAGE_BYTES)
            prims.cp_async_bulk_shared_cluster_global(
                s_big.subview(st * cutlass.Int32(NUM_BYTES_A)),
                gusf.subview(src),
                bar,
                16384,
            )
            prims.cp_async_bulk_shared_cluster_global(
                s_big.subview(cutlass.Int32(_SB_SPL) + st * cutlass.Int32(512)),
                gusf.subview(src + cutlass.Int32(16384)),
                bar,
                512,
            )
        cute.arch.sync_warp()
    else:
        if g < cutlass.Int32(SH_GT):
            if lane == 0:
                prims.mbarrier_arrive_expect_tx(bar, NUM_BYTES_A + 4 * 512)
            cute.arch.sync_warp()
            if lane < 4:
                q = lane >> cutlass.Int32(1)
                u = lane & cutlass.Int32(1)
                row0 = sid * cutlass.Int32(32) + u * cutlass.Int32(SH_I)
                kt = q * cutlass.Int32(SH_GT) + g
                prims.cp_async_bulk_tensor_shared_cta_global(
                    s_big.subview(
                        st * cutlass.Int32(NUM_BYTES_A) + lane * cutlass.Int32(4096)
                    ),
                    tma_gu,
                    (kt * cutlass.Int32(128), row0),
                    bar,
                    l2_cache_hint=EVICT_FIRST,
                )
                prims.cp_async_bulk_shared_cluster_global(
                    s_big.subview(
                        cutlass.Int32(_SB_RAW)
                        + st * cutlass.Int32(2048)
                        + lane * cutlass.Int32(512)
                    ),
                    gusf.subview(
                        ((row0 >> cutlass.Int32(7)) * cutlass.Int32(SH_KB // 4) + kt)
                        * cutlass.Int32(512)
                    ),
                    bar,
                    512,
                )
        else:
            gd = g - cutlass.Int32(SH_GT)
            jt = gd // cutlass.Int32(SH_DKT)
            kt = gd - jt * cutlass.Int32(SH_DKT)
            row0 = sid * cutlass.Int32(SH_DROWS) + jt * cutlass.Int32(128)
            if lane == 0:
                prims.mbarrier_arrive_expect_tx(bar, NUM_BYTES_A + 512)
                prims.cp_async_bulk_tensor_shared_cta_global(
                    s_big.subview(st * cutlass.Int32(NUM_BYTES_A)),
                    tma_dn,
                    (kt * cutlass.Int32(128), row0),
                    bar,
                    l2_cache_hint=EVICT_FIRST,
                )
                prims.cp_async_bulk_shared_cluster_global(
                    s_big.subview(cutlass.Int32(_SB_RAW) + st * cutlass.Int32(2048)),
                    dnsf.subview(
                        ((row0 >> cutlass.Int32(7)) * cutlass.Int32(SH_DKB // 4) + kt)
                        * cutlass.Int32(512)
                    ),
                    bar,
                    512,
                )
            cute.arch.sync_warp()

_shared_cta(tidx, warp, lane, sid, s_big, sh_bar, epochs, tdbg, bx, xb32, tma_gu, tma_dn, gusf, dnsf, hx, dnx, arp, tmem_ptr_i32, gu8, dn8)

Shared CTA sid (see SHARED): tcgen05 MXF8 (E4M3 x E4M3, UE8M0 per 32 K), m3_mx_gemv's tile order. gate_up: one 128-row MMA tile = 2 K slices x (32 gate + 32 up rows), B rows 8 q + t = token t's slice-q k-tile; down: 2 tiles of 128 rows, full K. Warps: 0 weights (TMA), 1 TMEM + scale splice + MMA, 4-7 epilogue; 2.. activation quant.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
@cute.jit
def _shared_cta(
    tidx,
    warp,
    lane,
    sid,
    s_big: cutlass.Array,
    sh_bar: cutlass.Array,
    epochs: cutlass.Array,
    tdbg: cutlass.Array,
    bx,
    xb32: cutlass.Array,
    tma_gu,
    tma_dn,
    gusf: cutlass.Array,
    dnsf: cutlass.Array,
    hx: cutlass.Array,
    dnx: cutlass.Array,
    arp: cutlass.Array,
    tmem_ptr_i32: cutlass.Array,
    gu8: cutlass.Array,
    dn8: cutlass.Array,
):
    """Shared CTA sid (see SHARED): tcgen05 MXF8 (E4M3 x E4M3, UE8M0 per 32 K), m3_mx_gemv's tile order. gate_up: one
    128-row MMA tile = 2 K slices x (32 gate + 32 up rows), B rows 8 q + t = token t's slice-q k-tile; down: 2 tiles
    of 128 rows, full K. Warps: 0 weights (TMA), 1 TMEM + scale splice + MMA, 4-7 epilogue; 2.. activation quant."""
    big32 = cutlass.Array(
        s_big.data_ptr(0), shape=(BIG // 4,), dtype=cutlass.Int32, alignment=16
    )
    bigf = cutlass.Array(
        s_big.data_ptr(0), shape=(BIG // 4,), dtype=cutlass.Float32, alignment=16
    )
    big8 = cutlass.Array(
        s_big.data_ptr(0), shape=(BIG,), dtype=cutlass.Int8, alignment=16
    )
    sh_full = sh_bar  # [0, SH_NST): stage full
    sh_empty = cutlass.Array(
        sh_bar.data_ptr(8), shape=(8,), dtype=cutlass.Int64, alignment=8
    )
    b_gu_rdy = sh_bar.subview(16)
    b_dn_rdy = sh_bar.subview(17)
    acc_gu = sh_bar.subview(18)
    acc_dn = sh_bar.subview(19)
    if warp == 0:
        prims.prefetch_tensormap(tma_gu)
        prims.prefetch_tensormap(tma_dn)
        if lane < SH_NST:
            prims.mbarrier_init(sh_full.subview(lane), 1)
            prims.mbarrier_init(
                sh_empty.subview(lane), 1 if SH_ARR1 else 33
            )  # the MMAs' commit + each splicer lane's reads done (SH_ARR1: the commit only)
        if lane == 0:
            prims.mbarrier_init(b_gu_rdy, 1)
            prims.mbarrier_init(b_dn_rdy, 1)
            prims.mbarrier_init(acc_gu, 1)
            prims.mbarrier_init(acc_dn, 1)
    if warp == 1:
        prims.tcgen05_alloc(tmem_ptr_i32, SH_TMEM)
        prims.tcgen05_relinquish_alloc_permit()
    prims.fence_mbarrier_init()
    prims.tcgen05_fence(prims.Tcgen05Fence.BEFORE_THREAD_SYNC)
    cute.arch.sync_warp()
    prims.barrier_cta_sync(0)
    prims.tcgen05_fence(prims.Tcgen05Fence.AFTER_THREAD_SYNC)
    tmem_raw = tmem_ptr_i32.load()
    base_col = tmem_raw & 0xFFFF
    base_row = tmem_raw >> 16
    if (warp == 0) & cutlass.Boolean(not SH_LATE):
        for g in cutlass.range_constexpr(
            SH_NST
        ):  # layer constants: before the grid dependency
            _sh_issue(
                lane, sid, cutlass.Int32(g), s_big, sh_full, tma_gu, tma_dn, gusf, dnsf
            )
        # the rest of this CTA's weights into L2 (64 gate / up rows of 6 KB, 256 down
        # rows of 768 B) (AR_IN, cfg sh_pf=0: skipped, so the 29 MB flood does not delay
        # the boundary reduce's loads)
        if cutlass.const_expr(not SH_PF_ON):
            pass
        elif cutlass.const_expr(SH_PRETILE):
            # this CTA's stages beyond the ring, 4 per lane
            for r in cutlass.range_constexpr(SH_PF):
                pg = (
                    cutlass.Int32(SH_NST)
                    + lane * cutlass.Int32(SH_PF)
                    + cutlass.Int32(r)
                )
                if pg < cutlass.Int32(SH_STAGES):
                    _l2_prefetch(
                        gusf.subview(
                            (sid * cutlass.Int32(SH_STAGES) + pg)
                            * cutlass.Int32(SH_STAGE_BYTES)
                        )
                        .data_ptr()
                        .toint(),
                        SH_STAGE_BYTES,
                    )
        else:
            for r in cutlass.range_constexpr(2):
                prw = sid * cutlass.Int32(32) + cutlass.Int32(r * SH_I) + lane
                _l2_prefetch(gu8.subview(prw * cutlass.Int32(H)).data_ptr().toint(), H)
            if lane == 0:
                _l2_prefetch(
                    dn8.subview(sid * cutlass.Int32(SH_DROWS * SH_I))
                    .data_ptr()
                    .toint(),
                    SH_DROWS * SH_I,
                )
    cute.arch.griddepcontrol_wait()
    if cutlass.const_expr(SH_LATE):
        if warp == 0:
            for g in cutlass.range_constexpr(
                SH_NST
            ):  # SH_LATE: the ring's first stages after the grid dependency
                _sh_issue(
                    lane,
                    sid,
                    cutlass.Int32(g),
                    s_big,
                    sh_full,
                    tma_gu,
                    tma_dn,
                    gusf,
                    dnsf,
                )
    if cutlass.const_expr(not LATE_TRIGGER):
        if arp.load(idx=0) == cutlass.Int64(0):
            cute.arch.griddepcontrol_launch_dependents()
    if cutlass.const_expr(SH_TRIG):
        if arp.load(idx=0) != cutlass.Int64(
            0
        ):  # E-T: every thread triggers after its own wait above
            cute.arch.griddepcontrol_launch_dependents()
    ep = epochs.load(idx=bx)
    tag16 = (ep & cutlass.Int32(0x7FFF)) | cutlass.Int32(0x8000)
    NQ = THREADS - 64  # activation quant threads (warps 2 ..)
    if warp == 0:
        for g in cutlass.range(SH_NST, SH_STAGES, unroll=1):
            _wait(
                sh_empty.subview(g % cutlass.Int32(SH_NST)),
                ((g // cutlass.Int32(SH_NST)) - cutlass.Int32(1)) & cutlass.Int32(1),
            )
            _sh_issue(lane, sid, g, s_big, sh_full, tma_gu, tma_dn, gusf, dnsf)
    elif warp == 1:
        # ---- MMA: gate_up (scale atoms spliced to the tile's row order), then down
        idesc_gu = prims.Tcgen05MxInstrDesc.build(
            a_dtype=cutlass.Float8E4M3FN,
            b_dtype=cutlass.Float8E4M3FN,
            scale_format=1,
            n_dim=SH_NB,
            m_dim=128,
        )
        idesc_dn = prims.Tcgen05MxInstrDesc.build(
            a_dtype=cutlass.Float8E4M3FN,
            b_dtype=cutlass.Float8E4M3FN,
            scale_format=1,
            n_dim=8,
            m_dim=128,
        )
        s2t_shape, s2t_mc = prims.S2TCopyMode.S2T_32x128b_WARPX4
        desc_a0 = prims.Tcgen05SmemDesc.build(
            s_big.subview(0),
            leading_byte_offset=16,
            stride_byte_offset=1024,
            base_offset=0,
            layout=2,
        )
        desc_bx = prims.Tcgen05SmemDesc.build(
            s_big.subview(_SB_BX),
            leading_byte_offset=16,
            stride_byte_offset=1024,
            base_offset=0,
            layout=2,
        )
        desc_bh = prims.Tcgen05SmemDesc.build(
            s_big.subview(_SB_BH),
            leading_byte_offset=16,
            stride_byte_offset=1024,
            base_offset=0,
            layout=2,
        )
        tcol = (base_row << 16) | base_col
        sq = sid & cutlass.Int32(3)
        _wait(b_gu_rdy, 0)
        prims.tcgen05_fence(prims.Tcgen05Fence.AFTER_THREAD_SYNC)
        for g in cutlass.range(SH_STAGES, unroll=1):
            st = g % cutlass.Int32(SH_NST)
            if g == cutlass.Int32(SH_GT):
                _wait(b_dn_rdy, 0)
                prims.tcgen05_fence(prims.Tcgen05Fence.AFTER_THREAD_SYNC)
            _wait(sh_full.subview(st), (g // cutlass.Int32(SH_NST)) & cutlass.Int32(1))
            raw = cutlass.Int32(_SB_RAW // 4) + st * cutlass.Int32(512)  # type: ignore[operator]
            if (g < cutlass.Int32(SH_GT)) & cutlass.Boolean(not SH_PRETILE):
                # MMA row 32 Q + i = quadrant Q's row i: word 4 i + Q <- raw atom Q's word 4 i + sid % 4
                w4 = [
                    big32.load(
                        idx=raw + cutlass.Int32(128 * qq) + lane * cutlass.Int32(4) + sq
                    )
                    for qq in range(4)
                ]
                big32.store(
                    (
                        cutlass.Int32(w4[0]),
                        cutlass.Int32(w4[1]),
                        cutlass.Int32(w4[2]),
                        cutlass.Int32(w4[3]),
                    ),
                    idx=cutlass.Int32(_SB_SPL // 4)
                    + st * cutlass.Int32(128)
                    + lane * cutlass.Int32(4),
                    alignment=16,
                )
                prims.fence_proxy("async_shared", space=prims.SharedSpace.shared_cta)
            cute.arch.sync_warp()
            if cutlass.const_expr(not SH_ARR1):
                prims.mbarrier_arrive(
                    sh_empty.subview(st)
                )  # this lane's generic reads of the slot are done
            prims.tcgen05_fence(prims.Tcgen05Fence.AFTER_THREAD_SYNC)
            if prims.elect_sync():
                if g < cutlass.Int32(SH_GT):
                    dsf = prims.Tcgen05SmemDesc.build(
                        s_big.subview(cutlass.Int32(_SB_SPL) + st * cutlass.Int32(512)),
                        leading_byte_offset=16,
                        stride_byte_offset=128,
                        base_offset=0,
                        layout=0,
                    )
                    prims.tcgen05_cp(
                        s2t_shape,
                        _tptr(base_row, base_col + SH_SFA + st * cutlass.Int32(4)),
                        dsf,
                        multicast=s2t_mc,
                    )
                    da = desc_a0 + cutlass.Int64(st * cutlass.Int32(NUM_BYTES_A >> 4))
                    db = desc_bx + cutlass.Int64(g * cutlass.Int32(SH_NB * 128 >> 4))
                    for kb in cutlass.range_constexpr(4):
                        prims.tcgen05_mma_block_scale(
                            prims.MMABlockScaleKind.MXF8F6F4,
                            prims.CTAGroup.CTA_1,
                            cutlass.inttoptr(tcol + SH_ACC_GU, 6, cutlass.Float32),
                            da + 2 * kb,
                            db + 2 * kb,
                            idesc_gu.set_sf_ids(a_sf_id=kb, b_sf_id=kb),
                            (g > cutlass.Int32(0)) | cutlass.Boolean(kb > 0),
                            cutlass.inttoptr(
                                tcol + SH_SFA + st * cutlass.Int32(4), 6, cutlass.Int32
                            ),
                            cutlass.inttoptr(
                                tcol + SH_SFB_GU + g * cutlass.Int32(4),
                                6,
                                cutlass.Int32,
                            ),
                        )
                    prims.tcgen05_commit(sh_empty.subview(st))
                    if g == cutlass.Int32(SH_GT - 1):
                        prims.tcgen05_commit(acc_gu)
                else:
                    gd = g - cutlass.Int32(SH_GT)
                    jt = gd // cutlass.Int32(SH_DKT)
                    kt = gd - jt * cutlass.Int32(SH_DKT)
                    dsf = prims.Tcgen05SmemDesc.build(
                        s_big.subview(
                            cutlass.Int32(_SB_SPL if SH_PRETILE else _SB_RAW)
                            + st * cutlass.Int32(512 if SH_PRETILE else 2048)
                        ),
                        leading_byte_offset=16,
                        stride_byte_offset=128,
                        base_offset=0,
                        layout=0,
                    )
                    prims.tcgen05_cp(
                        s2t_shape,
                        _tptr(base_row, base_col + SH_SFA + st * cutlass.Int32(4)),
                        dsf,
                        multicast=s2t_mc,
                    )
                    da = desc_a0 + cutlass.Int64(st * cutlass.Int32(NUM_BYTES_A >> 4))
                    db = desc_bh + cutlass.Int64(kt * cutlass.Int32(1024 >> 4))
                    for kb in cutlass.range_constexpr(4):
                        prims.tcgen05_mma_block_scale(
                            prims.MMABlockScaleKind.MXF8F6F4,
                            prims.CTAGroup.CTA_1,
                            cutlass.inttoptr(
                                tcol + SH_ACC_DN + jt * cutlass.Int32(8),
                                6,
                                cutlass.Float32,
                            ),
                            da + 2 * kb,
                            db + 2 * kb,
                            idesc_dn.set_sf_ids(a_sf_id=kb, b_sf_id=kb),
                            (kt > cutlass.Int32(0)) | cutlass.Boolean(kb > 0),
                            cutlass.inttoptr(
                                tcol + SH_SFA + st * cutlass.Int32(4), 6, cutlass.Int32
                            ),
                            cutlass.inttoptr(
                                tcol + SH_SFB_DN + kt * cutlass.Int32(4),
                                6,
                                cutlass.Int32,
                            ),
                        )
                    prims.tcgen05_commit(sh_empty.subview(st))
                    if g == cutlass.Int32(SH_STAGES - 1):
                        prims.tcgen05_commit(acc_dn)
            cute.arch.sync_warp()
    if warp >= 2:
        if cutlass.const_expr(AR_IN):
            if arp.load(idx=6) != cutlass.Int64(0):
                # AR_IN: routed CTA 0 writes the normed hidden states; wait for this call's release
                xra = cutlass.Int64(
                    _ld_relaxed_u64(arp.load(idx=6) + cutlass.Int64(72))
                )
                if (
                    lane == 0
                ):  # one poller per warp, backed off (the counter's L2 line is shared by every routed CTA)
                    xv = _ld_acquire_u32(xra)
                    while xv - (ep + cutlass.Int32(1)) < cutlass.Int32(0):
                        _nanosleep(100)
                        xv = _ld_acquire_u32(xra)
                cute.arch.sync_warp()
        # ---- the activation, MXFP8 per 32-K block (native mxfp8_quantize), into B (row
        # 8 q + t of stage tile i = token t's k-tile SH_GT q + i, 128-byte swizzle) and
        # its codes
        qt = tidx - cutlass.Int32(64)
        for r in cutlass.range_constexpr((M_MAX * SH_KB + NQ - 1) // NQ):
            q_ = qt + cutlass.Int32(r * NQ)
            if q_ < cutlass.Int32(M_MAX * SH_KB):
                t = q_ // cutlass.Int32(SH_KB)
                b = q_ - t * cutlass.Int32(SH_KB)
                wv = [
                    xb32.load(
                        idx=t * cutlass.Int32(H // 2)
                        + b * cutlass.Int32(16)
                        + cutlass.Int32(4 * z),
                        vector_size=4,
                        alignment=16,
                    )
                    for z in range(4)
                ]
                v = []
                for z in cutlass.range_constexpr(4):
                    for zz in cutlass.range_constexpr(4):
                        w = cutlass.Int32(wv[z][zz])
                        v.append((w << cutlass.Int32(16)).bitcast(cutlass.Float32))
                        v.append((w & cutlass.Int32(-65536)).bitcast(cutlass.Float32))
                amax = cutlass.Float32(0.0)
                for z in cutlass.range_constexpr(32):
                    amax = cute.arch.fmax(amax, cute.math.abs(v[z]))
                code, osc = _mx_osc(amax)
                words = _mx_words(v, osc)
                kt = b >> cutlass.Int32(2)
                sl = kt // cutlass.Int32(SH_GT)
                it = kt - sl * cutlass.Int32(SH_GT)
                n = sl * cutlass.Int32(8) + t
                c0 = (b & cutlass.Int32(3)) * cutlass.Int32(2)
                rw = (
                    cutlass.Int32(_SB_BX)
                    + it * cutlass.Int32(SH_NB * 128)
                    + n * cutlass.Int32(128)
                ) >> cutlass.Int32(2)
                big32.store(
                    (words[0], words[1], words[2], words[3]),
                    idx=rw + ((c0 ^ (n & cutlass.Int32(7))) << cutlass.Int32(2)),
                    alignment=16,
                )
                big32.store(
                    (words[4], words[5], words[6], words[7]),
                    idx=rw
                    + (
                        ((c0 + cutlass.Int32(1)) ^ (n & cutlass.Int32(7)))
                        << cutlass.Int32(2)
                    ),
                    alignment=16,
                )
                big8.store(cutlass.Int8(code), idx=cutlass.Int32(_SB_XC) + q_)
        prims.fence_proxy("async_shared", space=prims.SharedSpace.shared_cta)
        cute.arch.sync_warp()
        cute.arch.barrier(barrier_id=SHX_BAR, number_of_threads=NQ)
    if warp >= 4:
        if warp < 8:
            qd = warp - cutlass.Int32(4)
            # B scales of gate_up to TMEM: column of stage i, lane n = 8 q + t: token t's codes of k-tile SH_GT q + i
            n = lane
            t = n & cutlass.Int32(7)
            ok = (n < cutlass.Int32(SH_NB)) & (t < cutlass.Int32(M_MAX))
            for i in cutlass.range_constexpr(SH_GT):
                kt = (n >> cutlass.Int32(3)) * cutlass.Int32(SH_GT) + cutlass.Int32(i)
                wsf = big32.load(
                    idx=(
                        cutlass.Int32(_SB_XC)
                        + cutlass.select_(ok, t, cutlass.Int32(0))
                        * cutlass.Int32(SH_KB)
                        + kt * cutlass.Int32(4)
                    )
                    >> cutlass.Int32(2)
                )
                prims.tcgen05_st(
                    "32x32b",
                    _tptr(
                        base_row + qd * cutlass.Int32(32), base_col + SH_SFB_GU + i * 4
                    ),
                    cutlass.select_(ok, cutlass.Int32(wsf), cutlass.Int32(0)),
                )
            prims.tcgen05_wait(prims.Tcgen05Wait.STORE)
            prims.tcgen05_fence(prims.Tcgen05Fence.BEFORE_THREAD_SYNC)
            cute.arch.sync_warp()
            cute.arch.barrier(barrier_id=SHX_BAR + 1, number_of_threads=128)
            et = tidx - cutlass.Int32(128)
            if et == 0:
                prims.mbarrier_arrive(b_gu_rdy)
            # ---- gate_up out: quadrant qd lane l = MMA row 32 qd + l; slice q = qd / 2 holds token t at column 8 q + t
            _wait(acc_gu, 0)
            prims.tcgen05_fence(prims.Tcgen05Fence.AFTER_THREAD_SYNC)
            if cutlass.const_expr(SH_SPLIT == 1):
                # (TP2): one K slice; warp qd holds MMA rows 32 qd + l = gate (qd < 2) /
                # up (qd >= 2) position 32 (qd % 2) + l, i.e. GU row 32 qd + l;
                # m3_mx_gemv's owner sum (0 + rank 0), then bf16
                av = prims.tcgen05_ld(
                    "32x32b",
                    _tptr(
                        base_row + qd * cutlass.Int32(32),
                        base_col + SH_ACC_GU,
                        cutlass.Float32,
                    ),
                    num=8,
                )
                prims.tcgen05_wait(prims.Tcgen05Wait.LOAD)
                for tt in cutlass.range_constexpr(8):
                    bigf.store(
                        _bf16_round(
                            _add_rn(cutlass.Float32(0.0), cutlass.Float32(av[tt]))
                        ),
                        idx=cutlass.Int32(_SB_GU // 4)
                        + (qd * cutlass.Int32(32) + lane) * cutlass.Int32(8)
                        + cutlass.Int32(tt),
                    )
                cute.arch.sync_warp()
                cute.arch.barrier(barrier_id=SHX_BAR + 1, number_of_threads=128)
            elif cutlass.const_expr(SH_SPLIT == 2):
                av = prims.tcgen05_ld(
                    "32x32b",
                    _tptr(
                        base_row + qd * cutlass.Int32(32),
                        base_col + SH_ACC_GU,
                        cutlass.Float32,
                    ),
                    num=16,
                )
                prims.tcgen05_wait(prims.Tcgen05Wait.LOAD)
                if qd >= cutlass.Int32(2):
                    for tt in cutlass.range_constexpr(8):
                        bigf.store(
                            cutlass.Float32(av[8 + tt]),
                            idx=cutlass.Int32(_SB_XCH // 4)
                            + ((qd - cutlass.Int32(2)) * cutlass.Int32(32) + lane)
                            * cutlass.Int32(8)
                            + cutlass.Int32(tt),
                        )
                cute.arch.sync_warp()
                cute.arch.barrier(barrier_id=SHX_BAR + 1, number_of_threads=128)
                if qd < cutlass.Int32(2):
                    # m3_mx_gemv's owner sum: (0 + rank 0) + rank 1, then bf16
                    for tt in cutlass.range_constexpr(8):
                        tot = _add_rn(cutlass.Float32(0.0), cutlass.Float32(av[tt]))
                        tot = _add_rn(
                            tot,
                            bigf.load(
                                idx=cutlass.Int32(_SB_XCH // 4)
                                + (qd * cutlass.Int32(32) + lane) * cutlass.Int32(8)
                                + cutlass.Int32(tt)
                            ),
                        )
                        bigf.store(
                            _bf16_round(tot),
                            idx=cutlass.Int32(_SB_GU // 4)
                            + (qd * cutlass.Int32(32) + lane) * cutlass.Int32(8)
                            + cutlass.Int32(tt),
                        )
                cute.arch.sync_warp()
                cute.arch.barrier(barrier_id=SHX_BAR + 1, number_of_threads=128)
            else:
                # 16-row octants: warp qd = slice qd, lane l = (u = l / 16 gate / up,
                # position l % 16); its tokens are accumulator columns 8 qd + t
                av = prims.tcgen05_ld(
                    "32x32b",
                    _tptr(
                        base_row + qd * cutlass.Int32(32),
                        base_col + SH_ACC_GU + qd * cutlass.Int32(8),
                        cutlass.Float32,
                    ),
                    num=8,
                )
                prims.tcgen05_wait(prims.Tcgen05Wait.LOAD)
                if qd >= cutlass.Int32(1):
                    for tt in cutlass.range_constexpr(8):
                        bigf.store(
                            cutlass.Float32(av[tt]),
                            idx=cutlass.Int32(_SB_XCH // 4)
                            + ((qd - cutlass.Int32(1)) * cutlass.Int32(32) + lane)
                            * cutlass.Int32(8)
                            + cutlass.Int32(tt),
                        )
                cute.arch.sync_warp()
                cute.arch.barrier(barrier_id=SHX_BAR + 1, number_of_threads=128)
                if qd == cutlass.Int32(0):
                    # m3_mx_gemv's owner sum: (((0 + rank 0) + rank 1) + rank 2) + rank 3, then bf16
                    for tt in cutlass.range_constexpr(8):
                        tot = _add_rn(cutlass.Float32(0.0), cutlass.Float32(av[tt]))
                        for s_ in cutlass.range_constexpr(1, SH_SPLIT):
                            tot = _add_rn(
                                tot,
                                bigf.load(
                                    idx=cutlass.Int32(_SB_XCH // 4)
                                    + (cutlass.Int32((s_ - 1) * 32) + lane)
                                    * cutlass.Int32(8)
                                    + cutlass.Int32(tt)
                                ),
                            )
                        bigf.store(
                            _bf16_round(tot),
                            idx=cutlass.Int32(_SB_GU // 4)
                            + lane * cutlass.Int32(8)
                            + cutlass.Int32(tt),
                        )
                cute.arch.sync_warp()
                cute.arch.barrier(barrier_id=SHX_BAR + 1, number_of_threads=128)
            # h = silu_and_mul(gate, up) of positions 32 sid + p, published under the call's tag
            for r in cutlass.range_constexpr((SH_ROWS * M_MAX + 127) // 128):
                pq = et + cutlass.Int32(r * 128)
                if pq < cutlass.Int32(SH_ROWS * M_MAX):
                    p = pq // cutlass.Int32(M_MAX)
                    tt = pq - p * cutlass.Int32(M_MAX)
                    ga = bigf.load(
                        idx=cutlass.Int32(_SB_GU // 4) + p * cutlass.Int32(8) + tt
                    )
                    up = bigf.load(
                        idx=cutlass.Int32(_SB_GU // 4)
                        + (cutlass.Int32(SH_ROWS) + p) * cutlass.Int32(8)
                        + tt
                    )
                    q_a = cute.arch.fmin(cutlass.Float32(ga), cutlass.Float32(7.0))
                    q_bu = _min_xorsign_abs(cutlass.Float32(up), cutlass.Float32(7.0))
                    q_ub = _add_rn(q_bu, cutlass.Float32(1.0))
                    if cutlass.const_expr(SILU_VLLM):
                        q_ex = cute.math.exp(
                            _mul_rn(q_a, cutlass.Float32(-1.70200002193450927734)),
                            fastmath=False,
                        )
                        q_s = _bf16_round(
                            _div_rn(
                                q_a,
                                _add_rn(cutlass.Float32(1.0), cutlass.Float32(q_ex)),
                            )
                        )
                        q_h = _mul_rn(q_s, q_ub)
                    else:
                        q_e2 = _ex2_full(
                            _mul_rn(
                                _mul_rn(q_a, cutlass.Float32(-1.70200002193450927734)),
                                cutlass.Float32(1.4426950216293334961),
                            )
                        )
                        q_sg = _div_full(
                            cutlass.Float32(1.0), _add_rn(q_e2, cutlass.Float32(1.0))
                        )
                        q_h = _mul_rn(q_ub, _mul_rn(q_sg, q_a))
                    _st_relaxed_u32(
                        hx.subview(
                            tt * cutlass.Int32(SH_I) + sid * cutlass.Int32(SH_ROWS) + p
                        )
                        .data_ptr()
                        .toint(),
                        (tag16 << cutlass.Int32(16)) | _bf16_bits(q_h),
                    )
            # every shared CTA's h: (token, K block) per thread, 32 tagged words, MXFP8 into B (h) and its codes
            for rr in cutlass.range_constexpr((M_MAX * SH_DKB + 127) // 128):
                q_ = et + cutlass.Int32(rr * 128)
                if q_ < cutlass.Int32(M_MAX * SH_DKB):
                    t = q_ // cutlass.Int32(SH_DKB)
                    kb = q_ - t * cutlass.Int32(SH_DKB)
                    base = t * cutlass.Int32(SH_I) + kb * cutlass.Int32(32)
                    hv = [cutlass.Int32(0) for _ in range(32)]
                    pend = cutlass.Int32(1)
                    hd0 = cutlass.Int32(0)
                    while (pend != cutlass.Int32(0)) & (hd0 < cutlass.Int32(HANG_CAP)):
                        hd0 = hd0 + cutlass.Int32(1)
                        for q4 in cutlass.range_constexpr(8):
                            v4 = prims.load_ext(
                                hx.subview(base + cutlass.Int32(4 * q4)),
                                dtype=cutlass.Int32,
                                count=4,
                                order="relaxed",
                                scope="gpu",
                            )
                            for z in cutlass.range_constexpr(4):
                                hv[4 * q4 + z] = cutlass.Int32(v4[z])
                        okw = cutlass.Boolean(True)
                        for z in cutlass.range_constexpr(32):
                            okw = okw & (
                                ((hv[z] >> cutlass.Int32(16)) & cutlass.Int32(0xFFFF))
                                == tag16
                            )
                        pend = cutlass.select_(okw, cutlass.Int32(0), cutlass.Int32(1))
                    vals = [
                        (hv[z] << cutlass.Int32(16)).bitcast(cutlass.Float32)
                        for z in range(32)
                    ]
                    amax = cutlass.Float32(0.0)
                    for z in cutlass.range_constexpr(32):
                        amax = cute.arch.fmax(amax, cute.math.abs(vals[z]))
                    code, osc = _mx_osc(amax)
                    words = _mx_words(vals, osc)
                    kt = kb >> cutlass.Int32(2)
                    c0 = (kb & cutlass.Int32(3)) * cutlass.Int32(2)
                    rw = (
                        cutlass.Int32(_SB_BH)
                        + kt * cutlass.Int32(1024)
                        + t * cutlass.Int32(128)
                    ) >> cutlass.Int32(2)
                    big32.store(
                        (words[0], words[1], words[2], words[3]),
                        idx=rw + ((c0 ^ t) << cutlass.Int32(2)),
                        alignment=16,
                    )
                    big32.store(
                        (words[4], words[5], words[6], words[7]),
                        idx=rw + (((c0 + cutlass.Int32(1)) ^ t) << cutlass.Int32(2)),
                        alignment=16,
                    )
                    big8.store(cutlass.Int8(code), idx=cutlass.Int32(_SB_HC) + q_)
            prims.fence_proxy("async_shared", space=prims.SharedSpace.shared_cta)
            cute.arch.sync_warp()
            cute.arch.barrier(barrier_id=SHX_BAR + 1, number_of_threads=128)
            okh = lane < cutlass.Int32(M_MAX)
            for kt in cutlass.range_constexpr(SH_DKT):
                wsf = big32.load(
                    idx=(
                        cutlass.Int32(_SB_HC)
                        + cutlass.select_(okh, lane, cutlass.Int32(0))
                        * cutlass.Int32(SH_DKB)
                        + cutlass.Int32(4 * kt)
                    )
                    >> cutlass.Int32(2)
                )
                prims.tcgen05_st(
                    "32x32b",
                    _tptr(
                        base_row + qd * cutlass.Int32(32), base_col + SH_SFB_DN + kt * 4
                    ),
                    cutlass.select_(okh, cutlass.Int32(wsf), cutlass.Int32(0)),
                )
            prims.tcgen05_wait(prims.Tcgen05Wait.STORE)
            prims.tcgen05_fence(prims.Tcgen05Fence.BEFORE_THREAD_SYNC)
            cute.arch.sync_warp()
            cute.arch.barrier(barrier_id=SHX_BAR + 1, number_of_threads=128)
            if et == 0:
                prims.mbarrier_arrive(b_dn_rdy)
            # ---- down out: tile j row 32 qd + l -> y_sh row 256 sid + 128 j + 32 qd + l
            _wait(acc_dn, 0)
            prims.tcgen05_fence(prims.Tcgen05Fence.AFTER_THREAD_SYNC)
            for jt in cutlass.range_constexpr(SH_DT):
                dv = prims.tcgen05_ld(
                    "32x32b",
                    _tptr(
                        base_row + qd * cutlass.Int32(32),
                        base_col + SH_ACC_DN + jt * 8,
                        cutlass.Float32,
                    ),
                    num=8,
                )
                prims.tcgen05_wait(prims.Tcgen05Wait.LOAD)
                rowo = (
                    sid * cutlass.Int32(SH_DROWS)
                    + cutlass.Int32(128 * jt)
                    + qd * cutlass.Int32(32)
                    + lane
                )
                for tt in cutlass.range_constexpr(M_MAX):
                    _st_relaxed_u32(
                        dnx.subview(cutlass.Int32(tt * H) + rowo).data_ptr().toint(),
                        (tag16 << cutlass.Int32(16))
                        | _bf16_bits(cutlass.Float32(dv[tt])),
                    )
            prims.tcgen05_fence(prims.Tcgen05Fence.BEFORE_THREAD_SYNC)
    cute.arch.sync_warp()
    prims.barrier_cta_sync(0)
    if warp == 1:
        prims.tcgen05_fence(prims.Tcgen05Fence.AFTER_THREAD_SYNC)
        prims.tcgen05_dealloc(cutlass.inttoptr(tmem_raw, 6, cutlass.Float32), SH_TMEM)
    if tidx == 0:
        epochs.store(ep + cutlass.Int32(1), idx=bx)
    if cutlass.const_expr(PF_NEXT and PF_WHERE == 1):
        if warp == 0:
            _pf_next(arp, sid, lane, NSH)

_st_global_b32_if(addr, value, pred, *, loc=None, ip=None)

st.global.b32 when pred != 0.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _st_global_b32_if(addr, value, pred, *, loc=None, ip=None):
    """st.global.b32 when pred != 0."""
    _llvm.inline_asm(
        None, [cutlass.Int64(addr).ir_value(loc=loc, ip=ip), cutlass.Int32(value).ir_value(loc=loc, ip=ip),
               cutlass.Int32(pred).ir_value(loc=loc, ip=ip)],
        "{\n\t.reg .pred p;\n\tsetp.ne.s32 p, $2, 0;\n\t@p st.global.b32 [$0], $1;\n\t}", "l,r,r",
        has_side_effects=True, is_align_stack=False, asm_dialect=_llvm.AsmDialect.AD_ATT, loc=loc, ip=ip,
    )  # fmt: skip

_swiglu_quant(xv, gate_raw, is_up, a, c, alpha, beta, lim)

TRTLLM-Gen's FC1 epilogue (the swiGlu Bmm E2m1 output), operation for operation: lane value xv is the up row, gate_raw its gate row (fp32 sums). Returns (q, the scale's e4m3 bits) of the 16-row NVFP4 block (lanes r, r ^ 16 and r ^ 8 cover it; amax over the warp's up lanes of a half). a = fc31_alpha, c = fc31_scale_c.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _swiglu_quant(xv, gate_raw, is_up, a, c, alpha, beta, lim):
    """TRTLLM-Gen's FC1 epilogue (the swiGlu Bmm E2m1 output), operation for operation: lane value xv is the up row,
    gate_raw its gate row (fp32 sums). Returns (q, the scale's e4m3 bits) of the 16-row NVFP4 block (lanes r, r ^ 16
    and r ^ 8 cover it; amax over the warp's up lanes of a half). a = fc31_alpha, c = fc31_scale_c."""
    neg_max = cutlass.Float32(-3.40282346638528859812e38)
    gc = cutlass.select_(gate_raw > lim, lim, gate_raw)
    gc = cutlass.select_(gate_raw < neg_max, neg_max, gc)
    uc = cutlass.select_(xv > lim, lim, xv)
    uc = cutlass.select_(xv < -lim, -lim, uc)
    c1 = _mul_rn(a, _mul_rn(alpha, cutlass.Float32(1.4426950216293334961)))
    sgm = _rcp(_add_rn(_ex2(-_mul_rn(gc, c1)), cutlass.Float32(1.0)))
    gs = _mul_rn(gc, sgm)
    h = _mul_rn(_fma_rn(uc, a, _mul_rn(a, beta)), gs)
    h = cutlass.select_(is_up, h, cutlass.Float32(0.0))
    amax = cute.arch.fmax(_mul_rn(cute.math.abs(h), c), cutlass.Float32(0.0))
    for off in (16, 8, 4, 2, 1):
        amax = cute.arch.fmax(amax, cute.arch.shuffle_sync_bfly(amax, off))
    sfb = _e4m3_bits(_mul_rn(amax, cutlass.Float32(0.16666667163372039795)))
    sff = _e4m3_to_f32(sfb)
    osc = cutlass.select_(sff != cutlass.Float32(0.0), _rcp(sff), cutlass.Float32(0.0))
    return _mul_rn(_mul_rn(h, osc), c), sfb

_twiddle(score)

Float bits mapped so that unsigned order is float order (cub TwiddleIn).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
def _twiddle(score):
    """Float bits mapped so that unsigned order is float order (cub TwiddleIn)."""
    bits = (
        score.bitcast(cutlass.Int32)
        if hasattr(score, "bitcast")
        else cutlass.Float32(score).bitcast(cutlass.Int32)
    )
    return cutlass.select_(
        bits < cutlass.Int32(0), ~bits, bits | cutlass.Int32(-2147483648)
    )

_ue8m0_rp(x, *, loc=None, ip=None)

UE8M0 code of x rounded toward +inf, saturating (__nv_cvt_float_to_e8m0(x, SATFINITE, RoundPosInf)).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@dsl_user_op
def _ue8m0_rp(x, *, loc=None, ip=None):
    """UE8M0 code of x rounded toward +inf, saturating (__nv_cvt_float_to_e8m0(x, SATFINITE, RoundPosInf))."""
    return cutlass.Int32(
        _asm(
            _T.i32(),
            [cutlass.Float32(x)],
            "{\n.reg .b16 t;\ncvt.rp.satfinite.ue8m0x2.f32 t, $1, $1;\ncvt.u32.u16 $0, t;\n}",
            "=r,f",
            False,
            loc,
            ip,
        )
    ) & cutlass.Int32(0xFF)

_ug_c(ug)

Unit (in its expert) of FC1 unit index ug (see _ug_slot).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _ug_c(ug):
    """Unit (in its expert) of FC1 unit index ug (see _ug_slot)."""
    return ug - (ug // cutlass.Int32(U1)) * cutlass.Int32(U1)

_ug_slot(ug)

Slot (in its group) of FC1 unit index ug (slot-major).

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _ug_slot(ug):
    """Slot (in its group) of FC1 unit index ug (slot-major)."""
    return ug // cutlass.Int32(U1)

_waitd(bar, parity, tdbg, site)

Wait on bar at parity, then sync the warp.

Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/kernel.py
@cute.jit
def _waitd(bar: cutlass.Array, parity, tdbg: cutlass.Array, site: cutlass.Constexpr):
    """Wait on `bar` at `parity`, then sync the warp."""
    while not cute.arch.mbarrier_try_wait(bar.data_ptr(), parity):
        pass
    cute.arch.sync_warp()