A lightweight neural network compiler written in C that translates high-level layer definitions into a custom intermediate representation (IR) and instruction set, with optimization passes and a runtime simulator.
Model → IR → Optimizer → Codegen → Simulator
- Model loading from a config file (
.txt) — define layers, weights, and biases without recompiling - IR generation — converts layer definitions into abstract operations (MATMUL, ADD, RELU, etc.)
- Optimization passes
- Operator fusion: fuses MATMUL + ADD into a single LINEAR operation
- Redundant elimination: removes unnecessary ops (e.g. RELU after SIGMOID)
- Code generation — translates IR into a custom instruction set (LOAD, LINEAR, RELU, STORE, etc.)
- Runtime simulator — executes instructions using custom linear algebra kernels
- Supported layers — Dense, ReLU, Sigmoid, Softmax, Flatten
Define your model in a config file:
WEIGHTS W1 1.0 0.5 0.2 0.3 0.8 0.6
BIAS B1 0.1 0.2 0.3
DENSE 2 3 W1 B1
RELU
SOFTMAX
Then build and run:
make
./nn_compilernn_compiler/
├── include/ # Header files
├── src/
│ ├── main.c # Pipeline orchestration
│ ├── model.c # Model loading from config
│ ├── ir.c # IR generation
│ ├── optimizer.c # Optimization passes
│ ├── codegen.c # Instruction generation
│ ├── simulator.c # Runtime execution
│ └── math_ops.c # Linear algebra kernels
└── model.txt # Model config file
- GCC
- Make