← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
ck_model_api.h
Go to the documentation of this file.
1/**
2 * @file ck_model_api.h
3 * @brief Generic Model API - Model-agnostic interface for CK-Engine
4 *
5 * All generated models emit the same function names, making the inference
6 * engine completely model-agnostic. To use different models, compile
7 * separate binaries.
8 *
9 * Usage:
10 * void *model = ck_model_create();
11 * ck_model_load_weights(model, "weights.bump");
12 * ck_model_forward(model, tokens, num_tokens); // prefill
13 * ck_model_decode(model, &token, token_index); // decode
14 * float *logits = ck_model_get_logits(model);
15 * ck_model_free(model);
16 */
17
18#ifndef CK_MODEL_API_H
19#define CK_MODEL_API_H
20
21#include <stddef.h>
22#include <stdint.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/* ============================================================================
29 * MODEL CONFIGURATION (read-only, set by generated code)
30 * ============================================================================ */
31
32typedef struct {
44 const char *model_name;
45 const char *model_family; /* "qwen2", "llama", "mistral", etc. */
47
48/* ============================================================================
49 * GENERIC MODEL API - Same names for ALL models
50 * ============================================================================ */
51
52/**
53 * Get model configuration (dimensions, sizes, etc.)
54 * This is available before allocation.
55 */
57
58/**
59 * Create and allocate model memory.
60 * Returns opaque model pointer, or NULL on failure.
61 */
62void *ck_model_create(void);
63
64/**
65 * Free model memory.
66 */
67void ck_model_free(void *model);
68
69/**
70 * Precompute RoPE cos/sin caches.
71 * Call once after allocation, before inference.
72 */
73void ck_model_precompute_rope(void *model);
74
75/**
76 * Load weights from BUMP file into model.
77 * Returns 0 on success, -1 on failure.
78 */
79int ck_model_load_weights(void *model, const char *bump_path);
80
81/**
82 * Forward pass (prefill) - process multiple tokens.
83 * Used for initial prompt processing.
84 */
85void ck_model_forward(void *model, const int *tokens, int num_tokens);
86
87/**
88 * Decode single token at position token_index.
89 * Used for autoregressive generation.
90 */
91void ck_model_decode(void *model, const int *token, int token_index);
92
93/**
94 * Get pointer to output logits buffer.
95 * Size is vocab_size floats.
96 */
97float *ck_model_get_logits(void *model);
98
99/**
100 * Verify memory canaries (debug).
101 * Returns number of corrupted canaries (0 = OK).
102 */
103int ck_model_verify_canaries(void *model);
104
105/**
106 * Get model base pointer (for weight loading).
107 */
108void *ck_model_get_base(void *model);
109
110/**
111 * Get total model size in bytes.
112 */
113size_t ck_model_get_total_bytes(void *model);
114
115#ifdef __cplusplus
116}
117#endif
118
119#endif /* CK_MODEL_API_H */
void ck_model_precompute_rope(void *model)
void * ck_model_get_base(void *model)
void ck_model_forward(void *model, const int *tokens, int num_tokens)
int ck_model_verify_canaries(void *model)
void * ck_model_create(void)
int ck_model_load_weights(void *model, const char *bump_path)
void ck_model_free(void *model)
void ck_model_decode(void *model, const int *token, int token_index)
size_t ck_model_get_total_bytes(void *model)
float * ck_model_get_logits(void *model)
const CKModelConfig * ck_model_get_config(void)
const char * model_family
size_t activation_bytes
const char * model_name
size_t total_bytes
size_t weight_bytes
const char * token
Definition tokenizer.h:307