Skip to content

shashank976/tinyml-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinyml-compiler

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.

Pipeline

Model → IR → Optimizer → Codegen → Simulator

Features

  • 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

Usage

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_compiler

Project Structure

nn_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

Requirements

  • GCC
  • Make

About

A lightweight neural network compiler in C that translates layer definitions into a custom IR and instruction set, with optimization passes and a runtime simulator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors