CCodeGenerator
Core C code generator that converts SKaiNET ComputeGraph to Arduino-compatible C code.
This class leverages existing SKaiNET infrastructure (ComputeGraph, Operation interface, TensorSpec) to generate static C99-compatible code for Arduino microcontrollers.
The generator preserves topological ordering from ComputeGraph, validates operations using the existing Operation interface, and calculates memory requirements using TensorSpec.
Functions
Calculates memory requirements using existing TensorSpec shape information. Implements static memory allocation with ping-pong buffer strategy. Validates that all memory allocations are static and compile-time known.
Extracts weight arrays from Dense/Linear layers with exact weight preservation. Follows existing ModuleParameter structure patterns from Linear layer implementation.
Generates C code for activation functions using standard math library functions. Matches existing DefaultCpuOps implementations for consistency.
Generates C code for activation functions with exact numerical consistency. Matches existing DefaultCpuOps implementations for consistency.
Generates all layer code in topological order with numerical accuracy guarantees. Preserves execution order from ComputeGraph. Performs comprehensive validation before code generation.
Generates C code for Dense layer operations using nested loops. Follows existing DefaultCpuOps implementation patterns for matrix-vector multiplication.
Generates C code for Dense layer operations with exact numerical consistency. Follows existing DefaultCpuOps implementation patterns for matrix-vector multiplication.
Generates C code for transpose operations.
Validates buffer alternation pattern in generated code. Ensures ping-pong buffer strategy is correctly implemented.
Validates that generated code uses only static memory allocation. Ensures no malloc, calloc, realloc, or other dynamic allocation calls.
Validates the graph and checks for unsupported operations. Leverages existing Operation interface validation. Implements fail-fast validation before code generation.
Validates memory management patterns for C code generation. Ensures static memory allocation and proper buffer alternation.
Validates operations using existing Operation interface. Detects unsupported operations and generates clear error messages.