RoPE (Rotary Position Embedding) kernels with SIMD. More...
#include "ckernel_engine.h"#include "bf16_utils.h"#include "ckernel_quant.h"#include "ggml_runtime_compat.h"#include <dlfcn.h>#include <math.h>#include <stddef.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Go to the source code of this file.
Macros | |
| #define | _GNU_SOURCE |
| #define | CK_DEFINE_MROPE_STORAGE_WRAPPER(NAME, STORAGE_KIND) |
| #define | M_PI 3.14159265358979323846 |
Typedefs | |
| typedef void(* | ck_ggml_build_forward_expand_fn) (struct ggml_cgraph *, struct ggml_tensor *) |
| typedef void(* | ck_ggml_cpu_init_fn) (void) |
| typedef void(* | ck_ggml_free_fn) (struct ggml_context *) |
| typedef void *(* | ck_ggml_get_data_fn) (const struct ggml_tensor *) |
| typedef enum ggml_status(* | ck_ggml_graph_compute_with_ctx_fn) (struct ggml_context *, struct ggml_cgraph *, int) |
| typedef struct ggml_context *(* | ck_ggml_init_fn) (struct ggml_init_params) |
| typedef struct ggml_cgraph *(* | ck_ggml_new_graph_fn) (struct ggml_context *) |
| typedef struct ggml_tensor *(* | ck_ggml_new_tensor_1d_fn) (struct ggml_context *, enum ggml_type, int64_t) |
| typedef struct ggml_tensor *(* | ck_ggml_rope_multi_inplace_fn) (struct ggml_context *, struct ggml_tensor *, struct ggml_tensor *, struct ggml_tensor *, int, int[4], int, int, float, float, float, float, float, float) |
| typedef struct ggml_tensor *(* | ck_ggml_view_3d_fn) (struct ggml_context *, struct ggml_tensor *, int64_t, int64_t, int64_t, size_t, size_t, size_t) |
| typedef float(* | ck_rope_math_f32_binary_fn) (float, float) |
| typedef float(* | ck_rope_math_f32_fn) (float) |
Functions | |
| static void | ck_mrope_round_storage (float *data, size_t count, int storage_kind) |
| int | ck_multimodal_mrope_positions_2d (int32_t *positions, int total_tokens, int prefix_start, int position_base, int prefix_tokens, int grid_x, int grid_y, int text_pos) |
| static ck_ggml_build_forward_expand_fn | ck_resolve_ggml_build_forward_expand (void) |
| static ck_ggml_cpu_init_fn | ck_resolve_ggml_cpu_init (void) |
| static ck_ggml_free_fn | ck_resolve_ggml_free (void) |
| static ck_ggml_get_data_fn | ck_resolve_ggml_get_data (void) |
| static ck_ggml_graph_compute_with_ctx_fn | ck_resolve_ggml_graph_compute_with_ctx (void) |
| static ck_ggml_init_fn | ck_resolve_ggml_init (void) |
| static ck_ggml_new_graph_fn | ck_resolve_ggml_new_graph (void) |
| static ck_ggml_new_tensor_1d_fn | ck_resolve_ggml_new_tensor_1d (void) |
| static ck_ggml_rope_multi_inplace_fn | ck_resolve_ggml_rope_multi_inplace (void) |
| static ck_ggml_view_3d_fn | ck_resolve_ggml_view_3d (void) |
| static void | ck_rope_ensure_ggml_loaded (void) |
| static float | ck_rope_reference_cosf (float value) |
| static float | ck_rope_reference_powf (float base, float exponent) |
| static float | ck_rope_reference_sinf (float value) |
| static void * | ck_rope_resolve_ggml_symbol (const char *name) |
| static ck_rope_math_f32_fn | ck_rope_resolve_system_math_f32 (const char *name) |
| static int | explicit_mrope_apply_ggml_exact (float *x, const int32_t *positions, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int n_dims, const int sections[4], int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow, int rope_type) |
| static void | explicit_mrope_apply_head (float *x, const int32_t *positions, int num_tokens, int head_dim, int aligned_head_dim, int n_dims, const int sections[4], int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow, int is_imrope) |
| void | mrope_qk_imrope_positions (float *q, float *k, const int32_t *positions, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int n_dims, int section_0, int section_1, int section_2, int section_3, int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow) |
| void | mrope_qk_text (float *q, float *k, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int n_dims, int section_0, int section_1, int section_2, int section_3, int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow) |
| void | mrope_qk_text_imrope (float *q, float *k, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int n_dims, int section_0, int section_1, int section_2, int section_3, int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow) |
| void | mrope_qk_text_imrope_bf16_pytorch_storage (float *q, float *k, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int n_dims, int section_0, int section_1, int section_2, int section_3, int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow) |
| void | mrope_qk_text_imrope_positions_bf16_pytorch_storage (float *q, float *k, const int32_t *positions, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int n_dims, int section_0, int section_1, int section_2, int section_3, int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow) |
| void | mrope_qk_vision (float *q, float *k, const int32_t *positions, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int n_dims, int section_0, int section_1, int section_2, int section_3, int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow) |
| void | mrope_qk_vision_bf16_storage (float *q, float *k, const int32_t *positions, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int n_dims, int section_0, int section_1, int section_2, int section_3, int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow) |
| void | mrope_qk_vision_fp16_storage (float *q, float *k, const int32_t *positions, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int n_dims, int section_0, int section_1, int section_2, int section_3, int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow) |
| static void | mrope_rotate_pair (float x0, float x1, float cos_theta, float sin_theta, float *out0, float *out1) |
| static void | rope_apply_decode_pairwise_llama_cpu (float *rows, const float *cos_row, const float *sin_row, int num_heads, int aligned_head_dim, int rotary_dim) |
| static void | rope_apply_head (float *x, const float *cos_cache, const float *sin_cache, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int rotary_dim) |
| static void | rope_apply_head_pairwise (float *x, const float *cos_cache, const float *sin_cache, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int rotary_dim) |
| void | rope_backward (const float *d_out, float *d_x, const float *cos_cache, const float *sin_cache, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset) |
| static void | rope_backward_apply_head_pairwise (const float *d_out, float *d_x, const float *cos_cache, const float *sin_cache, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int rotary_dim) |
| void | rope_backward_inplace (float *d_x, const float *cos_cache, const float *sin_cache, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset) |
| void | rope_backward_qk (const float *d_q_out, const float *d_k_out, float *d_q, float *d_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_backward_qk_pairwise_with_rotary_dim (const float *d_q_out, const float *d_k_out, float *d_q, float *d_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, int rotary_dim) |
| void | rope_forward (float *x, const float *cos_cache, const float *sin_cache, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset) |
| static void | rope_forward_gemma4v_vision_xy_one (float *x, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int grid_w, int rotary_dim, float freq_base) |
| void | rope_forward_q_split_direct_f32 (float *q, const float *freq_factors, int use_freq_factors, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int rotary_dim, float freq_base) |
| 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_forward_qk_gemma4_direct (float *q, float *k, const float *freq_factors, int use_freq_factors, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int rotary_dim, float freq_base) |
| void | rope_forward_qk_gemma4v_vision_xy (float *q, float *k, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int grid_w, int rotary_dim, float freq_base) |
| void | rope_forward_qk_pairwise_llama_cpu (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, int rotary_dim) |
| void | rope_forward_qk_pairwise_with_rotary_dim (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, int rotary_dim) |
| void | rope_forward_qk_split_direct_f32 (float *q, float *k, const float *freq_factors, int use_freq_factors, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int rotary_dim, float freq_base) |
| void | rope_forward_qk_split_direct_token_range_f32 (float *q, float *k, const float *freq_factors, int use_freq_factors, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int rotary_dim, float freq_base, int token_begin, int token_end) |
| void | rope_forward_qk_split_llama_token_range_f32 (float *q, float *k, const float *freq_factors, int use_freq_factors, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int rotary_dim, float freq_base, int token_begin, int token_end) |
| void | rope_forward_qk_strided (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, int q_stride_tokens, int k_stride_tokens) |
| void | rope_forward_qk_strided_with_rotary_dim (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, int q_stride_tokens, int k_stride_tokens, int rotary_dim) |
| void | rope_forward_qk_with_rotary_dim (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, int rotary_dim) |
| void | rope_forward_qk_with_rotary_dim_cache_stride (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, int rotary_dim, int cache_rotary_dim) |
| static void | rope_forward_split_direct_one (float *x, const float *freq_factors, int use_freq_factors, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int rotary_dim, float freq_base) |
| void | rope_forward_strided (float *x, const float *cos_cache, const float *sin_cache, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int head_stride_tokens) |
| void | rope_forward_strided_with_rotary_dim (float *x, const float *cos_cache, const float *sin_cache, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int head_stride_tokens, int rotary_dim) |
| void | rope_forward_with_rotary_dim (float *x, const float *cos_cache, const float *sin_cache, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int rotary_dim) |
| 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 | rope_precompute_cache_llama_cpu (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 | rope_precompute_cache_split (float *cos_cache, float *sin_cache, int max_seq_len, int head_dim, float base) |
| static void | text_mrope_apply_head (float *x, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int n_dims, const int sections[4], int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow, int is_imrope) |
| static void | text_mrope_apply_positions_pytorch_bf16_storage (float *x, const int32_t *positions, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int n_dims, const int sections[4], float freq_base, float freq_scale) |
| static void | text_mrope_apply_pytorch_bf16_storage (float *x, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int pos_offset, int n_dims, float freq_base, float freq_scale) |
| static void | text_mrope_yarn (float theta_extrap, float freq_scale, const float corr_dims[2], int chan, float ext_factor, float attn_factor, float *cos_theta, float *sin_theta) |
| static void | vision_mrope_apply_head (float *x, const int32_t *positions, int num_tokens, int head_dim, int aligned_head_dim, int n_dims, const int sections[4], int n_ctx_orig, float freq_base, float freq_scale, float ext_factor, float attn_factor, float beta_fast, float beta_slow) |
| static void | vision_mrope_yarn (float theta_extrap, float freq_scale, const float corr_dims[2], int chan, float ext_factor, float attn_factor, float *cos_theta, float *sin_theta) |
| static float | vision_mrope_yarn_corr_dim (int n_dims, int n_ctx_orig, float n_rot, float base) |
| static void | vision_mrope_yarn_corr_dims (int n_dims, int n_ctx_orig, float freq_base, float beta_fast, float beta_slow, float dims[2]) |
| static float | vision_mrope_yarn_ramp (float low, float high, int chan) |
| static float | yarn_correction_dim (float rotations, int rotary_dim, float freq_base, int original_context) |
| static float | yarn_mscale (float factor, float scale) |
| void | yarn_rope_cache_contiguous_positions_f32 (float *cos_cache, float *sin_cache, int num_tokens, int rotary_dim, float freq_base, float factor, int original_context, float beta_fast, float beta_slow, float mscale, float mscale_all_dim) |
| void | yarn_rope_cache_explicit_positions_bf16 (uint16_t *cos_cache, uint16_t *sin_cache, const int32_t *positions, int num_tokens, int rotary_dim, float freq_base, float factor, int original_context, float beta_fast, float beta_slow, float mscale, float mscale_all_dim) |
| void | yarn_rope_cache_explicit_positions_f32 (float *cos_cache, float *sin_cache, const int32_t *positions, int num_tokens, int rotary_dim, float freq_base, float factor, int original_context, float beta_fast, float beta_slow, float mscale, float mscale_all_dim) |
| static void | yarn_rope_cache_explicit_positions_impl (float *cos_f32, float *sin_f32, uint16_t *cos_bf16, uint16_t *sin_bf16, const int32_t *positions, int num_tokens, int rotary_dim, float freq_base, float factor, int original_context, float beta_fast, float beta_slow, float mscale, float mscale_all_dim) |
RoPE (Rotary Position Embedding) kernels with SIMD.
After changes: make test && make llamacpp-parity-full
Applies rotary position embeddings to query and key vectors. Used by Llama, SmolLM, and most modern transformer architectures.
Math (Llama-style rotate-half): Split rotary_dim into two halves (0..half-1, half..rotary_dim-1). For each position m and index i in [0, half): x0 = x[i], x1 = x[i + half] x'[i] = x0 * cos(m * theta_i) - x1 * sin(m * theta_i) x'[i+half] = x0 * sin(m * theta_i) + x1 * cos(m * theta_i)
Where theta_i = 1 / (base^(2i/d)), typically base=10000.
Layout: x: [num_heads, num_tokens, head_dim] head-major cos_cache, sin_cache: [max_seq_len, rotary_dim/2] precomputed
Definition in file rope_kernels.c.
| #define _GNU_SOURCE |
Definition at line 32 of file rope_kernels.c.
| #define CK_DEFINE_MROPE_STORAGE_WRAPPER | ( | NAME, | |
| STORAGE_KIND | |||
| ) |
Definition at line 2627 of file rope_kernels.c.
| #define M_PI 3.14159265358979323846 |
Definition at line 56 of file rope_kernels.c.
| typedef void(* ck_ggml_build_forward_expand_fn) (struct ggml_cgraph *, struct ggml_tensor *) |
Definition at line 79 of file rope_kernels.c.
| typedef void(* ck_ggml_cpu_init_fn) (void) |
Definition at line 59 of file rope_kernels.c.
| typedef void(* ck_ggml_free_fn) (struct ggml_context *) |
Definition at line 61 of file rope_kernels.c.
| typedef void *(* ck_ggml_get_data_fn) (const struct ggml_tensor *) |
Definition at line 81 of file rope_kernels.c.
| typedef enum ggml_status(* ck_ggml_graph_compute_with_ctx_fn) (struct ggml_context *, struct ggml_cgraph *, int) |
Definition at line 79 of file rope_kernels.c.
| typedef struct ggml_context *(* ck_ggml_init_fn) (struct ggml_init_params) |
Definition at line 59 of file rope_kernels.c.
| typedef struct ggml_cgraph *(* ck_ggml_new_graph_fn) (struct ggml_context *) |
Definition at line 61 of file rope_kernels.c.
| typedef struct ggml_tensor *(* ck_ggml_new_tensor_1d_fn) (struct ggml_context *, enum ggml_type, int64_t) |
Definition at line 61 of file rope_kernels.c.
| typedef struct ggml_tensor *(* ck_ggml_rope_multi_inplace_fn) (struct ggml_context *, struct ggml_tensor *, struct ggml_tensor *, struct ggml_tensor *, int, int[4], int, int, float, float, float, float, float, float) |
Definition at line 61 of file rope_kernels.c.
| typedef struct ggml_tensor *(* ck_ggml_view_3d_fn) (struct ggml_context *, struct ggml_tensor *, int64_t, int64_t, int64_t, size_t, size_t, size_t) |
Definition at line 61 of file rope_kernels.c.
| typedef float(* ck_rope_math_f32_binary_fn) (float, float) |
Definition at line 83 of file rope_kernels.c.
| typedef float(* ck_rope_math_f32_fn) (float) |
Definition at line 82 of file rope_kernels.c.
|
static |
Definition at line 2615 of file rope_kernels.c.
References bf16_to_float(), ck_fp16_to_fp32(), ck_fp32_to_fp16(), and float_to_bf16().
| int ck_multimodal_mrope_positions_2d | ( | int32_t * | positions, |
| int | total_tokens, | ||
| int | prefix_start, | ||
| int | position_base, | ||
| int | prefix_tokens, | ||
| int | grid_x, | ||
| int | grid_y, | ||
| int | text_pos | ||
| ) |
Definition at line 2892 of file rope_kernels.c.
References token.
|
static |
Definition at line 250 of file rope_kernels.c.
References ck_rope_resolve_ggml_symbol().
Referenced by explicit_mrope_apply_ggml_exact().
|
static |
Definition at line 194 of file rope_kernels.c.
References ck_rope_resolve_ggml_symbol().
Referenced by explicit_mrope_apply_ggml_exact().
|
static |
Definition at line 210 of file rope_kernels.c.
References ck_rope_resolve_ggml_symbol().
Referenced by explicit_mrope_apply_ggml_exact().
|
static |
Definition at line 266 of file rope_kernels.c.
References ck_rope_resolve_ggml_symbol().
Referenced by explicit_mrope_apply_ggml_exact().
|
static |
Definition at line 258 of file rope_kernels.c.
References ck_rope_resolve_ggml_symbol().
Referenced by explicit_mrope_apply_ggml_exact().
|
static |
Definition at line 202 of file rope_kernels.c.
References ck_rope_resolve_ggml_symbol().
Referenced by explicit_mrope_apply_ggml_exact().
|
static |
Definition at line 242 of file rope_kernels.c.
References ck_rope_resolve_ggml_symbol().
Referenced by explicit_mrope_apply_ggml_exact().
|
static |
Definition at line 218 of file rope_kernels.c.
References ck_rope_resolve_ggml_symbol().
Referenced by explicit_mrope_apply_ggml_exact().
|
static |
Definition at line 234 of file rope_kernels.c.
References ck_rope_resolve_ggml_symbol().
Referenced by explicit_mrope_apply_ggml_exact().
|
static |
Definition at line 226 of file rope_kernels.c.
References ck_rope_resolve_ggml_symbol().
Referenced by explicit_mrope_apply_ggml_exact().
|
static |
Definition at line 143 of file rope_kernels.c.
Referenced by ck_rope_resolve_ggml_symbol().
|
static |
Definition at line 108 of file rope_kernels.c.
References ck_rope_resolve_system_math_f32().
Referenced by rope_forward_qk_split_llama_token_range_f32(), rope_precompute_cache_llama_cpu(), text_mrope_apply_positions_pytorch_bf16_storage(), text_mrope_apply_pytorch_bf16_storage(), text_mrope_yarn(), vision_mrope_yarn(), and yarn_rope_cache_explicit_positions_impl().
|
static |
Definition at line 126 of file rope_kernels.c.
Referenced by explicit_mrope_apply_head(), rope_forward_qk_split_llama_token_range_f32(), rope_precompute_cache_llama_cpu(), text_mrope_apply_positions_pytorch_bf16_storage(), text_mrope_apply_pytorch_bf16_storage(), vision_mrope_apply_head(), and yarn_rope_cache_explicit_positions_impl().
|
static |
Definition at line 117 of file rope_kernels.c.
References ck_rope_resolve_system_math_f32().
Referenced by rope_forward_qk_split_llama_token_range_f32(), rope_precompute_cache_llama_cpu(), text_mrope_apply_positions_pytorch_bf16_storage(), text_mrope_apply_pytorch_bf16_storage(), text_mrope_yarn(), vision_mrope_yarn(), and yarn_rope_cache_explicit_positions_impl().
|
static |
Definition at line 183 of file rope_kernels.c.
References ck_rope_ensure_ggml_loaded(), and RTLD_DEFAULT.
Referenced by ck_resolve_ggml_build_forward_expand(), ck_resolve_ggml_cpu_init(), ck_resolve_ggml_free(), ck_resolve_ggml_get_data(), ck_resolve_ggml_graph_compute_with_ctx(), ck_resolve_ggml_init(), ck_resolve_ggml_new_graph(), ck_resolve_ggml_new_tensor_1d(), ck_resolve_ggml_rope_multi_inplace(), and ck_resolve_ggml_view_3d().
|
static |
Definition at line 85 of file rope_kernels.c.
Referenced by ck_rope_reference_cosf(), and ck_rope_reference_sinf().
|
static |
Definition at line 1857 of file rope_kernels.c.
References ck_resolve_ggml_build_forward_expand(), ck_resolve_ggml_cpu_init(), ck_resolve_ggml_free(), ck_resolve_ggml_get_data(), ck_resolve_ggml_graph_compute_with_ctx(), ck_resolve_ggml_init(), ck_resolve_ggml_new_graph(), ck_resolve_ggml_new_tensor_1d(), ck_resolve_ggml_rope_multi_inplace(), ck_resolve_ggml_view_3d(), GGML_MROPE_SECTIONS, GGML_ROPE_TYPE_VISION, GGML_STATUS_SUCCESS, GGML_TYPE_F32, GGML_TYPE_I32, and ggml_init_params::mem_size.
Referenced by mrope_qk_imrope_positions(), and mrope_qk_vision().
|
static |
Definition at line 1994 of file rope_kernels.c.
References ck_rope_reference_powf(), mrope_rotate_pair(), vision_mrope_yarn(), and vision_mrope_yarn_corr_dims().
Referenced by mrope_qk_imrope_positions().
| void mrope_qk_imrope_positions | ( | float * | q, |
| float * | k, | ||
| const int32_t * | positions, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | n_dims, | ||
| int | section_0, | ||
| int | section_1, | ||
| int | section_2, | ||
| int | section_3, | ||
| int | n_ctx_orig, | ||
| float | freq_base, | ||
| float | freq_scale, | ||
| float | ext_factor, | ||
| float | attn_factor, | ||
| float | beta_fast, | ||
| float | beta_slow | ||
| ) |
Definition at line 2686 of file rope_kernels.c.
References ck_strict_parity_enabled(), explicit_mrope_apply_ggml_exact(), explicit_mrope_apply_head(), and GGML_ROPE_TYPE_IMROPE.
| void mrope_qk_text | ( | float * | q, |
| float * | k, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | n_dims, | ||
| int | section_0, | ||
| int | section_1, | ||
| int | section_2, | ||
| int | section_3, | ||
| int | n_ctx_orig, | ||
| float | freq_base, | ||
| float | freq_scale, | ||
| float | ext_factor, | ||
| float | attn_factor, | ||
| float | beta_fast, | ||
| float | beta_slow | ||
| ) |
Definition at line 2203 of file rope_kernels.c.
References text_mrope_apply_head().
| void mrope_qk_text_imrope | ( | float * | q, |
| float * | k, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | n_dims, | ||
| int | section_0, | ||
| int | section_1, | ||
| int | section_2, | ||
| int | section_3, | ||
| int | n_ctx_orig, | ||
| float | freq_base, | ||
| float | freq_scale, | ||
| float | ext_factor, | ||
| float | attn_factor, | ||
| float | beta_fast, | ||
| float | beta_slow | ||
| ) |
Definition at line 2273 of file rope_kernels.c.
References text_mrope_apply_head().
| void mrope_qk_text_imrope_bf16_pytorch_storage | ( | float * | q, |
| float * | k, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | n_dims, | ||
| int | section_0, | ||
| int | section_1, | ||
| int | section_2, | ||
| int | section_3, | ||
| int | n_ctx_orig, | ||
| float | freq_base, | ||
| float | freq_scale, | ||
| float | ext_factor, | ||
| float | attn_factor, | ||
| float | beta_fast, | ||
| float | beta_slow | ||
| ) |
Definition at line 2496 of file rope_kernels.c.
References text_mrope_apply_pytorch_bf16_storage().
| void mrope_qk_text_imrope_positions_bf16_pytorch_storage | ( | float * | q, |
| float * | k, | ||
| const int32_t * | positions, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | n_dims, | ||
| int | section_0, | ||
| int | section_1, | ||
| int | section_2, | ||
| int | section_3, | ||
| int | n_ctx_orig, | ||
| float | freq_base, | ||
| float | freq_scale, | ||
| float | ext_factor, | ||
| float | attn_factor, | ||
| float | beta_fast, | ||
| float | beta_slow | ||
| ) |
Definition at line 2460 of file rope_kernels.c.
References text_mrope_apply_positions_pytorch_bf16_storage().
| void mrope_qk_vision | ( | float * | q, |
| float * | k, | ||
| const int32_t * | positions, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | n_dims, | ||
| int | section_0, | ||
| int | section_1, | ||
| int | section_2, | ||
| int | section_3, | ||
| int | n_ctx_orig, | ||
| float | freq_base, | ||
| float | freq_scale, | ||
| float | ext_factor, | ||
| float | attn_factor, | ||
| float | beta_fast, | ||
| float | beta_slow | ||
| ) |
Definition at line 2534 of file rope_kernels.c.
References ck_strict_parity_enabled(), explicit_mrope_apply_ggml_exact(), GGML_ROPE_TYPE_VISION, and vision_mrope_apply_head().
| void mrope_qk_vision_bf16_storage | ( | float * | q, |
| float * | k, | ||
| const int32_t * | positions, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | n_dims, | ||
| int | section_0, | ||
| int | section_1, | ||
| int | section_2, | ||
| int | section_3, | ||
| int | n_ctx_orig, | ||
| float | freq_base, | ||
| float | freq_scale, | ||
| float | ext_factor, | ||
| float | attn_factor, | ||
| float | beta_fast, | ||
| float | beta_slow | ||
| ) |
Definition at line 2645 of file rope_kernels.c.
| void mrope_qk_vision_fp16_storage | ( | float * | q, |
| float * | k, | ||
| const int32_t * | positions, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | n_dims, | ||
| int | section_0, | ||
| int | section_1, | ||
| int | section_2, | ||
| int | section_3, | ||
| int | n_ctx_orig, | ||
| float | freq_base, | ||
| float | freq_scale, | ||
| float | ext_factor, | ||
| float | attn_factor, | ||
| float | beta_fast, | ||
| float | beta_slow | ||
| ) |
Definition at line 2646 of file rope_kernels.c.
|
inlinestatic |
Definition at line 1673 of file rope_kernels.c.
Referenced by explicit_mrope_apply_head(), text_mrope_apply_head(), and vision_mrope_apply_head().
|
static |
Definition at line 1519 of file rope_kernels.c.
Referenced by rope_forward_qk_pairwise_llama_cpu().
|
inlinestatic |
Definition at line 608 of file rope_kernels.c.
Referenced by rope_forward_strided_with_rotary_dim(), and rope_forward_with_rotary_dim().
|
inlinestatic |
Definition at line 707 of file rope_kernels.c.
Referenced by rope_forward_qk_pairwise_with_rotary_dim().
| void rope_backward | ( | const float * | d_out, |
| float * | d_x, | ||
| const float * | cos_cache, | ||
| const float * | sin_cache, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset | ||
| ) |
RoPE backward (inverse rotation)
test_rope.py::TestRoPEBackward::test_rope_backward
test_rope.py::TestRoPEBackward::test_rope_backward_vs_separate
RoPE backward: inverse rotation (rotate by -θ). Since cos(-θ) = cos(θ) and sin(-θ) = -sin(θ): d_x[2i] = d0 * c + d1 * s d_x[2i+1] = -d0 * s + d1 * c
After changes: make test
Definition at line 884 of file rope_kernels.c.
Referenced by rope_backward_bf16(), and rope_backward_qk().
|
inlinestatic |
Definition at line 741 of file rope_kernels.c.
Referenced by rope_backward_qk_pairwise_with_rotary_dim().
| void rope_backward_inplace | ( | float * | d_x, |
| const float * | cos_cache, | ||
| const float * | sin_cache, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset | ||
| ) |
RoPE backward in-place (overwrite with inverse rotation)
In-place backward: overwrite d_out with inverse-rotated gradients. Useful when d_x == d_out is acceptable (saves memory).
After changes: make test
Definition at line 991 of file rope_kernels.c.
| void rope_backward_qk | ( | const float * | d_q_out, |
| const float * | d_k_out, | ||
| float * | d_q, | ||
| float * | d_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 | ||
| ) |
RoPE backward for both dQ and dK
Combined RoPE backward for both dQ and dK gradients.
After changes: make test
Definition at line 2826 of file rope_kernels.c.
References rope_backward().
Referenced by ck_layer_backward_rmsnorm_swiglu().
| void rope_backward_qk_pairwise_with_rotary_dim | ( | const float * | d_q_out, |
| const float * | d_k_out, | ||
| float * | d_q, | ||
| float * | d_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, | ||
| int | rotary_dim | ||
| ) |
Definition at line 2843 of file rope_kernels.c.
References rope_backward_apply_head_pairwise().
| void rope_forward | ( | float * | x, |
| const float * | cos_cache, | ||
| const float * | sin_cache, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset | ||
| ) |
RoPE forward (head-major layout, in-place)
test_rope.py::TestRoPEForward::test_rope_forward
test_rope.py::TestRoPEForward::test_rope_vs_separate
test_parity.py::test_rope_parity
Applies rotary position embeddings in-place to Q or K tensor. x: [num_heads, num_tokens, head_dim] head-major
After changes: make test && make llamacpp-parity-full
Definition at line 796 of file rope_kernels.c.
References rope_forward_with_rotary_dim().
Referenced by model_layer_0_decode(), model_layer_0_decode(), model_layer_0_decode(), model_layer_0_decode(), model_layer_10_decode(), model_layer_10_decode(), model_layer_10_decode(), model_layer_10_decode(), model_layer_11_decode(), model_layer_11_decode(), model_layer_11_decode(), model_layer_11_decode(), model_layer_12_decode(), model_layer_12_decode(), model_layer_12_decode(), model_layer_12_decode(), model_layer_13_decode(), model_layer_13_decode(), model_layer_13_decode(), model_layer_13_decode(), model_layer_14_decode(), model_layer_14_decode(), model_layer_14_decode(), model_layer_14_decode(), model_layer_15_decode(), model_layer_15_decode(), model_layer_15_decode(), model_layer_15_decode(), model_layer_16_decode(), model_layer_16_decode(), model_layer_16_decode(), model_layer_16_decode(), model_layer_17_decode(), model_layer_17_decode(), model_layer_17_decode(), model_layer_17_decode(), model_layer_18_decode(), model_layer_18_decode(), model_layer_18_decode(), model_layer_18_decode(), model_layer_19_decode(), model_layer_19_decode(), model_layer_19_decode(), model_layer_19_decode(), model_layer_1_decode(), model_layer_1_decode(), model_layer_1_decode(), model_layer_1_decode(), model_layer_20_decode(), model_layer_20_decode(), model_layer_20_decode(), model_layer_20_decode(), model_layer_21_decode(), model_layer_21_decode(), model_layer_21_decode(), model_layer_21_decode(), model_layer_22_decode(), model_layer_22_decode(), model_layer_22_decode(), model_layer_22_decode(), model_layer_23_decode(), model_layer_23_decode(), model_layer_23_decode(), model_layer_23_decode(), model_layer_2_decode(), model_layer_2_decode(), model_layer_2_decode(), model_layer_2_decode(), model_layer_3_decode(), model_layer_3_decode(), model_layer_3_decode(), model_layer_3_decode(), model_layer_4_decode(), model_layer_4_decode(), model_layer_4_decode(), model_layer_4_decode(), model_layer_5_decode(), model_layer_5_decode(), model_layer_5_decode(), model_layer_5_decode(), model_layer_6_decode(), model_layer_6_decode(), model_layer_6_decode(), model_layer_6_decode(), model_layer_7_decode(), model_layer_7_decode(), model_layer_7_decode(), model_layer_7_decode(), model_layer_8_decode(), model_layer_8_decode(), model_layer_8_decode(), model_layer_8_decode(), model_layer_9_decode(), model_layer_9_decode(), model_layer_9_decode(), model_layer_9_decode(), qwen2_0_5b_decode_layer_0_decode(), qwen2_0_5b_decode_layer_0_decode(), qwen2_0_5b_decode_layer_10_decode(), qwen2_0_5b_decode_layer_10_decode(), qwen2_0_5b_decode_layer_11_decode(), qwen2_0_5b_decode_layer_11_decode(), qwen2_0_5b_decode_layer_12_decode(), qwen2_0_5b_decode_layer_12_decode(), qwen2_0_5b_decode_layer_13_decode(), qwen2_0_5b_decode_layer_13_decode(), qwen2_0_5b_decode_layer_14_decode(), qwen2_0_5b_decode_layer_14_decode(), qwen2_0_5b_decode_layer_15_decode(), qwen2_0_5b_decode_layer_15_decode(), qwen2_0_5b_decode_layer_16_decode(), qwen2_0_5b_decode_layer_16_decode(), qwen2_0_5b_decode_layer_17_decode(), qwen2_0_5b_decode_layer_17_decode(), qwen2_0_5b_decode_layer_18_decode(), qwen2_0_5b_decode_layer_18_decode(), qwen2_0_5b_decode_layer_19_decode(), qwen2_0_5b_decode_layer_19_decode(), qwen2_0_5b_decode_layer_1_decode(), qwen2_0_5b_decode_layer_1_decode(), qwen2_0_5b_decode_layer_20_decode(), qwen2_0_5b_decode_layer_20_decode(), qwen2_0_5b_decode_layer_21_decode(), qwen2_0_5b_decode_layer_21_decode(), qwen2_0_5b_decode_layer_22_decode(), qwen2_0_5b_decode_layer_22_decode(), qwen2_0_5b_decode_layer_23_decode(), qwen2_0_5b_decode_layer_23_decode(), qwen2_0_5b_decode_layer_2_decode(), qwen2_0_5b_decode_layer_2_decode(), qwen2_0_5b_decode_layer_3_decode(), qwen2_0_5b_decode_layer_3_decode(), qwen2_0_5b_decode_layer_4_decode(), qwen2_0_5b_decode_layer_4_decode(), qwen2_0_5b_decode_layer_5_decode(), qwen2_0_5b_decode_layer_5_decode(), qwen2_0_5b_decode_layer_6_decode(), qwen2_0_5b_decode_layer_6_decode(), qwen2_0_5b_decode_layer_7_decode(), qwen2_0_5b_decode_layer_7_decode(), qwen2_0_5b_decode_layer_8_decode(), qwen2_0_5b_decode_layer_8_decode(), qwen2_0_5b_decode_layer_9_decode(), and qwen2_0_5b_decode_layer_9_decode().
|
static |
Definition at line 1337 of file rope_kernels.c.
Referenced by rope_forward_qk_gemma4v_vision_xy().
| void rope_forward_q_split_direct_f32 | ( | float * | q, |
| const float * | freq_factors, | ||
| int | use_freq_factors, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | rotary_dim, | ||
| float | freq_base | ||
| ) |
Definition at line 1301 of file rope_kernels.c.
References rope_forward_split_direct_one().
| 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 | ||
| ) |
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.
References rope_forward_qk_with_rotary_dim().
Referenced by ck_layer_forward_rmsnorm_swiglu(), ck_layer_forward_rmsnorm_swiglu_decode(), ck_layer_forward_rmsnorm_swiglu_decode_fused(), ck_layer_forward_rmsnorm_swiglu_decode_fused_attn_impl(), ck_layer_forward_rmsnorm_swiglu_decode_q4_k(), ck_layer_forward_rmsnorm_swiglu_decode_quant(), ck_layer_forward_rmsnorm_swiglu_q4_k(), ck_layer_forward_rmsnorm_swiglu_quant(), ck_layer_forward_rmsnorm_swiglu_ref(), ck_test_rope(), qwen2_0_5b_decode_layer_0_decode(), qwen2_0_5b_decode_layer_0_decode(), qwen2_0_5b_decode_layer_0_decode(), qwen2_0_5b_decode_layer_0_prefill(), qwen2_0_5b_decode_layer_0_prefill(), qwen2_0_5b_decode_layer_10_decode(), qwen2_0_5b_decode_layer_10_decode(), qwen2_0_5b_decode_layer_10_decode(), qwen2_0_5b_decode_layer_10_prefill(), qwen2_0_5b_decode_layer_10_prefill(), qwen2_0_5b_decode_layer_11_decode(), qwen2_0_5b_decode_layer_11_decode(), qwen2_0_5b_decode_layer_11_decode(), qwen2_0_5b_decode_layer_11_prefill(), qwen2_0_5b_decode_layer_11_prefill(), qwen2_0_5b_decode_layer_12_decode(), qwen2_0_5b_decode_layer_12_decode(), qwen2_0_5b_decode_layer_12_decode(), qwen2_0_5b_decode_layer_12_prefill(), qwen2_0_5b_decode_layer_12_prefill(), qwen2_0_5b_decode_layer_13_decode(), qwen2_0_5b_decode_layer_13_decode(), qwen2_0_5b_decode_layer_13_decode(), qwen2_0_5b_decode_layer_13_prefill(), qwen2_0_5b_decode_layer_13_prefill(), qwen2_0_5b_decode_layer_14_decode(), qwen2_0_5b_decode_layer_14_decode(), qwen2_0_5b_decode_layer_14_decode(), qwen2_0_5b_decode_layer_14_prefill(), qwen2_0_5b_decode_layer_14_prefill(), qwen2_0_5b_decode_layer_15_decode(), qwen2_0_5b_decode_layer_15_decode(), qwen2_0_5b_decode_layer_15_decode(), qwen2_0_5b_decode_layer_15_prefill(), qwen2_0_5b_decode_layer_15_prefill(), qwen2_0_5b_decode_layer_16_decode(), qwen2_0_5b_decode_layer_16_decode(), qwen2_0_5b_decode_layer_16_decode(), qwen2_0_5b_decode_layer_16_prefill(), qwen2_0_5b_decode_layer_16_prefill(), qwen2_0_5b_decode_layer_17_decode(), qwen2_0_5b_decode_layer_17_decode(), qwen2_0_5b_decode_layer_17_decode(), qwen2_0_5b_decode_layer_17_prefill(), qwen2_0_5b_decode_layer_17_prefill(), qwen2_0_5b_decode_layer_18_decode(), qwen2_0_5b_decode_layer_18_decode(), qwen2_0_5b_decode_layer_18_decode(), qwen2_0_5b_decode_layer_18_prefill(), qwen2_0_5b_decode_layer_18_prefill(), qwen2_0_5b_decode_layer_19_decode(), qwen2_0_5b_decode_layer_19_decode(), qwen2_0_5b_decode_layer_19_decode(), qwen2_0_5b_decode_layer_19_prefill(), qwen2_0_5b_decode_layer_19_prefill(), qwen2_0_5b_decode_layer_1_decode(), qwen2_0_5b_decode_layer_1_decode(), qwen2_0_5b_decode_layer_1_decode(), qwen2_0_5b_decode_layer_1_prefill(), qwen2_0_5b_decode_layer_1_prefill(), qwen2_0_5b_decode_layer_20_decode(), qwen2_0_5b_decode_layer_20_decode(), qwen2_0_5b_decode_layer_20_decode(), qwen2_0_5b_decode_layer_20_prefill(), qwen2_0_5b_decode_layer_20_prefill(), qwen2_0_5b_decode_layer_21_decode(), qwen2_0_5b_decode_layer_21_decode(), qwen2_0_5b_decode_layer_21_decode(), qwen2_0_5b_decode_layer_21_prefill(), qwen2_0_5b_decode_layer_21_prefill(), qwen2_0_5b_decode_layer_22_decode(), qwen2_0_5b_decode_layer_22_decode(), qwen2_0_5b_decode_layer_22_decode(), qwen2_0_5b_decode_layer_22_prefill(), qwen2_0_5b_decode_layer_22_prefill(), qwen2_0_5b_decode_layer_23_decode(), qwen2_0_5b_decode_layer_23_decode(), qwen2_0_5b_decode_layer_23_decode(), qwen2_0_5b_decode_layer_23_prefill(), qwen2_0_5b_decode_layer_23_prefill(), qwen2_0_5b_decode_layer_2_decode(), qwen2_0_5b_decode_layer_2_decode(), qwen2_0_5b_decode_layer_2_decode(), qwen2_0_5b_decode_layer_2_prefill(), qwen2_0_5b_decode_layer_2_prefill(), qwen2_0_5b_decode_layer_3_decode(), qwen2_0_5b_decode_layer_3_decode(), qwen2_0_5b_decode_layer_3_decode(), qwen2_0_5b_decode_layer_3_prefill(), qwen2_0_5b_decode_layer_3_prefill(), qwen2_0_5b_decode_layer_4_decode(), qwen2_0_5b_decode_layer_4_decode(), qwen2_0_5b_decode_layer_4_decode(), qwen2_0_5b_decode_layer_4_prefill(), qwen2_0_5b_decode_layer_4_prefill(), qwen2_0_5b_decode_layer_5_decode(), qwen2_0_5b_decode_layer_5_decode(), qwen2_0_5b_decode_layer_5_decode(), qwen2_0_5b_decode_layer_5_prefill(), qwen2_0_5b_decode_layer_5_prefill(), qwen2_0_5b_decode_layer_6_decode(), qwen2_0_5b_decode_layer_6_decode(), qwen2_0_5b_decode_layer_6_decode(), qwen2_0_5b_decode_layer_6_prefill(), qwen2_0_5b_decode_layer_6_prefill(), qwen2_0_5b_decode_layer_7_decode(), qwen2_0_5b_decode_layer_7_decode(), qwen2_0_5b_decode_layer_7_decode(), qwen2_0_5b_decode_layer_7_prefill(), qwen2_0_5b_decode_layer_7_prefill(), qwen2_0_5b_decode_layer_8_decode(), qwen2_0_5b_decode_layer_8_decode(), qwen2_0_5b_decode_layer_8_decode(), qwen2_0_5b_decode_layer_8_prefill(), qwen2_0_5b_decode_layer_8_prefill(), qwen2_0_5b_decode_layer_9_decode(), qwen2_0_5b_decode_layer_9_decode(), qwen2_0_5b_decode_layer_9_decode(), qwen2_0_5b_decode_layer_9_prefill(), and qwen2_0_5b_decode_layer_9_prefill().
| void rope_forward_qk_gemma4_direct | ( | float * | q, |
| float * | k, | ||
| const float * | freq_factors, | ||
| int | use_freq_factors, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | rotary_dim, | ||
| float | freq_base | ||
| ) |
Definition at line 1317 of file rope_kernels.c.
References rope_forward_qk_split_direct_f32().
| void rope_forward_qk_gemma4v_vision_xy | ( | float * | q, |
| float * | k, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | grid_w, | ||
| int | rotary_dim, | ||
| float | freq_base | ||
| ) |
Definition at line 1404 of file rope_kernels.c.
References rope_forward_gemma4v_vision_xy_one().
| void rope_forward_qk_pairwise_llama_cpu | ( | 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, | ||
| int | rotary_dim | ||
| ) |
Definition at line 1540 of file rope_kernels.c.
References rope_apply_decode_pairwise_llama_cpu(), and token.
| void rope_forward_qk_pairwise_with_rotary_dim | ( | 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, | ||
| int | rotary_dim | ||
| ) |
Definition at line 1483 of file rope_kernels.c.
References rope_apply_head_pairwise().
| void rope_forward_qk_split_direct_f32 | ( | float * | q, |
| float * | k, | ||
| const float * | freq_factors, | ||
| int | use_freq_factors, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | rotary_dim, | ||
| float | freq_base | ||
| ) |
Definition at line 1180 of file rope_kernels.c.
References rope_forward_split_direct_one().
Referenced by rope_forward_qk_gemma4_direct().
| void rope_forward_qk_split_direct_token_range_f32 | ( | float * | q, |
| float * | k, | ||
| const float * | freq_factors, | ||
| int | use_freq_factors, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | rotary_dim, | ||
| float | freq_base, | ||
| int | token_begin, | ||
| int | token_end | ||
| ) |
Definition at line 1201 of file rope_kernels.c.
| void rope_forward_qk_split_llama_token_range_f32 | ( | float * | q, |
| float * | k, | ||
| const float * | freq_factors, | ||
| int | use_freq_factors, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | rotary_dim, | ||
| float | freq_base, | ||
| int | token_begin, | ||
| int | token_end | ||
| ) |
Definition at line 1265 of file rope_kernels.c.
References ck_rope_reference_cosf(), ck_rope_reference_powf(), and ck_rope_reference_sinf().
| void rope_forward_qk_strided | ( | 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, | ||
| int | q_stride_tokens, | ||
| int | k_stride_tokens | ||
| ) |
RoPE forward for both Q and K with custom strides (KV cache layouts)
test_rope.py::TestRoPEForward::test_rope_forward_qk_strided
test_kv_cache_attention.py::TestKVCacheAttention::test_qk_rope_strided
Combined QK RoPE with configurable strides for KV cache layouts.
After changes: make test
Definition at line 2778 of file rope_kernels.c.
References rope_forward_qk_strided_with_rotary_dim().
Referenced by mega_fused_attention_prefill(), mega_fused_attention_prefill_q8_0(), model_layer_0_prefill(), model_layer_0_prefill(), model_layer_0_prefill(), model_layer_0_prefill(), model_layer_10_prefill(), model_layer_10_prefill(), model_layer_10_prefill(), model_layer_10_prefill(), model_layer_11_prefill(), model_layer_11_prefill(), model_layer_11_prefill(), model_layer_11_prefill(), model_layer_12_prefill(), model_layer_12_prefill(), model_layer_12_prefill(), model_layer_12_prefill(), model_layer_13_prefill(), model_layer_13_prefill(), model_layer_13_prefill(), model_layer_13_prefill(), model_layer_14_prefill(), model_layer_14_prefill(), model_layer_14_prefill(), model_layer_14_prefill(), model_layer_15_prefill(), model_layer_15_prefill(), model_layer_15_prefill(), model_layer_15_prefill(), model_layer_16_prefill(), model_layer_16_prefill(), model_layer_16_prefill(), model_layer_16_prefill(), model_layer_17_prefill(), model_layer_17_prefill(), model_layer_17_prefill(), model_layer_17_prefill(), model_layer_18_prefill(), model_layer_18_prefill(), model_layer_18_prefill(), model_layer_18_prefill(), model_layer_19_prefill(), model_layer_19_prefill(), model_layer_19_prefill(), model_layer_19_prefill(), model_layer_1_prefill(), model_layer_1_prefill(), model_layer_1_prefill(), model_layer_1_prefill(), model_layer_20_prefill(), model_layer_20_prefill(), model_layer_20_prefill(), model_layer_20_prefill(), model_layer_21_prefill(), model_layer_21_prefill(), model_layer_21_prefill(), model_layer_21_prefill(), model_layer_22_prefill(), model_layer_22_prefill(), model_layer_22_prefill(), model_layer_22_prefill(), model_layer_23_prefill(), model_layer_23_prefill(), model_layer_23_prefill(), model_layer_23_prefill(), model_layer_2_prefill(), model_layer_2_prefill(), model_layer_2_prefill(), model_layer_2_prefill(), model_layer_3_prefill(), model_layer_3_prefill(), model_layer_3_prefill(), model_layer_3_prefill(), model_layer_4_prefill(), model_layer_4_prefill(), model_layer_4_prefill(), model_layer_4_prefill(), model_layer_5_prefill(), model_layer_5_prefill(), model_layer_5_prefill(), model_layer_5_prefill(), model_layer_6_prefill(), model_layer_6_prefill(), model_layer_6_prefill(), model_layer_6_prefill(), model_layer_7_prefill(), model_layer_7_prefill(), model_layer_7_prefill(), model_layer_7_prefill(), model_layer_8_prefill(), model_layer_8_prefill(), model_layer_8_prefill(), model_layer_8_prefill(), model_layer_9_prefill(), model_layer_9_prefill(), model_layer_9_prefill(), model_layer_9_prefill(), qwen2_0_5b_decode_layer_0_prefill(), qwen2_0_5b_decode_layer_0_prefill(), qwen2_0_5b_decode_layer_10_prefill(), qwen2_0_5b_decode_layer_10_prefill(), qwen2_0_5b_decode_layer_11_prefill(), qwen2_0_5b_decode_layer_11_prefill(), qwen2_0_5b_decode_layer_12_prefill(), qwen2_0_5b_decode_layer_12_prefill(), qwen2_0_5b_decode_layer_13_prefill(), qwen2_0_5b_decode_layer_13_prefill(), qwen2_0_5b_decode_layer_14_prefill(), qwen2_0_5b_decode_layer_14_prefill(), qwen2_0_5b_decode_layer_15_prefill(), qwen2_0_5b_decode_layer_15_prefill(), qwen2_0_5b_decode_layer_16_prefill(), qwen2_0_5b_decode_layer_16_prefill(), qwen2_0_5b_decode_layer_17_prefill(), qwen2_0_5b_decode_layer_17_prefill(), qwen2_0_5b_decode_layer_18_prefill(), qwen2_0_5b_decode_layer_18_prefill(), qwen2_0_5b_decode_layer_19_prefill(), qwen2_0_5b_decode_layer_19_prefill(), qwen2_0_5b_decode_layer_1_prefill(), qwen2_0_5b_decode_layer_1_prefill(), qwen2_0_5b_decode_layer_20_prefill(), qwen2_0_5b_decode_layer_20_prefill(), qwen2_0_5b_decode_layer_21_prefill(), qwen2_0_5b_decode_layer_21_prefill(), qwen2_0_5b_decode_layer_22_prefill(), qwen2_0_5b_decode_layer_22_prefill(), qwen2_0_5b_decode_layer_23_prefill(), qwen2_0_5b_decode_layer_23_prefill(), qwen2_0_5b_decode_layer_2_prefill(), qwen2_0_5b_decode_layer_2_prefill(), qwen2_0_5b_decode_layer_3_prefill(), qwen2_0_5b_decode_layer_3_prefill(), qwen2_0_5b_decode_layer_4_prefill(), qwen2_0_5b_decode_layer_4_prefill(), qwen2_0_5b_decode_layer_5_prefill(), qwen2_0_5b_decode_layer_5_prefill(), qwen2_0_5b_decode_layer_6_prefill(), qwen2_0_5b_decode_layer_6_prefill(), qwen2_0_5b_decode_layer_7_prefill(), qwen2_0_5b_decode_layer_7_prefill(), qwen2_0_5b_decode_layer_8_prefill(), qwen2_0_5b_decode_layer_8_prefill(), qwen2_0_5b_decode_layer_9_prefill(), and qwen2_0_5b_decode_layer_9_prefill().
| void rope_forward_qk_strided_with_rotary_dim | ( | 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, | ||
| int | q_stride_tokens, | ||
| int | k_stride_tokens, | ||
| int | rotary_dim | ||
| ) |
Definition at line 2796 of file rope_kernels.c.
References rope_forward_strided_with_rotary_dim().
Referenced by rope_forward_qk_strided().
| void rope_forward_qk_with_rotary_dim | ( | 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, | ||
| int | rotary_dim | ||
| ) |
Definition at line 1109 of file rope_kernels.c.
References rope_forward_with_rotary_dim().
Referenced by rope_forward_qk().
| void rope_forward_qk_with_rotary_dim_cache_stride | ( | 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, | ||
| int | rotary_dim, | ||
| int | cache_rotary_dim | ||
| ) |
Definition at line 1419 of file rope_kernels.c.
|
static |
Definition at line 1128 of file rope_kernels.c.
Referenced by rope_forward_q_split_direct_f32(), and rope_forward_qk_split_direct_f32().
| void rope_forward_strided | ( | float * | x, |
| const float * | cos_cache, | ||
| const float * | sin_cache, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | head_stride_tokens | ||
| ) |
RoPE forward with custom head stride (for KV cache layouts)
test_rope.py::TestRoPEForward::test_rope_strided
test_kv_cache_attention.py::TestKVCacheAttention::test_rope_decode
Variant with configurable head_stride_tokens for non-contiguous head layouts.
After changes: make test
Definition at line 837 of file rope_kernels.c.
References rope_forward_strided_with_rotary_dim().
| void rope_forward_strided_with_rotary_dim | ( | float * | x, |
| const float * | cos_cache, | ||
| const float * | sin_cache, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | head_stride_tokens, | ||
| int | rotary_dim | ||
| ) |
Definition at line 852 of file rope_kernels.c.
References rope_apply_head().
Referenced by rope_forward_qk_strided_with_rotary_dim(), and rope_forward_strided().
| void rope_forward_with_rotary_dim | ( | float * | x, |
| const float * | cos_cache, | ||
| const float * | sin_cache, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | pos_offset, | ||
| int | rotary_dim | ||
| ) |
Definition at line 809 of file rope_kernels.c.
References rope_apply_head().
Referenced by rope_forward(), rope_forward_bf16_with_rotary_dim(), and rope_forward_qk_with_rotary_dim().
| 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 | ||
| ) |
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().
| void rope_precompute_cache_llama_cpu | ( | 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 | ||
| ) |
Definition at line 560 of file rope_kernels.c.
References ck_rope_reference_cosf(), ck_rope_reference_powf(), and ck_rope_reference_sinf().
| void rope_precompute_cache_split | ( | float * | cos_cache, |
| float * | sin_cache, | ||
| int | max_seq_len, | ||
| int | head_dim, | ||
| float | base | ||
| ) |
Precompute RoPE cos/sin cache (split layout: head_dim/2) Legacy layout used before rotary_dim/scaling support.
| cos_cache | Output: [max_seq_len, head_dim/2] cos values |
| sin_cache | Output: [max_seq_len, head_dim/2] sin values |
| max_seq_len | Maximum sequence length for cache |
| head_dim | Full head dimension |
| base | RoPE base frequency (theta) |
Definition at line 340 of file rope_kernels.c.
|
static |
Definition at line 2106 of file rope_kernels.c.
References mrope_rotate_pair(), text_mrope_yarn(), and vision_mrope_yarn_corr_dims().
Referenced by mrope_qk_text(), and mrope_qk_text_imrope().
|
static |
Definition at line 2397 of file rope_kernels.c.
References bf16_to_float(), ck_rope_reference_cosf(), ck_rope_reference_powf(), ck_rope_reference_sinf(), and float_to_bf16().
Referenced by mrope_qk_text_imrope_positions_bf16_pytorch_storage().
|
static |
Definition at line 2343 of file rope_kernels.c.
References bf16_to_float(), ck_rope_reference_cosf(), ck_rope_reference_powf(), ck_rope_reference_sinf(), and float_to_bf16().
Referenced by mrope_qk_text_imrope_bf16_pytorch_storage().
|
static |
Definition at line 1648 of file rope_kernels.c.
References ck_rope_reference_cosf(), ck_rope_reference_sinf(), and vision_mrope_yarn_ramp().
Referenced by text_mrope_apply_head().
|
static |
Definition at line 1687 of file rope_kernels.c.
References ck_rope_reference_powf(), mrope_rotate_pair(), vision_mrope_yarn(), and vision_mrope_yarn_corr_dims().
Referenced by mrope_qk_vision().
|
static |
Definition at line 1624 of file rope_kernels.c.
References ck_rope_reference_cosf(), ck_rope_reference_sinf(), and vision_mrope_yarn_ramp().
Referenced by explicit_mrope_apply_head(), and vision_mrope_apply_head().
|
static |
Definition at line 1601 of file rope_kernels.c.
References M_PI.
Referenced by vision_mrope_yarn_corr_dims().
|
static |
Definition at line 1605 of file rope_kernels.c.
References end, start, and vision_mrope_yarn_corr_dim().
Referenced by explicit_mrope_apply_head(), text_mrope_apply_head(), and vision_mrope_apply_head().
|
static |
Definition at line 1619 of file rope_kernels.c.
Referenced by text_mrope_yarn(), and vision_mrope_yarn().
|
static |
Definition at line 426 of file rope_kernels.c.
References M_PI.
Referenced by yarn_rope_cache_explicit_positions_impl().
|
static |
Definition at line 436 of file rope_kernels.c.
Referenced by yarn_rope_cache_explicit_positions_impl().
| void yarn_rope_cache_contiguous_positions_f32 | ( | float * | cos_cache, |
| float * | sin_cache, | ||
| int | num_tokens, | ||
| int | rotary_dim, | ||
| float | freq_base, | ||
| float | factor, | ||
| int | original_context, | ||
| float | beta_fast, | ||
| float | beta_slow, | ||
| float | mscale, | ||
| float | mscale_all_dim | ||
| ) |
Definition at line 517 of file rope_kernels.c.
References yarn_rope_cache_explicit_positions_impl().
| void yarn_rope_cache_explicit_positions_bf16 | ( | uint16_t * | cos_cache, |
| uint16_t * | sin_cache, | ||
| const int32_t * | positions, | ||
| int | num_tokens, | ||
| int | rotary_dim, | ||
| float | freq_base, | ||
| float | factor, | ||
| int | original_context, | ||
| float | beta_fast, | ||
| float | beta_slow, | ||
| float | mscale, | ||
| float | mscale_all_dim | ||
| ) |
Definition at line 535 of file rope_kernels.c.
References yarn_rope_cache_explicit_positions_impl().
| void yarn_rope_cache_explicit_positions_f32 | ( | float * | cos_cache, |
| float * | sin_cache, | ||
| const int32_t * | positions, | ||
| int | num_tokens, | ||
| int | rotary_dim, | ||
| float | freq_base, | ||
| float | factor, | ||
| int | original_context, | ||
| float | beta_fast, | ||
| float | beta_slow, | ||
| float | mscale, | ||
| float | mscale_all_dim | ||
| ) |
Definition at line 498 of file rope_kernels.c.
References yarn_rope_cache_explicit_positions_impl().
|
static |
Definition at line 441 of file rope_kernels.c.
References ck_rope_reference_cosf(), ck_rope_reference_powf(), ck_rope_reference_sinf(), float_to_bf16(), token, yarn_correction_dim(), and yarn_mscale().
Referenced by yarn_rope_cache_contiguous_positions_f32(), yarn_rope_cache_explicit_positions_bf16(), and yarn_rope_cache_explicit_positions_f32().