← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
ckernel_codegen_v2_struct.c File Reference
#include "ckernel_codegen_v2_emit.h"
#include <stdio.h>

Go to the source code of this file.

Functions

int ck_codegen_v2_emit_preamble (FILE *out)
 
void ck_codegen_v2_emit_struct (FILE *out, const CKIRV2Graph *graph, const CKMemPlan *plan, const char *tag)
 

Function Documentation

◆ ck_codegen_v2_emit_preamble()

int ck_codegen_v2_emit_preamble ( FILE *  out)

Definition at line 5 of file ckernel_codegen_v2_struct.c.

6{
7 fprintf(out,
8 "/* Auto-generated runtime from CKIRV2Graph.\n"
9 " * This v2 emitter currently writes the schedule and buffer layout\n"
10 " * stubs. Kernel wiring will be layered on as IR v2 grows.\n"
11 " */\n\n");
12 fprintf(out,
13 "#include <stddef.h>\n"
14 "#include <stdint.h>\n"
15 "#include <stdio.h>\n"
16 "#include <string.h>\n\n");
17 return 0;
18}

Referenced by ck_codegen_v2_emit_runtime().

◆ ck_codegen_v2_emit_struct()

void ck_codegen_v2_emit_struct ( FILE *  out,
const CKIRV2Graph graph,
const CKMemPlan plan,
const char *  tag 
)

Definition at line 20 of file ckernel_codegen_v2_struct.c.

24{
25 const char *suffix = tag ? tag : "prefill";
26 fprintf(out, "typedef struct {\n"
27 " size_t offset_bytes;\n"
28 " size_t size_bytes;\n"
29 " int arena;\n"
30 "} CKV2BufferLayout;\n\n");
31
32 fprintf(out, "static const CKV2BufferLayout ck_v2_%s_buffers[] = {\n", suffix);
33 for (int i = 0; i < graph->num_buffers; ++i) {
34 const CKMemSpan *span = &plan->spans[i];
35 fprintf(out,
36 " { %zu, %zu, %d }, /* %s */\n",
37 span->offset_bytes,
38 span->size_bytes,
39 (int)span->arena,
40 graph->buffers[i].name ? graph->buffers[i].name : "unnamed");
41 }
42 fprintf(out, "};\n\n");
43
44 fprintf(out, "static const size_t ck_v2_%s_total_bytes[] = {\n", suffix);
45 for (int i = 0; i < CK_MEM_ARENA_COUNT; ++i) {
46 fprintf(out, " %zu%s\n",
47 plan->total_bytes[i],
48 (i + 1 == CK_MEM_ARENA_COUNT) ? "" : ",");
49 }
50 fprintf(out, "};\n\n");
51
52 fprintf(out, "typedef struct {\n"
53 " const CKV2BufferLayout *buffers;\n"
54 " int num_buffers;\n"
55 " const size_t *total_bytes;\n"
56 " size_t alignment_bytes;\n"
57 "} CKV2Runtime;\n\n");
58
59 fprintf(out, "static const CKV2Runtime ck_v2_%s_runtime = {\n"
60 " ck_v2_%s_buffers,\n"
61 " %d,\n"
62 " ck_v2_%s_total_bytes,\n"
63 " %d\n"
64 "};\n\n",
65 suffix,
66 suffix,
67 graph->num_buffers,
68 suffix,
70}
@ CK_MEM_ARENA_COUNT
#define CK_MEM_PLAN_DEFAULT_ALIGN
CKIRV2Buffer * buffers
CKMemSpan * spans
size_t total_bytes[CK_MEM_ARENA_COUNT]
size_t size_bytes
CKMemArenaKind arena
size_t offset_bytes

References CKMemSpan::arena, CKIRV2Graph::buffers, CK_MEM_ARENA_COUNT, CK_MEM_PLAN_DEFAULT_ALIGN, CKIRV2Buffer::name, CKIRV2Graph::num_buffers, CKMemSpan::offset_bytes, CKMemSpan::size_bytes, CKMemPlan::spans, and CKMemPlan::total_bytes.

Referenced by ck_codegen_v2_emit_runtime().