pub struct Glm5NextDsaState {
pub k_normed: DevicePtr,
pub gate: DevicePtr,
pub valid: DevicePtr,
/* private fields */
}Expand description
2026-09-25: One sequence’s indexer cache for one DSA layer, allocated once at
max_dsa_context rows and never grown.
Fields§
§k_normed: DevicePtr2026-09-25: [capacity, index_head_dim] BF16 indexer keys, after the k_norm
LayerNorm.
gate: DevicePtr2026-09-25: [capacity, index_head_dim] BF16 compress-gate projection.
valid: DevicePtr2026-09-25: [capacity] u8 per-position validity.
Implementations§
Source§impl Glm5NextDsaState
impl Glm5NextDsaState
Sourcepub fn snapshot_blob(
&self,
gpu: &dyn GpuBackend,
stream: u64,
) -> Result<Vec<u8>>
pub fn snapshot_blob( &self, gpu: &dyn GpuBackend, stream: u64, ) -> Result<Vec<u8>>
2026-09-25: Serialize the reachable indexer rows [0, len) for a
prefix-cache snapshot. Rows past len were never written or are
unreachable (rewind_to leaves them in place).
Sourcepub fn restore_blob(
&mut self,
blob: &[u8],
gpu: &dyn GpuBackend,
stream: u64,
) -> Result<()>
pub fn restore_blob( &mut self, blob: &[u8], gpu: &dyn GpuBackend, stream: u64, ) -> Result<()>
2026-09-25: Restore a snapshot’s indexer rows into this state.
A blob that is truncated, of another index_head_dim, inconsistent with
its header, or longer than this sequence’s reservation is an Err;
model-engine’s apply_aux_states propagates it with ?, so the
prefix-cache hit fails.
Source§impl Glm5NextDsaState
impl Glm5NextDsaState
Sourcepub fn alloc(gpu: &dyn GpuBackend, cfg: &Glm5NextDsaConfig) -> Result<Self>
pub fn alloc(gpu: &dyn GpuBackend, cfg: &Glm5NextDsaConfig) -> Result<Self>
2026-09-25: Reserve for the whole addressable context. alloc_state has no length
argument, so the cap, not the prompt, sizes this.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn capacity(&self) -> usize
Sourcepub fn index_head_dim(&self) -> usize
pub fn index_head_dim(&self) -> usize
2026-09-25: Indexer key width. The aux-state codec (aux_state.rs) refuses a blob
taken at a different width.
Sourcepub fn row_offset(&self, pos: usize) -> usize
pub fn row_offset(&self, pos: usize) -> usize
2026-09-25: Byte offset of row pos in k_normed / gate.
Sourcepub fn ensure_room(&self, n: usize) -> Result<()>
pub fn ensure_room(&self, n: usize) -> Result<()>
2026-09-25: Fails when n more rows would pass capacity.
Glm5NextDsaLayer::indexer_forward writes row len() before it advances, so it calls
this first: at len == capacity that row is past the end of every buffer.
Sourcepub fn ensure_room_through(&self, end: usize) -> Result<()>
pub fn ensure_room_through(&self, end: usize) -> Result<()>
2026-09-25: The same refusal for an absolute end row.
Before a graph replay the counter may still be ahead of the sequence (a rejected
draft; sync_to fixes it after the replay), so the replay check
(check_replay_room) asks about the end row seq_len + k instead.
Sourcepub fn advance(&mut self, n: usize) -> Result<()>
pub fn advance(&mut self, n: usize) -> Result<()>
2026-09-25: Advance after writing n rows at [len, len + n). Fails, without
changing len, when that would pass capacity.
Sourcepub fn rewind_to(&mut self, n: usize) -> Result<()>
pub fn rewind_to(&mut self, n: usize) -> Result<()>
2026-09-25: Rewind to n rows after a rejected speculative draft.
The rows in [n, len) are left in the cache but become unreachable: the selector reads
[0, len) and the next write starts at n, so they are overwritten before anything
can select over them. Only shrinks — growing is advance’s job, and a request to
“rewind” forward would mean the caller lost track of where the sequence is.
Sourcepub fn sync_to(&mut self, seq_len: usize, k: usize) -> Result<()>
pub fn sync_to(&mut self, seq_len: usize, k: usize) -> Result<()>
2026-09-25: Put the counter where decode_k would have left it, for a step served by
a replayed CUDA graph. seq_len is the sequence length before this step’s k rows.
The same reconcile decode_k does on entry: the counter is rewound to seq_len when
it is ahead (a rejected draft), a counter behind seq_len is an error, and then it
advances by k.
Sourcepub fn geometry(
&self,
cfg: &Glm5NextDsaConfig,
q_rows: usize,
) -> Result<DsaSelectGeometry>
pub fn geometry( &self, cfg: &Glm5NextDsaConfig, q_rows: usize, ) -> Result<DsaSelectGeometry>
2026-09-25: Plan a selection over everything cached so far.
Sourcepub fn free(&mut self, gpu: &dyn GpuBackend) -> Result<()>
pub fn free(&mut self, gpu: &dyn GpuBackend) -> Result<()>
2026-09-25: Release the per-sequence device buffers.
Takes &mut self because callers hold the state behind a dyn state object. A second
call does nothing (released is set first), since release_state on the layer and the
MTP proposer’s free_state can both reach one state. After the three frees succeed the
pointers are nulled and len is 0.