Skip to main content

Module irdec

Module irdec 

Source
Expand description

The TCG3 rANS lane decoder as tang-expr integer graphs.

One residual per evaluation: the lane’s 32-bit rANS state and word position go in and come out (loop-carried state), with renormalization, 16-bit word fetch from the stream, and the binarization (static priors or the learned mixture CDF). The same graph is lowered to the WGSL kernel (replacing the hand-written res_static_gen / res_learned_gen) and run by the CPU interpreter; a stream can also ship its own graphs (crate::shipdec).

The graphs are pure, so if becomes a predicate: a decision under a false predicate still computes its step but keeps the old state (and its word fetch reads in bounds or 0). Loops carry the predicate in their condition, so they run exactly the hand-written trip counts.

ABI (both roles): buffer 0 mt (u32: priors / σ and 2^x tables), buffer 1 stream (u32, two little-endian 16-bit words each); params p0 = x, p1 = pos, p2 = end (lane state and word bound), then

  • static: p3 = sig, p4 = e, p5 = cls, p6 = sctx, p7 = off_init (all u32);
  • learned: p3..p7 = the net outputs o0..o4 (i32), p8 = off_sig, p9 = off_pow (u32);
  • adaptive learned (per-lane APM, crate::lmodel3::Adapt): the learned params, then p10 = off_stretch (the stretch table in mt), p11 = wa, p12 = lim, p13 = mask (u32), and scratch buffer 2 adt (136 u32 words, (p << 8) | count per bin, reset per block by the host);

outputs x', pos' (u32), r (i32), plus the final effect token (u32, always 0) for the adaptive role.

Structs§

CpuRes
CPU evaluation of residual graphs (the interpreter; one per thread).
Lane
One lane’s rANS state (as lane_start in the kernel).

Constants§

BUFS
Buffer ABI of the residual graphs.
LEARNED_AD_PARAMS
Param types of the adaptive learned graph.
LEARNED_PARAMS
Param types of the learned graph.
OUTS
Output types of both residual graphs.
OUTS_AD
Output types of the adaptive learned graph (the last is the effect token).
RW_AD
Scratch-buffer ABI of the adaptive learned graph: the lane’s APM bins (adt[ad_b + i] in the kernel’s workgroup memory).
STATIC_PARAMS
Param types of the static graph.

Functions§

builtin_wgsl
The built-in residual decoders as WGSL.
builtin_wgsl_ad
builtin_wgsl with the adaptive learned decoder.
cpu_mt
mt for CPU decoding: priors at 0, then the σ, 2^x and stretch tables (the kernel’s layout); returns the buffer and (off_sig, off_pow).
learned_ad_graph
The learned-mixture residual decoder through the per-lane adaptive probability maps (the adaptive role, see the module docs).
learned_graph
The learned-mixture residual decoder (res_learned_gen).
splice_res
Replace the // RES_BEGIN … // RES_END region of a kernel source.
static_graph
The static-prior residual decoder (res_static_gen).
stream_words
Stream bytes as the kernels see them: u32 words, little endian.
wgsl
WGSL for res_static_gen / res_learned_gen from the given graphs (guarded: bounds-checked loads, for untrusted graphs). A learned graph with four outputs is the adaptive role: it reads the kernel’s ad_* state and adt bins (set up per block by ad_reset).