Expand description
Scalar (+ aarch64 NEON / x86 AVX2 + optional CUDA) kernels for Aria engine.
Structs§
- Cuda
Context - Persistent cuBLAS handle + device copies of host weight buffers.
- Gated
Delta Step - Bundled args for
gated_delta_step(avoids clippytoo_many_arguments).
Enums§
- Compute
Backend - Resolved backend used by Session GEMM.
- Compute
Pref - CLI / config preference. Orthogonal to
hybrid_execution. - Engine
Error - Unified engine error (requirements §3.6).
- Simd
Mode - Runtime SIMD selection. Tests force
SimdMode::Scalar.
Functions§
- attention
- Causal attention for single query step against KV cache. q: [n_heads * head_dim], k_cache/v_cache: [seq, n_kv_heads * head_dim]
- attention_
causal - Causal attention for a batch of queries
[seq_q, n_heads*head_dim]. Whenseq_q == seq_kv, querytattends to keys0..=t(prefill). Whenseq_q == 1, equivalent toattention(decode). - attention_
causal_ with_ scale - Prefill causal attention with an explicit softmax scale.
windowis the sliding-window length (None= full causal prefix). - attention_
with_ scale - Causal attention with an explicit softmax scale (Gemma-4 uses
1.0after QK-norm). - cpu_
simd_ label - dequant_
lookup_ group - Codebook lookup dequant (group share): indices [k_work, n], codebook [g, kc].
- fwht
- In-place orthogonal FWHT on length = power of two (scale 1/sqrt(n)).
- gated_
delta_ step - One-token Gated DeltaNet recurrence (Qwen3.5 / Bonsai linear attention).
- geglu
- GeGLU: gelu(gate) * up (Gemma
gelu_pytorch_tanhapproximates with tanh form). - gelu_
pytorch_ tanh - Match transformers
gelu_pytorch_tanh(used by Gemma GeGLU). - hadamard_
blocked_ rows - Apply blocked Hadamard on rows of a row-major
[rows, cols]matrix.inverse=false→ per-blockH@S;inverse=true→S@H. - hadamard_
blocked_ rows_ tiles - Same as
hadamard_blocked_rowsbut uses caller tile sizes (bundlehadamard.blocks). - hadamard_
blocked_ vec - Blocked unrotate on a length-
rowsvector (treat as[rows, 1]). - hdm_
linear - y = W_rot @ x followed by blocked unrotate on each out_f row (HDM fused path).
- kv_
sliding_ view - Restrict KV to the last
windowtokens (HF sliding-window).Noneis a no-op. - linear
- y = x @ W^T where W is [out_features, in_features] row-major (GGUF-style).
- linear_
cpu - Multi-threaded
linear(AVX2/FMA or NEON dots). Numerically close tolinear. - matmul
- C = A @ B^T style? We use row-major: out[m,n] = sum_k a[m,k] * b[k,n]
with
a: [m,k],b: [k,n]. - matmul_
blocked - Blocked matmul used as Neon / SIMD-friendly path (portable; aarch64 may specialize later).
- matmul_
dispatch - Dispatch scalar vs Neon (blocked) paths. Neon is available on all targets for parity tests;
on
aarch64this is the production SIMD entry (intrinsics may replace the body later). - moe_
topk_ route - Softmax (or sigmoid) top-k MoE routing. Returns (expert_ids, normalized weights).
- portable_
block_ signs - Portable ±1 signs matching Python
portable_block_signs. - pow2_
tile_ sizes - Greedy largest-pow2 tiling of row count (e.g. 10 → [8, 2]).
- resolve_
compute - Resolve preference.
Cudanever silently falls back to CPU. - rms_
norm - rms_
norm_ gemma - Gemma-style RMSNorm: x * rrms * (1 + weight).
- rope
- Apply RoPE to interleaved q/k pairs for one token (head_dim even).
- rope_
half - HF Llama/Qwen/Gemma RoPE: rotate half of the head dims as a contiguous block.
- rope_
half_ partial - Rotate only the first
rotary_dimdims of each head (partial_rotary_factor). - rope_
half_ proportional - Gemma-4 global (p-RoPE): rotate the first
factor * head_dim/2pairs ofrotate_halflayout; remaining pairs stay identity. Frequencies use the fullhead_dimdenominator (not the rotated subset). - short_
conv_ step - Causal depthwise short-conv one-token step (LFM2).
- silu_
vec - Elementwise SiLU (DeltaNet conv activation).
- softmax
- softmax_
inplace - softplus
- Numerically stable softplus.
- swiglu