Attention score/softmax/output kernels with SIMD (SSE/AVX/AVX512) More...
#include "bf16_utils.h"#include "attention_oracle_ggml.h"#include "ckernel_engine.h"#include "ck_threadpool.h"#include <dlfcn.h>#include <limits.h>#include <math.h>#include <float.h>#include <pthread.h>#include <stdio.h>#include <stdlib.h>#include "ck_speed_profiles.h"#include <string.h>Go to the source code of this file.
Macros | |
| #define | CK_ENABLE_LLAMA_CPP_PARITY 0 |
| #define | CK_GGML_FA_TILE_KV 64 |
| #define | CK_GGML_FA_TILE_Q 64 |
| #define | CK_GGML_FA_TILE_Q_LARGE 336 |
| #define | CK_GGML_FA_TILE_Q_LARGE_MIN_TOKENS 1536 |
| #define | CK_NOINLINE |
| #define | CK_OPTNONE |
| #define | FLASH_QUERY_IMPL attention_flash_query_causal |
| #define | FLASH_QUERY_IMPL attention_flash_query_causal |
| #define | FLASH_QUERY_IMPL_DECODE attention_flash_query_causal |
| #define | RTLD_DEFAULT ((void *)0) |
Typedefs | |
| typedef float(* | ck_attention_math_f32_fn) (float) |
Functions | |
| void | attention_backward_causal_head_major (const float *d_output, const float *q, const float *k, const float *v, const float *attn_weights, float *d_q, float *d_k, float *d_v, float *d_scores, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int aligned_context_window) |
| void | attention_backward_causal_head_major_gqa (const float *d_output, const float *q, const float *k, const float *v, const float *attn_weights, float *d_q, float *d_k, float *d_v, float *d_scores, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int aligned_context_window) |
| void | attention_backward_causal_head_major_gqa_bf16 (const uint16_t *d_output, float *d_x, const uint16_t *q, const uint16_t *k, const uint16_t *v, const float *attn_weights, float *d_q, float *d_k, float *d_v, float *d_scores, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int aligned_context_window, float *scratch_d_output, float *scratch_q, float *scratch_k, float *scratch_v) |
| static void | attention_flash_query_causal (const float *q_vec, const float *k_head, const float *v_head, int kv_tokens, int head_dim, int aligned_head_dim, float scale, float *out_vec) |
| static void | attention_flash_query_causal_exact (const float *q_vec, const float *k_head, const float *v_head, int kv_tokens, int head_dim, int aligned_head_dim, float scale, float *out_vec) |
| static void | attention_flash_query_causal_exact_f16kv (const float *q_vec, const float *k_head, const float *v_head, int kv_tokens, int head_dim, int aligned_head_dim, float scale, float *out_vec) |
| static void | attention_flash_query_causal_exact_prerounded_f16kv (const float *q_vec, const float *k_head, const float *v_head, int kv_tokens, int head_dim, int aligned_head_dim, float scale, float *out_vec) |
| void | attention_forward_causal_head_major (const float *q, const float *k, const float *v, float *scores, float *output, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int aligned_context_window) |
| void | attention_forward_causal_head_major_exact (const float *q, const float *k, const float *v, float *scores, float *output, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int aligned_context_window) |
| void | attention_forward_causal_head_major_gqa (const float *q, const float *k, const float *v, float *scores, float *output, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int aligned_context_window) |
| void | attention_forward_causal_head_major_gqa_bf16 (const uint16_t *q, const uint16_t *k, const uint16_t *v, float *scores, float *output, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int aligned_context_window, float *scratch_q, float *scratch_k, float *scratch_v) |
| void | attention_forward_causal_head_major_gqa_exact (const float *q, const float *k, const float *v, float *scores, float *output, int num_heads, int num_kv_heads, int num_tokens, int head_dim, int aligned_head_dim, int aligned_context_window) |
| void | attention_forward_causal_head_major_gqa_flash (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) |
| 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 | attention_forward_causal_head_major_gqa_flash_strided_f16kv (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 | attention_forward_causal_head_major_gqa_flash_strided_f16kv_serial (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 | attention_forward_causal_head_major_gqa_flash_strided_f16kv_workspace (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, float *rounded_kv, size_t rounded_kv_bytes) |
| void | attention_forward_causal_head_major_gqa_flash_strided_gemma4 (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 | attention_forward_causal_head_major_gqa_flash_strided_gemma4_token_output (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 | attention_forward_causal_head_major_gqa_flash_strided_token_output (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 | attention_forward_causal_head_major_gqa_llama_regular_strided_sliding_workspace (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, int sliding_window, float *scores, size_t scores_bytes, float *value_columns, size_t value_columns_bytes, float *scaled_scores, size_t scaled_scores_bytes) |
| ck_attention_status_t | attention_forward_causal_head_major_gqa_prefill_append_bf16cache_pytorch_contract (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_reduction_t reduction) |
| ck_attention_status_t | attention_forward_causal_head_major_gqa_prefill_append_bf16cache_pytorch_contract_workspace (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_reduction_t reduction, float *token_workspace, size_t token_workspace_bytes) |
| ck_attention_status_t | attention_forward_causal_head_major_gqa_prefill_append_f16cache_auto_workspace (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_reduction_t reduction, float *token_workspace, size_t token_workspace_bytes, void *gqa_workspace, size_t gqa_workspace_bytes, int route_num_heads, int route_num_kv_heads, int route_head_dim, int route_query_tokens, int route_min_kv_tokens, int route_workers, int route_query_tile_size, int route_concurrent_query_tiles) |
| ck_attention_status_t | attention_forward_causal_head_major_gqa_prefill_append_f16cache_contract (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_reduction_t reduction) |
| ck_attention_status_t | attention_forward_causal_head_major_gqa_prefill_append_f16cache_contract_workspace (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_reduction_t reduction, float *token_workspace, size_t token_workspace_bytes) |
| ck_attention_status_t | attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_config (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, int query_tile_size, int concurrent_query_tiles, void *workspace, size_t workspace_bytes) |
| size_t | attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_workspace_bytes (int num_heads, int num_kv_heads, int head_dim, int workers, int query_tile_size, int concurrent_query_tiles) |
| ck_attention_status_t | attention_forward_causal_head_major_gqa_prefill_append_f16cache_qtile64_schedule (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_prefill_schedule_t schedule) |
| ck_attention_status_t | attention_forward_causal_head_major_gqa_prefill_full_bf16cache_pytorch_contract (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_reduction_t reduction) |
| ck_attention_status_t | attention_forward_causal_head_major_gqa_prefill_segmented_f16cache_contract_workspace (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_reduction_t reduction, float *token_workspace, size_t token_workspace_bytes, const int *segment_lengths, int num_segments) |
| void | attention_forward_causal_head_major_shared_kv_gemma4 (const float *q, float *output, int num_heads, int num_tokens, int head_dim, int aligned_head_dim, int kv_stride_tokens) |
| void | attention_forward_chunk_head_major_gqa_flash_gemma4 (const float *q_chunk, const float *k_cache, const float *v_cache, float *out_chunk, int num_heads, int num_kv_heads, int q_tokens, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim) |
| ck_attention_status_t | attention_forward_decode_head_major_gqa_bf16cache_pytorch_contract (const float *q_token, const uint16_t *k_cache, const uint16_t *v_cache, float *out_token, int num_heads, int num_kv_heads, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_reduction_t reduction) |
| void | attention_forward_decode_head_major_gqa_flash (const float *q_token, const float *k_cache, const float *v_cache, float *out_token, int num_heads, int num_kv_heads, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim) |
| void | attention_forward_decode_head_major_gqa_flash_f16cache (const float *q_token, const uint16_t *k_cache, const uint16_t *v_cache, float *out_token, int num_heads, int num_kv_heads, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim) |
| ck_attention_status_t | attention_forward_decode_head_major_gqa_flash_f16cache_contract (const float *q_token, const uint16_t *k_cache, const uint16_t *v_cache, float *out_token, int num_heads, int num_kv_heads, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_reduction_t reduction) |
| void | attention_forward_decode_head_major_gqa_flash_f16cache_split (const float *q_token, const uint16_t *k_cache, const uint16_t *v_cache, float *out_token, int num_heads, int num_kv_heads, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim, int split_chunks) |
| static void | attention_forward_decode_head_major_gqa_flash_f16cache_split_partitioned (const float *q_token, const uint16_t *k_cache, const uint16_t *v_cache, float *out_token, int num_heads, int num_kv_heads, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim, int split_chunks, int partition_tokens) |
| void | attention_forward_decode_head_major_gqa_flash_f16kv (const float *q_token, const float *k_cache, const float *v_cache, float *out_token, int num_heads, int num_kv_heads, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim) |
| void | attention_forward_decode_head_major_gqa_flash_gemma4 (const float *q_token, const float *k_cache, const float *v_cache, float *out_token, int num_heads, int num_kv_heads, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim) |
| void | attention_forward_decode_head_major_gqa_llama_regular_sliding_workspace (const float *q, const float *k, const float *v, float *output, int num_heads, int num_kv_heads, int live_tokens, int kv_stride_tokens, int head_dim, int aligned_head_dim, int sliding_window, float *scores, size_t scores_bytes, float *value_columns, size_t value_columns_bytes, float *scaled_scores, size_t scaled_scores_bytes) |
| void | attention_forward_decode_head_major_gqa_regular (const float *q_token, const float *k_cache, const float *v_cache, float *out_token, int num_heads, int num_kv_heads, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim) |
| WARNING: This is NOT true flash attention! | |
| void | attention_forward_decode_head_major_shared_kv_gemma4 (const float *q_token, const float *k_cache, const float *v_cache, float *out_token, int num_heads, int kv_tokens, int cache_capacity, int head_dim, int aligned_head_dim) |
| void | attention_forward_full_head_major_gqa_exact_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 | attention_forward_full_head_major_gqa_flash (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) |
| void | attention_forward_full_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 | attention_forward_full_head_major_gqa_flash_strided_bf16_storage (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 | attention_forward_full_head_major_gqa_flash_strided_gemma4 (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 | attention_forward_full_head_major_gqa_ggml_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 | attention_forward_full_head_major_gqa_ggml_strided_workspace (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, float *score_rows, size_t score_rows_bytes, float *v_columns, size_t v_columns_bytes, float *probability_row, size_t probability_row_bytes) |
| void | attention_forward_full_head_major_gqa_pytorch_cpu_flash_bf16_storage (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 | attention_forward_full_head_major_gqa_pytorch_cpu_flash_bf16_storage_token_output (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 | attention_forward_full_head_major_gqa_sdpa_bf16_storage (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 | attention_forward_full_head_major_gqa_tiled336_f16kv_fp32_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 | attention_forward_full_head_major_gqa_tiled64_f16kv_fp32_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 | attention_forward_full_head_major_gqa_tiled_f16kv_fp32_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) |
| static void | attention_forward_head_major_gqa_flash_impl (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, int causal, int round_full_kv_fp16, int output_token_major, float scale) |
| static int | attention_forward_head_major_gqa_unfused_f16_strict (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, int causal, int output_token_major, float scale, int debug_layer_id) |
| void | attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4 (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, int visual_start, int visual_tokens) |
| static void | attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_impl (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, int visual_start, int visual_tokens, int output_token_major) |
| void | attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_token_output (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, int visual_start, int visual_tokens) |
| int | attention_forward_query_key_head_major_f32 (const float *query, const float *key, const float *value, float *output, float *score_scratch, int num_heads, int query_tokens, int key_tokens, int head_dim, float scale) |
| int | attention_forward_query_key_head_major_f32_packed_k (const float *query, const float *key, const float *value, float *output, float *score_scratch, float *key_transpose_scratch, int num_heads, int query_tokens, int key_tokens, int head_dim, float scale) |
| int | attention_forward_query_key_head_major_tiled_f16kv_fp32 (const float *query, const float *key, const float *value, float *output, int num_heads, int query_tokens, int key_tokens, int head_dim, float scale) |
| void | attention_forward_sparse_token_major_gqa_bf16cache_pytorch_cpu_flash_contract (const float *query, const uint16_t *key_cache, const uint16_t *value_cache, const float *selected_indices, float *output, float *score_scratch, int rows, int query_heads, int kv_heads, int head_dim, int selection_width, int context_length, int position) |
| static size_t | attention_output_index (int h, int token, int num_heads, int num_tokens, int aligned_head_dim, int token_major) |
| static void | attention_query_full_exact_regular (const float *q_vec, const float *k_head, const float *v_cols, int kv_tokens, int head_dim, int aligned_head_dim, float scale, float *score_row, float *out_vec, int layer_id, int head_id, int query_id) |
| static void | attention_query_full_ggml_regular (const float *q_vec, const float *k_head, const float *v_cols, int kv_tokens, int head_dim, int aligned_head_dim, float scale, float *score_row, float *out_vec, int layer_id, int head_id, int query_id) |
| static size_t | ck_attention_align64_size (size_t value) |
| static void | ck_attention_bf16_pytorch_flash_work (int ith, int nth, void *opaque) |
| int | ck_attention_bf16_pytorch_gqa_available (void) |
| static void | ck_attention_bf16_sdpa_work (int ith, int nth, void *opaque) |
| static void | ck_attention_causal_f16kv_work (int ith, int nth, void *opaque) |
| static float | ck_attention_dot_f16_llama (const uint16_t *x, const uint16_t *y, int n) |
| static float | ck_attention_dot_f16_unfused_llama (const uint16_t *x, const uint16_t *y, int n) |
| static void | ck_attention_f16_prefill_gqa_reuse_work (int ith, int nth, void *opaque) |
| static size_t | ck_attention_f16_prefill_gqa_reuse_worker_bytes (int num_heads, int num_kv_heads, int head_dim, int workers, int query_tile_size, int concurrent_query_tiles) |
| static ck_attention_status_t | ck_attention_f16_prefill_qtile64_dispatch (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, int cache_is_bf16, size_t q_head_stride, size_t output_head_stride, ck_attention_prefill_schedule_t schedule) |
| static void | ck_attention_f16_prefill_qtile64_work (int ith, int nth, void *opaque) |
| static float | ck_attention_f16_reduce_expf (float value) |
| static void | ck_attention_f16_split_work (int ith, int nth, void *opaque) |
| static void | ck_attention_flash_query_auto (const float *q_vec, const float *k_head, const float *v_head, int kv_tokens, int head_dim, int aligned_head_dim, float scale, float *out_vec) |
| static ck_attention_status_t | ck_attention_forward_causal_head_major_gqa_prefill_segmented_f16cache_schedule_workspace (const float *q, const uint16_t *k_cache, const uint16_t *v_cache, float *output, int num_heads, int num_kv_heads, int q_tokens, int past_tokens, int cache_capacity, int head_dim, int aligned_head_dim, ck_attention_reduction_t reduction, float *token_workspace, size_t token_workspace_bytes, const int *segment_lengths, int num_segments, ck_attention_prefill_schedule_t schedule) |
| static void | ck_attention_forward_full_head_major_gqa_tiled_f16kv_fp32_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, int query_tile_size) |
| static int | ck_attention_forward_query_key_head_major_f32_run (const float *query, const float *key, const float *value, float *output, float *score_scratch, float *key_transpose_scratch, int num_heads, int query_tokens, int key_tokens, int head_dim, float scale) |
| static int | ck_attention_full_bf16_pytorch_flash (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, int output_token_major) |
| static int | ck_attention_full_bf16_sdpa_amx_range (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, int head_begin, int head_step, int output_token_major) |
| static int | ck_attention_full_bf16_sdpa_tiled (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) |
| static int | ck_attention_full_bf16_sdpa_tiled_range (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, int head_begin, int head_step) |
| static void | ck_attention_full_grid_work (int ith, int nth, void *opaque) |
| static void | ck_attention_full_tiled_f16kv_fp32_range (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, int query_tile_size, int ith, int nth) |
| static void | ck_attention_full_tiled_f16kv_fp32_work (int ith, int nth, void *opaque) |
| static int | ck_attention_ggml_out_graph_enabled (void) |
| static void | ck_attention_gqa_team_barrier_wait (ck_attention_gqa_team_barrier_t *barrier) |
| static void | ck_attention_llama_regular_impl (const float *q, const float *k, const float *v, float *output, int num_heads, int num_kv_heads, int query_tokens, int live_tokens, int head_dim, int aligned_head_dim, int kv_stride_tokens, int sliding_window, float *scores, size_t scores_bytes, float *value_columns, size_t value_columns_bytes, float *scaled_scores, size_t scaled_scores_bytes, int batched_prefill) |
| static void | ck_attention_llama_regular_query (const float *query, const float *key_head, const float *value_columns, float *output, float *scores, float *scaled_scores, int live_tokens, int padded_tokens, int query_position, int head_dim, int aligned_head_dim, int sliding_window, int batched_prefill) |
| static void | ck_attention_mad_f16_llama (uint16_t *y, const uint16_t *x, float scale, int n) |
| static void | ck_attention_matmul_f32_accum (float *c, const float *a, const float *b, int m, int k, int n) |
| static int | ck_attention_parallel_enabled (int total_queries, int num_tokens, int head_dim) |
| static int | ck_attention_pick_active_threads (const ck_threadpool_t *pool, int total_queries, int num_tokens) |
| float | ck_attention_pytorch_sdpa_scale_f32 (int head_dim) |
| static void | ck_attention_query_key_f32_transpose_work (int ith, int nth, void *opaque) |
| static void | ck_attention_query_key_f32_work (int ith, int nth, void *opaque) |
| static float | ck_attention_reference_expf (float value) |
| static int | ck_attention_reverse_out_dot_enabled (void) |
| static void | ck_attention_scale_f16_llama (uint16_t *y, float scale, int n) |
| int | ck_attention_sparse_bf16_pytorch_gqa_available (void) |
| static float | ck_attention_strict_scale_f32 (int head_dim) |
| static int | ck_attention_strict_unfused_f16_enabled (void) |
| static void | ck_attention_trace (const char *branch, int layer_id, int head_id) |
| static void | ck_attention_trace_float (const char *tag, int layer_id, int head_id, float value) |
| static void | ck_attention_trace_query (const char *tag, int layer_id, int head_id, int query_id, int value) |
| static float | ck_attention_u16_cache_to_f32 (uint16_t value, int cache_is_bf16) |
| static int | ck_attention_vec_dump_enabled (void) |
| static void | ck_attention_vec_dump_exact_query (const float *q_vec, const float *k_head, const float *out_vec, int kv_tokens, int head_dim, int aligned_head_dim, float scale, int layer_id, int head_id, int query_id) |
| static int | ck_attention_vec_dump_next_layer_id (void) |
| static int | ck_attention_vec_dump_parse_env_int (const char *name, int *out) |
| static void | ck_attention_vec_dump_selected_query (const float *raw_scores, const float *probs, const float *out_vec, const float *v_cols, int kv_tokens, int head_dim, int layer_id, int head_id, int query_id) |
| static int | ck_attention_vec_dump_should_emit (int layer_id, int head_id, int query_id) |
| static void | ck_attention_vec_dump_tensor (const char *name, int layer_id, int query_id, const float *data, size_t elem_count) |
| static int | ck_attention_vec_dump_vcols_enabled (void) |
| static float | ck_bf16_dot_contract (const float *a, const float *b, int count) |
| static float | ck_ggml_vec_dot_f32_contig (const float *x, const float *y, int n) |
| static double | ck_ggml_vec_soft_max_row (int n, float *y, const float *x, float max) |
| static int | ck_llama_kv_pad_256 (int live_tokens, int capacity) |
| static float | ck_llama_regular_dot_f16 (const float *a, const float *b, int count) |
| static float | ck_llama_regular_gemm_f16 (const float *probability, const float *value_column, int count) |
| static void | ck_local_fp16_to_fp32_2d (const uint16_t *src, float *dst, int rows, int cols, int src_stride, int dst_stride) |
| static void | ck_local_fp16_to_fp32_row (const uint16_t *src, float *dst, int n) |
| static void | ck_round_fp16_buffer (const float *src, float *dst, size_t count) |
| static float | ck_round_fp16_scalar (float x) |
| static float | ck_vec_dot_f32_reverse_strict (const float *x, const float *y, int n) |
| static float | ck_vec_dot_f32_strict (const float *x, const float *y, int n) |
| static float | ck_vec_dot_f32x_f32_to_f32_via_f64 (const float *x, const float *y, int n) |
| static float | ck_vec_max_f32_contig (const float *x, int n) |
| static void | ck_vec_scale_f32_inplace (float *x, int n, float scale) |
| static void | convert_bf16_tensor_to_buf (const uint16_t *src, float *dst, size_t count) |
| static size_t | qkv_index (int h, int t, int d, int num_tokens, int aligned_head_dim) |
| static size_t | score_index (int h, int i, int j, int aligned_context_window) |
Variables | |
| static int | ck_attention_vec_dump_layer_seq = 0 |
| static const char | ck_attention_vec_dump_magic [8] = {'C', 'K', 'D', 'M', 'P', '\0', '\0', '\0'} |
| static const uint32_t | ck_attention_vec_dump_version = 1u |
Attention score/softmax/output kernels with SIMD (SSE/AVX/AVX512)
After changes: make test && make llamacpp-parity-full
Attention: softmax(Q @ K^T / sqrt(d)) @ V Supports GQA (grouped-query attention) with head broadcasting.
Definition in file attention_kernels.c.
| #define CK_ENABLE_LLAMA_CPP_PARITY 0 |
Definition at line 19 of file attention_kernels.c.
| #define CK_GGML_FA_TILE_KV 64 |
Definition at line 2816 of file attention_kernels.c.
| #define CK_GGML_FA_TILE_Q 64 |
Definition at line 2814 of file attention_kernels.c.
| #define CK_GGML_FA_TILE_Q_LARGE 336 |
Definition at line 2815 of file attention_kernels.c.
| #define CK_GGML_FA_TILE_Q_LARGE_MIN_TOKENS 1536 |
Definition at line 2817 of file attention_kernels.c.
| #define CK_NOINLINE |
Definition at line 328 of file attention_kernels.c.
| #define CK_OPTNONE |
Definition at line 336 of file attention_kernels.c.
| #define FLASH_QUERY_IMPL attention_flash_query_causal |
| #define FLASH_QUERY_IMPL attention_flash_query_causal |
| #define FLASH_QUERY_IMPL_DECODE attention_flash_query_causal |
| #define RTLD_DEFAULT ((void *)0) |
Definition at line 32 of file attention_kernels.c.
| typedef float(* ck_attention_math_f32_fn) (float) |
Definition at line 1167 of file attention_kernels.c.
| void attention_backward_causal_head_major | ( | const float * | d_output, |
| const float * | q, | ||
| const float * | k, | ||
| const float * | v, | ||
| const float * | attn_weights, | ||
| float * | d_q, | ||
| float * | d_k, | ||
| float * | d_v, | ||
| float * | d_scores, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | aligned_context_window | ||
| ) |
Causal attention backward (non-GQA version)
test_attention_backward.py::TestAttentionBackward::test_backward
test_attention_backward.py::TestAttentionBackward::test_backward_vs_separate
test_parity.py::test_attention_backward_parity
Non-GQA version where num_heads == num_kv_heads. Simpler than GQA, no head broadcasting needed.
After changes: make test && make llamacpp-parity-full
Definition at line 9175 of file attention_kernels.c.
References attention_backward_causal_head_major_gqa().
| void attention_backward_causal_head_major_gqa | ( | const float * | d_output, |
| const float * | q, | ||
| const float * | k, | ||
| const float * | v, | ||
| const float * | attn_weights, | ||
| float * | d_q, | ||
| float * | d_k, | ||
| float * | d_v, | ||
| float * | d_scores, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | aligned_context_window | ||
| ) |
GQA causal attention backward (score-matrix version)
test_attention_backward.py::TestAttentionBackwardGQA::test_gqa_backward
test_attention_backward.py::TestAttentionBackwardGQA::test_gqa_vs_separate
test_parity.py::test_attention_backward_parity
Computes dQ, dK, dV given dOutput and attention weights. Supports grouped-query attention with head broadcasting.
After changes: make test && make llamacpp-parity-full
Definition at line 9036 of file attention_kernels.c.
References qkv_index(), and score_index().
Referenced by attention_backward_causal_head_major(), attention_backward_causal_head_major_gqa_bf16(), and ck_layer_backward_rmsnorm_swiglu().
| void attention_backward_causal_head_major_gqa_bf16 | ( | const uint16_t * | d_output, |
| float * | d_x, | ||
| const uint16_t * | q, | ||
| const uint16_t * | k, | ||
| const uint16_t * | v, | ||
| const float * | attn_weights, | ||
| float * | d_q, | ||
| float * | d_k, | ||
| float * | d_v, | ||
| float * | d_scores, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | aligned_context_window, | ||
| float * | scratch_d_output, | ||
| float * | scratch_q, | ||
| float * | scratch_k, | ||
| float * | scratch_v | ||
| ) |
BF16 attention backward with caller-provided scratch buffers
Accepts BF16 inputs, converts to FP32, runs FP32 backward. Caller provides scratch buffers (no per-call malloc).
After changes: make test
Definition at line 8983 of file attention_kernels.c.
References attention_backward_causal_head_major_gqa(), and convert_bf16_tensor_to_buf().
|
static |
Definition at line 1941 of file attention_kernels.c.
References score.
Referenced by ck_attention_flash_query_auto().
|
static |
Definition at line 2003 of file attention_kernels.c.
References score.
Referenced by attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_impl().
|
static |
Definition at line 2119 of file attention_kernels.c.
References ck_round_fp16_scalar(), and score.
Referenced by attention_forward_decode_head_major_gqa_flash_f16kv(), attention_forward_decode_head_major_gqa_regular(), and ck_attention_causal_f16kv_work().
|
static |
Definition at line 2194 of file attention_kernels.c.
References ck_round_fp16_buffer(), ck_round_fp16_scalar(), and score.
Referenced by ck_attention_causal_f16kv_work().
| void attention_forward_causal_head_major | ( | const float * | q, |
| const float * | k, | ||
| const float * | v, | ||
| float * | scores, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | aligned_context_window | ||
| ) |
Causal attention forward (score-matrix version)
test_attention.py::TestAttentionForward::test_causal_forward
test_attention.py::TestAttentionForward::test_gqa_broadcast
test_attention.py::TestAttentionForward::test_exact_vs_fast
test_parity.py::test_attention_parity
Computes softmax(Q @ K^T / sqrt(d)) @ V with causal masking. Uses O(N^2) memory for scores matrix.
After changes: make test && make llamacpp-parity-full
Definition at line 1281 of file attention_kernels.c.
References causal_softmax_head_major(), qkv_index(), and score_index().
| void attention_forward_causal_head_major_exact | ( | const float * | q, |
| const float * | k, | ||
| const float * | v, | ||
| float * | scores, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | aligned_context_window | ||
| ) |
Causal attention forward (exact version using stdlib expf)
test_attention.py::TestAttentionForward::test_exact_single
test_attention.py::TestAttentionForward::test_exact_vs_fast
Uses standard library expf for numerical accuracy reference. Slower but provides maximum accuracy.
After changes: make test
Definition at line 1357 of file attention_kernels.c.
References causal_softmax_head_major_exact(), qkv_index(), and score_index().
| void attention_forward_causal_head_major_gqa | ( | const float * | q, |
| const float * | k, | ||
| const float * | v, | ||
| float * | scores, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | aligned_context_window | ||
| ) |
GQA causal attention forward (score-matrix version)
test_attention.py::TestAttentionForward::test_gqa_forward
test_attention.py::TestAttentionForward::test_gqa_broadcast
test_attention_backward.py::TestAttentionBackwardGQA::test_gqa_backward
test_parity.py::test_attention_gqa_parity
Grouped-query attention: Q has num_heads, K/V have num_kv_heads. Each query head maps to a KV head via ratio.
After changes: make test && make llamacpp-parity-full
Definition at line 1435 of file attention_kernels.c.
References causal_softmax_head_major(), qkv_index(), and score_index().
Referenced by ck_layer_forward_rmsnorm_swiglu(), ck_layer_forward_rmsnorm_swiglu_q4_k(), ck_layer_forward_rmsnorm_swiglu_quant(), and ck_layer_forward_rmsnorm_swiglu_ref().
| void attention_forward_causal_head_major_gqa_bf16 | ( | const uint16_t * | q, |
| const uint16_t * | k, | ||
| const uint16_t * | v, | ||
| float * | scores, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | aligned_context_window, | ||
| float * | scratch_q, | ||
| float * | scratch_k, | ||
| float * | scratch_v | ||
| ) |
BF16 GQA causal attention forward
bf16/test_attention_bf16.py::TestAttentionBF16::test_bf16_forward
bf16/test_attention_bf16.py::TestAttentionBF16::test_bf16_gqa
bf16/test_attention_bf16.py::TestAttentionBF16::test_bf16_flash
Accepts BF16 inputs, converts to FP32, uses exact softmax. Caller provides scratch buffers (no per-call malloc).
After changes: make test
Definition at line 1577 of file attention_kernels.c.
References attention_forward_causal_head_major_gqa_exact(), and convert_bf16_tensor_to_buf().
| void attention_forward_causal_head_major_gqa_exact | ( | const float * | q, |
| const float * | k, | ||
| const float * | v, | ||
| float * | scores, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | aligned_context_window | ||
| ) |
GQA causal attention forward (exact version using stdlib expf)
test_attention.py::TestAttentionForward::test_gqa_exact
bf16/test_attention_bf16.py::TestAttentionBF16::test_bf16_gqa
Uses standard library expf for numerical accuracy reference. Used by BF16 wrapper to avoid approximation error accumulation.
After changes: make test
Definition at line 1505 of file attention_kernels.c.
References causal_softmax_head_major_exact(), qkv_index(), and score_index().
Referenced by attention_forward_causal_head_major_gqa_bf16(), ck_layer_forward_rmsnorm_swiglu(), and ck_layer_forward_rmsnorm_swiglu_ref().
| void attention_forward_causal_head_major_gqa_flash | ( | 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 | ||
| ) |
Definition at line 4370 of file attention_kernels.c.
References attention_forward_head_major_gqa_flash_impl().
Referenced by ck_layer_forward_rmsnorm_swiglu(), ck_layer_forward_rmsnorm_swiglu_q4_k(), ck_layer_forward_rmsnorm_swiglu_quant(), ck_layer_forward_rmsnorm_swiglu_ref(), 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 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 | ||
| ) |
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.
References attention_forward_head_major_gqa_flash_impl().
Referenced by attention_forward_causal_head_major_gqa_flash_strided_sliding(), ck_test_attention_causal(), 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 attention_forward_causal_head_major_gqa_flash_strided_f16kv | ( | 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 | ||
| ) |
Definition at line 5343 of file attention_kernels.c.
References attention_forward_causal_head_major_gqa_flash_strided_f16kv_serial(), and attention_forward_causal_head_major_gqa_flash_strided_f16kv_workspace().
| void attention_forward_causal_head_major_gqa_flash_strided_f16kv_serial | ( | 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 | ||
| ) |
Definition at line 5287 of file attention_kernels.c.
References ck_attention_causal_f16kv_work().
Referenced by attention_forward_causal_head_major_gqa_flash_strided_f16kv().
| void attention_forward_causal_head_major_gqa_flash_strided_f16kv_workspace | ( | 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, | ||
| float * | rounded_kv, | ||
| size_t | rounded_kv_bytes | ||
| ) |
Definition at line 5303 of file attention_kernels.c.
References ck_attention_causal_f16kv_work(), ck_round_fp16_buffer(), ck_threadpool_dispatch_n(), ck_threadpool_global(), and ck_threadpool_n_threads().
Referenced by attention_forward_causal_head_major_gqa_flash_strided_f16kv().
| void attention_forward_causal_head_major_gqa_flash_strided_gemma4 | ( | 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 | ||
| ) |
Definition at line 5024 of file attention_kernels.c.
References attention_forward_head_major_gqa_flash_impl().
Referenced by attention_forward_causal_head_major_gqa_flash_strided_sliding_gemma4_impl(), and attention_forward_causal_head_major_shared_kv_gemma4().
| void attention_forward_causal_head_major_gqa_flash_strided_gemma4_token_output | ( | 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 | ||
| ) |
Definition at line 5047 of file attention_kernels.c.
References attention_forward_head_major_gqa_flash_impl().
Referenced by attention_forward_causal_head_major_gqa_flash_strided_sliding_gemma4_impl().
| void attention_forward_causal_head_major_gqa_flash_strided_token_output | ( | 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 | ||
| ) |
Definition at line 4444 of file attention_kernels.c.
References attention_forward_head_major_gqa_flash_impl().
| void attention_forward_causal_head_major_gqa_llama_regular_strided_sliding_workspace | ( | 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, | ||
| int | sliding_window, | ||
| float * | scores, | ||
| size_t | scores_bytes, | ||
| float * | value_columns, | ||
| size_t | value_columns_bytes, | ||
| float * | scaled_scores, | ||
| size_t | scaled_scores_bytes | ||
| ) |
Definition at line 5960 of file attention_kernels.c.
References ck_attention_llama_regular_impl().
| ck_attention_status_t attention_forward_causal_head_major_gqa_prefill_append_bf16cache_pytorch_contract | ( | const float * | q, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | q_tokens, | ||
| int | past_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| ck_attention_reduction_t | reduction | ||
| ) |
Definition at line 8673 of file attention_kernels.c.
References attention_forward_causal_head_major_gqa_prefill_append_bf16cache_pytorch_contract_workspace(), CK_ATTENTION_STATUS_INVALID_ARGUMENT, and CK_GGML_FA_TILE_Q.
| ck_attention_status_t attention_forward_causal_head_major_gqa_prefill_append_bf16cache_pytorch_contract_workspace | ( | const float * | q, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | q_tokens, | ||
| int | past_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| ck_attention_reduction_t | reduction, | ||
| float * | token_workspace, | ||
| size_t | token_workspace_bytes | ||
| ) |
Definition at line 8596 of file attention_kernels.c.
References attention_forward_decode_head_major_gqa_bf16cache_pytorch_contract(), bf16_to_float(), ck_attention_f16_prefill_qtile64_work(), CK_ATTENTION_STATUS_INVALID_ARGUMENT, CK_ATTENTION_STATUS_OK, CK_ATTENTION_STATUS_UNSUPPORTED_CONTRACT, CK_ATTN_REDUCTION_BF16_PYTORCH_SDPA, CK_GGML_FA_TILE_Q, ck_threadpool_dispatch_n(), ck_threadpool_global(), ck_threadpool_n_threads(), ck_threadpool_thread_id(), and float_to_bf16().
Referenced by attention_forward_causal_head_major_gqa_prefill_append_bf16cache_pytorch_contract().
| ck_attention_status_t attention_forward_causal_head_major_gqa_prefill_append_f16cache_auto_workspace | ( | const float * | q, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | q_tokens, | ||
| int | past_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| ck_attention_reduction_t | reduction, | ||
| float * | token_workspace, | ||
| size_t | token_workspace_bytes, | ||
| void * | gqa_workspace, | ||
| size_t | gqa_workspace_bytes, | ||
| int | route_num_heads, | ||
| int | route_num_kv_heads, | ||
| int | route_head_dim, | ||
| int | route_query_tokens, | ||
| int | route_min_kv_tokens, | ||
| int | route_workers, | ||
| int | route_query_tile_size, | ||
| int | route_concurrent_query_tiles | ||
| ) |
Definition at line 7335 of file attention_kernels.c.
References attention_forward_causal_head_major_gqa_prefill_append_f16cache_contract_workspace(), attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_config(), CK_ATTENTION_STATUS_INVALID_ARGUMENT, CK_ATTN_REDUCTION_F16_FLASH_AUTO_QTILE64, ck_threadpool_global(), and ck_threadpool_n_threads().
| ck_attention_status_t attention_forward_causal_head_major_gqa_prefill_append_f16cache_contract | ( | const float * | q, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | q_tokens, | ||
| int | past_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| ck_attention_reduction_t | reduction | ||
| ) |
Definition at line 7641 of file attention_kernels.c.
References attention_forward_causal_head_major_gqa_prefill_append_f16cache_contract_workspace(), CK_ATTENTION_STATUS_INVALID_ARGUMENT, CK_ATTN_REDUCTION_F16_FLASH_AUTO_QTILE64, and CK_GGML_FA_TILE_Q.
| ck_attention_status_t attention_forward_causal_head_major_gqa_prefill_append_f16cache_contract_workspace | ( | const float * | q, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | q_tokens, | ||
| int | past_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| ck_attention_reduction_t | reduction, | ||
| float * | token_workspace, | ||
| size_t | token_workspace_bytes | ||
| ) |
Definition at line 7419 of file attention_kernels.c.
References attention_forward_decode_head_major_gqa_flash_f16cache_contract(), ck_attention_f16_prefill_qtile64_dispatch(), CK_ATTENTION_STATUS_INVALID_ARGUMENT, CK_ATTENTION_STATUS_OK, CK_ATTENTION_STATUS_UNSUPPORTED_CONTRACT, CK_ATTN_PREFILL_SCHEDULE_QUERY_TILES, CK_ATTN_REDUCTION_F16_FLASH_AUTO_QTILE64, CK_ATTN_REDUCTION_F16_ONLINE_FP32_MERGE, CK_ATTN_REDUCTION_F16_ONLINE_SINGLE_RANGE, CK_ATTN_REDUCTION_FP32_ONLINE, and CK_GGML_FA_TILE_Q.
Referenced by attention_forward_causal_head_major_gqa_prefill_append_f16cache_auto_workspace(), and attention_forward_causal_head_major_gqa_prefill_append_f16cache_contract().
| ck_attention_status_t attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_config | ( | const float * | q, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | q_tokens, | ||
| int | past_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | query_tile_size, | ||
| int | concurrent_query_tiles, | ||
| void * | workspace, | ||
| size_t | workspace_bytes | ||
| ) |
Definition at line 7234 of file attention_kernels.c.
References attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_workspace_bytes(), ck_attention_align64_size(), ck_attention_f16_prefill_gqa_reuse_work(), ck_attention_f16_prefill_gqa_reuse_worker_bytes(), CK_ATTENTION_STATUS_INSUFFICIENT_WORKSPACE, CK_ATTENTION_STATUS_INVALID_ARGUMENT, CK_ATTENTION_STATUS_OK, CK_ATTENTION_STATUS_UNSUPPORTED_CONTRACT, CK_ATTN_PREFILL_SCHEDULE_GQA_SHARED_KV_TILES, CK_GGML_FA_TILE_KV, ck_threadpool_dispatch_n(), ck_threadpool_global(), ck_threadpool_n_threads(), and ck_threadpool_thread_id().
Referenced by attention_forward_causal_head_major_gqa_prefill_append_f16cache_auto_workspace().
| size_t attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_workspace_bytes | ( | int | num_heads, |
| int | num_kv_heads, | ||
| int | head_dim, | ||
| int | workers, | ||
| int | query_tile_size, | ||
| int | concurrent_query_tiles | ||
| ) |
Definition at line 6716 of file attention_kernels.c.
References ck_attention_align64_size(), ck_attention_f16_prefill_gqa_reuse_worker_bytes(), and CK_GGML_FA_TILE_KV.
Referenced by attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_config().
| ck_attention_status_t attention_forward_causal_head_major_gqa_prefill_append_f16cache_qtile64_schedule | ( | const float * | q, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | q_tokens, | ||
| int | past_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| ck_attention_prefill_schedule_t | schedule | ||
| ) |
Definition at line 7392 of file attention_kernels.c.
References ck_attention_f16_prefill_qtile64_dispatch(), CK_ATTENTION_STATUS_INVALID_ARGUMENT, and CK_GGML_FA_TILE_Q.
| ck_attention_status_t attention_forward_causal_head_major_gqa_prefill_full_bf16cache_pytorch_contract | ( | const float * | q, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | q_tokens, | ||
| int | past_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| ck_attention_reduction_t | reduction | ||
| ) |
Definition at line 8713 of file attention_kernels.c.
References CK_ATTENTION_STATUS_INVALID_ARGUMENT, CK_ATTENTION_STATUS_UNSUPPORTED_CONTRACT, and CK_ATTN_REDUCTION_BF16_PYTORCH_SDPA.
| ck_attention_status_t attention_forward_causal_head_major_gqa_prefill_segmented_f16cache_contract_workspace | ( | const float * | q, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | q_tokens, | ||
| int | past_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| ck_attention_reduction_t | reduction, | ||
| float * | token_workspace, | ||
| size_t | token_workspace_bytes, | ||
| const int * | segment_lengths, | ||
| int | num_segments | ||
| ) |
Definition at line 7616 of file attention_kernels.c.
References ck_attention_forward_causal_head_major_gqa_prefill_segmented_f16cache_schedule_workspace(), and CK_ATTN_PREFILL_SCHEDULE_QUERY_TILES.
| void attention_forward_causal_head_major_shared_kv_gemma4 | ( | const float * | q, |
| float * | output, | ||
| int | num_heads, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | kv_stride_tokens | ||
| ) |
Definition at line 5070 of file attention_kernels.c.
References attention_forward_causal_head_major_gqa_flash_strided_gemma4().
| void attention_forward_chunk_head_major_gqa_flash_gemma4 | ( | const float * | q_chunk, |
| const float * | k_cache, | ||
| const float * | v_cache, | ||
| float * | out_chunk, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | q_tokens, | ||
| int | kv_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim | ||
| ) |
Definition at line 6089 of file attention_kernels.c.
References attention_flash_decode().
| ck_attention_status_t attention_forward_decode_head_major_gqa_bf16cache_pytorch_contract | ( | const float * | q_token, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | out_token, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | kv_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| ck_attention_reduction_t | reduction | ||
| ) |
Definition at line 8522 of file attention_kernels.c.
References bf16_to_float(), CK_ATTENTION_STATUS_INVALID_ARGUMENT, CK_ATTENTION_STATUS_OK, CK_ATTENTION_STATUS_UNSUPPORTED_CONTRACT, CK_ATTN_REDUCTION_BF16_PYTORCH_SDPA, float_to_bf16(), score, and token.
Referenced by attention_forward_causal_head_major_gqa_prefill_append_bf16cache_pytorch_contract_workspace().
| void attention_forward_decode_head_major_gqa_flash | ( | const float * | q_token, |
| const float * | k_cache, | ||
| const float * | v_cache, | ||
| float * | out_token, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | kv_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim | ||
| ) |
Flash attention decode (single token attends to KV cache)
test_flash_attention.py::TestFlashAttention::test_flash_decode
test_kv_cache_attention.py::TestKVCacheAttention::test_flash_decode
test_fused_attention_decode.py::TestFusedAttentionDecode::test_flash_decode
test_attention.py::TestAttentionForward::test_flash_decode
Single query token attends to kv_tokens in KV cache. Uses true flash attention from attention_flash_true.c.
After changes: make test && make llamacpp-parity-full
Definition at line 6002 of file attention_kernels.c.
References attention_flash_decode().
Referenced by attention_forward_decode_head_major_gqa_flash_sliding(), mega_fused_attention_decode_q5_0(), mega_fused_attention_decode_q5_0_parallel_simd(), 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().
| void attention_forward_decode_head_major_gqa_flash_f16cache | ( | const float * | q_token, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | out_token, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | kv_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim | ||
| ) |
Definition at line 8750 of file attention_kernels.c.
References attention_flash_decode(), CK_FP16_TO_FP32, ck_local_fp16_to_fp32_2d(), and score.
Referenced by attention_forward_decode_head_major_gqa_flash_f16cache_contract().
| ck_attention_status_t attention_forward_decode_head_major_gqa_flash_f16cache_contract | ( | const float * | q_token, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | out_token, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | kv_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| ck_attention_reduction_t | reduction | ||
| ) |
Definition at line 6586 of file attention_kernels.c.
References attention_forward_decode_head_major_gqa_flash_f16cache(), attention_forward_decode_head_major_gqa_flash_f16cache_split(), CK_ATTENTION_STATUS_INVALID_ARGUMENT, CK_ATTENTION_STATUS_OK, CK_ATTENTION_STATUS_UNSUPPORTED_CONTRACT, CK_ATTN_REDUCTION_F16_ONLINE_FP32_MERGE, CK_ATTN_REDUCTION_F16_ONLINE_SINGLE_RANGE, CK_ATTN_REDUCTION_FP32_ONLINE, and ck_get_num_threads().
Referenced by attention_forward_causal_head_major_gqa_prefill_append_f16cache_contract_workspace(), and ck_attention_forward_causal_head_major_gqa_prefill_segmented_f16cache_schedule_workspace().
| void attention_forward_decode_head_major_gqa_flash_f16cache_split | ( | const float * | q_token, |
| const uint16_t * | k_cache, | ||
| const uint16_t * | v_cache, | ||
| float * | out_token, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | kv_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | split_chunks | ||
| ) |
Definition at line 6565 of file attention_kernels.c.
References attention_forward_decode_head_major_gqa_flash_f16cache_split_partitioned().
Referenced by attention_forward_decode_head_major_gqa_flash_f16cache_contract().
|
static |
Definition at line 6450 of file attention_kernels.c.
References ck_attention_f16_reduce_expf(), ck_attention_f16_split_work(), ck_threadpool_dispatch_n(), ck_threadpool_global(), and ck_threadpool_n_threads().
Referenced by attention_forward_decode_head_major_gqa_flash_f16cache_split().
| void attention_forward_decode_head_major_gqa_flash_f16kv | ( | const float * | q_token, |
| const float * | k_cache, | ||
| const float * | v_cache, | ||
| float * | out_token, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | kv_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim | ||
| ) |
Definition at line 6151 of file attention_kernels.c.
References attention_flash_query_causal_exact_f16kv().
| void attention_forward_decode_head_major_gqa_flash_gemma4 | ( | const float * | q_token, |
| const float * | k_cache, | ||
| const float * | v_cache, | ||
| float * | out_token, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | kv_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim | ||
| ) |
Definition at line 6046 of file attention_kernels.c.
References attention_flash_decode().
Referenced by attention_forward_decode_head_major_gqa_flash_sliding_gemma4(), and attention_forward_decode_head_major_shared_kv_gemma4().
| void attention_forward_decode_head_major_gqa_llama_regular_sliding_workspace | ( | const float * | q, |
| const float * | k, | ||
| const float * | v, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | live_tokens, | ||
| int | kv_stride_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| int | sliding_window, | ||
| float * | scores, | ||
| size_t | scores_bytes, | ||
| float * | value_columns, | ||
| size_t | value_columns_bytes, | ||
| float * | scaled_scores, | ||
| size_t | scaled_scores_bytes | ||
| ) |
Definition at line 5975 of file attention_kernels.c.
References ck_attention_llama_regular_impl().
| void attention_forward_decode_head_major_gqa_regular | ( | const float * | q_token, |
| const float * | k_cache, | ||
| const float * | v_cache, | ||
| float * | out_token, | ||
| int | num_heads, | ||
| int | num_kv_heads, | ||
| int | kv_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim | ||
| ) |
WARNING: This is NOT true flash attention!
This function is named "flash" but implements regular attention with O(n) complexity. It's kept for reference and as a fallback.
TRUE flash attention is implemented in attention_flash_true.c
test_kv_cache_attention.py::TestKVCacheAttention::test_regular_decode
test_attention.py::TestAttentionForward::test_regular_decode
Regular attention decode (score-matrix version) for fallback.
After changes: make test
Definition at line 8873 of file attention_kernels.c.
References attention_flash_query_causal_exact_f16kv(), ck_attention_strict_scale_f32(), ck_strict_parity_enabled(), and FLASH_QUERY_IMPL_DECODE.
Referenced by ck_attention_flash_decode_wrapper(), ck_layer_forward_rmsnorm_swiglu_decode_fused_attn_impl(), ck_layer_forward_rmsnorm_swiglu_decode_q4_k(), 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_10_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_11_decode(), 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_13_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_14_decode(), 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_16_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_17_decode(), 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_19_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_1_decode(), 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_21_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_22_decode(), 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_2_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_3_decode(), 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_5_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_6_decode(), 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_8_decode(), qwen2_0_5b_decode_layer_8_decode(), qwen2_0_5b_decode_layer_8_decode(), qwen2_0_5b_decode_layer_9_decode(), qwen2_0_5b_decode_layer_9_decode(), and qwen2_0_5b_decode_layer_9_decode().
| void attention_forward_decode_head_major_shared_kv_gemma4 | ( | const float * | q_token, |
| const float * | k_cache, | ||
| const float * | v_cache, | ||
| float * | out_token, | ||
| int | num_heads, | ||
| int | kv_tokens, | ||
| int | cache_capacity, | ||
| int | head_dim, | ||
| int | aligned_head_dim | ||
| ) |
Definition at line 6135 of file attention_kernels.c.
References attention_forward_decode_head_major_gqa_flash_gemma4().
| void attention_forward_full_head_major_gqa_exact_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 | ||
| ) |
Definition at line 5372 of file attention_kernels.c.
References attention_query_full_exact_regular(), ck_attention_head_full_ggml_graph_oracle_regular(), ck_attention_strict_scale_f32(), ck_attention_trace(), ck_attention_vec_dump_next_layer_id(), ck_strict_parity_enabled(), and qkv_index().
| void attention_forward_full_head_major_gqa_flash | ( | 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 | ||
| ) |
Definition at line 4391 of file attention_kernels.c.
References attention_forward_head_major_gqa_flash_impl().
| void attention_forward_full_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 | ||
| ) |
Definition at line 4467 of file attention_kernels.c.
References attention_forward_head_major_gqa_flash_impl().
| void attention_forward_full_head_major_gqa_flash_strided_bf16_storage | ( | 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 | ||
| ) |
Definition at line 4920 of file attention_kernels.c.
References attention_forward_head_major_gqa_flash_impl(), bf16_to_float(), and float_to_bf16().
| void attention_forward_full_head_major_gqa_flash_strided_gemma4 | ( | 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 | ||
| ) |
Definition at line 5084 of file attention_kernels.c.
References attention_forward_head_major_gqa_flash_impl().
| void attention_forward_full_head_major_gqa_ggml_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 | ||
| ) |
Definition at line 5690 of file attention_kernels.c.
References attention_forward_full_head_major_gqa_ggml_strided_workspace().
| void attention_forward_full_head_major_gqa_ggml_strided_workspace | ( | 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, | ||
| float * | score_rows, | ||
| size_t | score_rows_bytes, | ||
| float * | v_columns, | ||
| size_t | v_columns_bytes, | ||
| float * | probability_row, | ||
| size_t | probability_row_bytes | ||
| ) |
Definition at line 5449 of file attention_kernels.c.
References attention_query_full_ggml_regular(), ck_attention_full_ggml_graph_oracle_multihead(), ck_attention_ggml_out_graph_enabled(), ck_attention_head_full_ggml_graph_oracle_regular(), ck_attention_strict_scale_f32(), ck_attention_trace(), ck_attention_trace_float(), ck_attention_vec_dump_next_layer_id(), ck_strict_parity_enabled(), and qkv_index().
Referenced by attention_forward_full_head_major_gqa_ggml_strided().
| void attention_forward_full_head_major_gqa_pytorch_cpu_flash_bf16_storage | ( | 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 | ||
| ) |
Definition at line 4973 of file attention_kernels.c.
References ck_attention_full_bf16_pytorch_flash().
| void attention_forward_full_head_major_gqa_pytorch_cpu_flash_bf16_storage_token_output | ( | 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 | ||
| ) |
Definition at line 4998 of file attention_kernels.c.
References ck_attention_full_bf16_pytorch_flash().
| void attention_forward_full_head_major_gqa_sdpa_bf16_storage | ( | 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 | ||
| ) |
Definition at line 4948 of file attention_kernels.c.
References bf16_to_float(), ck_attention_full_bf16_sdpa_tiled(), and float_to_bf16().
| void attention_forward_full_head_major_gqa_tiled336_f16kv_fp32_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 | ||
| ) |
Definition at line 3564 of file attention_kernels.c.
References ck_attention_forward_full_head_major_gqa_tiled_f16kv_fp32_strided(), and CK_GGML_FA_TILE_Q_LARGE.
| void attention_forward_full_head_major_gqa_tiled64_f16kv_fp32_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 | ||
| ) |
Definition at line 3547 of file attention_kernels.c.
References ck_attention_forward_full_head_major_gqa_tiled_f16kv_fp32_strided(), and CK_GGML_FA_TILE_Q.
| void attention_forward_full_head_major_gqa_tiled_f16kv_fp32_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 | ||
| ) |
Definition at line 3527 of file attention_kernels.c.
References ck_attention_forward_full_head_major_gqa_tiled_f16kv_fp32_strided(), CK_GGML_FA_TILE_Q, CK_GGML_FA_TILE_Q_LARGE, and CK_GGML_FA_TILE_Q_LARGE_MIN_TOKENS.
|
static |
Definition at line 4109 of file attention_kernels.c.
References attention_forward_head_major_gqa_unfused_f16_strict(), attention_output_index(), ck_attention_full_ggml_graph_oracle_multihead(), ck_attention_full_grid_work(), ck_attention_parallel_enabled(), ck_attention_pick_active_threads(), ck_attention_strict_scale_f32(), ck_attention_strict_unfused_f16_enabled(), ck_attention_vec_dump_enabled(), ck_attention_vec_dump_next_layer_id(), ck_attention_vec_dump_selected_query(), ck_attention_vec_dump_should_emit(), ck_ggml_vec_dot_f32_contig(), ck_ggml_vec_soft_max_row(), ck_round_fp16_buffer(), ck_strict_parity_enabled(), ck_threadpool_dispatch_n(), ck_threadpool_global(), ck_vec_max_f32_contig(), ck_vec_scale_f32_inplace(), FLASH_QUERY_IMPL, and qkv_index().
Referenced by attention_forward_causal_head_major_gqa_flash(), attention_forward_causal_head_major_gqa_flash_strided(), attention_forward_causal_head_major_gqa_flash_strided_gemma4(), attention_forward_causal_head_major_gqa_flash_strided_gemma4_token_output(), attention_forward_causal_head_major_gqa_flash_strided_token_output(), attention_forward_full_head_major_gqa_flash(), attention_forward_full_head_major_gqa_flash_strided(), attention_forward_full_head_major_gqa_flash_strided_bf16_storage(), attention_forward_full_head_major_gqa_flash_strided_gemma4(), and attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_impl().
|
static |
Definition at line 4021 of file attention_kernels.c.
References attention_output_index(), ck_attention_dot_f16_unfused_llama(), ck_attention_vec_dump_selected_query(), CK_FP32_TO_FP16, ck_ggml_vec_soft_max_row(), ck_vec_max_f32_contig(), and qkv_index().
Referenced by attention_forward_head_major_gqa_flash_impl().
| void attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4 | ( | 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, | ||
| int | visual_start, | ||
| int | visual_tokens | ||
| ) |
Definition at line 5216 of file attention_kernels.c.
References attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_impl().
|
static |
Definition at line 5108 of file attention_kernels.c.
References attention_flash_query_causal_exact(), attention_forward_head_major_gqa_flash_impl(), attention_output_index(), ck_attention_vec_dump_enabled(), ck_attention_vec_dump_exact_query(), ck_attention_vec_dump_next_layer_id(), ck_strict_parity_enabled(), FLASH_QUERY_IMPL, and qkv_index().
Referenced by attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4(), and attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_token_output().
| void attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_token_output | ( | 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, | ||
| int | visual_start, | ||
| int | visual_tokens | ||
| ) |
Definition at line 5228 of file attention_kernels.c.
References attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_impl().
| int attention_forward_query_key_head_major_f32 | ( | const float * | query, |
| const float * | key, | ||
| const float * | value, | ||
| float * | output, | ||
| float * | score_scratch, | ||
| int | num_heads, | ||
| int | query_tokens, | ||
| int | key_tokens, | ||
| int | head_dim, | ||
| float | scale | ||
| ) |
Definition at line 210 of file attention_kernels.c.
References ck_attention_forward_query_key_head_major_f32_run().
| int attention_forward_query_key_head_major_f32_packed_k | ( | const float * | query, |
| const float * | key, | ||
| const float * | value, | ||
| float * | output, | ||
| float * | score_scratch, | ||
| float * | key_transpose_scratch, | ||
| int | num_heads, | ||
| int | query_tokens, | ||
| int | key_tokens, | ||
| int | head_dim, | ||
| float | scale | ||
| ) |
Definition at line 227 of file attention_kernels.c.
References ck_attention_forward_query_key_head_major_f32_run().
| int attention_forward_query_key_head_major_tiled_f16kv_fp32 | ( | const float * | query, |
| const float * | key, | ||
| const float * | value, | ||
| float * | output, | ||
| int | num_heads, | ||
| int | query_tokens, | ||
| int | key_tokens, | ||
| int | head_dim, | ||
| float | scale | ||
| ) |
Definition at line 3581 of file attention_kernels.c.
References ck_attention_forward_full_head_major_gqa_tiled_f16kv_fp32_strided(), ck_attention_strict_scale_f32(), CK_GGML_FA_TILE_Q, CK_GGML_FA_TILE_Q_LARGE, and CK_GGML_FA_TILE_Q_LARGE_MIN_TOKENS.
| void attention_forward_sparse_token_major_gqa_bf16cache_pytorch_cpu_flash_contract | ( | const float * | query, |
| const uint16_t * | key_cache, | ||
| const uint16_t * | value_cache, | ||
| const float * | selected_indices, | ||
| float * | output, | ||
| float * | score_scratch, | ||
| int | rows, | ||
| int | query_heads, | ||
| int | kv_heads, | ||
| int | head_dim, | ||
| int | selection_width, | ||
| int | context_length, | ||
| int | position | ||
| ) |
Definition at line 8452 of file attention_kernels.c.
References CK_ATTENTION_STATUS_OK.
|
inlinestatic |
Definition at line 265 of file attention_kernels.c.
References qkv_index(), and token.
Referenced by attention_forward_head_major_gqa_flash_impl(), attention_forward_head_major_gqa_unfused_f16_strict(), attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_impl(), and ck_attention_full_grid_work().
|
static |
Definition at line 2247 of file attention_kernels.c.
References ck_attention_vec_dump_selected_query(), ck_attention_vec_dump_should_emit(), ck_vec_dot_f32_strict(), ck_vec_dot_f32x_f32_to_f32_via_f64(), and score.
Referenced by attention_forward_full_head_major_gqa_exact_strided().
|
static |
Definition at line 2319 of file attention_kernels.c.
References ck_attention_vec_dump_selected_query(), ck_attention_vec_dump_should_emit(), ck_ggml_vec_dot_f32_contig(), ck_ggml_vec_soft_max_row(), ck_vec_max_f32_contig(), and ck_vec_scale_f32_inplace().
Referenced by attention_forward_full_head_major_gqa_ggml_strided_workspace().
|
inlinestatic |
Definition at line 6673 of file attention_kernels.c.
Referenced by attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_config(), attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_workspace_bytes(), ck_attention_f16_prefill_gqa_reuse_work(), and ck_attention_f16_prefill_gqa_reuse_worker_bytes().
|
static |
Definition at line 4858 of file attention_kernels.c.
References ck_attention_full_bf16_sdpa_amx_range().
Referenced by ck_attention_full_bf16_pytorch_flash().
| int ck_attention_bf16_pytorch_gqa_available | ( | void | ) |
Definition at line 8511 of file attention_kernels.c.
Referenced by ck_attention_sparse_bf16_pytorch_gqa_available().
|
static |
Definition at line 4846 of file attention_kernels.c.
References ck_attention_full_bf16_sdpa_tiled_range().
Referenced by ck_attention_full_bf16_sdpa_tiled().
|
static |
Definition at line 5254 of file attention_kernels.c.
References attention_flash_query_causal_exact_f16kv(), attention_flash_query_causal_exact_prerounded_f16kv(), and qkv_index().
Referenced by attention_forward_causal_head_major_gqa_flash_strided_f16kv_serial(), and attention_forward_causal_head_major_gqa_flash_strided_f16kv_workspace().
|
inlinestatic |
Definition at line 6214 of file attention_kernels.c.
References CK_FP16_TO_FP32.
Referenced by ck_attention_f16_split_work().
|
inlinestatic |
Definition at line 1105 of file attention_kernels.c.
References CK_FP16_TO_FP32.
Referenced by attention_forward_head_major_gqa_unfused_f16_strict().
|
static |
Definition at line 6943 of file attention_kernels.c.
References ck_attention_align64_size(), ck_attention_gqa_team_barrier_wait(), ck_attention_matmul_f32_accum(), ck_attention_reference_expf(), ck_attention_strict_scale_f32(), ck_attention_u16_cache_to_f32(), CK_GGML_FA_TILE_KV, ck_ggml_vec_soft_max_row(), ck_vec_max_f32_contig(), and ck_vec_scale_f32_inplace().
Referenced by attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_config().
|
static |
Definition at line 6678 of file attention_kernels.c.
References ck_attention_align64_size(), and CK_GGML_FA_TILE_KV.
Referenced by attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_config(), and attention_forward_causal_head_major_gqa_prefill_append_f16cache_gqa_reuse_workspace_bytes().
|
static |
Definition at line 7175 of file attention_kernels.c.
References ck_attention_f16_prefill_qtile64_work(), CK_ATTENTION_STATUS_INVALID_ARGUMENT, CK_ATTENTION_STATUS_OK, CK_ATTN_PREFILL_SCHEDULE_KV_GROUP_QUERY_TILES, CK_ATTN_PREFILL_SCHEDULE_KV_HEADS, CK_ATTN_PREFILL_SCHEDULE_QUERY_TILES, CK_GGML_FA_TILE_Q, ck_threadpool_dispatch_n(), ck_threadpool_global(), ck_threadpool_n_threads(), and ck_threadpool_thread_id().
Referenced by attention_forward_causal_head_major_gqa_prefill_append_f16cache_contract_workspace(), and attention_forward_causal_head_major_gqa_prefill_append_f16cache_qtile64_schedule().
|
static |
Definition at line 6765 of file attention_kernels.c.
References ck_attention_matmul_f32_accum(), ck_attention_reference_expf(), ck_attention_strict_scale_f32(), ck_attention_u16_cache_to_f32(), CK_ATTN_PREFILL_SCHEDULE_KV_GROUP_QUERY_TILES, CK_ATTN_PREFILL_SCHEDULE_QUERY_TILES, CK_GGML_FA_TILE_KV, CK_GGML_FA_TILE_Q, ck_ggml_vec_soft_max_row(), ck_vec_max_f32_contig(), and ck_vec_scale_f32_inplace().
Referenced by attention_forward_causal_head_major_gqa_prefill_append_bf16cache_pytorch_contract_workspace(), ck_attention_f16_prefill_qtile64_dispatch(), and ck_attention_forward_causal_head_major_gqa_prefill_segmented_f16cache_schedule_workspace().
|
inlinestatic |
Definition at line 6209 of file attention_kernels.c.
References ck_attention_reference_expf().
Referenced by attention_forward_decode_head_major_gqa_flash_f16cache_split_partitioned().
|
static |
Definition at line 6377 of file attention_kernels.c.
References ck_attention_dot_f16_llama(), ck_attention_mad_f16_llama(), ck_attention_reference_expf(), ck_attention_scale_f16_llama(), ck_attention_strict_scale_f32(), CK_FP16_TO_FP32, CK_FP32_TO_FP16, end, and score.
Referenced by attention_forward_decode_head_major_gqa_flash_f16cache_split_partitioned().
|
inlinestatic |
Definition at line 3641 of file attention_kernels.c.
References attention_flash_query_causal().
Referenced by ck_attention_full_grid_work().
|
static |
Definition at line 7503 of file attention_kernels.c.
References attention_forward_decode_head_major_gqa_flash_f16cache_contract(), ck_attention_f16_prefill_qtile64_work(), CK_ATTENTION_STATUS_INVALID_ARGUMENT, CK_ATTENTION_STATUS_OK, CK_ATTN_PREFILL_SCHEDULE_KV_HEADS, CK_ATTN_REDUCTION_F16_FLASH_AUTO_QTILE64, CK_ATTN_REDUCTION_F16_ONLINE_SINGLE_RANGE, CK_GGML_FA_TILE_Q, ck_threadpool_dispatch_n(), ck_threadpool_global(), ck_threadpool_n_threads(), and ck_threadpool_thread_id().
Referenced by attention_forward_causal_head_major_gqa_prefill_segmented_f16cache_contract_workspace().
|
static |
Definition at line 3486 of file attention_kernels.c.
References ck_attention_full_tiled_f16kv_fp32_work(), ck_threadpool_dispatch_n(), ck_threadpool_global(), and ck_threadpool_n_threads().
Referenced by attention_forward_full_head_major_gqa_tiled336_f16kv_fp32_strided(), attention_forward_full_head_major_gqa_tiled64_f16kv_fp32_strided(), attention_forward_full_head_major_gqa_tiled_f16kv_fp32_strided(), and attention_forward_query_key_head_major_tiled_f16kv_fp32().
|
static |
Definition at line 153 of file attention_kernels.c.
References ck_attention_query_key_f32_transpose_work(), ck_attention_query_key_f32_work(), ck_threadpool_dispatch_n(), ck_threadpool_global(), and ck_threadpool_n_threads().
Referenced by attention_forward_query_key_head_major_f32(), and attention_forward_query_key_head_major_f32_packed_k().
|
static |
Definition at line 4870 of file attention_kernels.c.
References ck_attention_bf16_pytorch_flash_work(), ck_threadpool_dispatch_n(), ck_threadpool_global(), and ck_threadpool_n_threads().
Referenced by attention_forward_full_head_major_gqa_pytorch_cpu_flash_bf16_storage(), and attention_forward_full_head_major_gqa_pytorch_cpu_flash_bf16_storage_token_output().
|
static |
Definition at line 4616 of file attention_kernels.c.
References bf16_to_float(), ck_attention_pytorch_sdpa_scale_f32(), ck_gemm_bf16_amx_available(), ck_gemm_bf16_fp32out_amx_raw(), and float_to_bf16().
Referenced by ck_attention_bf16_pytorch_flash_work().
|
static |
Definition at line 4896 of file attention_kernels.c.
References ck_attention_bf16_sdpa_work(), ck_threadpool_dispatch_n(), ck_threadpool_global(), and ck_threadpool_n_threads().
Referenced by attention_forward_full_head_major_gqa_sdpa_bf16_storage().
|
static |
Definition at line 4753 of file attention_kernels.c.
References bf16_to_float(), ck_attention_pytorch_sdpa_scale_f32(), ck_bf16_dot_contract(), and float_to_bf16().
Referenced by ck_attention_bf16_sdpa_work().
|
static |
Definition at line 3959 of file attention_kernels.c.
References attention_output_index(), ck_attention_flash_query_auto(), and qkv_index().
Referenced by attention_forward_head_major_gqa_flash_impl().
|
static |
Definition at line 3314 of file attention_kernels.c.
References ck_attention_matmul_f32_accum(), ck_attention_reference_expf(), ck_attention_strict_scale_f32(), CK_GGML_FA_TILE_KV, ck_ggml_vec_soft_max_row(), ck_round_fp16_scalar(), ck_vec_max_f32_contig(), ck_vec_scale_f32_inplace(), and qkv_index().
Referenced by ck_attention_full_tiled_f16kv_fp32_work().
|
static |
Definition at line 3474 of file attention_kernels.c.
References ck_attention_full_tiled_f16kv_fp32_range().
Referenced by ck_attention_forward_full_head_major_gqa_tiled_f16kv_fp32_strided().
|
static |
Definition at line 426 of file attention_kernels.c.
Referenced by attention_forward_full_head_major_gqa_ggml_strided_workspace().
|
inlinestatic |
Definition at line 6743 of file attention_kernels.c.
Referenced by ck_attention_f16_prefill_gqa_reuse_work().
|
static |
Definition at line 5894 of file attention_kernels.c.
References ck_attention_llama_regular_query(), ck_attention_vec_dump_enabled(), ck_attention_vec_dump_next_layer_id(), ck_attention_vec_dump_selected_query(), ck_attention_vec_dump_should_emit(), ck_llama_kv_pad_256(), and token.
Referenced by attention_forward_causal_head_major_gqa_llama_regular_strided_sliding_workspace(), and attention_forward_decode_head_major_gqa_llama_regular_sliding_workspace().
|
static |
Definition at line 5856 of file attention_kernels.c.
References ck_ggml_vec_soft_max_row(), ck_llama_regular_dot_f16(), ck_llama_regular_gemm_f16(), ck_vec_max_f32_contig(), ck_vec_scale_f32_inplace(), and token.
Referenced by ck_attention_llama_regular_impl().
|
inlinestatic |
Definition at line 6331 of file attention_kernels.c.
References CK_FP16_TO_FP32, and CK_FP32_TO_FP16.
Referenced by ck_attention_f16_split_work().
|
static |
Definition at line 3293 of file attention_kernels.c.
Referenced by ck_attention_f16_prefill_gqa_reuse_work(), ck_attention_f16_prefill_qtile64_work(), and ck_attention_full_tiled_f16kv_fp32_range().
|
static |
Definition at line 3986 of file attention_kernels.c.
Referenced by attention_forward_head_major_gqa_flash_impl().
|
static |
Definition at line 4000 of file attention_kernels.c.
References ck_threadpool_n_threads().
Referenced by attention_forward_head_major_gqa_flash_impl().
| float ck_attention_pytorch_sdpa_scale_f32 | ( | int | head_dim | ) |
Definition at line 4518 of file attention_kernels.c.
Referenced by ck_attention_full_bf16_sdpa_amx_range(), and ck_attention_full_bf16_sdpa_tiled_range().
|
static |
Definition at line 59 of file attention_kernels.c.
Referenced by ck_attention_forward_query_key_head_major_f32_run().
|
static |
Definition at line 78 of file attention_kernels.c.
References score.
Referenced by ck_attention_forward_query_key_head_major_f32_run().
|
static |
Definition at line 1169 of file attention_kernels.c.
Referenced by ck_attention_f16_prefill_gqa_reuse_work(), ck_attention_f16_prefill_qtile64_work(), ck_attention_f16_reduce_expf(), ck_attention_f16_split_work(), and ck_attention_full_tiled_f16kv_fp32_range().
|
static |
Definition at line 413 of file attention_kernels.c.
|
inlinestatic |
Definition at line 6297 of file attention_kernels.c.
References CK_FP16_TO_FP32, and CK_FP32_TO_FP16.
Referenced by ck_attention_f16_split_work().
| int ck_attention_sparse_bf16_pytorch_gqa_available | ( | void | ) |
Definition at line 8502 of file attention_kernels.c.
References ck_attention_bf16_pytorch_gqa_available().
|
static |
Definition at line 1154 of file attention_kernels.c.
Referenced by attention_forward_decode_head_major_gqa_regular(), attention_forward_full_head_major_gqa_exact_strided(), attention_forward_full_head_major_gqa_ggml_strided_workspace(), attention_forward_head_major_gqa_flash_impl(), attention_forward_query_key_head_major_tiled_f16kv_fp32(), ck_attention_f16_prefill_gqa_reuse_work(), ck_attention_f16_prefill_qtile64_work(), ck_attention_f16_split_work(), and ck_attention_full_tiled_f16kv_fp32_range().
|
static |
Definition at line 4015 of file attention_kernels.c.
Referenced by attention_forward_head_major_gqa_flash_impl().
|
static |
Definition at line 522 of file attention_kernels.c.
Referenced by attention_forward_full_head_major_gqa_exact_strided(), and attention_forward_full_head_major_gqa_ggml_strided_workspace().
|
static |
Definition at line 560 of file attention_kernels.c.
Referenced by attention_forward_full_head_major_gqa_ggml_strided_workspace().
|
static |
Definition at line 539 of file attention_kernels.c.
Referenced by ck_attention_vec_dump_selected_query(), and ck_attention_vec_dump_should_emit().
|
inlinestatic |
Definition at line 6760 of file attention_kernels.c.
References bf16_to_float(), and CK_FP16_TO_FP32.
Referenced by ck_attention_f16_prefill_gqa_reuse_work(), and ck_attention_f16_prefill_qtile64_work().
|
static |
Definition at line 401 of file attention_kernels.c.
Referenced by attention_forward_head_major_gqa_flash_impl(), attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_impl(), ck_attention_llama_regular_impl(), and ck_attention_vec_dump_should_emit().
|
static |
Definition at line 2067 of file attention_kernels.c.
References ck_attention_vec_dump_selected_query(), and ck_attention_vec_dump_should_emit().
Referenced by attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_impl().
|
static |
Definition at line 480 of file attention_kernels.c.
References ck_attention_vec_dump_layer_seq.
Referenced by attention_forward_full_head_major_gqa_exact_strided(), attention_forward_full_head_major_gqa_ggml_strided_workspace(), attention_forward_head_major_gqa_flash_impl(), attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_impl(), and ck_attention_llama_regular_impl().
|
static |
Definition at line 432 of file attention_kernels.c.
References end.
Referenced by ck_attention_vec_dump_should_emit().
|
static |
Definition at line 580 of file attention_kernels.c.
References ck_attention_trace_query(), ck_attention_vec_dump_should_emit(), ck_attention_vec_dump_tensor(), and ck_attention_vec_dump_vcols_enabled().
Referenced by attention_forward_head_major_gqa_flash_impl(), attention_forward_head_major_gqa_unfused_f16_strict(), attention_query_full_exact_regular(), attention_query_full_ggml_regular(), ck_attention_llama_regular_impl(), and ck_attention_vec_dump_exact_query().
|
static |
Definition at line 449 of file attention_kernels.c.
References ck_attention_trace_query(), ck_attention_vec_dump_enabled(), and ck_attention_vec_dump_parse_env_int().
Referenced by attention_forward_head_major_gqa_flash_impl(), attention_query_full_exact_regular(), attention_query_full_ggml_regular(), ck_attention_llama_regular_impl(), ck_attention_vec_dump_exact_query(), and ck_attention_vec_dump_selected_query().
|
static |
Definition at line 487 of file attention_kernels.c.
References ck_attention_vec_dump_magic, and ck_attention_vec_dump_version.
Referenced by ck_attention_vec_dump_selected_query().
|
static |
Definition at line 407 of file attention_kernels.c.
Referenced by ck_attention_vec_dump_selected_query().
|
static |
Definition at line 4490 of file attention_kernels.c.
References bf16_to_float(), and float_to_bf16().
Referenced by ck_attention_full_bf16_sdpa_tiled_range().
|
static |
Definition at line 1016 of file attention_kernels.c.
Referenced by attention_forward_head_major_gqa_flash_impl(), and attention_query_full_ggml_regular().
|
static |
Definition at line 1204 of file attention_kernels.c.
Referenced by attention_forward_head_major_gqa_flash_impl(), attention_forward_head_major_gqa_unfused_f16_strict(), attention_query_full_ggml_regular(), ck_attention_f16_prefill_gqa_reuse_work(), ck_attention_f16_prefill_qtile64_work(), ck_attention_full_tiled_f16kv_fp32_range(), and ck_attention_llama_regular_query().
|
inlinestatic |
Definition at line 5728 of file attention_kernels.c.
Referenced by ck_attention_llama_regular_impl().
|
inlinestatic |
Definition at line 5742 of file attention_kernels.c.
References CK_FP16_TO_FP32, and CK_FP32_TO_FP16.
Referenced by ck_attention_llama_regular_query().
|
inlinestatic |
Definition at line 5811 of file attention_kernels.c.
References CK_FP16_TO_FP32, and CK_FP32_TO_FP16.
Referenced by ck_attention_llama_regular_query().
|
inlinestatic |
Definition at line 308 of file attention_kernels.c.
References ck_local_fp16_to_fp32_row().
Referenced by attention_forward_decode_head_major_gqa_flash_f16cache().
|
inlinestatic |
Definition at line 298 of file attention_kernels.c.
References CK_FP16_TO_FP32.
Referenced by ck_local_fp16_to_fp32_2d().
|
static |
Definition at line 282 of file attention_kernels.c.
References ck_round_fp16_scalar().
Referenced by attention_flash_query_causal_exact_prerounded_f16kv(), attention_forward_causal_head_major_gqa_flash_strided_f16kv_workspace(), and attention_forward_head_major_gqa_flash_impl().
|
inlinestatic |
Definition at line 278 of file attention_kernels.c.
References CK_FP16_TO_FP32, and CK_FP32_TO_FP16.
Referenced by attention_flash_query_causal_exact_f16kv(), attention_flash_query_causal_exact_prerounded_f16kv(), ck_attention_full_tiled_f16kv_fp32_range(), and ck_round_fp16_buffer().
|
static |
Definition at line 365 of file attention_kernels.c.
|
static |
Definition at line 339 of file attention_kernels.c.
Referenced by attention_query_full_exact_regular().
|
static |
Definition at line 352 of file attention_kernels.c.
Referenced by attention_query_full_exact_regular().
|
inlinestatic |
Definition at line 2826 of file attention_kernels.c.
Referenced by attention_forward_head_major_gqa_flash_impl(), attention_forward_head_major_gqa_unfused_f16_strict(), attention_query_full_ggml_regular(), ck_attention_f16_prefill_gqa_reuse_work(), ck_attention_f16_prefill_qtile64_work(), ck_attention_full_tiled_f16kv_fp32_range(), and ck_attention_llama_regular_query().
|
inlinestatic |
Definition at line 2819 of file attention_kernels.c.
Referenced by attention_forward_head_major_gqa_flash_impl(), attention_query_full_ggml_regular(), ck_attention_f16_prefill_gqa_reuse_work(), ck_attention_f16_prefill_qtile64_work(), ck_attention_full_tiled_f16kv_fp32_range(), and ck_attention_llama_regular_query().
|
static |
Definition at line 247 of file attention_kernels.c.
References bf16_tensor_to_float().
Referenced by attention_backward_causal_head_major_gqa_bf16(), and attention_forward_causal_head_major_gqa_bf16().
|
inlinestatic |
Definition at line 255 of file attention_kernels.c.
Referenced by attention_backward_causal_head_major_gqa(), attention_forward_causal_head_major(), attention_forward_causal_head_major_exact(), attention_forward_causal_head_major_gqa(), attention_forward_causal_head_major_gqa_exact(), attention_forward_full_head_major_gqa_exact_strided(), attention_forward_full_head_major_gqa_ggml_strided_workspace(), attention_forward_head_major_gqa_flash_impl(), attention_forward_head_major_gqa_unfused_f16_strict(), attention_forward_mixed_visual_chunk_head_major_gqa_flash_strided_gemma4_impl(), attention_output_index(), ck_attention_causal_f16kv_work(), ck_attention_full_grid_work(), and ck_attention_full_tiled_f16kv_fp32_range().
|
inlinestatic |
Definition at line 1259 of file attention_kernels.c.
Referenced by attention_backward_causal_head_major_gqa(), attention_forward_causal_head_major(), attention_forward_causal_head_major_exact(), attention_forward_causal_head_major_gqa(), and attention_forward_causal_head_major_gqa_exact().
|
static |
Definition at line 393 of file attention_kernels.c.
Referenced by ck_attention_vec_dump_next_layer_id().
|
static |
Definition at line 391 of file attention_kernels.c.
Referenced by ck_attention_vec_dump_tensor().
|
static |
Definition at line 392 of file attention_kernels.c.
Referenced by ck_attention_vec_dump_tensor().