Skip to content

C code generation for neural networks in ONNX format. Generated code is dependency free.

Notifications You must be signed in to change notification settings

danielbinschmid/C-CodeGen-NN

Repository files navigation

C-CodeGen-NN

This repository contains a toolchain to generate code for neural networks described by the ONNX format to dependency free C code using ApacheTVM.
The target is to generate C code that can be used for circuit simulation frameworks such as Chipyard or Synopsis.

Features

  • FrontEnds: ONNX
  • Build tools: standard gcc, riscv64-unknown-elf, riscv64-unknown-elf baremetal

Setup

  • Tested with python version 3.9.15
  • Dependency management via poetry

After activating fresh virtual python environment:

$ pip install --upgrade pip
$ pip install poetry
$ poetry install

Usage

  1. Prepare onnx file. Modify prepare.sh to your needs. Generate dummy verification data:
$ ./prepare.sh
  1. Generate C code. Modify generate.sh to your needs. Generate C code:
$ ./generate.sh
  1. Build. Build with e.g.
$ cd <c_code_dir>
$ make
  1. Run. C code logs computed output and reference output to the console. They match if the generated C code generated by TVM is correct. If they do not match, the issue either lies in the verification data or at Apache TVM. Execute e.g. via:
$ cd <build_dir>
$ ./executable

Notes

  • Most of the steps work with multiple input and output arguments of the neural network but not all. For multiple inputs and outputs, the scripts need to be adjusted.
  • An example output can be found in output/cnn_mnist for a basic CNN.

About

C code generation for neural networks in ONNX format. Generated code is dependency free.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published