NNC is a proof-of-concept neural network compiler. Its goal is to take neural network models, potentially from formats like ONNX, and compile them into efficient code, such as C.
Compiling it to lower level code means you dont need a runtime to execute it while still being more efficient
- Frontend: Support for parsing neural network models (e.g., ONNX).
- Intermediate Representation (IR): An internal representation for neural network graphs.
- Code Generation: Generate target code (e.g., C) from the IR.
Generate C from an ONNX model:
cargo run -- --model <path-to-model.onnx> --out-dir out --mode lib --weights external
Options:
--model <path>: path to input ONNX model (default:out/resnet_model.onnx)--out-dir <path>: output directory for generated artifacts (default:out)--mode <dummy|file|lib>: generation mode--weights <embedded|external>: embed weights in C or emitweights.bin
When using --mode file, you need an input.bin file. You can generate this using the included gen_input utility:
-
Random/Dummy Data:
cargo run --bin gen_input -- --model <path-to-model.onnx> --out out/input.bin
-
From Text File: Create a
.txtfile (e.g.,input.txt) with numbers separated by spaces, commas, or newlines.cargo run --bin gen_input -- --model <path-to-model.onnx> --data input.txt --out out/input.bin
The utility automatically handles shape extraction from the model and provides zero-padding if your text file is smaller than the required input size.
The text file should contain numeric values separated by spaces, commas, or newlines.
0.1, 0.5, 0.2
0.8 1.0
0.0
0.3
Run the end-to-end pipeline validation:
cargo test
The integration test in tests/e2e_pipeline.rs writes a deterministic tiny ONNX fixture, runs the full compiler pipeline, and verifies generated artifacts/symbols.
- Extend parsing in
src/frontend/onnx.rsand codegen insrc/codegen/c.rs. - Run
cargo testto ensure the E2E generation path still works. - Prefer adding focused fixtures/tests when introducing new operators to prevent regressions.
Contributions are welcome! Please feel free to open issues or submit pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.