vllm.models.kimi_k3.nvidia.specialized_decode.cutedsl.common.primitives
¶
Inline-PTX, memory, synchronization and math helpers of the decode kernels.
Functions:
-
acquire_tensormap_asm–acquire_tensormapas one asm block on the unfolded address. -
alloc–Row-major
shapetensor from aSmemAllocator. -
asm–f(*args) -> (code, constraints, operands[, result, pure])as one inline-PTX -
at–Pointer to
tensor[coord]. -
attn_res_rstd–rsqrtf(total / 7168 + eps) as attn_res_kernel.cu compiles it (--use_fast_math);
-
bf16–FP32 of the low (or high) BF16 half of
word. -
chunk_mma–(d, adesc, bdesc, sfa, sfa_src, sfb, sfb_src, copy_sfb, accum, empty_bar,
-
commit_asm–commitas an asm block on the unfolded address. -
copy_g2s–16-byte cp.async, or a static/dynamic
sizebulk copy onbarrier. -
dot–fmachain overzip(a, b)fromacc, or froma[0] * b[0]. -
ds_tile_scale–The fp8_ds_mla tile scale exp2f(ceilf(log2f(max(amax / 448, 1e-4)))) as the
-
fma2–Lanewise a * b + c of FP32 pairs in one packed instruction (IEEE per lane).
-
inv_rms–rsqrt(value / 3584 + eps);
m8: the mean as a reciprocal product refined by -
launch–Launch kernel(args[:-1]) on stream args[-1]; an int dimension means (n, 1, 1).
-
ldmatrix–count8x8 b16 shared matrices; lanes 8i..8i+7 address matrix i's rows. -
load_tmem–countFP32 TMEM columns of this lane, waiting for the load. -
load_vector–cache"weight": a streaming L2 evict_first load of static weights; else -
load_words–countwords (a tuple);scopeis a relaxed load at that scope. -
mma–m16n8k16 (FP8: k32) mma.sync.
-
mma_bf16_block–Warp-uniform issue of one 64-K block (K-major 128B-swizzled A and B): the
-
mma_into–acc += a @ bwith onemma;accis a four-element register view. -
mma_mx–One block-scaled MXF8 tcgen05 MMA;
accumulateis a runtime flag. -
mul2–Lanewise a * b of FP32 pairs in one packed instruction (IEEE per lane).
-
multicast_words–Relaxed multimem store of FP32 ("f32") or integer ("b32", "bf16x2") words.
-
mx_exponent–E8M0 scale of an MXFP8 block: amax's exponent minus 8, plus one when its
-
no_neg_zero–wordwith each negative-zero BF16 half made +0. -
nvfp4_scale–The E4M3 scale code of a 16-value NVFP4 block, sf = e4m3(max(amax / 6, 2^-9)),
-
pack_e2m1–E2M1 (round to nearest, satfinite) of 8 values, element 0 in the low nibble
-
pack_pair–BF16x2 of (low, high);
policy=Noneis the bare conversion. -
prefetch_bulk–prefetch_bytesof a 64-bit address through the NVVM op. -
ptx–One verbatim asm block; a tuple
result(even a 1-tuple) returns a tuple. -
published–readyand no word is the mailboxsentinel. -
push_float–DSMEM store of one FP32
value(or a 4-tuple) completing onbarrier -
query_norm_rsqrt–rsqrt(total / 1536 + eps) of the q_a RMSNorm as the stock layer computes it:
-
rcp_approx–1.f / value under --use_fast_math.
-
release_tmem–CTA teardown: warp
ownerfrees the TMEM after every tcgen05 operation. -
rms_norm_rstd–rsqrt(total / 7168 + eps) of vllm_c's rms_norm of a 7168-wide row (IEEE
-
scatter_reduce–Warp-reduce
countvalues; lane groups end up owning one value each. -
sigmoid–1 / (1 + exp(-x)); correctly rounded when
fast_mathis None. -
sigmoid_reciprocal–1 / (1 + exp(-x)) from its denominator: an approximate divide with
fast_math, -
situ–Routed-expert SiTU as the stock trtllm-gen FC1 epilogue computes it from the
-
situ_and_mul–The
SituAndMulop as the deployment runs it, before the BF16 store: the -
situ_gate–The gate factor of the
_Csitu_and_mul kernel: (0.5 beta) * tanh(g * -
situ_tanh–tanhfof the_Csitu_and_mul kernel (csrc/activation_kernels.cu, built -
situ_up–The up factor of the
_Ckernel: linear_beta * tanh(u * fl(1 / linear_beta)), -
sleep_ns–nsis an immediate if a Python int, else a register. -
split–(first, count) of part
ioftotalitems splitnways. -
store_f32x4–when: a predicate, so callers need no branch. -
store_fp8_pair–FP8 E4M3 (satfinite) of
lowandhighas the two bytes atpointer. -
store_pair–BF16x2 (a, b) with negative-zero halves made +0.
-
store_words–scopeis a relaxed global store at that scope. -
thread–(thread, warp, lane, CTA) indices.
-
try_wait–Acquire parity probe at
scope("cluster", or "cta" when every arrival is -
view–dtypetensor at byteoffsetof pointerbase. -
wait_tmem–wait, then order later tcgen05 operations after it.
_vector(count, first=0)
¶
(".vN", "{\(first,...}") of an N-word access; ("", "\)first") for one word.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
acquire_tensormap_asm(pointer)
¶
acquire_tensormap as one asm block on the unfolded address.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
alloc(allocator, dtype, shape, align=16)
¶
Row-major shape tensor from a SmemAllocator.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
asm(result=None, *, pure=False)
¶
f(*args) -> (code, constraints, operands[, result, pure]) as one inline-PTX
op. Pointer operands pass their address: 32-bit for "r" (shared), 64-bit for "l".
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
at(tensor, *coord)
¶
attn_res_rstd(total, eps, scale=None)
¶
rsqrtf(total / 7168 + eps) as attn_res_kernel.cu compiles it (--use_fast_math);
with scale its fused output norm's rsqrtf(total / 7168 + eps * scale * scale).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
bf16(word, high=False)
¶
chunk_mma(*args)
¶
(d, adesc, bdesc, sfa, sfa_src, sfb, sfb_src, copy_sfb, accum, empty_bar, acc_bar): four K32 MMAs of one K128 chunk, with optional completion arrivals.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
commit_asm(barrier)
¶
commit as an asm block on the unfolded address.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
copy_g2s(dst, src, size=16, barrier=None, *, evict_first=False)
¶
16-byte cp.async, or a static/dynamic size bulk copy on barrier.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
dot(a, b, acc=None, **kwargs)
¶
fma chain over zip(a, b) from acc, or from a[0] * b[0].
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
ds_tile_scale(amax)
¶
The fp8_ds_mla tile scale exp2f(ceilf(log2f(max(amax / 448, 1e-4)))) as the stock writer concat_and_cache_ds_mla computes it: an IEEE divide, libdevice's log2f (inlined below) and an exact ex2 of the integer.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
fma2(a, b, c)
¶
Lanewise a * b + c of FP32 pairs in one packed instruction (IEEE per lane).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
inv_rms(value, eps, *, m8=False)
¶
rsqrt(value / 3584 + eps); m8: the mean as a reciprocal product refined by
its FMA residual.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
launch(kernel, args, grid, block, cluster=None, pdl=True, **options)
¶
Launch kernel(args[:-1]) on stream args[-1]; an int dimension means (n, 1, 1).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
ldmatrix(pointer, *, trans=False, count=4)
¶
count 8x8 b16 shared matrices; lanes 8i..8i+7 address matrix i's rows.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
load_tmem(address, count=1)
¶
count FP32 TMEM columns of this lane, waiting for the load.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
load_vector(pointer, *, cache='cg')
¶
cache "weight": a streaming L2 evict_first load of static weights; else
ld.global.<cache>. Side-effecting in every mode.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
load_words(pointer, *, count=2, shared=False, evict_first=False, mutable=False, volatile=False, scope=None, cache_policy='cg', word_type='b32', result_type=Uint32)
¶
count words (a tuple); scope is a relaxed load at that scope.
mutable (a side-effecting load) for data written during the step (activations,
tables, refills). Only static weights use evict_first.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
mma(a, b, accumulator, *, fp8=False, bf16=False)
¶
m16n8k16 (FP8: k32) mma.sync.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
mma_bf16_block(d, a, b, instruction, accumulate, empty, release)
¶
Warp-uniform issue of one 64-K block (K-major 128B-swizzled A and B): the
elected lane runs the four K16 BF16 MMAs into d (the first accumulates iff
accumulate is nonzero) and, if release, commits empty.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
mma_into(acc, a, b, **kwargs)
¶
acc += a @ b with one mma; acc is a four-element register view.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
mma_mx(d, a, b, instruction, sfa, sfb, accumulate)
¶
One block-scaled MXF8 tcgen05 MMA; accumulate is a runtime flag.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
mul2(a, b)
¶
Lanewise a * b of FP32 pairs in one packed instruction (IEEE per lane).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
multicast_words(address, words, *, kind='f32')
¶
Relaxed multimem store of FP32 ("f32") or integer ("b32", "bf16x2") words.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
mx_exponent(amax)
¶
E8M0 scale of an MXFP8 block: amax's exponent minus 8, plus one when its mantissa exceeds 448's (1.75), as the trtllm-gen MoE FC1 epilogue and FlashInfer's mxfp8_quantize round it.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
no_neg_zero(word)
¶
word with each negative-zero BF16 half made +0.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
nvfp4_scale(amax)
¶
The E4M3 scale code of a 16-value NVFP4 block, sf = e4m3(max(amax / 6, 2^-9)), and 1 / float(sf), with IEEE divisions (vLLM's nvfp4_ds_mla writer).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
pack_e2m1(values)
¶
E2M1 (round to nearest, satfinite) of 8 values, element 0 in the low nibble (cvt's first source is the high nibble).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
pack_pair(low, high, *, policy='plain')
¶
BF16x2 of (low, high); policy=None is the bare conversion.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
prefetch_bulk(address, size, *, loc=None, ip=None)
¶
prefetch_bytes of a 64-bit address through the NVVM op.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
ptx(assembly, constraints, operands=(), result=None, *, effects, loc=None, ip=None)
¶
One verbatim asm block; a tuple result (even a 1-tuple) returns a tuple.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
published(words, ready=True, *, sentinel=2147483648)
¶
ready and no word is the mailbox sentinel.
push_float(pointer, value, barrier, peer, when=None)
¶
DSMEM store of one FP32 value (or a 4-tuple) completing on barrier
(when: predicated on it).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
query_norm_rsqrt(total, eps, *, triton=False)
¶
rsqrt(total / 1536 + eps) of the q_a RMSNorm as the stock layer computes it:
vllm_c's rms_norm (IEEE divide; K3.1 DSA), or triton K3 MLA's Triton
fused_q_kv_rmsnorm (Triton's fp32 divide).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
rcp_approx(value)
¶
release_tmem(tmem, columns, warp, owner)
¶
CTA teardown: warp owner frees the TMEM after every tcgen05 operation.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
rms_norm_rstd(total, eps)
¶
rsqrt(total / 7168 + eps) of vllm_c's rms_norm of a 7168-wide row (IEEE divide).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
scatter_reduce(values, lane, count)
¶
Warp-reduce count values; lane groups end up owning one value each.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
sigmoid(value, fast_math=None)
¶
1 / (1 + exp(-x)); correctly rounded when fast_math is None.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
sigmoid_reciprocal(denominator, *, fast_math)
¶
1 / (1 + exp(-x)) from its denominator: an approximate divide with fast_math,
else the approximate reciprocal refined by two IEEE FMAs (out-of-range: div.rn).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
situ(g, u, beta, linear_beta, inv_beta, inv_linear_beta)
¶
Routed-expert SiTU as the stock trtllm-gen FC1 epilogue computes it from the FP32 accumulators: (beta * tanh(g * inv_beta) * sigmoid(g)) * (linear_beta * tanh(u * inv_linear_beta)), in that order, with tanh.approx and sigmoid as rcp.approx(1 + ex2.approx(-g log2 e)).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
situ_and_mul(gate, up, beta, linear_beta)
¶
The SituAndMul op as the deployment runs it, before the BF16 store: the
op enabled (custom_ops "all", e.g. compilation mode NONE under the breakable
CUDA graph), i.e. the _C situ_and_mul kernel, gate factor times up factor.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
situ_gate(gate, beta)
¶
The gate factor of the _C situ_and_mul kernel: (0.5 beta) * tanh(g *
fl(1 / beta)) * (1 + tanh(0.5 g)), sigmoid(g) taken as (1 + tanh(g / 2)) / 2.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
situ_tanh(x)
¶
tanhf of the _C situ_and_mul kernel (csrc/activation_kernels.cu, built
without fast math), from its PTX: an odd polynomial below 0.6, else copysign(1 - 2
/ (1 + ex2.approx.ftz(2|x| log2 e)), x) with rcp.approx.ftz, 1 from 9.01; non-FTZ
multiplies and FMAs.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
situ_up(up, linear_beta)
¶
The up factor of the _C kernel: linear_beta * tanh(u * fl(1 / linear_beta)),
or u when linear_beta <= 0 (unset).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
sleep_ns(ns)
¶
ns is an immediate if a Python int, else a register.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
split(total, i, n)
¶
(first, count) of part i of total items split n ways.
store_f32x4(pointer, values, when=None)
¶
when: a predicate, so callers need no branch.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
store_fp8_pair(pointer, low, high)
¶
FP8 E4M3 (satfinite) of low and high as the two bytes at pointer.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
store_pair(pointer, a, b)
¶
BF16x2 (a, b) with negative-zero halves made +0.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
store_words(pointer, words, *, shared=False, scope=None)
¶
scope is a relaxed global store at that scope.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
thread()
¶
(thread, warp, lane, CTA) indices.
try_wait(barrier, phase=0, *, test=False, scope='cluster')
¶
Acquire parity probe at scope ("cluster", or "cta" when every arrival is
CTA-local); test is the non-blocking probe of phase 0.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
view(base, offset, dtype, shape, stride=None)
¶
dtype tensor at byte offset of pointer base.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/cutedsl/common/primitives.py
wait_tmem(barrier, phase=0, scope='cluster')
¶
wait, then order later tcgen05 operations after it.