Strict ggml-backed full-attention oracles for parity debugging. More...
#include "attention_oracle_ggml.h"#include "ckernel_engine.h"#include <ggml.h>#include <ggml-backend.h>#include <ggml-alloc.h>#include <dlfcn.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Go to the source code of this file.
Macros | |
| #define | CK_ENABLE_LLAMA_CPP_PARITY 1 |
| #define | RTLD_DEFAULT ((void *)0) |
Typedefs | |
| typedef void(* | ck_ggml_backend_cpu_set_n_threads_fn) (ggml_backend_t, int) |
| typedef void(* | ck_ggml_backend_free_fn) (ggml_backend_t) |
| typedef ggml_backend_buffer_type_t(* | ck_ggml_backend_get_default_buffer_type_fn) (ggml_backend_t) |
| typedef ggml_backend_t(* | ck_ggml_backend_init_by_type_fn) (enum ggml_backend_dev_type, const char *) |
| typedef bool(* | ck_ggml_backend_sched_alloc_graph_fn) (ggml_backend_sched_t, struct ggml_cgraph *) |
| typedef void(* | ck_ggml_backend_sched_free_fn) (ggml_backend_sched_t) |
| typedef enum ggml_status(* | ck_ggml_backend_sched_graph_compute_fn) (ggml_backend_sched_t, struct ggml_cgraph *) |
| typedef ggml_backend_sched_t(* | ck_ggml_backend_sched_new_fn) (ggml_backend_t *, ggml_backend_buffer_type_t *, int, size_t, bool, bool) |
| typedef void(* | ck_ggml_backend_sched_reset_fn) (ggml_backend_sched_t) |
| typedef void(* | ck_ggml_backend_tensor_get_fn) (const struct ggml_tensor *, void *, size_t, size_t) |
| typedef void(* | ck_ggml_backend_tensor_set_fn) (struct ggml_tensor *, const void *, size_t, size_t) |
| typedef void(* | ck_ggml_build_forward_expand_fn) (struct ggml_cgraph *, struct ggml_tensor *) |
| typedef struct ggml_tensor *(* | ck_ggml_cont_2d_fn) (struct ggml_context *, struct ggml_tensor *, int64_t, int64_t) |
| typedef struct ggml_tensor *(* | ck_ggml_cont_fn) (struct ggml_context *, struct ggml_tensor *) |
| typedef void(* | ck_ggml_cpu_init_fn) (void) |
| typedef void(* | ck_ggml_free_fn) (struct ggml_context *) |
| typedef enum ggml_status(* | ck_ggml_graph_compute_with_ctx_fn) (struct ggml_context *, struct ggml_cgraph *, int) |
| typedef struct ggml_context *(* | ck_ggml_init_fn) (struct ggml_init_params) |
| typedef struct ggml_tensor *(* | ck_ggml_mul_mat_graph_fn) (struct ggml_context *, struct ggml_tensor *, struct ggml_tensor *) |
| typedef struct ggml_cgraph *(* | ck_ggml_new_graph_fn) (struct ggml_context *) |
| typedef struct ggml_tensor *(* | ck_ggml_new_tensor_1d_fn) (struct ggml_context *, enum ggml_type, int64_t) |
| typedef struct ggml_tensor *(* | ck_ggml_new_tensor_2d_fn) (struct ggml_context *, enum ggml_type, int64_t, int64_t) |
| typedef struct ggml_tensor *(* | ck_ggml_permute_fn) (struct ggml_context *, struct ggml_tensor *, int, int, int, int) |
| typedef void(* | ck_ggml_set_input_fn) (struct ggml_tensor *) |
| typedef struct ggml_tensor *(* | ck_ggml_soft_max_ext_fn) (struct ggml_context *, struct ggml_tensor *, struct ggml_tensor *, float, float) |
| typedef struct ggml_tensor *(* | ck_ggml_view_3d_fn) (struct ggml_context *, struct ggml_tensor *, int64_t, int64_t, int64_t, size_t, size_t, size_t) |
Variables | |
| static int | ck_attention_oracle_layer_seq = 0 |
| static const char | ck_attention_oracle_magic [8] = {'C', 'K', 'D', 'M', 'P', '\0', '\0', '\0'} |
| static const uint32_t | ck_attention_oracle_version = 1u |
Strict ggml-backed full-attention oracles for parity debugging.
These helpers intentionally mirror ggml graph composition for encoder-style full attention. They are composite parity scaffolding, not production CK kernels, and are only used from strict parity paths.
Definition in file attention_oracle_ggml.c.
| #define CK_ENABLE_LLAMA_CPP_PARITY 1 |
Definition at line 10 of file attention_oracle_ggml.c.
| #define RTLD_DEFAULT ((void *)0) |
Definition at line 18 of file attention_oracle_ggml.c.
| typedef void(* ck_ggml_backend_cpu_set_n_threads_fn) (ggml_backend_t, int) |
Definition at line 42 of file attention_oracle_ggml.c.
| typedef void(* ck_ggml_backend_free_fn) (ggml_backend_t) |
Definition at line 41 of file attention_oracle_ggml.c.
| typedef ggml_backend_buffer_type_t(* ck_ggml_backend_get_default_buffer_type_fn) (ggml_backend_t) |
Definition at line 43 of file attention_oracle_ggml.c.
| typedef ggml_backend_t(* ck_ggml_backend_init_by_type_fn) (enum ggml_backend_dev_type, const char *) |
Definition at line 40 of file attention_oracle_ggml.c.
| typedef bool(* ck_ggml_backend_sched_alloc_graph_fn) (ggml_backend_sched_t, struct ggml_cgraph *) |
Definition at line 49 of file attention_oracle_ggml.c.
| typedef void(* ck_ggml_backend_sched_free_fn) (ggml_backend_sched_t) |
Definition at line 47 of file attention_oracle_ggml.c.
| typedef enum ggml_status(* ck_ggml_backend_sched_graph_compute_fn) (ggml_backend_sched_t, struct ggml_cgraph *) |
Definition at line 49 of file attention_oracle_ggml.c.
| typedef ggml_backend_sched_t(* ck_ggml_backend_sched_new_fn) (ggml_backend_t *, ggml_backend_buffer_type_t *, int, size_t, bool, bool) |
Definition at line 46 of file attention_oracle_ggml.c.
| typedef void(* ck_ggml_backend_sched_reset_fn) (ggml_backend_sched_t) |
Definition at line 48 of file attention_oracle_ggml.c.
| typedef void(* ck_ggml_backend_tensor_get_fn) (const struct ggml_tensor *, void *, size_t, size_t) |
Definition at line 45 of file attention_oracle_ggml.c.
| typedef void(* ck_ggml_backend_tensor_set_fn) (struct ggml_tensor *, const void *, size_t, size_t) |
Definition at line 44 of file attention_oracle_ggml.c.
| typedef void(* ck_ggml_build_forward_expand_fn) (struct ggml_cgraph *, struct ggml_tensor *) |
Definition at line 36 of file attention_oracle_ggml.c.
| typedef struct ggml_tensor *(* ck_ggml_cont_2d_fn) (struct ggml_context *, struct ggml_tensor *, int64_t, int64_t) |
Definition at line 26 of file attention_oracle_ggml.c.
| typedef struct ggml_tensor *(* ck_ggml_cont_fn) (struct ggml_context *, struct ggml_tensor *) |
Definition at line 26 of file attention_oracle_ggml.c.
| typedef void(* ck_ggml_cpu_init_fn) (void) |
Definition at line 38 of file attention_oracle_ggml.c.
| typedef void(* ck_ggml_free_fn) (struct ggml_context *) |
Definition at line 26 of file attention_oracle_ggml.c.
| typedef enum ggml_status(* ck_ggml_graph_compute_with_ctx_fn) (struct ggml_context *, struct ggml_cgraph *, int) |
Definition at line 36 of file attention_oracle_ggml.c.
| typedef struct ggml_context *(* ck_ggml_init_fn) (struct ggml_init_params) |
Definition at line 1 of file attention_oracle_ggml.c.
| typedef struct ggml_tensor *(* ck_ggml_mul_mat_graph_fn) (struct ggml_context *, struct ggml_tensor *, struct ggml_tensor *) |
Definition at line 26 of file attention_oracle_ggml.c.
| typedef struct ggml_cgraph *(* ck_ggml_new_graph_fn) (struct ggml_context *) |
Definition at line 26 of file attention_oracle_ggml.c.
| typedef struct ggml_tensor *(* ck_ggml_new_tensor_1d_fn) (struct ggml_context *, enum ggml_type, int64_t) |
Definition at line 26 of file attention_oracle_ggml.c.
| typedef struct ggml_tensor *(* ck_ggml_new_tensor_2d_fn) (struct ggml_context *, enum ggml_type, int64_t, int64_t) |
Definition at line 26 of file attention_oracle_ggml.c.
| typedef struct ggml_tensor *(* ck_ggml_permute_fn) (struct ggml_context *, struct ggml_tensor *, int, int, int, int) |
Definition at line 26 of file attention_oracle_ggml.c.
| typedef void(* ck_ggml_set_input_fn) (struct ggml_tensor *) |
Definition at line 39 of file attention_oracle_ggml.c.
| typedef struct ggml_tensor *(* ck_ggml_soft_max_ext_fn) (struct ggml_context *, struct ggml_tensor *, struct ggml_tensor *, float, float) |
Definition at line 26 of file attention_oracle_ggml.c.
| typedef struct ggml_tensor *(* ck_ggml_view_3d_fn) (struct ggml_context *, struct ggml_tensor *, int64_t, int64_t, int64_t, size_t, size_t, size_t) |
Definition at line 26 of file attention_oracle_ggml.c.
| int ck_attention_full_ggml_graph_oracle_multihead | ( | 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 | scale | ||
| ) |
Definition at line 683 of file attention_oracle_ggml.c.
References ck_attention_oracle_dump_enabled(), ck_attention_oracle_dump_layer_id(), ck_attention_oracle_dump_meta(), ck_attention_oracle_dump_tensor(), ck_attention_oracle_meta_dump_enabled(), ck_attention_oracle_qkv_index(), ck_resolve_ggml_build_forward_expand(), ck_resolve_ggml_cont(), ck_resolve_ggml_cont_2d(), ck_resolve_ggml_cpu_init(), ck_resolve_ggml_free(), ck_resolve_ggml_graph_compute_with_ctx(), ck_resolve_ggml_init(), ck_resolve_ggml_mul_mat_graph(), ck_resolve_ggml_new_graph(), ck_resolve_ggml_new_tensor_1d(), ck_resolve_ggml_new_tensor_2d(), ck_resolve_ggml_permute(), ck_resolve_ggml_set_input(), ck_resolve_ggml_soft_max_ext(), ck_resolve_ggml_view_3d(), ck_strict_store_next_gemm_a(), GGML_STATUS_SUCCESS, GGML_TYPE_F32, and ggml_init_params::mem_size.
Referenced by attention_forward_full_head_major_gqa_ggml_strided_workspace(), and attention_forward_head_major_gqa_flash_impl().
| int ck_attention_head_full_ggml_graph_oracle_regular | ( | const float * | q_head, |
| const float * | k_head, | ||
| const float * | v_head, | ||
| float * | out_head, | ||
| int | num_tokens, | ||
| int | head_dim, | ||
| int | aligned_head_dim, | ||
| float | scale | ||
| ) |
Definition at line 544 of file attention_oracle_ggml.c.
References ck_attention_oracle_dump_enabled(), ck_attention_oracle_meta_dump_enabled(), ck_resolve_ggml_build_forward_expand(), ck_resolve_ggml_cont(), ck_resolve_ggml_cont_2d(), ck_resolve_ggml_cpu_init(), ck_resolve_ggml_free(), ck_resolve_ggml_graph_compute_with_ctx(), ck_resolve_ggml_init(), ck_resolve_ggml_mul_mat_graph(), ck_resolve_ggml_new_graph(), ck_resolve_ggml_new_tensor_1d(), ck_resolve_ggml_new_tensor_2d(), ck_resolve_ggml_permute(), ck_resolve_ggml_set_input(), ck_resolve_ggml_soft_max_ext(), ck_resolve_ggml_view_3d(), GGML_STATUS_SUCCESS, GGML_TYPE_F32, and ggml_init_params::mem_size.
Referenced by attention_forward_full_head_major_gqa_exact_strided(), and attention_forward_full_head_major_gqa_ggml_strided_workspace().
|
static |
Definition at line 71 of file attention_oracle_ggml.c.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), ck_attention_head_full_ggml_graph_oracle_regular(), and ck_attention_oracle_dump_tensor().
|
static |
Definition at line 119 of file attention_oracle_ggml.c.
References ck_attention_oracle_layer_seq.
Referenced by ck_attention_full_ggml_graph_oracle_multihead().
|
static |
Definition at line 227 of file attention_oracle_ggml.c.
References ck_attention_oracle_meta_dump_enabled(), and ck_attention_oracle_should_dump_layer().
Referenced by ck_attention_full_ggml_graph_oracle_multihead().
|
static |
Definition at line 141 of file attention_oracle_ggml.c.
References ck_attention_oracle_dump_enabled(), ck_attention_oracle_magic, ck_attention_oracle_should_dump_layer(), ck_attention_oracle_version, ck_resolve_ggml_backend_tensor_get(), and GGML_TYPE_F32.
Referenced by ck_attention_full_ggml_graph_oracle_multihead().
|
static |
Definition at line 83 of file attention_oracle_ggml.c.
References end.
Referenced by ck_attention_oracle_should_dump_layer().
|
static |
Definition at line 77 of file attention_oracle_ggml.c.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), ck_attention_head_full_ggml_graph_oracle_regular(), and ck_attention_oracle_dump_meta().
|
inlinestatic |
Definition at line 109 of file attention_oracle_ggml.c.
Referenced by ck_attention_full_ggml_graph_oracle_multihead().
|
static |
Definition at line 100 of file attention_oracle_ggml.c.
References ck_attention_oracle_exact_dump_layer().
Referenced by ck_attention_oracle_dump_meta(), and ck_attention_oracle_dump_tensor().
|
static |
Definition at line 126 of file attention_oracle_ggml.c.
|
static |
Definition at line 456 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
|
static |
Definition at line 434 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
|
static |
Definition at line 445 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
|
static |
Definition at line 423 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
|
static |
Definition at line 500 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
|
static |
Definition at line 478 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
|
static |
Definition at line 533 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
|
static |
Definition at line 467 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
|
static |
Definition at line 489 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
|
static |
Definition at line 522 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_oracle_dump_tensor().
|
static |
Definition at line 511 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
|
static |
Definition at line 379 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 324 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 335 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 401 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 269 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 390 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 258 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 346 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 368 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 280 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 291 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 313 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 412 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 357 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 302 of file attention_oracle_ggml.c.
References RTLD_DEFAULT.
Referenced by ck_attention_full_ggml_graph_oracle_multihead(), and ck_attention_head_full_ggml_graph_oracle_regular().
|
static |
Definition at line 69 of file attention_oracle_ggml.c.
Referenced by ck_attention_oracle_dump_layer_id().
|
static |
Definition at line 67 of file attention_oracle_ggml.c.
Referenced by ck_attention_oracle_dump_tensor().
|
static |
Definition at line 68 of file attention_oracle_ggml.c.
Referenced by ck_attention_oracle_dump_tensor().