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.

Constructors

Link copied to clipboard
constructor(graph: ComputeGraph)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

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.

Link copied to clipboard

Extracts weight arrays from Dense/Linear layers with exact weight preservation. Follows existing ModuleParameter structure patterns from Linear layer implementation.

Link copied to clipboard

Generates C code for activation functions using standard math library functions. Matches existing DefaultCpuOps implementations for consistency.

Link copied to clipboard

Generates C code for activation functions with exact numerical consistency. Matches existing DefaultCpuOps implementations for consistency.

Link copied to clipboard

Generates all layer code in topological order with numerical accuracy guarantees. Preserves execution order from ComputeGraph. Performs comprehensive validation before code generation.

Link copied to clipboard
fun generateDenseLayer(node: GraphNode, denseIndex: Int? = null): LayerCode

Generates C code for Dense layer operations using nested loops. Follows existing DefaultCpuOps implementation patterns for matrix-vector multiplication.

Link copied to clipboard
fun generateDenseLayerWithAccuracy(node: GraphNode, addNode: GraphNode? = null, denseIndex: Int? = null): LayerCode

Generates C code for Dense layer operations with exact numerical consistency. Follows existing DefaultCpuOps implementation patterns for matrix-vector multiplication.

Link copied to clipboard

Generates C code for transpose operations.

Link copied to clipboard

Validates buffer alternation pattern in generated code. Ensures ping-pong buffer strategy is correctly implemented.

Link copied to clipboard

Validates that generated code uses only static memory allocation. Ensures no malloc, calloc, realloc, or other dynamic allocation calls.

Link copied to clipboard

Validates the graph and checks for unsupported operations. Leverages existing Operation interface validation. Implements fail-fast validation before code generation.

Link copied to clipboard

Validates memory management patterns for C code generation. Ensures static memory allocation and proper buffer alternation.

Link copied to clipboard

Validates operations using existing Operation interface. Detects unsupported operations and generates clear error messages.