#include "ckernel_ir.h"
#include "ckernel_codegen.h"
#include <stdio.h>
#include <string.h>
Go to the source code of this file.
|
| int | main (int argc, char **argv) |
| |
◆ main()
| int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 7 of file ckernel_ir_demo.c.
12 " %s /path/to/config.json [--emit out.c] [--emit-lib] # parse config, dump + codegen\n"
13 " %s --ir /path/to/ir.json [--emit out.c] [--emit-lib] # parse IR JSON, dump + codegen\n"
16 " --emit out.c Write generated C code to file\n"
17 " --emit-lib Generate shared library API (no main)\n"
18 " Without --emit-lib: generates standalone executable with main()\n",
26 const char *emit_path = NULL;
29 for (
int i = 1; i < argc; ++i) {
30 if (strcmp(argv[i],
"--emit") == 0 && i + 1 < argc) {
31 emit_path = argv[++i];
32 }
else if (strcmp(argv[i],
"--emit-lib") == 0) {
37 if (strcmp(argv[1],
"--ir") == 0) {
39 fprintf(stderr,
"Missing IR JSON path after --ir\n");
42 const char *ir_path = argv[2];
44 fprintf(stderr,
"Failed to parse IR JSON: %s\n", ir_path);
48 fprintf(stderr,
"Failed to build backward IR from IR JSON\n");
53 const char *config_path = argv[1];
56 fprintf(stderr,
"Failed to parse config.json: %s\n", config_path);
61 fprintf(stderr,
"Failed to build decoder IR\n");
66 fprintf(stderr,
"Failed to build backward IR\n");
72 printf(
"=== Forward IR ===\n");
74 printf(
"\n=== Backward IR (skeleton) ===\n");
77 printf(
"\n=== Generated C Skeleton ===\n");
81 const char *mode_str = (emit_mode ==
CK_EMIT_LIBRARY) ?
"library" :
"standalone";
83 fprintf(stderr,
"\n[ck_ir_demo] %s runtime written to %s\n", mode_str, emit_path);
85 fprintf(stderr,
"\n[ck_ir_demo] failed to write %s runtime to %s\n", mode_str, emit_path);
90 if (strcmp(argv[1],
"--ir") != 0) {
92 fprintf(stderr,
"\n[ck_ir_demo] JSON IR written to build/ir.json\n");
94 fprintf(stderr,
"\n[ck_ir_demo] Failed to write JSON IR to build/ir.json\n");
int ck_codegen_emit_runtime(const CKIRGraph *forward, const char *path, CKEmitMode mode)
void ck_codegen_c_skeleton(const CKIRGraph *forward, const CKIRGraph *backward, FILE *out)
int ck_build_decoder_ir(const CKModelConfig *cfg, CKIRGraph *graph)
int ck_ir_serialize_json(const CKIRGraph *graph, const char *path)
int ck_build_decoder_backward_ir(const CKIRGraph *forward, CKIRGraph *backward)
void ck_ir_dump(const CKIRGraph *graph, FILE *out)
int ck_model_config_from_hf_json(const char *path, CKModelConfig *cfg)
int ck_ir_parse_json(const char *path, CKIRGraph *graph)
void ck_ir_free(CKIRGraph *graph)
References ck_build_decoder_backward_ir(), ck_build_decoder_ir(), ck_codegen_c_skeleton(), ck_codegen_emit_runtime(), CK_EMIT_LIBRARY, CK_EMIT_STANDALONE, ck_ir_dump(), ck_ir_free(), ck_ir_parse_json(), ck_ir_serialize_json(), and ck_model_config_from_hf_json().