vllm.models.minimax_m3.amd.mono.drafter.device
¶
Device helpers of the DSpark drafter kernels: memory, bounded waits, the MXFP8 GEMV and the row norms.
Every function is traced inside a @flyc.kernel body; the ones with control
flow over traced values are @traced (FlyDSL rewrites only the kernel body's
own AST). Conventions:
- a global
baseis a wave-uniform Int64 address (a buffer resource); offsets are per lane, in elements; - tagged pairs are 8 bytes: (value word, tag word);
- data other CTAs read after a flag is stored device-coherent (
CM_DEV) and published bypublish.
Functions:
-
bf16_bits–bf16 bits of
x(RNE) in the low half of an Int32. -
bf16r–xrounded to bf16 (RNE), as f32. -
bfpair–bf16(a) | bf16(b) << 16 as an Int32.
-
exp–The natural exponent as exp2 of x log2(e) (denormal-safe llvm.exp2).
-
fail–A timed-out wait sets the health word to [1, rank, site].
-
gst32–A 32-bit store at a per-lane 64-bit address.
-
hw_sqrt–v_sqrt_f32 (~1 ulp), not the correctly rounded libm expansion.
-
ld–Load
nelements (i32 unlessdtype) at elementidxofbase. -
ld8–Byte
idxofbase, zero-extended. -
ldn–ldthrough a resource ofnbytes: elements past it read 0 without a -
mma8–Acc += A B, 16x16x128 e4m3 with e8m0 scales (in the low byte).
-
mma_chain–One tile's partials over chunks 0..nc-1, in order.
-
mx_scale–VLLM's MXFP8 block scale of amax
am: (e8m0 exponent as f32, 1 / scale). -
norm_row–Gemma RMSNorm of a row: s = v (+ the residual in LDS
res) becomes the -
norm_w–A thread's 16 norm weights (8 bf16-pair words).
-
opaque–vthrough a side-effecting asm that also readsloop_var. -
poll_pairs–Wait for the
npairs (1, 2, 4 or 8) from pairidxofbaseto carry -
poll_rows–poll_pairsof every base inbasesin one batch (one round trip a -
publish–Drain the CTA's stores, then set flag
iofbasetotag. -
quant_store–MXFP8 of a thread's 16 values -> e4m3
x8[t][16 tid ..], e8m0 -
red_store–Wave
wave's partial of tilet->red[8 t + wave][row][token]. -
red_sum–Tile
t's (row, token) summed over waves 0..7, in order. -
row_sum4–A thread's 16 values of row
t: bf16 of the 4 source ranks' bf16 partials -
row_x–A thread's 16 values of row
tof bf16x_in[rows][6144]. -
st–Store
v(a Numeric or a Vector) at elementidxofbase. -
w_chunk–MFMA operand (8 words) and scale of row
row, chunkcofwave. -
wait_flags–Wait for flags 0..n-1 of
base(n <= 512), then a CTA barrier. -
xq_chunk–bf16 row
rowofx[16][K], chunkcofwave, quantized to MXFP8 in
_spin(load_all, pending, dl, health)
¶
Re-issue load_all until pending clears.
Every CHECK_EVERY rounds the clock is checked against dl and the health
word read. Returns (values, failed): failed is 1 when the wait timed out, 2 when
it gave up on a failure reported elsewhere.
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
bf16_bits(x)
¶
bf16 bits of x (RNE) in the low half of an Int32.
bf16r(x)
¶
bfpair(a, b)
¶
exp(x)
¶
fail(health, fl, rank, site)
¶
A timed-out wait sets the health word to [1, rank, site].
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
gst32(addr, v)
¶
A 32-bit store at a per-lane 64-bit address.
hw_sqrt(x)
¶
v_sqrt_f32 (~1 ulp), not the correctly rounded libm expansion.
ld(base, idx, n=1, cm=0, dtype=None)
¶
ld8(base, idx)
¶
ldn(base, nbytes, idx, n=1, cm=0, dtype=None)
¶
ld through a resource of nbytes: elements past it read 0 without a
memory access.
mma8(a, sa, b, sb, acc)
¶
Acc += A B, 16x16x128 e4m3 with e8m0 scales (in the low byte).
mma_chain(ws, xs, nc)
¶
One tile's partials over chunks 0..nc-1, in order.
mx_scale(am)
¶
VLLM's MXFP8 block scale of amax am: (e8m0 exponent as f32, 1 / scale).
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
norm_row(v, res, w, add, red, tid, lane, wave)
¶
Gemma RMSNorm of a row: s = v (+ the residual in LDS res) becomes the
residual; returns bf16(s rstd (1 + w)), 16 values a thread. red: 8 LDS
floats.
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
norm_w(w, tid)
¶
A thread's 16 norm weights (8 bf16-pair words).
opaque(v, loop_var)
¶
v through a side-effecting asm that also reads loop_var.
Per-lane values derived from it are not loop-invariant for LLVM: hoisted out of the layer loop they would stay live across it and spill.
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
poll_pairs(base, idx, n, tag, dl, health, cm=CM_DEV)
¶
Wait for the n pairs (1, 2, 4 or 8) from pair idx of base to carry
tag. Returns ([n value words], failed).
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
poll_rows(bases, idx, n, tag, dl, health, cm=CM_SYS)
¶
poll_pairs of every base in bases in one batch (one round trip a
round). Returns ([[n value words] a base], failed).
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
publish(base, i, tag, tid)
¶
Drain the CTA's stores, then set flag i of base to tag.
The drain is an explicit vmcnt(0): on gfx950 a workgroup-scope release fence emits no wait for global stores, and the flag must not overtake another wave's data.
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
quant_store(o, t, x8, xs8, tid)
¶
MXFP8 of a thread's 16 values -> e4m3 x8[t][16 tid ..], e8m0
xs8[t][tid / 2].
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
red_store(red, t, acc, wave, g4, l16)
¶
Wave wave's partial of tile t -> red[8 t + wave][row][token].
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
red_sum(red, t, row, tok)
¶
Tile t's (row, token) summed over waves 0..7, in order.
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
row_sum4(sym, Y, t, tid, tag, dl, health, rank, site)
¶
A thread's 16 values of row t: bf16 of the 4 source ranks' bf16 partials
summed in rank order, polled from the symmetric buffer at Y.
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
row_x(x_in, t, tid)
¶
A thread's 16 values of row t of bf16 x_in[rows][6144].
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
st(base, idx, v, cm=0)
¶
w_chunk(w, s, row, K, wave, g4, c)
¶
MFMA operand (8 words) and scale of row row, chunk c of wave.
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
wait_flags(base, n, tag, tid, dl, health, rank, site)
¶
Wait for flags 0..n-1 of base (n <= 512), then a CTA barrier.
Source code in vllm/models/minimax_m3/amd/mono/drafter/device.py
xq_chunk(x, row, K, wave, g4, l16, c)
¶
bf16 row row of x[16][K], chunk c of wave, quantized to MXFP8 in
the operand layout. A 32-k block is units 2b and 2b + 1, held by lanes 16
apart. Returns (operand: 8 words, scale of block g).