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.
- FrontEnds: ONNX
- Build tools: standard gcc, riscv64-unknown-elf, riscv64-unknown-elf baremetal
- 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
- Prepare onnx file. Modify prepare.sh to your needs. Generate dummy verification data:
$ ./prepare.sh
- Generate C code. Modify generate.sh to your needs. Generate C code:
$ ./generate.sh
- Build. Build with e.g.
$ cd <c_code_dir>
$ make
- 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
- 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.