Kernel Catalog
This document lists the high-performance C kernels available in the engine. These kernels are designed to be "micro-libraries"βyou can copy src/kernels/rope_kernels.c into your own project without taking the rest of the engine.
Registry snapshot: the v8 provider registry (version/v8/kernel_maps/KERNEL_REGISTRY.json) currently holds 364 provider maps across 126 ops (commit f7aedf6e4, 2026-09-12). The tables below are a curated catalog, not the full census β for the registry organized by operation family with selection rules, see v8 Kernel Architecture and Kernel Maps and Provider Selection.
Naming Convention
_naive: Reference implementation, easy to read, slow._parallel: OpenMP-accelerated for multi-core CPUs.
_avx512: Explicit intrinsics for AVX-512 (x86_64)._head_major: Optimized memory layout where the "Head" dimension is outermost or stride-optimized.
1. Attention, RoPE & Recurrent State
| Kernel | Source File | Description |
|---|---|---|
attention_forward_causal_head_major |
attention_kernels.c |
Standard Scaled Dot-Product Attention (SDPA) with causal masking. Expects [Head, Token, Dim] layout. |
rope_forward |
rope_kernels.c |
Rotary Positional Embeddings. Rotates query/key vectors in-place. |
causal_softmax_head_major |
softmax_kernels.c |
Softmax applied to attention scores, masking out future tokens (causal mask). |
gated_deltanet_autoregressive_forward |
deltanet_kernels.c |
Single-token Gated DeltaNet recurrent update for Qwen3.5/qwen3next parity. Updates per-head state matrices [Head, Dim, Dim] and emits [Head, Dim] output. |
qwen4_qsa_index_select_bf16 / attention_forward_sparse_token_major_gqa_bf16cache_pytorch_cpu_flash_contract |
qwen4_exp_kernels.c / attention_kernels.c |
Query-Selected Attention (QSA): qsa_index_select picks the token indices each query attends to; qsa_attention runs sparse token-major GQA against the BF16 cache. Concept: Sparse / Query-Selected Attention. |
mamba2_selective_scan_f32_parallel_dispatch |
mamba2_kernels.c, ck_parallel_prefill_v8.c |
Mamba2 selective scan with a parallel prefill dispatch variant that chunks by independent head ranges (serial fallback below the chunk threshold). Details: Throughput kernels beyond MoE. |
Composed vs Fused Gates
Not every gated block needs its own standalone kernel file.
- Gated attention is still normal causal attention plus a gate epilogue:
attention -> sigmoid -> mul -> outproj. CK can express that as stitched kernels without inventing a dedicatedgated_attention_kernels.c. - SwiGLU / GeGLU follow the same rule. We keep the atomic activation kernels and only use fused decode helpers where profiling justifies the extra complexity.
- Gated DeltaNet is different because the gate participates inside the recurrent state update itself. That makes
src/kernels/deltanet_kernels.ca real kernel family, not just a wrapper around GEMM/GEMV.
Rule of thumb: keep CK graph-first and stitch atomic kernels by default; add fused wrappers only when measurements show the gate epilogue is a real hotspot.
Qwen3.5 DeltaNet Block Flow
The Qwen3.5 / qwen3next linear-attention block is easier to reason about if you separate the three different gating roles instead of collapsing them into one "state-space" idea.
- Project from the token input
x. The block produces[q, k, v, z]fromssm_in(x)and[beta, alpha]fromssm_beta_alpha(x). - Run the short convolution path. The local conv cache mixes the projected
q/k/vlanes before the recurrent update. Thez,beta, andalphalanes do not go through that conv kernel. - Turn
alphainto the recurrent decay gate. In llama.cpp this becomes a decay controlgviasoftplus(alpha + dt)followed by a learned scale. That gate controls how much of the old recurrent state survives. - Update the per-head memory matrix
S_t. DeltaNet keeps a recurrent state matrix[Head, Dim, Dim], not just a hidden state vector. - Normalize and gate the recurrent output. After the DeltaNet core produces
h_t, the block applies gated normalization:RMSNorm(h_t) * SiLU(z). - Project back out. The gated normalized result goes through
ssm_outto rejoin the residual stream.
For single-token decode, the recurrent update that CK matches in src/kernels/deltanet_kernels.c is:
q_hat = norm(q) / sqrt(d)
k_hat = norm(k)
beta_s = sigmoid(beta)
gate = exp(g)
S_decay = gate * S_prev
kv_mem = S_decay^T * k_hat
delta = beta_s * (v - kv_mem)
S_new = S_decay + outer(k_hat, delta)
out = S_new^T * q_hat
Interpretation:
gcontrols forgetting / decay of old memory.betacontrols how aggressively the block writes the correction term.zis the output gate applied after the recurrent core, during gated normalization.
This is why Qwen3.5 feels Mamba-like without being "just Mamba": it has a short convolution path and a recurrent cache, but the core memory update is a DeltaNet matrix-state rule, and Qwen3.5 alternates these DeltaNet blocks with separate full Gated Attention blocks.
π Flash Attention Analysis
For a detailed comparison of attention implementations and performance analysis (including benchmarks vs llama.cpp), see:
Flash Attention Analysis: Why llama.cpp is Faster
SIMD optimizations, threading strategies, and performance trade-offs.
π Gated DeltaNet Deep Dive
Visual infographic of the single-token recurrent update, memory layout, ISA dispatch, and how DeltaNet compares to standard attention:
Gated DeltaNet: Recurrent Attention Deep Dive
SVG diagrams, SIMD tier breakdown, and CK-Engine kernel rules.
ποΈ Audio Pipeline: Whisper Tiny
How one WAV file becomes tokens: PCM conversion, STFT/FFT-400, log-Mel, Conv1D stem, generated encoder memory, and persistent-KV decode β every stage a kernel-map contract:
Pipeline infographic, nightly gates, parity evidence, and current limitations.
Kernel-by-kernel math for WAV decode, resample, STFT, log-Mel, Conv1D stem, and the token transpose.
Parakeet TDT Bring-up
Native FP32 WAV-to-transcript for the pinned Parakeet TDT 0.6B v3: grouped Conv2D subsampling, 24 FastConformer blocks with Transformer-XL relative attention, a stateful LSTM prediction network, and a greedy token-duration decode β exact 50-token and 50-duration trajectory from BUMPWGT5 weights:
Parakeet TDT Native CPU Bring-up
Architecture diagram, TDT blank/duration decode semantics, tested runbook, troubleshooting map, and honest unsupported boundaries.
πΊοΈ v8 Kernel Architecture
The full v8 registry organized by operation family β provider selection rules, equivalence groups, and the math behind MLA, DeltaNet, Mamba2, MoE routing, and quantized GEMM:
Registry census, selection filter chain, and per-op-family contracts.
What Laguna, Cohere2, Instella, and Nemotron-H each forced the registry to grow.
π§© MoE Expert Kernels
Grouped/bucketed expert prefill for Qwen3.5-MoE, Laguna's mixed-quant compact experts, and the parallel throughput kernels (Mamba2 prefill, Q5_1 unpack reuse):
MoE Expert Kernels: Grouped Prefill and Mixed-Quant Compact Experts
Provider-by-provider math, equivalence groups, and evidence captions.
π§ Cohere Kernel Story
How the Cohere family mostly composes the existing registry β Command R's single new kernel, North's zero-new-kernel MoE, the Compass BF16 vision frontend, and the Transcribe audio provider foundation:
Cohere Kernel Story: Reuse, BF16 Vision, and the Transcribe Audio Stack
Registry reuse map and frontend pipeline infographics with honest status badges.
Muse-Glimmer Text
How Muse-Glimmer composes grouped-query attention, centered normalization, attention gates, and caller-owned scratch while preserving PyTorch eager BF16 arithmetic:
Muse-Glimmer Text Bring-up and Certification
Numerical X-ray findings, pinned Ryzen evidence, reproduction commands, memory limits, and open certification gates.
2. Elementwise & Activation
| Kernel | Source File | Description |
|---|---|---|
gelu_fast_inplace |
gelu_kernels.c |
Gaussian Error Linear Unit. Uses the fast approximation (tanh). |
swiglu_forward |
swiglu_kernels.c |
SwiGLU activation (Gated Linear Unit with Swish). Used in Llama/Mistral. Input size is 2 * dim. |
sigmoid_forward |
sigmoid_kernels.c |
Standard logistic sigmoid function. |
hyper_stream_expand_f32 / hyper_connection_mix_bf16 / hyper_stream_inject_f32 |
hyper_connection_kernels.c |
Hyper-connection multi-stream residuals: expand the residual stream into N lanes, mix lanes after each block (hyper_connection_mix, hyper_connection_final_mix), and inject back into the single-stream residual. BF16 and Q4_K/Q5_0/Q6_K weight variants exist. Concept: Hyper-Connections. |
qwen4_ple_ngram_embed_bf16 / qwen4_ple_gate_conv_inject_bf16 |
qwen4_exp_kernels.c |
Per-Layer Embedding (PLE): n-gram embedding lookup (ple_ngram_embed) and the gate/conv injection that folds the per-layer embedding into the hidden state (ple_gate_conv_inject). Concept: Per-Layer Embedding. |
3. Normalization
| Kernel | Source File | Description |
|---|---|---|
rmsnorm_forward |
rmsnorm_kernels.c |
Root Mean Square Normalization. Lighter than LayerNorm (no mean subtraction). |
layernorm_naive_serial |
layernorm_kernels.c |
Standard LayerNorm. Subtracts mean, divides by variance. |
4. GEMM (Matrix Multiplication)
| Kernel | Source File | Description |
|---|---|---|
gemm_naive_parallel |
gemm_kernels.c |
OpenMP-parallelized SGEMM (C = A * B). |
gemm_avx512_parallel |
gemm_kernels.c |
Hand-tuned AVX-512 implementation for max throughput on modern Intel/AMD chips. |
moe_swiglu_expert_forward_nvfp4 / moe_swiglu_shared_forward_nvfp4 |
gemm_kernels_nvfp4.c, gemm_kernels_q8_0.c |
NVFP4 (E2M1 weights with FP sub-scales) routed and shared SwiGLU expert MLPs, computed against Q8_0 activations via a workspace path. Format deep dive: NVFP4. |
moe_swiglu_packed_expert_forward_bf16 / moe_swiglu_expert_forward_q4k_q5k_bucketed |
axpy_kernels.c, gemm_kernels_q4k_q8k.c, ck_parallel_prefill_v8.c |
Packed MoE experts (all experts in one weight blob) and bucketed expert prefill that groups tokens by expert before the Q4_K/Q5_K GEMMs. Details: Grouped and bucketed expert prefill. |
gemm_nt_q5_1_q8_1_parallel_dispatch (variant gemm_nt_q5_1_q8_1_m4) |
gemm_kernels_q5_1_q8_1.c, ck_parallel_prefill_v8.c |
Q5_1 weight x Q8_1 activation prefill GEMM; the AVX2 m4 tile unpacks each Q5_1 block once and dots it against four activation rows. Details: Throughput kernels beyond MoE. |
gemv_bf16_parallel_dispatch / gemv_bf16_bf16_storage_parallel_dispatch |
gemm_kernels_bf16.c |
BF16 decode GEMV with parallel dispatch, in FP32-accumulate and BF16-storage variants. |
patch_projection_image_bf16_native_storage |
gemm_kernels_bf16.c |
Vision patch projection as a BF16 GEMM over image patches (native-storage variant for the Cohere Compass frontend; a oneDNN conv3d-storage variant also exists). See Cohere Kernel Story. |
5. Loss & Training Kernels
| Kernel | Source File | Description |
|---|---|---|
softmax_cross_entropy_loss |
loss_kernels.c |
Fused softmax + CE loss/gradient kernel used by v7 training parity harness. |
softmax_cross_entropy_loss_ptref |
loss_kernels.c |
Strict PyTorch-reference CE variant for parity experiments and drift diagnostics. |
Cross-Entropy Deep Dive (v7)
For full derivation (p - one_hot), PyTorch reduction semantics (ignore_index, denominator rules), and long-horizon drift-fix evidence, see:
Audio Frontend (Cohere Transcribe)
The Transcribe audio frontend turns a WAV file into encoder-ready features with the following providers; the full pipeline story is in the Cohere Kernel Story β Transcribe audio stack.
| Kernel | Source File | Description |
|---|---|---|
audio_stft_power_precomputed_f32 (+ audio_stft_power_centered_window_f32, audio_stft_power_fft400_f32) |
audio_kernels.c |
Short-time Fourier transform power spectrum (audio_stft), with precomputed tables, centered-window, and FFT-400 variants. |
audio_log_mel_time_major_f32 |
audio_kernels.c |
Log-Mel filterbank energies, time-major output (audio_log_mel). |
audio_preemphasis_f32 / audio_feature_normalize_per_feature_f32 |
audio_kernels.c |
Pre-emphasis filter (audio_preemphasis) and per-feature normalization (audio_feature_normalize) for the frontend features. |
audio_conv2d_whc_grouped_f32 / audio_glu_split_channel_major_f32 |
audio_kernels.c |
Grouped Conv2D over width/height/channel feature maps (audio_conv2d) and the split channel-major GLU (audio_glu) in the encoder stem. |
audio_relative_shift_f32 |
audio_kernels.c |
Relative-position shift for the Transformer-XL-style attention bias (audio_relative_shift). |
Memory Layouts
Most kernels assume Row-Major contiguous memory unless specified otherwise.
- Matrices:
[Rows, Cols] - Attention Tensors:
[Heads, Tokens, Head_Dim](Head-Major) helps with cache locality during the attention loop.
Catalog refreshed against version/v8/kernel_maps/KERNEL_REGISTRY.json (364 provider maps across
126 ops) at commit f7aedf6e4 (2026-09-12). Provider counts are a hand-maintained snapshot until
the docs build regenerates them; the registry JSON is the source of truth.