← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
ckernel_codegen_v2_schedule.c
Go to the documentation of this file.
2
3#include <stdio.h>
4
5static const char *ck_codegen_v2_dtype_name(CKDataType dtype)
6{
7 switch (dtype) {
8 case CK_DT_FP32:
9 return "fp32";
10 case CK_DT_BF16:
11 return "bf16";
12 case CK_DT_FP16:
13 return "fp16";
14 case CK_DT_Q4_0:
15 return "q4_0";
16 case CK_DT_Q4_K:
17 return "q4_k";
18 case CK_DT_Q6_K:
19 return "q6_k";
20 case CK_DT_Q8_0:
21 return "q8_0";
22 default:
23 return "unknown";
24 }
25}
26
27static void emit_schedule_block(FILE *out,
28 const CKIRV2Graph *graph,
29 const char *func_name,
30 const char *label,
31 const char *runtime_sym)
32{
33 fprintf(out, "void %s(void) {\n", func_name);
34 fprintf(out, " /* %s schedule (no-op placeholders). */\n", label);
35 for (int i = 0; i < graph->num_nodes; ++i) {
36 const CKIRV2Node *node = &graph->nodes[i];
37 fprintf(out,
38 " /* node %d: layer=%d op=%s kernel=%s dtype=%s */\n",
39 i,
40 (int)node->layer,
41 node->op ? node->op : "none",
42 node->kernel ? node->kernel : "none",
44 for (int b = 0; b < node->n_bindings; ++b) {
45 const CKIRV2Binding *bind = &node->bindings[b];
46 const char *buf_name = "unknown";
47 if (bind->buffer >= 0 && bind->buffer < graph->num_buffers) {
48 buf_name = graph->buffers[bind->buffer].name ? graph->buffers[bind->buffer].name : "unnamed";
49 }
50 fprintf(out,
51 " /* bind: %s -> %s */\n",
52 bind->arg ? bind->arg : "arg",
53 buf_name);
54 }
55 fprintf(out, " ck_v2_dispatch_node(%d);\n", i);
56 }
57 fprintf(out, " (void)%s;\n", runtime_sym ? runtime_sym : "ck_v2_runtime");
58 fprintf(out, "}\n\n");
59}
60
62 const CKIRV2Graph *graph,
63 const char *prefill_runtime,
64 const char *decode_runtime,
65 const char *backward_runtime)
66{
67 emit_schedule_block(out, graph, "ck_v2_run_prefill", "prefill",
68 prefill_runtime ? prefill_runtime : "ck_v2_prefill_runtime");
69 emit_schedule_block(out, graph, "ck_v2_run_decode", "decode",
70 decode_runtime ? decode_runtime : "ck_v2_decode_runtime");
71 emit_schedule_block(out, graph, "ck_v2_run_backward", "backward",
72 backward_runtime ? backward_runtime : "ck_v2_backward_runtime");
73
74 fprintf(out,
75 "void ck_v2_run_forward(void) {\n"
76 " ck_v2_run_prefill();\n"
77 "}\n\n");
78}
static const char * ck_codegen_v2_dtype_name(CKDataType dtype)
void ck_codegen_v2_emit_schedule(FILE *out, const CKIRV2Graph *graph, const char *prefill_runtime, const char *decode_runtime, const char *backward_runtime)
static void emit_schedule_block(FILE *out, const CKIRV2Graph *graph, const char *func_name, const char *label, const char *runtime_sym)
CKDataType
Supported data types in C-Kernel-Engine.
@ CK_DT_Q4_K
@ CK_DT_Q4_0
@ CK_DT_Q8_0
@ CK_DT_FP32
@ CK_DT_FP16
@ CK_DT_Q6_K
@ CK_DT_BF16
CKIRV2Node * nodes
CKIRV2Buffer * buffers
uint8_t n_bindings
uint16_t layer
CKIRV2Binding bindings[24]
CKDataType kernel_dtype
char * kernel