- Install Docker to run without root
- Set up
FINN_XILINX_VERSIONenvironment variables pointing respectively to the Xilinx tools installation directory and version (e.g.
- Clone the FINN compiler from the repo:
git clone https://github.com/Xilinx/finn/and go into the directory where it is cloned
./run-docker.sh quicktestto verify your installation.
- Optionally, follow the instructions on PYNQ board first-time setup or Alveo first-time setup for board setup.
- Optionally, set up a Vivado/Vitis license.
- All done! See Running FINN in Docker for the various options on how to run the FINN compiler.
How do I use FINN?¶
We strongly recommend that you first watch one of the pre-recorded FINN tutorial videos, then follow the Jupyter notebook tutorials for training and deploying an MLP for network intrusion detection . You may also want to check out the other Tutorials, and the FINN examples repository .
Our aim in FINN is not to accelerate common off-the-shelf neural networks, but instead provide you with a set of tools to train customized networks and create highly-efficient FPGA implementations from them. In general, the approach for using the FINN framework is as follows:
- Train your own quantized neural network (QNN) in Brevitas. We have some guidelines on quantization-aware training (QAT).
- Export to FINN-ONNX by following this tutorial .
- Use FINN’s
build_dataflowsystem on the exported model by following this tutorial
- Adjust your QNN topology, quantization settings and
build_dataflowconfiguration to get the desired results.
Please note that the framework is still under development, and how well this works will depend on how similar your custom network is to the examples we provide. If there are substantial differences, you will most likely have to write your own Python scripts that call the appropriate FINN compiler functions that process your design correctly, or adding new functions (including Vitis HLS layers) as required. The advanced FINN tutorials can be useful here. For custom networks, we recommend making a copy of the BNN-PYNQ end-to-end Jupyter notebook tutorials as a starting point, visualizing the model at intermediate steps and adding calls to new transformations as needed. Once you have a working flow, you can implement a command line entry for this by using the “advanced mode” described in the Command Line Entry section.
Running FINN in Docker¶
FINN runs inside a Docker container, it comes with a script to easily build and launch the container. If you are not familiar with Docker, there are many excellent online resources to get started. You may want to review the General FINN Docker tips and Environment variables as well. If you want to use prebuilt images, read Using a prebuilt image.
The above mentioned script to build and launch the FINN docker container is called run-docker.sh . It can be launched in the following modes:
Launch interactive shell¶
Simply running sh run-docker.sh without any additional arguments will create a Docker container with all dependencies and give you a terminal with you can use for development for experimentation:
Launch a Build with
FINN is currently more compiler infrastructure than compiler, but we do offer a Command Line Entry entry for certain use-cases. These run a predefined flow or a user-defined flow from the command line as follows:
bash ./run_docker.sh build_dataflow <path/to/dataflow_build_dir/>
bash ./run_docker.sh build_custom <path/to/custom_build_dir/>
Launch Jupyter notebooks¶
FINN comes with numerous Jupyter notebook tutorials, which you can launch with:
bash ./run-docker.sh notebook
This will launch the Jupyter notebook server inside a Docker container, and print a link on the terminal that you can open in your browser to run the FINN notebooks or create new ones.
The link will look something like this (the token you get will be different):
run-docker.sh script forwards ports 8888 for Jupyter and 8081 for Netron, and launches the notebook server with appropriate arguments.
Prior to running the run-docker.sh script, there are several environment variables you can set to configure certain aspects of FINN. These are summarized below:
FINN_XILINX_PATHpoints to your Xilinx tools installation on the host (e.g.
FINN_XILINX_VERSIONsets the Xilinx tools version to be used (e.g.
- (required for Alveo)
PLATFORM_REPO_PATHSpoints to the Vitis platform files (DSA).
- (required for Alveo)
XRT_DEB_VERSIONspecifies the .deb to be installed for XRT inside the container (see default value in
NUM_DEFAULT_WORKERS(default 4) specifies the degree of parallelization for the transformations that can be run in parallel, potentially reducing build time
FINN_HOST_BUILD_DIRspecifies which directory on the host will be used as the build directory. Defaults to
JUPYTER_PORT(default 8888) changes the port for Jupyter inside Docker
JUPYTER_PASSWD_HASH(default “”) Set the Jupyter notebook password hash. If set to empty string, token authentication will be used (token printed in terminal on launch).
LOCALHOST_URL(default localhost) sets the base URL for accessing e.g. Netron from inside the container. Useful when running FINN remotely.
NETRON_PORT(default 8081) changes the port for Netron inside Docker
ALVEO_BOARDspecifies the type of PYNQ/Alveo board used (see “supported hardware” below) for the test suite
ALVEO_PORT) specify ip address and port number to access the PYNQ board / Alveo target
ALVEO_PASSWORD) specify the PYNQ board / Alveo host access credentials for the test suite. For PYNQ, password is always needed to run as sudo. For Alveo, you can leave the password empty and place your ssh private key in the
finn/ssh_keysfolder to use keypair authentication.
ALVEO_TARGET_DIR) specifies the target dir on the PYNQ board / Alveo host for the test suite
IMAGENET_VAL_PATHspecifies the path to the ImageNet validation directory for tests.
FINN_DOCKER_PREBUILT(default 0) if set to 1 then skip Docker image building and use the image tagged with
FINN_DOCKER_TAG(autogenerated) specifies the Docker image tag to use.
FINN_DOCKER_RUN_AS_ROOT(default 0) if set to 1 then run Docker container as root, default is the current user.
FINN_DOCKER_GPU(autodetected) if not 0 then expose all Nvidia GPUs or those selected by
NVIDIA_VISIBLE_DEVICESto Docker container for accelerated DNN training. Requires Nvidia Container Toolkit
FINN_DOCKER_EXTRA(default “”) pass extra arguments to the
docker runcommand when executing
FINN_SKIP_DEP_REPOS(default “0”) skips the download of FINN dependency repos (uses the ones already downloaded under deps/.
NVIDIA_VISIBLE_DEVICES(default “”) specifies specific Nvidia GPUs to use in Docker container. Possible values are a comma-separated list of GPU UUID(s) or index(es) e.g.
none, or void/empty/unset.
DOCKER_BUILDKIT(default “1”) enables Docker BuildKit for faster Docker image rebuilding (recommended).
General FINN Docker tips¶
- Several folders including the root directory of the FINN compiler and the
FINN_HOST_BUILD_DIRwill be mounted into the Docker container and can be used to exchange files.
- Do not use
sudoto launch the FINN Docker. Instead, setup Docker to run without root.
- If you want a new terminal on an already-running container, you can do this with
docker exec -it <name_of_container> bash.
- The container is spawned with the –rm option, so make sure that any important files you created inside the container are either in the finn compiler folder (which is mounted from the host computer) or otherwise backed up.
Using a prebuilt image¶
By default the
run-docker.sh script tries to re-build the Docker image with each run. After the first run this should go quite fast thanks to Docker caching.
If you are having trouble building the Docker image or need offline access, you can use prebuilt images by following these steps:
- Pull a prebuilt Docker image with
docker pull maltanar/finn:<tag>where
- Set the
FINN_DOCKER_TAGto the name of the image you just pulled e.g.
- You can now launch the Docker image in all modes without re-building or any internet access.
Supported FPGA Hardware¶
Shell-integrated accelerator + driver: For quick deployment, we target boards supported by PYNQ . For these platforms, we can build a full bitfile including DMAs to move data into and out of the FINN-generated accelerator, as well as a Python driver to launch the accelerator. We support the Pynq-Z1, Pynq-Z2, Ultra96, ZCU102 and ZCU104 boards, as well as Alveo cards.
Vivado IPI support for any Xilinx FPGA: FINN generates a Vivado IP Integrator (IPI) design from the neural network with AXI stream (FIFO) in-out interfaces, which can be integrated onto any Xilinx FPGA as part of a larger system. It’s up to you to take the FINN-generated accelerator (what we call “stitched IP” in the tutorials), wire it up to your FPGA design and send/receive neural network data to/from the accelerator.
PYNQ board first-time setup¶
We use host to refer to the PC running the FINN Docker environment, which will build the accelerator+driver and package it up, and target to refer to the PYNQ board. To be able to access the target from the host, you’ll need to set up SSH public key authentication:
Start on the target side:
- Note down the IP address of your PYNQ board. This IP address must be accessible from the host.
- Ensure the
bitstringpackage is installed:
sudo pip3 install bitstring
Continue on the host side (replace the
<PYNQ_USERNAME> with the IP address and username of your board from the first step):
- Launch the Docker container from where you cloned finn with
- Go into the ssh_keys directory (e.g.
ssh-keygento create a key pair e.g.
ssh-copy-id -i id_rsa.pub <PYNQ_USERNAME>@<PYNQ_IP>to install the keys on the remote system
- Test that you can
ssh <PYNQ_USERNAME>@<PYNQ_IP>without having to enter the password. Pass the
-vflag to the ssh command if it doesn’t work to help you debug.
Alveo first-time setup¶
We use host to refer to the PC running the FINN Docker environment, which will build the accelerator+driver and package it up, and target to refer to the PC where the Alveo card is installed. These two can be the same PC, or connected over the network – FINN includes some utilities to make it easier to test on remote PCs too. Prior to first usage, you need to set up both the host and the target in the following manner:
On the target side:
- Install Xilinx XRT.
- Install the Vitis platform files for Alveo and set up the
PLATFORM_REPO_PATHSenvironment variable to point to your installation, for instance
- Create a conda environment named finn-pynq-alveo by following this guide to set up PYNQ for Alveo. It’s best to follow the recommended environment.yml (set of package versions) in this guide.
- Activate the environment with conda activate finn-pynq-alveo and install the bitstring package with
pip install bitstring.
- Done! You should now be able to e.g.
import pynqin Python scripts.
On the host side:
- Install Vitis 2022.1 and set up the
VITIS_PATHenvironment variable to point to your installation.
- Install Xilinx XRT. Ensure that the
XRT_DEB_VERSIONenvironment variable reflects which version of XRT you have installed.
- Install the Vitis platform files for Alveo and set up the
PLATFORM_REPO_PATHSenvironment variable to point to your installation. This must be the same path as the target’s platform files (target step 2)
- Set up the
ALVEO_*environment variables accordingly for your target, see description of environment variables above.
- Set up public key authentication. Copy your private key to the
finn/ssh_keysfolder on the host to get password-less deployment and remote execution.
If you are targeting Xilinx FPGA parts that needs specific licenses (non-WebPack) you can make these available to the
FINN Docker container by passing extra arguments. To do this, you can use the
FINN_DOCKER_EXTRA environment variable as follows:
export FINN_DOCKER_EXTRA=" -v /path/to/licenses:/path/to/licenses -e XILINXD_LICENSE_FILE=/path/to/licenses "
The above example mounts
/path/to/licenses from the host into the same path on the Docker container, and sets the
value of the
XILINXD_LICENSE_FILE environment variable.
- Ubuntu 18.04 with
- Docker without root
- A working Vitis/Vivado 2022.1 installation
FINN_XILINX_VERSIONenvironment variables correctly set, see Quickstart
- (optional) Vivado/Vitis license if targeting non-WebPack FPGA parts.
- (optional) A PYNQ board with a network connection, see PYNQ board first-time setup
We also recommend running the FINN compiler on a system with sufficiently strong hardware:
- RAM. Depending on your target FPGA platform, your system must have sufficient RAM to be able to run Vivado/Vitis synthesis for that part. See this page for more information. For targeting Zynq and Zynq UltraScale+ parts, at least 8 GB is recommended. Larger parts may require up to 16 GB. For targeting Alveo parts with Vitis, at least 64 GB RAM is recommended.
- CPU. FINN can parallelize HLS synthesis and several other operations for different
layers, so using a multi-core CPU is recommended. However, this should be balanced
against the memory usage as a high degree of parallelization will require more
memory. See the
NUM_DEFAULT_WORKERSenvironment variable below for more on how to control the degree of parallelization.
- Storage. While going through the build steps, FINN will generate many files as part of
the process. For larger networks, you may need 10s of GB of space for the temporary
files generated during the build.
By default, these generated files will be placed under
/tmp/finn_dev_<username>. You can override this location by using the
FINN_HOST_BUILD_DIRenvironment variable. Mapping the generated file dir to a fast SSD will result in quicker builds.