This section describes how to use Tensil with Sabana
At the end of this guide you will be able to run ResNet-20 on using Sabana.


If you have not done it yet, follow our instructions to:
  • Install the Sabana CLI
  • Install the Sabana Python SDK
You will also need to install docker in order to run the Tensil compiler and generator. Follow their instructions here.

Create the image

Create a new Sabana project, using the AXI4-Stream Send (128 bit) and two AXI4 (128 bit) shell:
sabana new tensil
Select the following options:
Welcome to sabana, let's create a project
✔ Select a language · Verilog
✔ Select shell type · AXI4
✔ Select a starting point · AXI4-Stream Send (128 bit) and two AXI4 (128 bit) shell

Generate the accelerator

An architecture file is required to generate an accelerator. This file describes the parameters that will be used to generate the accelerator. For convenience we use the same parameters from the Pynq-Z1 architecture in our image.
We will be using Tensil version 1.0.15
Copy the Pynq-Z1 architecture shipped in the Tensil docker container to the project directory:
cd tensil
docker run --rm -it --user "$(id -u):$(id -g)" -v $(pwd):/work -w /work tensilai/tensil:$tag cp /demo/arch/pynqz1.tarch ./$tarch_file
Generate the Tensil accelerator by running the following commands:
docker run --rm -it --user "$(id -u):$(id -g)" -v $(pwd):/work -w /work tensilai/tensil:$tag tensil rtl -a /work/$tarch_file -s true -d 128
Copy the generated files to the src folder:
cp bram_dp_128x2048.v bram_dp_128x8192.v top_tensil.v src/
rm bram_dp_128x2048.v bram_dp_128x8192.v top_tensil.v top_tensil.fir firrtl_black_box_resource_files.f top_tensil.anno.json architecture_params.h

Integrate the accelerator

The next step is to instantiate the Tensil module in the sabana.v file. For convenience, download the sabana.v file from our examples repository and move it to the src directory:
mv sabana.v src/

Build the accelerator

Push the project to Sabana with the following command:
sabana push
This process will take about 7 minutes to complete.

Run ResNet-20

Generate the ML model files

If you have access to a Linux/AMD64 machine you could compile the model yourself using the Tensil docker container via following command:
docker run --user "$(id -u):$(id -g)" -v $(pwd):/work -w /work -it tensilai/tensil:$tag tensil compile -a /work/$tarch_file -m /demo/models/resnet20v2_cifar.onnx -o "Identity:0" -s true
mv resnet20v2_cifar_onnx_tensil.tdata resnet20v2_cifar_onnx_tensil.tmodel resnet20v2_cifar_onnx_tensil.tprog tests/
If you don't have easy access to a Linux/AMD64 machine we recommend using our pre-compiled model files stored in the examples GitHub repository:
wget -O tests/resnet20v2_cifar_onnx_tensil.tdata\?raw\=true
wget -O tests/resnet20v2_cifar_onnx_tensil.tmodel\?raw\=true
wget -O tests/resnet20v2_cifar_onnx_tensil.tprog\?raw\=true

Download Tensil driver dependencies

mv tensil-1.0.15/drivers/tcu_pynq tests/
rm -rf tensil-1.0.15

Download the Sabana example driver

mkdir tests/tcu_sabana
touch tests/tcu_sabana/
wget -O tests/tcu_sabana/

Download the cifar dataset

mkdir tests/deploy
tar xfvz cifar-10-python.tar.gz
rm cifar-10-batches-py/data_batch_*
cp -r cifar-10-batches-py/* tests/deploy
rm -r cifar-10-batches-py
rm cifar-10-python.tar.gz

Run the Sabana example test

wget -O tests/
First run the script without modifications to test everything is correctly setup, this will use our pre-built image:
cd tests python3
Now modify line 100 in the script. Change the user in the image triple to your username.
if __name__ == "__main__":
drv = Driver(image="<your-username>/tensil:0.1.0", debug=False)
This will make the Driver object to use the image you previously created. Re-run the script:
You have successfully integrated a Tensil accelerator in a Sabana image and have run ResNet-20 on it!

Further reading