← Back to C-Kernel-Engine Docs Doxygen Source Documentation
ckernel_codegen.h
Go to the documentation of this file.
1 #ifndef CKERNEL_CODEGEN_H
2 #define CKERNEL_CODEGEN_H
3 
4 #include "ckernel_ir.h"
5 
6 #include <stdio.h>
7 
8 /**
9  * Code generation output mode.
10  */
11 typedef enum {
12  CK_EMIT_STANDALONE = 0, /* Emit with main() for standalone executable */
13  CK_EMIT_LIBRARY = 1, /* Emit as library with API functions, no main() */
14 } CKEmitMode;
15 
16 /**
17  * Emit a C skeleton for forward + backward execution based on the IR.
18  *
19  * This does not yet generate full pointer arithmetic or memory planning.
20  * It is intended as a starting point that:
21  * - Defines a model config / runtime context
22  * - Shows a per-layer forward loop over IR nodes
23  * - Sketches a backward loop over the backward IR
24  */
25 void ck_codegen_c_skeleton(const CKIRGraph *forward,
26  const CKIRGraph *backward,
27  FILE *out);
28 
29 /**
30  * Emit a C runtime file that stitches kernels for the given forward IR.
31  *
32  * @param forward The forward IR graph
33  * @param path Output file path
34  * @param mode CK_EMIT_STANDALONE for executable with main(),
35  * CK_EMIT_LIBRARY for shared object with API functions
36  *
37  * Returns 0 on success, non-zero on failure.
38  */
39 int ck_codegen_emit_runtime(const CKIRGraph *forward, const char *path, CKEmitMode mode);
40 
41 #endif /* CKERNEL_CODEGEN_H */
int ck_codegen_emit_runtime(const CKIRGraph *forward, const char *path, CKEmitMode mode)
CKEmitMode
@ CK_EMIT_STANDALONE
@ CK_EMIT_LIBRARY
void ck_codegen_c_skeleton(const CKIRGraph *forward, const CKIRGraph *backward, FILE *out)