12 size_t len = strlen(s);
13 char *out = (
char *)malloc(len + 1);
38 if (!name || !out_mode) {
41 if (strcmp(name,
"prefill") == 0) {
45 if (strcmp(name,
"decode") == 0) {
49 if (strcmp(name,
"backward") == 0) {
63 const char *cur = cond;
64 while (*cur ==
' ' || *cur ==
'\t') {
67 if (strncmp(cur,
"mode", 4) == 0) {
69 while (*cur ==
' ' || *cur ==
'\t') {
72 if (cur[0] ==
'=' && cur[1] ==
'=') {
74 while (*cur ==
' ' || *cur ==
'\t') {
77 char mode_buf[16] = {0};
79 while (*cur && idx < (
int)(
sizeof(mode_buf) - 1) &&
80 ((*cur >=
'a' && *cur <=
'z') || *cur ==
'_' || *cur ==
'-')) {
81 mode_buf[idx++] = *cur++;
86 return mode == target;
90 if (strcmp(node->
condition,
"training_enabled") == 0 ||
91 strcmp(node->
condition,
"backward_only") == 0) {
94 if (strcmp(node->
condition,
"inference_only") == 0) {
97 if (strcmp(node->
condition,
"prefill_only") == 0) {
100 if (strcmp(node->
condition,
"decode_only") == 0) {
134 for (
int i = 0; i < input->
num_nodes; ++i) {
141 if (!output->
nodes) {
145 for (
int i = 0; i < input->
num_nodes; ++i) {
167 for (
int j = 0; j < dst->
n_inputs; ++j) {
170 for (
int j = 0; j < dst->
n_outputs; ++j) {
182 if (!input || !output || !plan) {
185 memset(output, 0,
sizeof(*output));
186 memset(plan, 0,
sizeof(*plan));
223 if (!input || !path) {
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)
@ CK_IR_V2_NODE_INFERENCE_ONLY
static int ck_ir_v2_lower_copy_nodes(const CKIRV2Graph *input, CKIRV2LowerMode mode, CKIRV2Graph *output)
static int ck_ir_v2_lower_node_enabled(const CKIRV2Node *node, CKIRV2LowerMode mode)
static char * ck_ir_v2_lower_strdup(const char *s)
const char * ck_ir_v2_lower_mode_name(CKIRV2LowerMode mode)
int ck_ir_v2_lower_emit_json(const CKIRV2Graph *input, CKIRV2LowerMode mode, const char *path)
int ck_ir_v2_lower_mode_from_string(const char *name, CKIRV2LowerMode *out_mode)
int ck_ir_v2_lower_graph(const CKIRV2Graph *input, CKIRV2LowerMode mode, CKIRV2Graph *output, CKMemPlan *plan)
static int ck_ir_v2_lower_copy_buffers(const CKIRV2Graph *input, CKIRV2Graph *output)
@ CK_IR_V2_LOWER_BACKWARD
int ck_mem_plan_build_training_with_tokens(const CKIRV2Graph *graph, CKMemPlan *plan, size_t alignment_bytes, int tokens_override)
void ck_mem_plan_free(CKMemPlan *plan)
#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)
CKIRV2Binding bindings[24]