← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
ckernel_ir_v2_lower.h File Reference
#include "ckernel_ir_v2.h"
#include "ckernel_mem_plan.h"

Go to the source code of this file.

Enumerations

enum  CKIRV2LowerMode { CK_IR_V2_LOWER_PREFILL = 0 , CK_IR_V2_LOWER_DECODE = 1 , CK_IR_V2_LOWER_BACKWARD = 2 }
 

Functions

int ck_ir_v2_lower_emit_json (const CKIRV2Graph *input, CKIRV2LowerMode mode, const char *path)
 
int ck_ir_v2_lower_graph (const CKIRV2Graph *input, CKIRV2LowerMode mode, CKIRV2Graph *output, CKMemPlan *plan)
 
int ck_ir_v2_lower_mode_from_string (const char *name, CKIRV2LowerMode *out_mode)
 
const char * ck_ir_v2_lower_mode_name (CKIRV2LowerMode mode)
 

Enumeration Type Documentation

◆ CKIRV2LowerMode

Enumerator
CK_IR_V2_LOWER_PREFILL 
CK_IR_V2_LOWER_DECODE 
CK_IR_V2_LOWER_BACKWARD 

Definition at line 11 of file ckernel_ir_v2_lower.h.

11 {
CKIRV2LowerMode
@ CK_IR_V2_LOWER_BACKWARD
@ CK_IR_V2_LOWER_DECODE
@ CK_IR_V2_LOWER_PREFILL

Function Documentation

◆ ck_ir_v2_lower_emit_json()

int ck_ir_v2_lower_emit_json ( const CKIRV2Graph input,
CKIRV2LowerMode  mode,
const char *  path 
)

Definition at line 219 of file ckernel_ir_v2_lower.c.

222{
223 if (!input || !path) {
224 return -1;
225 }
226 CKIRV2Graph lowered = {0};
227 CKMemPlan plan = {0};
228 if (ck_ir_v2_lower_graph(input, mode, &lowered, &plan) != 0) {
229 return -1;
230 }
231 int tokens_override = (mode == CK_IR_V2_LOWER_DECODE) ? 1 : -1;
232 int base_context = (tokens_override >= 0) ? input->config.context_window : -1;
233 int rc = ck_ir_v2_serialize_json_with_plan(&lowered, &plan,
235 tokens_override,
236 base_context,
237 path);
238 ck_ir_v2_free(&lowered);
239 ck_mem_plan_free(&plan);
240 return rc;
241}
int ck_ir_v2_serialize_json_with_plan(const CKIRV2Graph *graph, const struct CKMemPlan *plan, const char *mode, int tokens_override, int base_context_window, const char *path)
void ck_ir_v2_free(CKIRV2Graph *graph)
const char * ck_ir_v2_lower_mode_name(CKIRV2LowerMode mode)
int ck_ir_v2_lower_graph(const CKIRV2Graph *input, CKIRV2LowerMode mode, CKIRV2Graph *output, CKMemPlan *plan)
void ck_mem_plan_free(CKMemPlan *plan)
CKModelConfig config

References ck_ir_v2_free(), CK_IR_V2_LOWER_DECODE, ck_ir_v2_lower_graph(), ck_ir_v2_lower_mode_name(), ck_ir_v2_serialize_json_with_plan(), ck_mem_plan_free(), CKIRV2Graph::config, and CKModelConfig::context_window.

Referenced by main().

◆ ck_ir_v2_lower_graph()

int ck_ir_v2_lower_graph ( const CKIRV2Graph input,
CKIRV2LowerMode  mode,
CKIRV2Graph output,
CKMemPlan plan 
)

Definition at line 177 of file ckernel_ir_v2_lower.c.

181{
182 if (!input || !output || !plan) {
183 return -1;
184 }
185 memset(output, 0, sizeof(*output));
186 memset(plan, 0, sizeof(*plan));
187
188 output->config = input->config;
189 output->has_pos_emb = input->has_pos_emb;
191 output->fused_qkv = input->fused_qkv;
192 output->gated_mlp = input->gated_mlp;
193
194 if (ck_ir_v2_lower_copy_buffers(input, output) != 0 ||
195 ck_ir_v2_lower_copy_nodes(input, mode, output) != 0) {
196 ck_ir_v2_free(output);
197 return -1;
198 }
199
200 int tokens_override = (mode == CK_IR_V2_LOWER_DECODE) ? 1 : -1;
201 int rc = 0;
202 if (mode == CK_IR_V2_LOWER_BACKWARD) {
205 tokens_override);
206 } else {
209 tokens_override);
210 }
211 if (rc != 0) {
212 ck_ir_v2_free(output);
213 ck_mem_plan_free(plan);
214 return -1;
215 }
216 return 0;
217}
static int ck_ir_v2_lower_copy_nodes(const CKIRV2Graph *input, CKIRV2LowerMode mode, CKIRV2Graph *output)
static int ck_ir_v2_lower_copy_buffers(const CKIRV2Graph *input, CKIRV2Graph *output)
int ck_mem_plan_build_training_with_tokens(const CKIRV2Graph *graph, CKMemPlan *plan, size_t alignment_bytes, int tokens_override)
#define CK_MEM_PLAN_DEFAULT_ALIGN
int ck_mem_plan_build_inference_with_tokens(const CKIRV2Graph *graph, CKMemPlan *plan, size_t alignment_bytes, int tokens_override)
int tie_word_embeddings

References ck_ir_v2_free(), CK_IR_V2_LOWER_BACKWARD, ck_ir_v2_lower_copy_buffers(), ck_ir_v2_lower_copy_nodes(), CK_IR_V2_LOWER_DECODE, ck_mem_plan_build_inference_with_tokens(), ck_mem_plan_build_training_with_tokens(), CK_MEM_PLAN_DEFAULT_ALIGN, ck_mem_plan_free(), CKIRV2Graph::config, CKIRV2Graph::fused_qkv, CKIRV2Graph::gated_mlp, CKIRV2Graph::has_pos_emb, and CKIRV2Graph::tie_word_embeddings.

Referenced by ck_ir_v2_lower_emit_json().

◆ ck_ir_v2_lower_mode_from_string()

int ck_ir_v2_lower_mode_from_string ( const char *  name,
CKIRV2LowerMode out_mode 
)

Definition at line 36 of file ckernel_ir_v2_lower.c.

37{
38 if (!name || !out_mode) {
39 return -1;
40 }
41 if (strcmp(name, "prefill") == 0) {
42 *out_mode = CK_IR_V2_LOWER_PREFILL;
43 return 0;
44 }
45 if (strcmp(name, "decode") == 0) {
46 *out_mode = CK_IR_V2_LOWER_DECODE;
47 return 0;
48 }
49 if (strcmp(name, "backward") == 0) {
50 *out_mode = CK_IR_V2_LOWER_BACKWARD;
51 return 0;
52 }
53 return -1;
54}

References CK_IR_V2_LOWER_BACKWARD, CK_IR_V2_LOWER_DECODE, and CK_IR_V2_LOWER_PREFILL.

Referenced by ck_ir_v2_lower_node_enabled(), and main().

◆ ck_ir_v2_lower_mode_name()

const char * ck_ir_v2_lower_mode_name ( CKIRV2LowerMode  mode)

Definition at line 22 of file ckernel_ir_v2_lower.c.

23{
24 switch (mode) {
26 return "prefill";
28 return "decode";
30 return "backward";
31 default:
32 return "unknown";
33 }
34}

References CK_IR_V2_LOWER_BACKWARD, CK_IR_V2_LOWER_DECODE, and CK_IR_V2_LOWER_PREFILL.

Referenced by ck_ir_v2_lower_emit_json(), and main().