C-Kernel-Engine Parity Testing API. More...
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Macros | |
| #define | CK_BLOCK_Q4_0_SIZE 18 |
| #define | CK_BLOCK_Q4_K_SIZE 144 |
| #define | CK_BLOCK_Q6_K_SIZE 210 |
| #define | CK_BLOCK_Q8_K_SIZE 292 |
| #define | CK_QK4_0 32 /* Elements per Q4_0 block */ |
| #define | CK_QK8_0 32 /* Elements per Q8_0 block */ |
| #define | CK_QK_K 256 /* Elements per K-quant super-block */ |
Functions | |
| 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) |
| Q5_0 GEMM - batched matrix multiply with Q5_0 weights (32-element blocks) | |
| void | ck_test_gemm_q6_k (const void *weight_q6k, const float *input_f32, float *output, int rows, int cols, int n_tokens) |
| Q6_K GEMM - batched matrix multiply with Q6_K weights. | |
| void | ck_test_gemm_q8_0 (const void *weight_q8_0, const float *input_f32, float *output, int rows, int cols, int n_tokens) |
| Q8_0 GEMM - batched matrix multiply with Q8_0 weights (32-element blocks) | |
| 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 (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 (takes pre-quantized Q8_0 input) | |
C-Kernel-Engine Parity Testing API.
Exposes individual CK kernels for parity testing against llama.cpp/ggml. This API mirrors the test-kernel-parity.cpp interface in llama.cpp.
Usage:
Definition in file ck_parity_api.h.
| #define CK_BLOCK_Q4_0_SIZE 18 |
Definition at line 36 of file ck_parity_api.h.
| #define CK_BLOCK_Q4_K_SIZE 144 |
Definition at line 33 of file ck_parity_api.h.
| #define CK_BLOCK_Q6_K_SIZE 210 |
Definition at line 34 of file ck_parity_api.h.
| #define CK_BLOCK_Q8_K_SIZE 292 |
Definition at line 35 of file ck_parity_api.h.
| #define CK_QK4_0 32 /* Elements per Q4_0 block */ |
Definition at line 29 of file ck_parity_api.h.
| #define CK_QK8_0 32 /* Elements per Q8_0 block */ |
Definition at line 30 of file ck_parity_api.h.
| #define CK_QK_K 256 /* Elements per K-quant super-block */ |
Definition at line 28 of file ck_parity_api.h.
| 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 | ||
| ) |
Q5_0 GEMM - batched matrix multiply with Q5_0 weights (32-element blocks)
Computes: output[t,r] = sum_k(weight[r,k] * input[t,k])
| weight_q5_0 | Q5_0 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 32) |
| n_tokens | Batch size |
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 | ||
| ) |
Q6_K GEMM - batched matrix multiply with Q6_K weights.
Computes: output[t,r] = sum_k(weight[r,k] * input[t,k])
| weight_q6k | Q6_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 |
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 | ||
| ) |
Q8_0 GEMM - batched matrix multiply with Q8_0 weights (32-element blocks)
Computes: output[t,r] = sum_k(weight[r,k] * input[t,k])
| weight_q8_0 | Q8_0 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 32) |
| n_tokens | Batch size |
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 tests the mega_fused_outproj_mlp_prefill kernel which fuses:
| 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 |
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 (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) |
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 (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) |
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().