C-Kernel-Engine Parity Testing API Implementation. More...
#include "ck_parity_api.h"#include "ckernel_quant.h"#include <math.h>#include <stdlib.h>#include <string.h>Go to the source code of this file.
Functions | |
| void | attention_forward_causal_head_major_gqa_flash_strided (const float *q, const float *k, const float *v, float *output, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int kv_stride_tokens) |
| void | attn_gate_sigmoid_mul_forward (const float *x, const float *gate, float *out, int rows, int num_heads, int state_dim) |
| int | ck_get_block_q4_k_size (void) |
| Get Q4_K block size in bytes. | |
| int | ck_get_block_q6_k_size (void) |
| Get Q6_K block size in bytes. | |
| int | ck_get_block_q8_k_size (void) |
| Get Q8_K block size in bytes. | |
| int | ck_get_qk_k (void) |
| Get QK_K (elements per super-block) | |
| void | ck_test_attention_causal (const float *q, const float *k, const float *v, float *out, int num_heads, int num_kv_heads, int tokens, int seq_len, int head_dim) |
| Multi-head causal attention for prefill (head-major layout) | |
| void | ck_test_attn_gate_sigmoid_mul (const float *x, const float *gate, float *out, int rows, int dim) |
| Multiply attention output rows by sigmoid(gate) elementwise. | |
| void | ck_test_dequant_q4_0 (const void *src, float *dst, int n) |
| Dequantize Q4_0 data to FP32. | |
| void | ck_test_dequant_q4_k (const void *src, float *dst, int n) |
| Dequantize Q4_K data to FP32. | |
| void | ck_test_dequant_q6_k (const void *src, float *dst, int n) |
| Dequantize Q6_K data to FP32. | |
| void | ck_test_gated_deltanet_autoregressive (const float *q, const float *k, const float *v, const float *g, const float *beta, const float *state_in, float *state_out, float *out, int num_heads, int state_dim, float norm_eps) |
| Gated DeltaNet autoregressive update. | |
| void | ck_test_gemm_q4_k (const void *weight_q4k, const float *input_f32, float *output, int rows, int cols, int n_tokens) |
| Q4_K GEMM - batched matrix multiply with quantized weights. | |
| void | ck_test_gemm_q5_0 (const void *weight_q5_0, const float *input_f32, float *output, int rows, int cols, int n_tokens) |
| Test Q5_0 x Q8_0 GEMM (batch matrix multiply) | |
| void | ck_test_gemm_q6_k (const void *weight_q6k, const float *input_f32, float *output, int rows, int cols, int n_tokens) |
| Test Q6_K x Q8_K GEMM (batch matrix multiply) | |
| void | ck_test_gemm_q8_0 (const void *weight_q8_0, const float *input_f32, float *output, int rows, int cols, int n_tokens) |
| Test Q8_0 x Q8_0 GEMM (batch matrix multiply) | |
| void | ck_test_gemv_q4_k (const void *weight_q4k, const float *input_f32, float *output, int cols) |
| Q4_K GEMV - dot product of quantized weights and FP32 input. | |
| void | ck_test_gemv_q5_0 (const void *weight_q5_0, const float *input_f32, float *output, int rows, int cols) |
| Q5_0 GEMV - matrix-vector multiply with Q5_0 weights. | |
| void | ck_test_gemv_q5_0_q8_0 (const void *weight_q5_0, const float *input_f32, float *output, int rows, int cols) |
| Q5_0 x Q8_0 quantized GEMV - matches llama.cpp's approach. | |
| void | ck_test_gemv_q6_k (const void *weight_q6k, const float *input_f32, float *output, int cols) |
| Q6_K GEMV. | |
| void | ck_test_gemv_q8_0 (const void *weight_q8_0, const float *input_f32, float *output, int rows, int cols) |
| Q8_0 GEMV - matrix-vector multiply with Q8_0 weights. | |
| void | ck_test_gemv_q8_0_q8_0 (const void *weight_q8_0, const float *input_f32, float *output, int rows, int cols) |
| Q8_0 x Q8_0 quantized GEMV - matches llama.cpp's approach. | |
| void | ck_test_outproj_mlp_fused_q5_0 (const float *attn_out, const float *residual, const float *ln2_gamma, const void *wo, const void *w1, const void *w2, float *output, int tokens, int num_heads, int head_dim, int embed_dim, int intermediate, float eps, int w2_is_q6k) |
| Test mega-fused OutProj + MLP kernel (Q5_0 weights) | |
| void | ck_test_quantize_q8_k (const float *src, void *dst, int n) |
| Quantize FP32 to Q8_K (for activations) | |
| void | ck_test_recurrent_conv_state_update (const float *state_in, const float *q, const float *k, const float *v, float *conv_x, float *state_out, int history_len, int num_seqs, int num_tokens, int q_dim, int k_dim, int v_dim) |
| Build the recurrent convolution input history window. | |
| void | ck_test_recurrent_dt_gate (const float *alpha, const float *dt_bias, const float *a, float *gate, int rows, int dim) |
| Transform recurrent alpha rows into the DeltaNet gate. | |
| void | ck_test_recurrent_norm_gate (const float *x, const float *gate, const float *weight, float *out, int rows, int num_heads, int head_dim, float eps) |
| Per-head RMSNorm followed by SiLU(z) gating for recurrent outputs. | |
| void | ck_test_recurrent_qk_l2_norm (float *q, float *k, int rows, int q_dim, int k_dim, int head_dim, float eps) |
| Apply per-head L2 normalization to recurrent Q/K rows in-place. | |
| void | ck_test_recurrent_silu (const float *x, float *out, int rows, int dim) |
| Apply SiLU elementwise to recurrent rows. | |
| void | ck_test_recurrent_split_conv_qkv (const float *packed_qkv, float *q, float *k, float *v, int rows, int q_dim, int k_dim, int v_dim) |
| Split the post-convolution recurrent packed QKV rows. | |
| void | ck_test_recurrent_split_qkv (const float *packed_qkv, float *q, float *k, float *v, int rows, int q_dim, int k_dim, int v_dim) |
| Split a packed recurrent QKV matrix into explicit Q, K, and V outputs. | |
| void | ck_test_rmsnorm (const float *input, const float *weight, float *output, int n_tokens, int dim, float eps) |
| RMSNorm. | |
| void | ck_test_rope (float *q, float *k, int n_tokens, int n_heads, int n_heads_kv, int head_dim, int pos_offset, float theta) |
| RoPE (Rotary Position Embedding) | |
| void | ck_test_rope_interleaved (float *q, float *k, int n_tokens, int n_heads, int n_heads_kv, int head_dim, int pos_offset, float theta) |
| RoPE with interleaved format (for llama.cpp compatibility) | |
| void | ck_test_softmax (const float *input, float *output, int n) |
| Softmax (simple, non-causal) | |
| void | ck_test_split_q_gate (const float *packed_qg, float *q, float *gate, int rows, int q_dim, int gate_dim, int group_dim) |
| Split a packed full-attention Q+gate matrix into Q rows and gate rows. | |
| void | ck_test_ssm_conv1d (const float *conv_x, const float *kernel, float *out, int kernel_size, int num_channels, int num_tokens, int num_seqs) |
| qwen3next/Qwen3.5 SSM causal depthwise convolution. | |
| void | ck_test_swiglu (const float *gate_up, float *output, int n_tokens, int intermediate_dim) |
| SwiGLU activation. | |
| void | ck_test_vec_dot_q4_k_q8_k (const void *weight_q4_k, const void *input_q8_k, float *output, int cols) |
| void | ck_test_vec_dot_q5_0_q8_0 (const void *weight_q5_0, const void *input_q8_0, float *output, int cols) |
| Direct Q5_0 x Q8_0 dot product test (takes pre-quantized Q8_0 input) | |
| void | ck_test_vec_dot_q6_k_q8_k (const void *weight_q6_k, const void *input_q8_k, float *output, int cols) |
| void | ck_test_vec_dot_q8_0_q8_0 (const void *weight_q8_0, const void *input_q8_0, float *output, int cols) |
| Direct Q8_0 x Q8_0 dot product test (takes pre-quantized Q8_0 input) | |
| void | dequant_q4_0_row (const void *src, float *dst, size_t n_elements) |
| Dequantize Q4_0 row (multiple blocks) | |
| void | dequant_q4_k_row (const void *src, float *dst, size_t n_elements) |
| Dequantize Q4_K row (multiple blocks) | |
| void | dequant_q6_k_row (const void *src, float *dst, size_t n_elements) |
| Dequantize Q6_K row (multiple blocks) | |
| void | gated_deltanet_autoregressive_forward (const float *q, const float *k, const float *v, const float *g, const float *beta, const float *state_in, float *state_out, float *out, int num_heads, int state_dim, float norm_eps) |
| void | gemm_nt_q4_k_q8_k (const void *A_q8, const void *B, const float *bias, float *C, int M, int N, int K) |
| void | gemm_nt_q5_0_q8_0 (const void *A_q8, const void *B_q5, const float *bias, float *C, int M, int N, int K) |
| Batch GEMM with Q5_0 weights and Q8_0 activations for prefill. | |
| void | gemm_nt_q6_k_q8_k (const void *A_q8, const void *B, const float *bias, float *C, int M, int N, int K) |
| NT GEMM: C = A @ B^T where A is Q8_K and B is Q6_K. | |
| void | gemm_nt_q8_0_q8_0 (const void *A_q8, const void *B_q8, const float *bias, float *C, int M, int N, int K) |
| gemm_nt_q8_0_q8_0 with optional bias (matches header signature) | |
| void | gemv_q4_k_q8_k (float *y, const void *W, const void *x_q8, int M, int K) |
| void | gemv_q5_0 (float *y, const void *W, const float *x, int M, int K) |
| Auto-dispatch GEMV for Q5_0 weights based on CPU features. | |
| void | gemv_q5_0_q8_0 (float *y, const void *W, const void *x_q8, int M, int K) |
| Matrix-vector multiply with Q5_0 weights and Q8_0 input. | |
| void | gemv_q6_k_q8_k (float *y, const void *W, const void *x_q8, int M, int K) |
| GEMV: y = W @ x where W is Q6_K and x is Q8_K. | |
| void | gemv_q8_0 (float *y, const void *W, const float *x, int M, int K) |
| Auto-dispatch GEMV for Q8_0 weights based on CPU features. | |
| void | gemv_q8_0_q8_0 (float *y, const void *W, const void *x_q8, int M, int K) |
| Matrix-vector multiply with Q8_0 weights and Q8_0 input. | |
| void | mega_fused_outproj_mlp_prefill (float *output, const float *attn_out, const float *residual, const float *ln2_gamma, const void *wo, const float *bo, int wo_dt, const void *w1, const float *b1, int w1_dt, const void *w2, const float *b2, int w2_dt, int tokens, int embed_dim, int aligned_embed_dim, int num_heads, int aligned_head_dim, int intermediate_dim, int aligned_intermediate_dim, float eps, void *scratch) |
| size_t | mega_fused_outproj_mlp_prefill_scratch_size (int tokens, int aligned_embed_dim, int num_heads, int aligned_head_dim, int aligned_intermediate_dim) |
| Get scratch buffer size for mega_fused_outproj_mlp_prefill. | |
| void | quantize_row_q8_0 (const float *x, void *vy, int k) |
| Quantize FP32 to Q8_0 format (scalar reference) | |
| void | quantize_row_q8_k (const float *x, void *vy, int k) |
| void | recurrent_conv_state_update_forward (const float *state_in, const float *q, const float *k, const float *v, float *conv_x, float *state_out, int history_len, int num_seqs, int num_tokens, int q_dim, int k_dim, int v_dim) |
| void | recurrent_dt_gate_forward (const float *alpha, const float *dt_bias, const float *a, float *gate, int rows, int num_heads, int state_dim) |
| void | recurrent_norm_gate_forward (const float *x, const float *gate, const float *weight, float *out, int rows, int num_heads, int head_dim, float eps) |
| void | recurrent_qk_l2_norm_forward (float *q, float *k, int rows, int q_dim, int k_dim, int head_dim, float eps) |
| void | recurrent_silu_forward (const float *x, float *out, int rows, int dim) |
| void | recurrent_split_conv_qkv_forward (const float *packed_qkv, float *q, float *k, float *v, int rows, int q_dim, int k_dim, int v_dim) |
| void | recurrent_split_qkv_forward (const float *packed_qkv, float *q, float *k, float *v, int rows, int q_dim, int k_dim, int v_dim) |
| void | rmsnorm_forward (const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps) |
| void | rope_forward_qk (float *q, float *k, const float *cos_cache, const float *sin_cache, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset) |
| void | rope_precompute_cache (float *cos_cache, float *sin_cache, int max_seq_len, int head_dim, float base, int rotary_dim, const char *scaling_type, float scaling_factor) |
| void | split_q_gate_forward (const float *packed_qg, float *q, float *gate, int rows, int q_dim, int gate_dim, int group_dim) |
| void | ssm_conv1d_forward (const float *conv_x, const float *kernel, float *out, int kernel_size, int num_channels, int num_tokens, int num_seqs) |
| void | swiglu_forward (const float *input, float *output, int tokens, int dim) |
| void | vec_dot_q5_0_q8_0 (int n, float *s, const void *vx, const void *vy) |
| Auto-dispatch quantized dot product Q5_0 x Q8_0. | |
| void | vec_dot_q6_k_q8_k (int n, float *s, const void *vx, const void *vy) |
| Q6_K x Q8_K dot product (single row) | |
| void | vec_dot_q8_0_q8_0 (int n, float *s, const void *vx, const void *vy) |
| Auto-dispatch quantized dot product Q8_0 x Q8_0. | |
C-Kernel-Engine Parity Testing API Implementation.
Wraps CK kernels for parity testing against llama.cpp/ggml.
Definition in file ck_parity_api.c.
|
extern |
Flash attention forward with custom KV stride (for KV cache)
test_flash_attention.py::TestFlashAttention::test_flash_strided
test_kv_cache_attention.py::TestKVCacheAttention::test_flash_attention
Variant with configurable kv_stride_tokens for KV cache layouts where K/V may not be contiguous in memory.
After changes: make test
Definition at line 4422 of file attention_kernels.c.
Referenced by ck_test_attention_causal().
|
extern |
Definition at line 116 of file hybrid_attention_kernels.c.
Referenced by ck_test_attn_gate_sigmoid_mul().
| int ck_get_block_q4_k_size | ( | void | ) |
Get Q4_K block size in bytes.
Definition at line 1026 of file ck_parity_api.c.
| int ck_get_block_q6_k_size | ( | void | ) |
Get Q6_K block size in bytes.
Definition at line 1031 of file ck_parity_api.c.
| int ck_get_block_q8_k_size | ( | void | ) |
Get Q8_K block size in bytes.
Definition at line 1036 of file ck_parity_api.c.
| int ck_get_qk_k | ( | void | ) |
Get QK_K (elements per super-block)
Definition at line 1041 of file ck_parity_api.c.
References QK_K.
| void ck_test_attention_causal | ( | const float * | q, |
| const float * | k, | ||
| const float * | v, | ||
| float * | out, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | tokens, | ||
| int | seq_len, | ||
| int | head_dim | ||
| ) |
Multi-head causal attention for prefill (head-major layout)
Layout (head-major, matches llama.cpp test): Q: [num_heads, tokens, head_dim] K: [num_kv_heads, seq_len, head_dim] V: [num_kv_heads, seq_len, head_dim] out: [num_heads, tokens, head_dim]
Supports GQA (grouped-query attention) where num_heads > num_kv_heads. Causal masking: token t can only attend to positions 0..t (inclusive).
| q | Query [num_heads, tokens, head_dim] |
| k | Key [num_kv_heads, seq_len, head_dim] |
| v | Value [num_kv_heads, seq_len, head_dim] |
| out | Output [num_heads, tokens, head_dim] |
| num_heads | Number of query heads |
| num_kv_heads | Number of key/value heads (for GQA) |
| tokens | Number of query tokens |
| seq_len | Key/value sequence length (for prefill: seq_len == tokens) |
| head_dim | Dimension per head |
Definition at line 884 of file ck_parity_api.c.
References attention_forward_causal_head_major_gqa_flash_strided().
| void ck_test_attn_gate_sigmoid_mul | ( | const float * | x, |
| const float * | gate, | ||
| float * | out, | ||
| int | rows, | ||
| int | dim | ||
| ) |
Multiply attention output rows by sigmoid(gate) elementwise.
Layout: x : [rows, dim] gate : [rows, dim] out : [rows, dim]
Definition at line 859 of file ck_parity_api.c.
References attn_gate_sigmoid_mul_forward().
| void ck_test_dequant_q4_0 | ( | const void * | src, |
| float * | dst, | ||
| int | n | ||
| ) |
Dequantize Q4_0 data to FP32.
Definition at line 202 of file ck_parity_api.c.
References dequant_q4_0_row().
| void ck_test_dequant_q4_k | ( | const void * | src, |
| float * | dst, | ||
| int | n | ||
| ) |
Dequantize Q4_K data to FP32.
| src | Input Q4_K blocks |
| dst | Output FP32 values |
| n | Number of elements (must be multiple of 256) |
Definition at line 192 of file ck_parity_api.c.
References dequant_q4_k_row().
| void ck_test_dequant_q6_k | ( | const void * | src, |
| float * | dst, | ||
| int | n | ||
| ) |
Dequantize Q6_K data to FP32.
Definition at line 197 of file ck_parity_api.c.
References dequant_q6_k_row().
| void ck_test_gated_deltanet_autoregressive | ( | const float * | q, |
| const float * | k, | ||
| const float * | v, | ||
| const float * | g, | ||
| const float * | beta, | ||
| const float * | state_in, | ||
| float * | state_out, | ||
| float * | out, | ||
| int | num_heads, | ||
| int | state_dim, | ||
| float | norm_eps | ||
| ) |
Gated DeltaNet autoregressive update.
Layout: q, k, v [num_heads, state_dim] g, beta [num_heads] state_* [num_heads, state_dim, state_dim] row-major per head out [num_heads, state_dim]
This mirrors the single-token recurrent update used by qwen3next in llama.cpp after projections/convolution but before output projection.
Definition at line 741 of file ck_parity_api.c.
References gated_deltanet_autoregressive_forward().
| void ck_test_gemm_q4_k | ( | const void * | weight_q4k, |
| const float * | input_f32, | ||
| float * | output, | ||
| int | rows, | ||
| int | cols, | ||
| int | n_tokens | ||
| ) |
Q4_K GEMM - batched matrix multiply with quantized weights.
Computes: output[t,r] = sum_k(weight[r,k] * input[t,k])
| weight_q4k | Q4_K quantized weights [rows, cols] |
| input_f32 | FP32 input [n_tokens, cols] |
| output | FP32 output [n_tokens, rows] |
| rows | Number of output rows |
| cols | Number of columns (must be multiple of 256) |
| n_tokens | Batch size |
Definition at line 434 of file ck_parity_api.c.
References CK_QK_K, gemm_nt_q4_k_q8_k(), and quantize_row_q8_k().
| void ck_test_gemm_q5_0 | ( | const void * | weight_q5_0, |
| const float * | input_f32, | ||
| float * | output, | ||
| int | rows, | ||
| int | cols, | ||
| int | n_tokens | ||
| ) |
Test Q5_0 x Q8_0 GEMM (batch matrix multiply)
Q5_0 GEMM - batched matrix multiply with Q5_0 weights (32-element blocks)
Used for MLP W1 (gate/up projection) and attention Q/K with Q5_0 weights.
Definition at line 533 of file ck_parity_api.c.
References CK_QK8_0, gemm_nt_q5_0_q8_0(), and quantize_row_q8_0().
| void ck_test_gemm_q6_k | ( | const void * | weight_q6k, |
| const float * | input_f32, | ||
| float * | output, | ||
| int | rows, | ||
| int | cols, | ||
| int | n_tokens | ||
| ) |
Test Q6_K x Q8_K GEMM (batch matrix multiply)
Q6_K GEMM - batched matrix multiply with Q6_K weights.
Used for MLP W2 (down projection) with Q6_K weights.
Definition at line 467 of file ck_parity_api.c.
References CK_QK_K, gemm_nt_q6_k_q8_k(), and quantize_row_q8_k().
| void ck_test_gemm_q8_0 | ( | const void * | weight_q8_0, |
| const float * | input_f32, | ||
| float * | output, | ||
| int | rows, | ||
| int | cols, | ||
| int | n_tokens | ||
| ) |
Test Q8_0 x Q8_0 GEMM (batch matrix multiply)
Q8_0 GEMM - batched matrix multiply with Q8_0 weights (32-element blocks)
Used for attention V projection with Q8_0 weights.
Definition at line 500 of file ck_parity_api.c.
References CK_QK8_0, gemm_nt_q8_0_q8_0(), and quantize_row_q8_0().
| void ck_test_gemv_q4_k | ( | const void * | weight_q4k, |
| const float * | input_f32, | ||
| float * | output, | ||
| int | cols | ||
| ) |
Q4_K GEMV - dot product of quantized weights and FP32 input.
Internally quantizes input to Q8_K, then computes dot product.
| weight_q4k | Q4_K quantized weights [cols] |
| input_f32 | FP32 input vector [cols] |
| output | Output scalar [1] |
| cols | Number of columns (must be multiple of 256) |
Definition at line 220 of file ck_parity_api.c.
References CK_QK_K, gemv_q4_k_q8_k(), and quantize_row_q8_k().
| void ck_test_gemv_q5_0 | ( | const void * | weight_q5_0, |
| const float * | input_f32, | ||
| float * | output, | ||
| int | rows, | ||
| int | cols | ||
| ) |
Q5_0 GEMV - matrix-vector multiply with Q5_0 weights.
| weight_q5_0 | Q5_0 quantized weights [rows * cols] |
| input_f32 | FP32 input vector [cols] |
| output | FP32 output vector [rows] |
| rows | Number of output rows |
| cols | Number of columns (must be multiple of 32) |
Definition at line 263 of file ck_parity_api.c.
References CK_QK8_0, gemv_q5_0_q8_0(), and quantize_row_q8_0().
| void ck_test_gemv_q5_0_q8_0 | ( | const void * | weight_q5_0, |
| const float * | input_f32, | ||
| float * | output, | ||
| int | rows, | ||
| int | cols | ||
| ) |
Q5_0 x Q8_0 quantized GEMV - matches llama.cpp's approach.
This version quantizes the input to Q8_0 first, then uses integer dot products (like llama.cpp does). Use this for parity testing.
| weight_q5_0 | Q5_0 quantized weights [rows * cols] |
| input_f32 | FP32 input vector [cols] - will be quantized to Q8_0 |
| output | FP32 output vector [rows] |
| rows | Number of output rows |
| cols | Number of columns (must be multiple of 32) |
Definition at line 319 of file ck_parity_api.c.
References CK_QK8_0, gemv_q5_0_q8_0(), and quantize_row_q8_0().
| void ck_test_gemv_q6_k | ( | const void * | weight_q6k, |
| const float * | input_f32, | ||
| float * | output, | ||
| int | cols | ||
| ) |
Q6_K GEMV.
Definition at line 242 of file ck_parity_api.c.
References CK_QK_K, gemv_q6_k_q8_k(), and quantize_row_q8_k().
| void ck_test_gemv_q8_0 | ( | const void * | weight_q8_0, |
| const float * | input_f32, | ||
| float * | output, | ||
| int | rows, | ||
| int | cols | ||
| ) |
Q8_0 GEMV - matrix-vector multiply with Q8_0 weights.
| weight_q8_0 | Q8_0 quantized weights [rows * cols] |
| input_f32 | FP32 input vector [cols] |
| output | FP32 output vector [rows] |
| rows | Number of output rows |
| cols | Number of columns (must be multiple of 32) |
Definition at line 291 of file ck_parity_api.c.
References CK_QK8_0, gemv_q8_0_q8_0(), and quantize_row_q8_0().
| void ck_test_gemv_q8_0_q8_0 | ( | const void * | weight_q8_0, |
| const float * | input_f32, | ||
| float * | output, | ||
| int | rows, | ||
| int | cols | ||
| ) |
Q8_0 x Q8_0 quantized GEMV - matches llama.cpp's approach.
This version quantizes the input to Q8_0 first, then uses integer dot products (like llama.cpp does). Use this for parity testing.
| weight_q8_0 | Q8_0 quantized weights [rows * cols] |
| input_f32 | FP32 input vector [cols] - will be quantized to Q8_0 |
| output | FP32 output vector [rows] |
| rows | Number of output rows |
| cols | Number of columns (must be multiple of 32) |
Definition at line 345 of file ck_parity_api.c.
References CK_QK8_0, gemv_q8_0_q8_0(), and quantize_row_q8_0().
| void ck_test_outproj_mlp_fused_q5_0 | ( | const float * | attn_out, |
| const float * | residual, | ||
| const float * | ln2_gamma, | ||
| const void * | wo, | ||
| const void * | w1, | ||
| const void * | w2, | ||
| float * | output, | ||
| int | tokens, | ||
| int | num_heads, | ||
| int | head_dim, | ||
| int | embed_dim, | ||
| int | intermediate, | ||
| float | eps, | ||
| int | w2_is_q6k | ||
| ) |
Test mega-fused OutProj + MLP kernel (Q5_0 weights)
This is a simplified wrapper for parity testing that:
| attn_out | Attention output [num_heads, tokens, head_dim] (FP32, head-major) |
| residual | Residual input [tokens, embed_dim] (FP32) |
| ln2_gamma | RMSNorm gamma [embed_dim] (FP32) |
| wo | OutProj weights [embed_dim, embed_dim] (Q5_0) |
| w1 | MLP W1 weights [2*intermediate, embed_dim] (Q5_0) |
| w2 | MLP W2 weights [embed_dim, intermediate] (Q4_K or Q6_K) |
| output | Output [tokens, embed_dim] (FP32) |
| tokens | Number of tokens |
| num_heads | Number of attention heads |
| head_dim | Dimension per head |
| embed_dim | Embedding dimension (= num_heads * head_dim) |
| intermediate | MLP intermediate dimension |
| eps | RMSNorm epsilon |
| w2_is_q6k | If true, W2 is Q6_K; if false, W2 is Q4_K |
Definition at line 959 of file ck_parity_api.c.
References mega_fused_outproj_mlp_prefill(), and mega_fused_outproj_mlp_prefill_scratch_size().
| void ck_test_quantize_q8_k | ( | const float * | src, |
| void * | dst, | ||
| int | n | ||
| ) |
Quantize FP32 to Q8_K (for activations)
| src | Input FP32 values |
| dst | Output Q8_K blocks |
| n | Number of elements (must be multiple of 256) |
Definition at line 211 of file ck_parity_api.c.
References quantize_row_q8_k().
| void ck_test_recurrent_conv_state_update | ( | const float * | state_in, |
| const float * | q, | ||
| const float * | k, | ||
| const float * | v, | ||
| float * | conv_x, | ||
| float * | state_out, | ||
| int | history_len, | ||
| int | num_seqs, | ||
| int | num_tokens, | ||
| int | q_dim, | ||
| int | k_dim, | ||
| int | v_dim | ||
| ) |
Build the recurrent convolution input history window.
Layout: state_in [num_seqs, channels, history_len] q [num_seqs * num_tokens, q_dim] k [num_seqs * num_tokens, k_dim] v [num_seqs * num_tokens, v_dim] conv_x [num_seqs, channels, history_len + num_tokens] state_out [num_seqs, channels, history_len]
Definition at line 811 of file ck_parity_api.c.
References recurrent_conv_state_update_forward().
| void ck_test_recurrent_dt_gate | ( | const float * | alpha, |
| const float * | dt_bias, | ||
| const float * | a, | ||
| float * | gate, | ||
| int | rows, | ||
| int | dim | ||
| ) |
Transform recurrent alpha rows into the DeltaNet gate.
Layout: alpha : [rows, dim] dt_bias : [dim] a : [dim] gate : [rows, dim]
Definition at line 801 of file ck_parity_api.c.
References recurrent_dt_gate_forward().
| void ck_test_recurrent_norm_gate | ( | const float * | x, |
| const float * | gate, | ||
| const float * | weight, | ||
| float * | out, | ||
| int | rows, | ||
| int | num_heads, | ||
| int | head_dim, | ||
| float | eps | ||
| ) |
Per-head RMSNorm followed by SiLU(z) gating for recurrent outputs.
Definition at line 868 of file ck_parity_api.c.
References recurrent_norm_gate_forward().
| void ck_test_recurrent_qk_l2_norm | ( | float * | q, |
| float * | k, | ||
| int | rows, | ||
| int | q_dim, | ||
| int | k_dim, | ||
| int | head_dim, | ||
| float | eps | ||
| ) |
Apply per-head L2 normalization to recurrent Q/K rows in-place.
Layout: q : [rows, q_dim] k : [rows, k_dim] where q_dim and k_dim are multiples of head_dim.
Definition at line 848 of file ck_parity_api.c.
References recurrent_qk_l2_norm_forward().
| void ck_test_recurrent_silu | ( | const float * | x, |
| float * | out, | ||
| int | rows, | ||
| int | dim | ||
| ) |
Apply SiLU elementwise to recurrent rows.
Definition at line 828 of file ck_parity_api.c.
References recurrent_silu_forward().
| void ck_test_recurrent_split_conv_qkv | ( | const float * | packed_qkv, |
| float * | q, | ||
| float * | k, | ||
| float * | v, | ||
| int | rows, | ||
| int | q_dim, | ||
| int | k_dim, | ||
| int | v_dim | ||
| ) |
Split the post-convolution recurrent packed QKV rows.
Definition at line 836 of file ck_parity_api.c.
References recurrent_split_conv_qkv_forward().
| void ck_test_recurrent_split_qkv | ( | const float * | packed_qkv, |
| float * | q, | ||
| float * | k, | ||
| float * | v, | ||
| int | rows, | ||
| int | q_dim, | ||
| int | k_dim, | ||
| int | v_dim | ||
| ) |
Split a packed recurrent QKV matrix into explicit Q, K, and V outputs.
Layout: packed_qkv : [rows, q_dim + k_dim + v_dim] q : [rows, q_dim] k : [rows, k_dim] v : [rows, v_dim]
Definition at line 789 of file ck_parity_api.c.
References recurrent_split_qkv_forward().
| void ck_test_rmsnorm | ( | const float * | input, |
| const float * | weight, | ||
| float * | output, | ||
| int | n_tokens, | ||
| int | dim, | ||
| float | eps | ||
| ) |
RMSNorm.
Computes: output = (input / rms(input)) * weight where rms(x) = sqrt(mean(x^2) + eps)
| input | Input tensor [n_tokens, dim] |
| weight | Normalization weights [dim] |
| output | Output tensor [n_tokens, dim] |
| n_tokens | Number of tokens |
| dim | Hidden dimension |
| eps | Epsilon for numerical stability |
Definition at line 565 of file ck_parity_api.c.
References rmsnorm_forward().
| void ck_test_rope | ( | float * | q, |
| float * | k, | ||
| int | n_tokens, | ||
| int | n_heads, | ||
| int | n_heads_kv, | ||
| int | head_dim, | ||
| int | pos_offset, | ||
| float | theta | ||
| ) |
RoPE (Rotary Position Embedding)
Applies rotary position embeddings to Q and K tensors.
NOTE: CK uses rotate-half format (split first/second halves) while some implementations use interleaved format. The test harness should account for this.
| q | Query tensor [n_tokens, n_heads * head_dim], modified in-place |
| k | Key tensor [n_tokens, n_heads_kv * head_dim], modified in-place |
| n_tokens | Number of tokens |
| n_heads | Number of query heads |
| n_heads_kv | Number of key/value heads |
| head_dim | Dimension per head |
| pos_offset | Starting position for RoPE |
| theta | RoPE base frequency (typically 10000.0) |
Definition at line 575 of file ck_parity_api.c.
References rope_forward_qk(), and rope_precompute_cache().
| void ck_test_rope_interleaved | ( | float * | q, |
| float * | k, | ||
| int | n_tokens, | ||
| int | n_heads, | ||
| int | n_heads_kv, | ||
| int | head_dim, | ||
| int | pos_offset, | ||
| float | theta | ||
| ) |
RoPE with interleaved format (for llama.cpp compatibility)
Uses interleaved format: (x0, x1) -> (x0*cos - x1*sin, x0*sin + x1*cos)
Definition at line 653 of file ck_parity_api.c.
| void ck_test_softmax | ( | const float * | input, |
| float * | output, | ||
| int | n | ||
| ) |
Softmax (simple, non-causal)
Computes: output[i] = exp(input[i]) / sum(exp(input))
| input | Input tensor [n] |
| output | Output tensor [n] |
| n | Number of elements |
Definition at line 719 of file ck_parity_api.c.
| void ck_test_split_q_gate | ( | const float * | packed_qg, |
| float * | q, | ||
| float * | gate, | ||
| int | rows, | ||
| int | q_dim, | ||
| int | gate_dim, | ||
| int | group_dim | ||
| ) |
Split a packed full-attention Q+gate matrix into Q rows and gate rows.
Layout: packed_qg : [rows, q_dim + gate_dim] q : [rows, q_dim] gate : [rows, gate_dim]
Definition at line 778 of file ck_parity_api.c.
References split_q_gate_forward().
| void ck_test_ssm_conv1d | ( | const float * | conv_x, |
| const float * | kernel, | ||
| float * | out, | ||
| int | kernel_size, | ||
| int | num_channels, | ||
| int | num_tokens, | ||
| int | num_seqs | ||
| ) |
qwen3next/Qwen3.5 SSM causal depthwise convolution.
Layout: conv_x [num_seqs, num_channels, kernel_size - 1 + num_tokens] kernel [num_channels, kernel_size] out [num_seqs, num_tokens, num_channels]
This mirrors ggml's GGML_OP_SSM_CONV used immediately before the DeltaNet recurrent update in qwen3next/Qwen3.5.
Definition at line 767 of file ck_parity_api.c.
References ssm_conv1d_forward().
| void ck_test_swiglu | ( | const float * | gate_up, |
| float * | output, | ||
| int | n_tokens, | ||
| int | intermediate_dim | ||
| ) |
SwiGLU activation.
Computes: output = SiLU(gate) * up where SiLU(x) = x * sigmoid(x)
| gate_up | Input tensor [n_tokens, 2 * intermediate_dim] Layout: [gate_0..gate_D-1, up_0..up_D-1] per token |
| output | Output tensor [n_tokens, intermediate_dim] |
| n_tokens | Number of tokens |
| intermediate_dim | Intermediate dimension |
Definition at line 712 of file ck_parity_api.c.
References swiglu_forward().
| void ck_test_vec_dot_q4_k_q8_k | ( | const void * | weight_q4_k, |
| const void * | input_q8_k, | ||
| float * | output, | ||
| int | cols | ||
| ) |
Direct Q4_K x Q8_K dot product using identical pre-quantized bytes.
Definition at line 375 of file ck_parity_api.c.
References gemv_q4_k_q8_k().
| void ck_test_vec_dot_q5_0_q8_0 | ( | const void * | weight_q5_0, |
| const void * | input_q8_0, | ||
| float * | output, | ||
| int | cols | ||
| ) |
Direct Q5_0 x Q8_0 dot product test (takes pre-quantized Q8_0 input)
Direct Q5_0 x Q8_0 dot product (takes pre-quantized Q8_0 input)
This is a "direct" test that bypasses FP32-to-Q8_0 conversion. Useful for isolating kernel bugs from quantization bugs.
| weight_q5_0 | Q5_0 quantized weights [cols] |
| input_q8_0 | Q8_0 quantized input [cols] (pre-quantized!) |
| output | Output scalar [1] |
| cols | Number of elements (must be multiple of 32) |
Definition at line 406 of file ck_parity_api.c.
References vec_dot_q5_0_q8_0().
| void ck_test_vec_dot_q6_k_q8_k | ( | const void * | weight_q6_k, |
| const void * | input_q8_k, | ||
| float * | output, | ||
| int | cols | ||
| ) |
Direct Q6_K x Q8_K dot product using identical pre-quantized bytes.
Definition at line 384 of file ck_parity_api.c.
References gemv_q6_k_q8_k().
| void ck_test_vec_dot_q8_0_q8_0 | ( | const void * | weight_q8_0, |
| const void * | input_q8_0, | ||
| float * | output, | ||
| int | cols | ||
| ) |
Direct Q8_0 x Q8_0 dot product test (takes pre-quantized Q8_0 input)
Direct Q8_0 x Q8_0 dot product (takes pre-quantized Q8_0 input)
| weight_q8_0 | Q8_0 quantized weights [cols] |
| input_q8_0 | Q8_0 quantized input [cols] (pre-quantized!) |
| output | Output scalar [1] |
| cols | Number of elements (must be multiple of 32) |
Definition at line 422 of file ck_parity_api.c.
References vec_dot_q8_0_q8_0().
|
extern |
Dequantize Q4_0 row (multiple blocks)
| src | Q4_0 data |
| dst | FP32 output |
| n_elements | Number of elements to dequantize |
Definition at line 63 of file dequant_kernels.c.
Referenced by ck_test_dequant_q4_0(), and dequant_row().
|
extern |
Dequantize Q4_K row (multiple blocks)
Definition at line 372 of file dequant_kernels.c.
Referenced by ck_test_dequant_q4_k(), and dequant_row().
|
extern |
Dequantize Q6_K row (multiple blocks)
Definition at line 422 of file dequant_kernels.c.
Referenced by ck_test_dequant_q6_k(), and dequant_row().
|
extern |
Definition at line 1906 of file deltanet_kernels.c.
Referenced by ck_test_gated_deltanet_autoregressive(), and gated_deltanet_prefill_forward().
|
extern |
Definition at line 397 of file gemm_kernels_q4k_q8k.c.
Referenced by ck_test_gemm_q4_k().
|
extern |
Batch GEMM with Q5_0 weights and Q8_0 activations for prefill.
Computes C = A @ B^T + bias where: A: [M x K] Q8_0 quantized activations (M tokens, K features) B: [N x K] Q5_0 quantized weights (N outputs, K features) C: [M x N] FP32 output
This is the INT8 batch kernel for prefill, using pre-quantized activations to avoid FP32->Q8_0 conversion overhead per operation.
| A_q8 | Input activations in Q8_0 format [M rows of K/32 blocks each] |
| B_q5 | Weights in Q5_0 format [N rows of K/32 blocks each] |
| bias | Optional bias vector [N], NULL if not used |
| C | Output matrix [M x N], row-major FP32 |
| M | Batch size (number of tokens) |
| N | Output dimension (number of output features) |
| K | Input dimension (must be multiple of 32) |
Definition at line 1728 of file gemm_kernels_q5_0.c.
Referenced by ck_test_gemm_q5_0(), and gemm_nt_q5_0_q8_0_m2n4_tile().
|
extern |
NT GEMM: C = A @ B^T where A is Q8_K and B is Q6_K.
This is the typical inference pattern:
| A_q8 | Input activations in Q8_K format |
| B | Weight matrix in Q6_K format |
| bias | Optional bias vector [N] |
| C | Output matrix |
| M | Batch size (number of tokens) |
| N | Output dimension |
| K | Input dimension |
Definition at line 1515 of file gemm_kernels_q6k_q8k.c.
Referenced by ck_test_gemm_q6_k().
|
extern |
gemm_nt_q8_0_q8_0 with optional bias (matches header signature)
C[m,n] = A[m,K] @ B[n,K]^T + bias[n]
Definition at line 552 of file gemm_batch_int8.c.
Referenced by ck_test_gemm_q8_0().
|
extern |
Definition at line 273 of file gemm_kernels_q4k_q8k.c.
Referenced by ck_test_gemv_q4_k(), and ck_test_vec_dot_q4_k_q8_k().
|
extern |
Auto-dispatch GEMV for Q5_0 weights based on CPU features.
Dispatch priority (best available):
Uses ck_features.h for standardized feature detection.
| y | Output vector [M] |
| W | Weight matrix in Q5_0 format [M x K] |
| x | Input vector [K] |
| M | Number of output rows |
| K | Number of input columns (hidden dimension) |
Definition at line 550 of file gemm_kernels_q5_0.c.
Referenced by dot_q5_0(), gemm_nt_q5_0(), and gemm_q5_0().
|
extern |
Matrix-vector multiply with Q5_0 weights and Q8_0 input.
| y | Output vector [M] |
| W | Weight matrix in Q5_0 format [M x K] |
| x_q8 | Input vector in Q8_0 format [K] |
| M | Number of output rows |
| K | Number of columns (must be multiple of 32) |
Definition at line 1640 of file gemm_kernels_q5_0.c.
Referenced by ck_test_gemv_q5_0(), and ck_test_gemv_q5_0_q8_0().
|
extern |
GEMV: y = W @ x where W is Q6_K and x is Q8_K.
Definition at line 1341 of file gemm_kernels_q6k_q8k.c.
Referenced by ck_test_gemv_q6_k(), ck_test_vec_dot_q6_k_q8_k(), and gemm_q6_k_q8_k().
|
extern |
Auto-dispatch GEMV for Q8_0 weights based on CPU features.
Dispatch priority (best available):
Uses ck_features.h for standardized feature detection.
| y | Output vector [M] |
| W | Weight matrix in Q8_0 format [M x K] |
| x | Input vector [K] |
| M | Number of output rows |
| K | Number of input columns (hidden dimension) |
Definition at line 694 of file gemm_kernels_q8_0.c.
Referenced by dot_q8_0(), gemm_nt_q8_0_rowloop(), and gemm_q8_0().
|
extern |
Matrix-vector multiply with Q8_0 weights and Q8_0 input.
| y | Output vector [M] |
| W | Weight matrix in Q8_0 format [M x K] |
| x_q8 | Input vector in Q8_0 format [K] |
| M | Number of output rows |
| K | Number of columns (must be multiple of 32) |
Definition at line 1405 of file gemm_kernels_q8_0.c.
Referenced by ck_test_gemv_q8_0(), ck_test_gemv_q8_0_q8_0(), gemm_q8_0_q8_0_m2n4_strided(), and gemv_q8_0_q8_0_x4().
|
extern |
Referenced by ck_test_outproj_mlp_fused_q5_0().
|
extern |
Get scratch buffer size for mega_fused_outproj_mlp_prefill.
Definition at line 159 of file mega_fused_outproj_mlp_prefill.c.
Referenced by ck_test_outproj_mlp_fused_q5_0().
|
extern |
Quantize FP32 to Q8_0 format (scalar reference)
| x | Input FP32 values |
| vy | Output Q8_0 blocks |
| k | Number of elements (must be multiple of 32) |
Definition at line 125 of file gemm_kernels_q8_0.c.
Referenced by ck_test_gemm_q5_0(), ck_test_gemm_q8_0(), ck_test_gemv_q5_0(), ck_test_gemv_q5_0_q8_0(), ck_test_gemv_q8_0(), and ck_test_gemv_q8_0_q8_0().
|
extern |
Definition at line 121 of file gemm_kernels_q4k_q8k.c.
Referenced by ck_test_gemm_q4_k(), ck_test_gemm_q6_k(), ck_test_gemv_q4_k(), ck_test_gemv_q6_k(), and ck_test_quantize_q8_k().
|
extern |
Definition at line 8 of file recurrent_state_kernels.c.
Referenced by ck_test_recurrent_conv_state_update().
|
extern |
Definition at line 65 of file recurrent_gate_kernels.c.
Referenced by ck_test_recurrent_dt_gate().
|
extern |
Definition at line 18 of file recurrent_norm_kernels.c.
Referenced by ck_test_recurrent_norm_gate().
|
extern |
Definition at line 86 of file recurrent_qk_norm_kernels.c.
Referenced by ck_test_recurrent_qk_l2_norm().
|
extern |
Definition at line 137 of file recurrent_gate_kernels.c.
Referenced by ck_test_recurrent_silu().
|
extern |
Definition at line 97 of file recurrent_split_kernels.c.
Referenced by ck_test_recurrent_split_conv_qkv().
|
extern |
Definition at line 5 of file recurrent_split_kernels.c.
Referenced by ck_test_recurrent_split_qkv(), and recurrent_split_conv_qkv_forward().
|
extern |
Definition at line 621 of file rmsnorm_kernels.c.
Referenced by ck_test_rmsnorm().
|
extern |
RoPE forward for both Q and K (common inference pattern)
test_rope.py::TestRoPEForward::test_rope_forward_qk
test_fused_attention_decode.py::TestFusedAttentionDecode::test_qk_rope
test_parity.py::test_rope_qk_parity
Combined RoPE forward for both Q and K in one call. q: [num_heads, num_tokens, head_dim] k: [num_kv_heads, num_tokens, head_dim]
After changes: make test && make llamacpp-parity-full
Definition at line 1094 of file rope_kernels.c.
Referenced by ck_test_rope().
|
extern |
Precompute RoPE cos/sin cache with rotary_dim and scaling support
test_rope.py::TestRoPECache::test_cache_computation
test_rope.py::TestRoPECache::test_cache_values
Precomputes cos(m * theta_i) and sin(m * theta_i) for positions 0..max_seq_len-1. Only computes for first rotary_dim channels; remaining head_dim - rotary_dim channels are NOT rotated (pass through unchanged).
Scaling types:
| cos_cache | Output: [max_seq_len, rotary_dim/2] cos values |
| sin_cache | Output: [max_seq_len, rotary_dim/2] sin values |
| max_seq_len | Maximum sequence length for cache |
| head_dim | Full head dimension (for frequency computation) |
| base | RoPE base frequency (theta) |
| rotary_dim | Number of dimensions to rotate (0 = use head_dim) |
| scaling_type | Scaling type string: "none", "linear", "dynamic", "yarn" |
| scaling_factor | Scaling factor (1.0 = no scaling) |
After changes: make test
Definition at line 384 of file rope_kernels.c.
Referenced by ck_test_rope().
|
extern |
Definition at line 38 of file hybrid_attention_kernels.c.
Referenced by ck_test_split_q_gate().
|
extern |
Definition at line 128 of file ssm_kernels.c.
Referenced by ck_test_ssm_conv1d().
|
extern |
SwiGLU forward pass
test_swiglu.py::TestSwiGLUForward::test_forward_tokens
test_swiglu.py::TestSwiGLUForward::test_forward_single
test_mlp.py::TestMLPForward::test_swiglu_mlp
test_fused_swiglu_decode.py::TestFusedSwiGLUDecode::test_fused_swiglu_decode
test_parity.py::test_swiglu_parity
SwiGLU: y = silu(gate) * up where silu(x) = x * sigmoid(x)
After changes: make test && make llamacpp-parity-full
Definition at line 237 of file swiglu_kernels.c.
Referenced by ck_test_swiglu().
|
extern |
Auto-dispatch quantized dot product Q5_0 x Q8_0.
Dispatch priority:
Definition at line 1602 of file gemm_kernels_q5_0.c.
Referenced by ck_test_vec_dot_q5_0_q8_0().
|
extern |
Q6_K x Q8_K dot product (single row)
Definition at line 1324 of file gemm_kernels_q6k_q8k.c.
|
extern |
Auto-dispatch quantized dot product Q8_0 x Q8_0.
Definition at line 1368 of file gemm_kernels_q8_0.c.
Referenced by ck_test_vec_dot_q8_0_q8_0().