Expand description
2026-09-25: The per-model GPU buffer arena: every intermediate tensor of a forward pass, allocated once and reused by every step.
Owner: gpu-runtime. Invariants:
- Every buffer is allocated at its
BufferSizessize. The gated ones (ssd_scratch,gdn_fla_scratch,ffn_*,moe_fp8_scratch,q2_*,lora_*,ssm_rowwise_w_bf16) areDevicePtr::NULLwhen that size is 0. - No device memory is allocated after construction, and
releasefrees every pointer field.
Re-exports§
pub use decode_meta::DECODE_META_MAX_ROWS;pub use decode_meta::DECODE_META_MIN_ROWS;pub use decode_meta::DecodeMetaLayout;
Modules§
- decode_
meta - 2026-09-25: Fixed-stride batched-decode metadata layout, derived from the serve
max_batch_size.
Structs§
- Buffer
Arena - 2026-09-25: The GPU buffers of one forward pass,
M = max_batch_tokens.BufferSizes::from_configholds each buffer’s size formula. - Buffer
Sizes - 2026-09-25: Byte size of each arena buffer.
Mismax_batch_tokensandceil16(M)is M rounded up to a multiple of 16. - MoeFp8
Scratch - 2026-09-25: Disjoint regions; shared/gate/up/down phases reuse these on one stream.
Constants§
- GATEUP_
FUSED_ MAX_ M - 2026-09-25: The widest
Mthe fused dense-FFN gate+up decode GEMM serves, and so the row extent offfn_gate_up_fused. Declared here because the arena is sized in this crate; the dispatch (layers/dense_ffn_gateup_fused.rsin metrale-model-layers) reads it for its5..=GATEUP_FUSED_MAX_Mband, so the band and the buffer cannot disagree. - Q12_
SIZING_ STREAMS - 2026-09-25: Streams
scratchis provisioned for in the kernel-batched prefill staging. A batch whose footprint does not fit is refused bycheck_kernel_batched_eligible(metrale-model-engine) and runs per stream, so this sets how often the batched path is available, not safety. - VERIFY_
ROW_ CAP - 2026-09-29: Most rows (
R = Σ ks) one batched MTP verify scores: 128 sequences at one draft (the serve’s widest batch,DECODE_META_MAX_ROWS). It sizes the verify block-table rows (sizes/regions.rs) and the logits floor here; model-engine’sVERIFY_ROW_CAPand the scheduler’sVERIFY_ROW_BUDGETare this value. Was 160 (32 sequences at up to five rows).
Functions§
- q2_
dequant_ scratch_ bytes - 2026-09-25: Bytes of the keep-packed Q2_0 dequant scratch:
hidden_sizetimes the widest of intermediate, QKVZ, Mamba-2 in_proj, the q projection and 2 · kv_heads · head_dim, in BF16. This covers a weight[N, K]withhidden_sizeas one dimension and the other at most that width; the dequant callers debug-assertN * K * 2against the allocated size. It does not depend on the batch. - q12_
batched_ scratch_ bytes - 2026-09-25: Scratch bytes of the kernel-batched prefill staging for
nstreams ofchunk_lentokens each. BothBufferSizes::from_configandcheck_kernel_batched_eligiblecall it (or the varlen form), so they agree on whether a batch fits. The terms followprefill_b/batch_kernel.rs(MoE top-K area,nper-stream metadata blocks),prefill_b/stage_batched.rs(positions, three streams under MRoPE, slots, the block-table and seq_len pointer arrays,cu_seqlens,kv_lens) and theh_state_ptrstable. - q12_
batched_ scratch_ bytes_ varlen - 2026-09-25:
q12_batched_scratch_bytesfor a ragged batch:total_tokensis the packed total andmax_chunk_lensizes the per-stream metadata slots, so a varlen batch is not charged the longest stream’s length for every stream. - ssm_
rowwise_ w_ bf16_ bytes - 2026-09-25: Slab bytes: the per-layer pair times
num_ssm_layers, or 0 unlessMETRALE_FP8_ROWWISE=1. The predicate is the one in the loader’srowwise_fp8_enabled(weight_loader/qwen35_dense/rowwise_fp8.rs): the loader installs the row-wise weights on it and the arms then need this slab, so the two must agree. - ssm_
rowwise_ w_ bf16_ bytes_ for - 2026-09-25:
ssm_rowwise_w_bf16_byteswith the lever passed in, for tests that must not set the process environment. - ssm_
rowwise_ w_ bf16_ layer_ bytes - 2026-09-25: BF16 bytes of one GDN layer’s row-wise copies:
in_proj_qkvz[ssm_qkvz_size, hidden]andout_proj[hidden, value_dim], the two weightsset_fp8_rowwise_prefill_weightsinstalls, withvalue_dim = linear_num_value_heads * linear_value_head_dim. At the Qwen3.8-27B shapes ofbuffers/tests.rs(hidden 5120, 16x128 key heads, 48x128 value heads) that is167772160 + 62914560B.