Skip to content

vllm.models.muse_spark.nvidia.specialized_decode.cutedsl.common.primitives

PTX building blocks and launch helpers of the Muse Spark specialized decode.

Every Lamport kernel of the package (the boundary gathers, the attention boundary, the MoE tail and the unpooler's zero-copy epilogue) is built from these. BF16 negative zero (0x8000) marks a slot that has not been written yet; a three-generation stage state (NEXT_STAGE written by the consumer, ACTIVE_STAGE by the publisher) lets a fast rank publish the next call while a slow one still reads the current one.

Functions:

_clobbered(constraints, clobber_memory)

constraints with a memory clobber added when clobber_memory.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
def _clobbered(constraints: str, clobber_memory: bool) -> str:
    """``constraints`` with a memory clobber added when ``clobber_memory``."""
    return f"{constraints},~{{memory}}" if clobber_memory else constraints

_load_shared_u32x4(address, loc, ip)

Four words at the shared address, the struct of one ld.shared.v4; side-effecting, so it does not move across the barriers and mbarrier waits that guard the data.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
def _load_shared_u32x4(address, loc, ip):
    """Four words at the shared ``address``, the struct of one ld.shared.v4;
    side-effecting, so it does not move across the barriers and mbarrier waits
    that guard the data."""
    return _ordered(
        "ld.shared.v4.u32 {$0, $1, $2, $3}, [$4];",
        "=r,=r,=r,=r,r",
        (Int32(address),),
        loc,
        ip,
        result=llvm.StructType.get_literal([T.i32()] * 4),
    )

_ordered(text, constraints, operands, loc, ip, result=None)

Side-effecting asm: kept in program order with the other side-effecting operations.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
def _ordered(text, constraints, operands, loc, ip, result=None):
    """Side-effecting asm: kept in program order with the other side-effecting
    operations."""
    return _asm(
        result,
        _ir(operands, loc=loc, ip=ip),
        text,
        constraints,
        side_effects=True,
        loc=loc,
        ip=ip,
    )

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

A + b, round to nearest, subnormal inputs and result flushed to a zero of the same sign (the add of code built with fast math).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def add_ftz_f32(a: Float32, b: Float32, *, loc=None, ip=None) -> Float32:
    """A + b, round to nearest, subnormal inputs and result flushed to a zero
    of the same sign (the add of code built with fast math)."""
    return _f32_op("add.rn.ftz.f32 $0, $1, $2;", "=f,f,f", (a, b), loc, ip)

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

A + b, round to nearest, subnormals kept.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def add_rn(a: Float32, b: Float32, *, loc=None, ip=None) -> Float32:
    """A + b, round to nearest, subnormals kept."""
    return _f32_op("add.rn.f32 $0, $1, $2;", "=f,f,f", (a, b), loc, ip)

atomic_add1_acq_rel_u32(pointer, *, loc=None, ip=None)

Add 1 to the global word at pointer and return its value before (acquire-release, GPU scope): a ticket.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def atomic_add1_acq_rel_u32(pointer: cute.Pointer, *, loc=None, ip=None) -> Uint32:
    """Add 1 to the global word at ``pointer`` and return its value before
    (acquire-release, GPU scope): a ticket."""
    address = pointer.toint(loc=loc, ip=ip)
    return Uint32(
        _asm(
            T.i32(),
            [address.ir_value(loc=loc, ip=ip)],
            "atom.acq_rel.gpu.global.add.u32 $0, [$1], 1;",
            "=r,l",
            side_effects=True,
            loc=loc,
            ip=ip,
        )
    )

atomic_add1_acq_rel_u32_address(address, *, loc=None, ip=None)

atomic_add1_acq_rel_u32 of the global word at address.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def atomic_add1_acq_rel_u32_address(address: Int64, *, loc=None, ip=None) -> Uint32:
    """``atomic_add1_acq_rel_u32`` of the global word at ``address``."""
    return Uint32(
        _asm(
            T.i32(),
            [address.ir_value(loc=loc, ip=ip)],
            "atom.acq_rel.gpu.global.add.u32 $0, [$1], 1;",
            "=r,l",
            side_effects=True,
            loc=loc,
            ip=ip,
        )
    )

atomic_add1_u32_address(address, *, loc=None, ip=None)

atomicAdd(address, 1) (relaxed, GPU scope): the word before.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def atomic_add1_u32_address(address: Int64, *, loc=None, ip=None) -> Uint32:
    """``atomicAdd(address, 1)`` (relaxed, GPU scope): the word before."""
    return Uint32(
        _ordered(
            "atom.global.add.u32 $0, [$1], 1;",
            "=r,l,~{memory}",
            (Int64(address),),
            loc,
            ip,
            T.i32(),
        )
    )

atomic_exch_zero_u32_address(address, *, loc=None, ip=None)

atomicExch(address, 0) (relaxed, GPU scope).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def atomic_exch_zero_u32_address(address: Int64, *, loc=None, ip=None) -> None:
    """``atomicExch(address, 0)`` (relaxed, GPU scope)."""
    _ordered(
        "{\n\t.reg .b32 old;\n\tatom.global.exch.b32 old, [$0], 0;\n\t}",
        "l,~{memory}",
        (Int64(address),),
        loc,
        ip,
    )

bf16x2_to_f32x2(word, *, loc=None, ip=None)

The BF16 pair in word widened to FP32 (exact): (bits 0-15, 16-31).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def bf16x2_to_f32x2(word: Uint32, *, loc=None, ip=None) -> tuple[Float32, Float32]:
    """The BF16 pair in ``word`` widened to FP32 (exact): (bits 0-15, 16-31)."""
    pair = _asm(
        ir.Type.parse("!llvm.struct<(f32, f32)>"),
        [Uint32(word).ir_value(loc=loc, ip=ip)],
        "{ .reg .b16 hl, hh;\n"
        "  mov.b32 {hl, hh}, $2;\n"
        "  cvt.f32.bf16 $0, hl;\n"
        "  cvt.f32.bf16 $1, hh; }",
        "=f,=f,r",
        side_effects=False,
        loc=loc,
        ip=ip,
    )
    return (
        Float32(llvm.extractvalue(T.f32(), pair, [0], loc=loc, ip=ip)),
        Float32(llvm.extractvalue(T.f32(), pair, [1], loc=loc, ip=ip)),
    )

cp_async_cg_16(destination, source, predicate, *, loc=None, ip=None)

Copy 16 bytes from global source to this CTA's shared destination asynchronously, bypassing L1, if predicate.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def cp_async_cg_16(
    destination: Int32, source: Int64, predicate: Int32, *, loc=None, ip=None
) -> None:
    """Copy 16 bytes from global ``source`` to this CTA's shared
    ``destination`` asynchronously, bypassing L1, if ``predicate``."""
    _ordered(
        "{\n\t.reg .pred p;\n\tsetp.ne.s32 p, $2, 0;\n\t"
        "@p cp.async.cg.shared.global [$0], [$1], 16;\n\t}",
        "r,l,r,~{memory}",
        (Int32(destination), Int64(source), Int32(predicate)),
        loc,
        ip,
    )

cp_async_wait(pending, *, loc=None, ip=None)

Wait until at most pending of this thread's cp.async groups are in flight.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def cp_async_wait(pending: cutlass.Constexpr[int], *, loc=None, ip=None) -> None:
    """Wait until at most ``pending`` of this thread's cp.async groups are in
    flight."""
    _ordered(f"cp.async.wait_group {pending};", "~{memory}", (), loc, ip)

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

A / b as div.full.f32 (Triton's FP32 division).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def div_full_f32(a: Float32, b: Float32, *, loc=None, ip=None) -> Float32:
    """A / b as ``div.full.f32`` (Triton's FP32 division)."""
    return _f32_op("div.full.f32 $0, $1, $2;", "=f,f,f", (a, b), loc, ip)

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

2 ** a by ex2.approx, subnormals flushed.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def ex2_approx_ftz(a: Float32, *, loc=None, ip=None) -> Float32:
    """2 ** a by ex2.approx, subnormals flushed."""
    return _f32_op("ex2.approx.ftz.f32 $0, $1;", "=f,f", (a,), loc, ip)

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

The bit pattern of an FP32 value.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def f32_bits(value: Float32, *, loc=None, ip=None) -> Int32:
    """The bit pattern of an FP32 value."""
    return Int32(
        llvm.bitcast(T.i32(), Float32(value).ir_value(loc=loc, ip=ip), loc=loc, ip=ip)
    )

fence_mbarrier_init_cluster(*, loc=None, ip=None)

Release this CTA's mbarrier initializations to the cluster.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def fence_mbarrier_init_cluster(*, loc=None, ip=None) -> None:
    """Release this CTA's mbarrier initializations to the cluster."""
    _ordered("fence.mbarrier_init.release.cluster;", "~{memory}", (), loc, ip)

fma_ftz_f32(a, b, c, *, loc=None, ip=None)

A * b + c with one rounding, subnormals flushed.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def fma_ftz_f32(a: Float32, b: Float32, c: Float32, *, loc=None, ip=None) -> Float32:
    """A * b + c with one rounding, subnormals flushed."""
    return _f32_op("fma.rn.ftz.f32 $0, $1, $2, $3;", "=f,f,f,f", (a, b, c), loc, ip)

fma_rn(a, b, c, *, loc=None, ip=None)

A * b + c with one rounding.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def fma_rn(a: Float32, b: Float32, c: Float32, *, loc=None, ip=None) -> Float32:
    """A * b + c with one rounding."""
    return _f32_op("fma.rn.f32 $0, $1, $2, $3;", "=f,f,f,f", (a, b, c), loc, ip)

fms_rn(a, b, c, *, loc=None, ip=None)

A * b - c with one rounding (the negation is exact, -0 included).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def fms_rn(a: Float32, b: Float32, c: Float32, *, loc=None, ip=None) -> Float32:
    """A * b - c with one rounding (the negation is exact, -0 included)."""
    return _f32_op(
        "{\n\t.reg .f32 n;\n\tneg.f32 n, $3;\n\tfma.rn.f32 $0, $1, $2, n;\n\t}",
        "=f,f,f,f",
        (a, b, c),
        loc,
        ip,
    )

global_timer_ns(*, loc=None, ip=None)

The GPU's global nanosecond timer (bounds the Lamport spins).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def global_timer_ns(*, loc=None, ip=None) -> Int64:
    """The GPU's global nanosecond timer (bounds the Lamport spins)."""
    return Int64(
        _asm(
            T.i64(),
            [],
            "mov.u64 $0, %globaltimer;",
            "=l",
            side_effects=True,
            loc=loc,
            ip=ip,
        )
    )

ldmc_bf16x8(address, predicate=None, *, loc=None, ip=None)

Reduce-load eight BF16s; an omitted predicate loads, false returns zeros.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def ldmc_bf16x8(address: Int64, predicate: Int32 | None = None, *, loc=None, ip=None):
    """Reduce-load eight BF16s; an omitted predicate loads, false returns zeros."""
    predicate = Int32(1) if predicate is None else Int32(predicate)
    loaded = _asm(
        llvm.StructType.get_literal([T.i32()] * 4),
        [address.ir_value(loc=loc, ip=ip), predicate.ir_value(loc=loc, ip=ip)],
        (
            "{\n\t"
            ".reg .pred p;\n\t"
            "setp.ne.s32 p, $5, 0;\n\t"
            "@!p mov.u32 $0, 0;\n\t"
            "@!p mov.u32 $1, 0;\n\t"
            "@!p mov.u32 $2, 0;\n\t"
            "@!p mov.u32 $3, 0;\n\t"
            "@p multimem.ld_reduce.relaxed.sys.global.add.acc::f32.v4.bf16x2 "
            "{$0, $1, $2, $3}, [$4];\n\t"
            "}"
        ),
        "=r,=r,=r,=r,l,r",
        side_effects=True,
        loc=loc,
        ip=ip,
    )
    return _words(loaded, 4, loc=loc, ip=ip)

load_f16x8_as_f32(base, offset)

8 FP16 elements from element offset of base (one 16-byte access), converted exactly to FP32.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@cute.jit
def load_f16x8_as_f32(base: cute.Tensor, offset: Int64):
    """8 FP16 elements from element ``offset`` of ``base`` (one 16-byte
    access), converted exactly to FP32."""
    pointer = cute.make_ptr(
        Float16,
        (base.iterator + offset).llvm_ptr,
        cute.AddressSpace.gmem,
        assumed_align=16,
    )
    return packed_u32x4_to_f16x8(load_global_u32x4(pointer)).to(Float32)

load_global_cg_f32_address(address, *, loc=None, ip=None)

An FP32 load cached in L2 only (another CTA's store, after a fence).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def load_global_cg_f32_address(address: Int64, *, loc=None, ip=None) -> Float32:
    """An FP32 load cached in L2 only (another CTA's store, after a fence)."""
    return Float32(
        _ordered(
            "ld.global.cg.f32 $0, [$1];", "=f,l", (Int64(address),), loc, ip, T.f32()
        )
    )

load_global_cg_f32x2_address(address, *, loc=None, ip=None)

load_global_cg_f32_address of two FP32.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def load_global_cg_f32x2_address(address: Int64, *, loc=None, ip=None) -> tuple:
    """``load_global_cg_f32_address`` of two FP32."""
    struct = _ordered(
        "ld.global.cg.v2.f32 {$0, $1}, [$2];",
        "=f,=f,l",
        (Int64(address),),
        loc,
        ip,
        llvm.StructType.get_literal([T.f32()] * 2),
    )
    return _unpack(struct, Float32, 2, loc=loc, ip=ip)

load_global_f32x4_address(address, *, ordered=False, loc=None, ip=None)

Four FP32 at the 16-byte aligned address in one load; ordered as for load_global_u32_address. A coherent load, not ld.global.nc: ptxas moves read-only-path loads across griddepcontrol.wait either way, so they cannot read what the PDL primary grid writes.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def load_global_f32x4_address(
    address: Int64,
    *,
    ordered: cutlass.Constexpr[bool] = False,
    loc=None,
    ip=None,
) -> tuple[Float32, Float32, Float32, Float32]:
    """Four FP32 at the 16-byte aligned ``address`` in one load; ``ordered``
    as for ``load_global_u32_address``. A coherent load, not ``ld.global.nc``:
    ptxas moves read-only-path loads across ``griddepcontrol.wait`` either way,
    so they cannot read what the PDL primary grid writes."""
    loaded = _asm(
        llvm.StructType.get_literal([T.f32()] * 4),
        [address.ir_value(loc=loc, ip=ip)],
        "ld.global.v4.f32 {$0, $1, $2, $3}, [$4];",
        "=f,=f,=f,=f,l",
        side_effects=ordered,
        loc=loc,
        ip=ip,
    )
    a, b, c, d = _unpack(loaded, Float32, 4, loc=loc, ip=ip)
    return a, b, c, d

load_global_nc_f32_address(address, *, loc=None, ip=None)

A read-only FP32 load through the non-coherent path, in program order.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def load_global_nc_f32_address(address: Int64, *, loc=None, ip=None) -> Float32:
    """A read-only FP32 load through the non-coherent path, in program order."""
    return Float32(
        _ordered(
            "ld.global.nc.f32 $0, [$1];", "=f,l", (Int64(address),), loc, ip, T.f32()
        )
    )

load_global_nc_s32_or(address, predicate, other, *, loc=None, ip=None)

The read-only word at address if predicate, else other.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def load_global_nc_s32_or(
    address: Int64, predicate: Int32, other: Int32, *, loc=None, ip=None
) -> Int32:
    """The read-only word at ``address`` if ``predicate``, else ``other``."""
    return Int32(
        _ordered(
            "{\n\t.reg .pred p;\n\tsetp.ne.s32 p, $2, 0;\n\tmov.b32 $0, $3;\n\t"
            "@p ld.global.nc.s32 $0, [$1];\n\t}",
            "=r,l,r,r",
            (Int64(address), Int32(predicate), Int32(other)),
            loc,
            ip,
            T.i32(),
        )
    )

load_global_nc_u32x4_address(address, *, loc=None, ip=None)

Four words of data no thread of the grid writes (the read-only path), in program order with the other side-effecting operations.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def load_global_nc_u32x4_address(address: Int64, *, loc=None, ip=None) -> tuple:
    """Four words of data no thread of the grid writes (the read-only path),
    in program order with the other side-effecting operations."""
    struct = _ordered(
        "ld.global.nc.v4.u32 {$0, $1, $2, $3}, [$4];",
        "=r,=r,=r,=r,l",
        (Int64(address),),
        loc,
        ip,
        llvm.StructType.get_literal([T.i32()] * 4),
    )
    return _unpack(struct, Uint32, 4, loc=loc, ip=ip)

load_global_u32x4(pointer, predicate=None, *, volatile=False, loc=None, ip=None)

Load four words; an omitted predicate loads normally, false returns zeros.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def load_global_u32x4(
    pointer: cute.Pointer,
    predicate: Int32 | None = None,
    *,
    volatile: cutlass.Constexpr[bool] = False,
    loc=None,
    ip=None,
):
    """Load four words; an omitted predicate loads normally, false returns zeros."""
    predicate = Int32(1) if predicate is None else Int32(predicate)
    address = pointer.toint(loc=loc, ip=ip)
    opcode = "ld.volatile.global.v4.u32" if volatile else "ld.global.v4.u32"
    loaded = _asm(
        llvm.StructType.get_literal([T.i32()] * 4),
        [address.ir_value(loc=loc, ip=ip), predicate.ir_value(loc=loc, ip=ip)],
        (
            "{\n\t"
            ".reg .pred p;\n\t"
            "setp.ne.s32 p, $5, 0;\n\t"
            "@!p mov.u32 $0, 0;\n\t"
            "@!p mov.u32 $1, 0;\n\t"
            "@!p mov.u32 $2, 0;\n\t"
            "@!p mov.u32 $3, 0;\n\t"
            f"@p {opcode} {{$0, $1, $2, $3}}, [$4];\n\t"
            "}"
        ),
        "=r,=r,=r,=r,l,r",
        side_effects=volatile,
        loc=loc,
        ip=ip,
    )
    return _words(loaded, 4, loc=loc, ip=ip)

load_shared_f32_or(address, predicate, other, *, loc=None, ip=None)

The FP32 at shared address if predicate, else other.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def load_shared_f32_or(
    address: Int32, predicate: Int32, other: Float32, *, loc=None, ip=None
) -> Float32:
    """The FP32 at shared ``address`` if ``predicate``, else ``other``."""
    return Float32(
        _ordered(
            "{\n\t.reg .pred p;\n\tsetp.ne.s32 p, $2, 0;\n\tmov.f32 $0, $3;\n\t"
            "@p ld.shared.f32 $0, [$1];\n\t}",
            "=f,r,r,f",
            (Int32(address), Int32(predicate), Float32(other)),
            loc,
            ip,
            T.f32(),
        )
    )

load_shared_u32x4_address(address, *, loc=None, ip=None)

load_shared_u32x4 by address.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def load_shared_u32x4_address(address: Int32, *, loc=None, ip=None):
    """``load_shared_u32x4`` by address."""
    return _words(_load_shared_u32x4(address, loc, ip), 4, loc=loc, ip=ip)

load_shared_u32x4_unpacked(address, *, loc=None, ip=None)

load_shared_u32x4_address as a tuple of four Uint32.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def load_shared_u32x4_unpacked(address: Int32, *, loc=None, ip=None) -> tuple:
    """``load_shared_u32x4_address`` as a tuple of four Uint32."""
    return _unpack(_load_shared_u32x4(address, loc, ip), Uint32, 4, loc=loc, ip=ip)

lowest_set_bit(mask, *, loc=None, ip=None)

The index of the lowest set bit of a nonzero mask (CUDA's __ffs(mask) - 1).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def lowest_set_bit(mask: Uint32, *, loc=None, ip=None) -> Int32:
    """The index of the lowest set bit of a nonzero ``mask`` (CUDA's
    ``__ffs(mask) - 1``)."""
    return Int32(
        _asm(
            T.i32(),
            [Uint32(mask).ir_value(loc=loc, ip=ip)],
            "{\n\t.reg .b32 r;\n\tbrev.b32 r, $1;\n\tbfind.shiftamt.u32 $0, r;\n\t}",
            "=r,r",
            side_effects=False,
            loc=loc,
            ip=ip,
        )
    )

map_shared_address_to_peer(address, peer_rank, *, loc=None, ip=None)

The shared::cluster address of this CTA's shared address in the cluster's CTA peer_rank.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def map_shared_address_to_peer(
    address: Int32, peer_rank: Int32, *, loc=None, ip=None
) -> Int32:
    """The shared::cluster address of this CTA's shared ``address`` in the
    cluster's CTA ``peer_rank``."""
    return Int32(
        _asm(
            T.i32(),
            _ir((Int32(address), Int32(peer_rank)), loc=loc, ip=ip),
            "mapa.shared::cluster.u32 $0, $1, $2;",
            "=r,r,r",
            side_effects=False,
            loc=loc,
            ip=ip,
        )
    )

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

The larger of a and b (a NaN operand yields the other), subnormals flushed.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def max_ftz_f32(a: Float32, b: Float32, *, loc=None, ip=None) -> Float32:
    """The larger of a and b (a NaN operand yields the other), subnormals
    flushed."""
    return _f32_op("max.ftz.f32 $0, $1, $2;", "=f,f,f", (a, b), loc, ip)

mbarrier_arrive_expect_tx_address(bar, num_bytes, *, clobber_memory=False, loc=None, ip=None)

Arrive on the shared mbarrier at bar expecting num_bytes transaction bytes.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def mbarrier_arrive_expect_tx_address(
    bar: Int32,
    num_bytes: Int32,
    *,
    clobber_memory: cutlass.Constexpr[bool] = False,
    loc=None,
    ip=None,
) -> None:
    """Arrive on the shared mbarrier at ``bar`` expecting ``num_bytes``
    transaction bytes."""
    _ordered(
        "mbarrier.arrive.expect_tx.shared::cta.b64 _, [$0], $1;",
        _clobbered("r,r", clobber_memory),
        (Int32(bar), Int32(num_bytes)),
        loc,
        ip,
    )

mbarrier_init_address(bar, count, *, clobber_memory=False, loc=None, ip=None)

Initialize the shared mbarrier at bar for count arrivals (a Python int is an immediate operand, an Int32 a register).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def mbarrier_init_address(
    bar: Int32,
    count: Int32 | int,
    *,
    clobber_memory: cutlass.Constexpr[bool] = False,
    loc=None,
    ip=None,
) -> None:
    """Initialize the shared mbarrier at ``bar`` for ``count`` arrivals (a
    Python int is an immediate operand, an Int32 a register)."""
    operands = [Int32(bar)]
    if isinstance(count, int):
        text = f"mbarrier.init.shared::cta.b64 [$0], {count};"
        constraints = "r"
    else:
        text = "mbarrier.init.shared::cta.b64 [$0], $1;"
        constraints = "r,r"
        operands.append(Int32(count))
    _ordered(text, _clobbered(constraints, clobber_memory), operands, loc, ip)

mbarrier_try_wait_phase0_cluster(address, *, loc=None, ip=None)

1 once phase 0 of the shared mbarrier at address has completed (acquire at cluster scope: the stores that completed it are visible), 0 when the bounded wait ends first.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def mbarrier_try_wait_phase0_cluster(address: Int32, *, loc=None, ip=None) -> Int32:
    """1 once phase 0 of the shared mbarrier at ``address`` has completed
    (acquire at cluster scope: the stores that completed it are visible), 0
    when the bounded wait ends first."""
    return Int32(
        _ordered(
            "{\n\t.reg .pred p;\n\t"
            "mbarrier.try_wait.parity.acquire.cluster.shared::cta.b64 p, [$1], 0;"
            "\n\tselp.b32 $0, 1, 0, p;\n\t}",
            "=r,r,~{memory}",
            (Int32(address),),
            loc,
            ip,
            T.i32(),
        )
    )

mbarrier_wait_address(bar, parity, *, loc=None, ip=None)

Spin until the phase of parity completes (acquire, CTA scope).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def mbarrier_wait_address(bar: Int32, parity: Int32, *, loc=None, ip=None) -> None:
    """Spin until the phase of ``parity`` completes (acquire, CTA scope)."""
    _mbarrier_wait(bar, parity, "", loc, ip)

mbarrier_wait_cluster_address(bar, parity, *, loc=None, ip=None)

mbarrier_wait_address with cluster-scope acquire: for a phase that peers complete (st.async complete_tx, release at cluster scope).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def mbarrier_wait_cluster_address(
    bar: Int32, parity: Int32, *, loc=None, ip=None
) -> None:
    """``mbarrier_wait_address`` with cluster-scope acquire: for a phase that
    peers complete (st.async complete_tx, release at cluster scope)."""
    _mbarrier_wait(bar, parity, ".acquire.cluster", loc, ip)

membar_gl(*, loc=None, ip=None)

The fence of __threadfence().

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def membar_gl(*, loc=None, ip=None) -> None:
    """The fence of ``__threadfence()``."""
    _ordered("membar.gl;", "~{memory}", (), loc, ip)

mma_m16n8k16_bf16(a, b0, b1, c, *, ordered=False, loc=None, ip=None)

mma.sync m16n8k16 row.col with BF16 operands and FP32 accumulation: the four accumulators of A (four words) x B (b0, b1) + C (four FP32). ordered makes it side-effecting asm, kept in program order with the other side-effecting operations; otherwise the compiler schedules it.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def mma_m16n8k16_bf16(
    a,
    b0: Uint32,
    b1: Uint32,
    c,
    *,
    ordered: cutlass.Constexpr[bool] = False,
    loc=None,
    ip=None,
) -> tuple:
    """mma.sync m16n8k16 row.col with BF16 operands and FP32 accumulation: the
    four accumulators of A (four words) x B (b0, b1) + C (four FP32).
    ``ordered`` makes it side-effecting asm, kept in program order with the
    other side-effecting operations; otherwise the compiler schedules it."""
    struct = _asm(
        llvm.StructType.get_literal([T.f32()] * 4),
        _ir([Uint32(w) for w in (*a, b0, b1)], loc=loc, ip=ip)
        + _ir([Float32(x) for x in c], loc=loc, ip=ip),
        "mma.sync.aligned.m16n8k16.row.col.f32.bf16.bf16.f32 {$0, $1, $2, $3}, "
        "{$4, $5, $6, $7}, {$8, $9}, {$10, $11, $12, $13};",
        "=f,=f,=f,=f,r,r,r,r,r,r,f,f,f,f",
        side_effects=ordered,
        loc=loc,
        ip=ip,
    )
    return _unpack(struct, Float32, 4, loc=loc, ip=ip)

movmatrix_trans_b16(word, *, loc=None, ip=None)

This lane's word of the warp's 8x8 b16 matrix, transposed.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def movmatrix_trans_b16(word: Uint32, *, loc=None, ip=None) -> Uint32:
    """This lane's word of the warp's 8x8 b16 matrix, transposed."""
    return Uint32(
        _ordered(
            "movmatrix.sync.aligned.m8n8.trans.b16 $0, $1;",
            "=r,r",
            (Uint32(word),),
            loc,
            ip,
            T.i32(),
        )
    )

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

A * b, round to nearest, subnormals flushed; never contracted.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def mul_ftz_f32(a: Float32, b: Float32, *, loc=None, ip=None) -> Float32:
    """A * b, round to nearest, subnormals flushed; never contracted."""
    return _f32_op("mul.rn.ftz.f32 $0, $1, $2;", "=f,f,f", (a, b), loc, ip)

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

A * b, round to nearest, subnormals kept; never contracted.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def mul_rn(a: Float32, b: Float32, *, loc=None, ip=None) -> Float32:
    """A * b, round to nearest, subnormals kept; never contracted."""
    return _f32_op("mul.rn.f32 $0, $1, $2;", "=f,f,f", (a, b), loc, ip)

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

Two FP32 rounded to nearest-even BF16, lo in bits 0-15, hi in bits 16-31.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def pack_bf16x2_rn(lo: Float32, hi: Float32, *, loc=None, ip=None) -> Uint32:
    """Two FP32 rounded to nearest-even BF16, lo in bits 0-15, hi in bits 16-31."""
    return Uint32(
        _asm(
            T.i32(),
            [hi.ir_value(loc=loc, ip=ip), lo.ir_value(loc=loc, ip=ip)],
            "cvt.rn.bf16x2.f32 $0, $1, $2;",
            "=r,f,f",
            side_effects=False,
            loc=loc,
            ip=ip,
        )
    )

pack_bf16x8_rn(values)

8 FP32 scalars rounded to nearest-even BF16, as 4 packed words (an rmem tensor; traced inline).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
def pack_bf16x8_rn(values: list):
    """8 FP32 scalars rounded to nearest-even BF16, as 4 packed words (an
    rmem tensor; traced inline)."""
    words = cute.make_rmem_tensor(cute.make_layout((VEC_BF16 // 2,)), Uint32)
    for q in range(VEC_BF16 // 2):
        words[q] = pack_bf16x2_rn(values[2 * q], values[2 * q + 1])
    return words

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

1 / a by rcp.approx, subnormals flushed (the fast-math 1 / a).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def rcp_approx_ftz(a: Float32, *, loc=None, ip=None) -> Float32:
    """1 / a by rcp.approx, subnormals flushed (the fast-math 1 / a)."""
    return _f32_op("rcp.approx.ftz.f32 $0, $1;", "=f,f", (a,), loc, ip)

regs(values)

An 8-wide FP32 TensorSSA (load_f32x8, load_bf16x8_as_f32) as its 8 scalars (traced inline).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
def regs(values) -> list:
    """An 8-wide FP32 TensorSSA (``load_f32x8``, ``load_bf16x8_as_f32``) as
    its 8 scalars (traced inline)."""
    fragment = cute.make_rmem_tensor(cute.make_layout((VEC_BF16,)), Float32)
    fragment.store(values)
    return [fragment[i] for i in range(VEC_BF16)]

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

A rounded to BF16 (nearest even), widened back.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def round_bf16(a: Float32, *, loc=None, ip=None) -> Float32:
    """A rounded to BF16 (nearest even), widened back."""
    return _f32_op(
        "{\n\t.reg .b16 h;\n\tcvt.rn.bf16.f32 h, $1;\n\tcvt.f32.bf16 $0, h;\n\t}",
        "=f,f",
        (a,),
        loc,
        ip,
    )

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

rsqrt.approx with subnormal inputs kept (rsqrtf without fast math).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def rsqrt_approx_f32(a: Float32, *, loc=None, ip=None) -> Float32:
    """rsqrt.approx with subnormal inputs kept (``rsqrtf`` without fast math)."""
    return _f32_op("rsqrt.approx.f32 $0, $1;", "=f,f", (a,), loc, ip)

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

rsqrt.approx with subnormals flushed (libdevice's rsqrt under FTZ).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def rsqrt_approx_ftz(a: Float32, *, loc=None, ip=None) -> Float32:
    """rsqrt.approx with subnormals flushed (libdevice's rsqrt under FTZ)."""
    return _f32_op("rsqrt.approx.ftz.f32 $0, $1;", "=f,f", (a,), loc, ip)

scale_or_neg_inf(x, scale, key, last, first=None, *, loc=None, ip=None)

scale * x (round to nearest, subnormals flushed) for a key in [first, last] (no lower bound without first), else -inf.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def scale_or_neg_inf(
    x: Float32,
    scale: Float32,
    key: Int32,
    last: Int32,
    first: Int32 | None = None,
    *,
    loc=None,
    ip=None,
) -> Float32:
    """``scale * x`` (round to nearest, subnormals flushed) for a ``key`` in
    [first, last] (no lower bound without ``first``), else -inf."""
    operands = [Float32(scale), Float32(x), Int32(key), Int32(last)]
    test = "setp.le.s32 p, $3, $4;"
    if first is not None:
        operands.append(Int32(first))
        test += "\n\tsetp.ge.and.s32 p, $3, $5, p;"
    return Float32(
        _asm(
            T.f32(),
            _ir(operands, loc=loc, ip=ip),
            f"{{\n\t.reg .pred p;\n\t.reg .f32 v;\n\t{test}\n\t"
            "mul.rn.ftz.f32 v, $1, $2;\n\tselp.f32 $0, v, 0fFF800000, p;\n\t}",
            "=f,f,f,r,r" + (",r" if first is not None else ""),
            side_effects=False,
            loc=loc,
            ip=ip,
        )
    )

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

tl.sigmoid(x): x * -log2(e), ex2.approx, + 1, then 1 / that with div.full.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def sigmoid_f32(x: Float32, *, loc=None, ip=None) -> Float32:
    """``tl.sigmoid(x)``: x * -log2(e), ex2.approx, + 1, then 1 / that with
    div.full."""
    return _f32_op(
        "{\n\t.reg .f32 a, e, d;\n\tmul.f32 a, $1, 0fBFB8AA3B;\n\t"
        "ex2.approx.f32 e, a;\n\tadd.f32 d, e, 0f3F800000;\n\t"
        "div.full.f32 $0, 0f3F800000, d;\n\t}",
        "=f,f",
        (x,),
        loc,
        ip,
    )

stmc_bf16x8(address, values, predicate=None, *, loc=None, ip=None)

Multicast-store eight BF16s; an omitted predicate stores, false skips.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def stmc_bf16x8(
    address: Int64, values, predicate: Int32 | None = None, *, loc=None, ip=None
) -> None:
    """Multicast-store eight BF16s; an omitted predicate stores, false skips."""
    predicate = Int32(1) if predicate is None else Int32(predicate)
    words = [values[index].ir_value(loc=loc, ip=ip) for index in range(4)]
    _asm(
        None,
        [address.ir_value(loc=loc, ip=ip), *words, predicate.ir_value(loc=loc, ip=ip)],
        (
            "{\n\t"
            ".reg .pred p;\n\t"
            "setp.ne.s32 p, $5, 0;\n\t"
            "@p multimem.st.relaxed.sys.global.v4.bf16x2 "
            "[$0], {$1, $2, $3, $4};\n\t"
            "}"
        ),
        "l,r,r,r,r,r",
        side_effects=True,
        loc=loc,
        ip=ip,
    )

store_async_cluster_f32x2(remote, lo, hi, remote_bar, predicate=None, *, clobber_memory=False, loc=None, ip=None)

Store (lo, hi) at cluster address remote (map_shared_address_to_peer), completing 8 transaction bytes on the peer's mbarrier at cluster address remote_bar; with a predicate, only if it is true.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def store_async_cluster_f32x2(
    remote: Int32,
    lo: Float32,
    hi: Float32,
    remote_bar: Int32,
    predicate: Int32 | None = None,
    *,
    clobber_memory: cutlass.Constexpr[bool] = False,
    loc=None,
    ip=None,
) -> None:
    """Store (lo, hi) at cluster address ``remote``
    (``map_shared_address_to_peer``), completing 8 transaction bytes on the
    peer's mbarrier at cluster address ``remote_bar``; with a ``predicate``,
    only if it is true."""
    text = (
        "st.async.shared::cluster.mbarrier::complete_tx::bytes.v2.f32 [$0], "
        "{$1, $2}, [$3];"
    )
    constraints = "r,f,f,r"
    operands = [Int32(remote), Float32(lo), Float32(hi), Int32(remote_bar)]
    if predicate is not None:
        text = f"{{\n\t.reg .pred p;\n\tsetp.ne.s32 p, $4, 0;\n\t@p {text}\n\t}}"
        constraints += ",r"
        operands.append(Int32(predicate))
    _ordered(text, _clobbered(constraints, clobber_memory), operands, loc, ip)

store_async_cluster_f32x4(address, values, mbarrier, *, loc=None, ip=None)

Four FP32 into a cluster CTA's shared memory (map_shared_address_to_peer), completing 16 transaction bytes on that CTA's mbarrier (mbarrier, mapped the same way).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def store_async_cluster_f32x4(
    address: Int32, values, mbarrier: Int32, *, loc=None, ip=None
) -> None:
    """Four FP32 into a cluster CTA's shared memory
    (``map_shared_address_to_peer``), completing 16 transaction bytes on that
    CTA's mbarrier (``mbarrier``, mapped the same way)."""
    _ordered(
        "st.async.shared::cluster.mbarrier::complete_tx::bytes.v4.f32 [$0], "
        "{$1, $2, $3, $4}, [$5];",
        "r,f,f,f,f,r,~{memory}",
        (Int32(address), *(Float32(v) for v in values), Int32(mbarrier)),
        loc,
        ip,
    )

store_bf16x8_rn(base, offset, values)

8 FP32 scalars rounded to nearest-even BF16 and stored as one 16-byte access at element offset of the BF16 base (traced inline).

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
def store_bf16x8_rn(base: cute.Tensor, offset: Int64, values: list) -> None:
    """8 FP32 scalars rounded to nearest-even BF16 and stored as one 16-byte
    access at element ``offset`` of the BF16 ``base`` (traced inline)."""
    store_global_u32x4(
        Int64((base.iterator + offset).toint()), pack_bf16x8_rn(values).load()
    )

store_global_f32_address(address, value, predicate, *, loc=None, ip=None)

Store value at global address if predicate.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def store_global_f32_address(
    address: Int64, value: Float32, predicate: Int32, *, loc=None, ip=None
) -> None:
    """Store ``value`` at global ``address`` if ``predicate``."""
    _ordered(
        "{\n\t.reg .pred p;\n\tsetp.ne.s32 p, $2, 0;\n\t"
        "@p st.global.f32 [$0], $1;\n\t}",
        "l,f,r",
        (Int64(address), Float32(value), Int32(predicate)),
        loc,
        ip,
    )

store_shared_f32_address(address, value, predicate, *, loc=None, ip=None)

Store value at shared address if predicate.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def store_shared_f32_address(
    address: Int32, value: Float32, predicate: Int32, *, loc=None, ip=None
) -> None:
    """Store ``value`` at shared ``address`` if ``predicate``."""
    _ordered(
        "{\n\t.reg .pred p;\n\tsetp.ne.s32 p, $2, 0;\n\t"
        "@p st.shared.f32 [$0], $1;\n\t}",
        "r,f,r",
        (Int32(address), Float32(value), Int32(predicate)),
        loc,
        ip,
    )

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

A - b, round to nearest, subnormals flushed.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def sub_ftz_f32(a: Float32, b: Float32, *, loc=None, ip=None) -> Float32:
    """A - b, round to nearest, subnormals flushed."""
    return _f32_op("sub.rn.ftz.f32 $0, $1, $2;", "=f,f,f", (a, b), loc, ip)

tma_load_2d(dst, tensor_map, c0, c1, bar, *, loc=None, ip=None)

The box of tensor_map at (c0, c1) (inner coordinate first) into shared dst, its bytes completing on mbarrier bar.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def tma_load_2d(
    dst: Int32,
    tensor_map: Int64,
    c0: Int32,
    c1: Int32,
    bar: Int32,
    *,
    loc=None,
    ip=None,
) -> None:
    """The box of ``tensor_map`` at (c0, c1) (inner coordinate first) into
    shared ``dst``, its bytes completing on mbarrier ``bar``."""
    _ordered(
        "cp.async.bulk.tensor.2d.shared::cluster.global.mbarrier::complete_tx"
        "::bytes [$0], [$1, {$2, $3}], [$4];",
        "r,l,r,r,r",
        (Int32(dst), Int64(tensor_map), Int32(c0), Int32(c1), Int32(bar)),
        loc,
        ip,
    )

tma_prefetch_2d_l2(tensor_map, c0, c1, *, loc=None, ip=None)

Prefetch the box of tensor_map at (c0, c1) into L2.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def tma_prefetch_2d_l2(
    tensor_map: Int64, c0: Int32, c1: Int32, *, loc=None, ip=None
) -> None:
    """Prefetch the box of ``tensor_map`` at (c0, c1) into L2."""
    _ordered(
        "cp.async.bulk.prefetch.tensor.2d.L2.global.tile [$0, {$1, $2}];",
        "l,r,r",
        (Int64(tensor_map), Int32(c0), Int32(c1)),
        loc,
        ip,
    )

trap(*, loc=None, ip=None)

Abort the kernel: the launch fails instead of hanging.

Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/common/primitives.py
@dsl_user_op
def trap(*, loc=None, ip=None) -> None:
    """Abort the kernel: the launch fails instead of hanging."""
    _asm(None, [], "trap;", "", side_effects=True, loc=loc, ip=ip)