#include <stdint.h>#include <stdio.h>Go to the source code of this file.
Data Structures | |
| struct | CKInputRef |
| struct | CKIRGraph |
| struct | CKIRNode |
| struct | CKKernelId |
| struct | CKModelConfig |
Enumerations | |
| enum | CKOpType { CK_OP_RMSNORM = 0 , CK_OP_LINEAR_QKV , CK_OP_ATTENTION , CK_OP_ADD , CK_OP_LINEAR , CK_OP_SPLIT , CK_OP_SWIGLU , CK_OP_RMSNORM_BWD , CK_OP_LINEAR_QKV_BWD , CK_OP_ATTENTION_BWD , CK_OP_ADD_BWD , CK_OP_LINEAR_BWD , CK_OP_SPLIT_BWD , CK_OP_SWIGLU_BWD } |
Functions | |
| int | ck_build_decoder_backward_ir (const CKIRGraph *forward, CKIRGraph *backward) |
| int | ck_build_decoder_ir (const CKModelConfig *cfg, CKIRGraph *graph) |
| void | ck_ir_dump (const CKIRGraph *graph, FILE *out) |
| void | ck_ir_free (CKIRGraph *graph) |
| int | ck_ir_parse_json (const char *path, CKIRGraph *graph) |
| int | ck_ir_serialize_json (const CKIRGraph *graph, const char *path) |
| int | ck_model_config_from_hf_json (const char *path, CKModelConfig *cfg) |
| enum CKOpType |
Definition at line 35 of file ckernel_ir.h.
Build a naive backward IR graph from a forward decoder IR.
This reverses the node order and maps each forward op to a corresponding *_BWD op type. This is an early skeleton useful for planning backprop codegen; it does not yet encode full gradient wiring.
Definition at line 456 of file ckernel_ir.c.
References CKIRGraph::config, CKIRNode::id, CKIRNode::inputs, map_forward_to_backward(), CKIRNode::n_inputs, CKIRNode::n_outputs, CKIRGraph::nodes, CKIRGraph::num_nodes, and CKIRNode::op.
Referenced by main().
| int ck_build_decoder_ir | ( | const CKModelConfig * | cfg, |
| CKIRGraph * | graph | ||
| ) |
Build a simple decoder-only IR graph for the given config.
For now this constructs a canonical pattern per layer: RMSNorm -> QKV Linear -> Attention -> Add (residual) RMSNorm -> W1 Linear -> Split -> SwiGLU -> W2 Linear -> Add
The IR is suitable as a starting point for later fusion and codegen. Returns 0 on success, non-zero on failure.
Definition at line 305 of file ckernel_ir.c.
References CK_OP_ADD, CK_OP_ATTENTION, CK_OP_LINEAR, CK_OP_LINEAR_QKV, CK_OP_RMSNORM, CK_OP_SPLIT, CK_OP_SWIGLU, CKIRGraph::config, CKIRNode::id, CKIRNode::inputs, CKKernelId::layer, CKIRNode::n_inputs, CKIRNode::n_outputs, CKKernelId::node, CKIRGraph::nodes, CKModelConfig::num_layers, CKIRGraph::num_nodes, CKIRNode::op, CKInputRef::out_index, and CKInputRef::producer.
Referenced by main().
| void ck_ir_dump | ( | const CKIRGraph * | graph, |
| FILE * | out | ||
| ) |
Dump a human-readable view of the IR to the given stream.
Definition at line 524 of file ckernel_ir.c.
References CKIRGraph::config, CKModelConfig::context_window, CKModelConfig::hidden_size, CKIRNode::id, CKIRNode::inputs, CKModelConfig::intermediate_size, CKKernelId::layer, CKIRNode::n_inputs, CKIRNode::n_outputs, CKKernelId::node, CKIRGraph::nodes, CKModelConfig::num_heads, CKModelConfig::num_kv_heads, CKModelConfig::num_layers, CKIRGraph::num_nodes, CKIRNode::op, op_name(), CKInputRef::producer, CKModelConfig::rms_norm_eps, CKModelConfig::rope_theta, and CKModelConfig::vocab_size.
Referenced by main().
| void ck_ir_free | ( | CKIRGraph * | graph | ) |
Free any heap-allocated memory owned by the graph.
Definition at line 493 of file ckernel_ir.c.
References CKIRGraph::nodes, and CKIRGraph::num_nodes.
Referenced by main().
| int ck_ir_parse_json | ( | const char * | path, |
| CKIRGraph * | graph | ||
| ) |
Parse a JSON IR map file (as produced by ck_ir_serialize_json) back into a CKIRGraph. This enables a two-stage pipeline:
config.json -> CKIRGraph -> ir.json ir.json -> CKIRGraph -> codegen / analysis
Returns 0 on success, non-zero on failure.
Definition at line 665 of file ckernel_ir.c.
References CKIRGraph::config, CKModelConfig::context_window, CKModelConfig::hidden_size, CKIRNode::id, CKIRNode::inputs, CKModelConfig::intermediate_size, CKKernelId::layer, CKIRNode::n_inputs, CKIRNode::n_outputs, CKKernelId::node, CKIRGraph::nodes, CKModelConfig::num_heads, CKModelConfig::num_kv_heads, CKModelConfig::num_layers, CKIRGraph::num_nodes, CKIRNode::op, CKInputRef::out_index, parse_float_field_in_range(), parse_int_field(), parse_op(), CKInputRef::producer, CKModelConfig::rms_norm_eps, CKModelConfig::rope_theta, and CKModelConfig::vocab_size.
Referenced by main().
| int ck_ir_serialize_json | ( | const CKIRGraph * | graph, |
| const char * | path | ||
| ) |
Serialize a CKIRGraph to a simple JSON IR map file.
This is an explicit per-node, per-layer view of the decoder stack. It is intentionally low-level and mirrors ck_ir_dump(), but in a machine-readable format. Higher-level tooling can later reorganize this into header/block/ footer sections.
Returns 0 on success, non-zero on failure.
Definition at line 575 of file ckernel_ir.c.
References CKIRGraph::config, CKModelConfig::context_window, CKModelConfig::hidden_size, CKIRNode::id, CKIRNode::inputs, CKModelConfig::intermediate_size, CKKernelId::layer, CKIRNode::n_inputs, CKIRNode::n_outputs, CKKernelId::node, CKIRGraph::nodes, CKModelConfig::num_heads, CKModelConfig::num_kv_heads, CKModelConfig::num_layers, CKIRGraph::num_nodes, CKIRNode::op, op_name(), CKInputRef::out_index, CKInputRef::producer, CKModelConfig::rms_norm_eps, CKModelConfig::rope_theta, and CKModelConfig::vocab_size.
Referenced by main().
| int ck_model_config_from_hf_json | ( | const char * | path, |
| CKModelConfig * | cfg | ||
| ) |
Parse a HuggingFace-style config.json into CKModelConfig.
This is a very small, dependency-free parser that looks for a handful of integer keys. If a "text_config" object is present, it will parse the fields from that object (so vision_config does not override text).
Keys recognized (with common fallbacks):
Returns 0 on success, non-zero on failure.
Definition at line 209 of file ckernel_ir.c.
References CKModelConfig::context_window, find_object_range(), CKModelConfig::hidden_size, CKModelConfig::intermediate_size, CKModelConfig::num_heads, CKModelConfig::num_kv_heads, CKModelConfig::num_layers, parse_float_field_any(), parse_int_field_any(), CKModelConfig::rms_norm_eps, CKModelConfig::rope_theta, and CKModelConfig::vocab_size.
Referenced by main().