Skip to content

Commit

Permalink
Merge pull request #12 from Xilinx/dev
Browse files Browse the repository at this point in the history
finn-examples v0.0.3b
  • Loading branch information
maltanar authored Jun 15, 2021
2 parents eaebe90 + ce4e090 commit 8e659a4
Show file tree
Hide file tree
Showing 11 changed files with 2,203 additions and 526 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dummy_out = accel.execute(dummy_in)
| <img src="docs/img/cifar-10.png" width="150"/><br/>CIFAR-10 | CNV (VGG-11-like) | several variants:<br>1/2-bit weights/activations | all |
| <img src="docs/img/mnist.jpg" width="150"/><br/><br>MNIST | 3-layer fully-connected | several variants:<br>1/2-bit weights/activations | all |
| <img src="docs/img/imagenet.jpg" width="150"/><br/><br>ImageNet | MobileNet-v1 | 4-bit weights and activations<br>8-bit first layer weights | Alveo U250<br>ZCU104 |
| <img src="docs/img/imagenet.jpg" width="150"/><br/><br>ImageNet | ResNet-50 | 1-bit weights 2-bit activations<br>4-bit residuals<br>8-bit first/last layer weights | Alveo U250 |

## Supported Boards

Expand Down
2 changes: 1 addition & 1 deletion build/get-finn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# URL for git repo to be cloned
REPO_URL=https://github.com/Xilinx/finn
# commit hash for repo
REPO_COMMIT=e5da788bdc74fc9c234bb0176521ad51e830c22e
REPO_COMMIT=c8be5048a7f1647f7c72be7c7cd158e851d47a86
# directory (under the same folder as this script) to clone to
REPO_DIR=finn

Expand Down
33 changes: 33 additions & 0 deletions build/resnet50/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Resnet 50

Implementation of a binary ResNet50 FINN-style dataflow accelerator targeting Alveo boards.

## Build bitfiles for Resnet 50

We use a specialized build script that replaces a few of the standard steps
in FINN with custom ones.

To add support for two MAC per DSP per cycle install [
finn-experimental](https://github.com/Xilinx/finn-experimental). This allows 16x more FPS per MHz (Alveo U250 implementation).

**Resnet 50 is currently only supported on Alveo U250.**

0. Ensure you have performed the *Setup* steps in the top-level README for setting up the FINN requirements and environment variables.

1. Download the pretrained Resnet 50 ONNX model from the releases page, and extract
the zipfile under `resnet50/models`. You should have e.g. `resnet50/models∕resnet50_w1a2_exported.onnx` as a result.
You can use the provided `resnet50/models/download_resnet50.sh` script for this.

2. Launch the build as follows:
```SHELL
# update this according to where you cloned this repo:
FINN_EXAMPLES=/path/to/finn-examples
# cd into finn submodule
cd $FINN_EXAMPLES/build/finn
# launch the build on the resnet50 folder
./run-docker.sh build_custom /path/to/finn-examples/build/resnet50
```

5. The generated outputs will be under `resnet50/output_<topology>_<board>`. You can find a description of the generated files [here](https://finn-dev.readthedocs.io/en/latest/command_line.html#simple-dataflow-build-mode).

<!-- ## Where did the ONNX model files come from? -->
94 changes: 94 additions & 0 deletions build/resnet50/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright (c) 2020, Xilinx
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of FINN nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import finn.builder.build_dataflow as build
import finn.builder.build_dataflow_config as build_cfg
from finn.util.basic import alveo_default_platform
from warnings import warn
# custom steps for resnet50v1.5
from custom_steps import (
step_resnet50_tidy,
step_resnet50_streamline,
step_resnet50_convert_to_hls,
step_resnet50_set_fifo_depths,
step_resnet50_slr_floorplan
)

model_name = "resnet50_w1a2"
board = "U250"
vitis_platform = alveo_default_platform[board]
synth_clk_period_ns = 4.0
target_fps = 300

resnet50_build_steps = [
step_resnet50_tidy,
step_resnet50_streamline,
step_resnet50_convert_to_hls,
"step_create_dataflow_partition",
"step_apply_folding_config",
"step_generate_estimate_reports",
"step_hls_codegen",
"step_hls_ipgen",
step_resnet50_set_fifo_depths,
step_resnet50_slr_floorplan,
"step_synthesize_bitfile",
"step_make_pynq_driver",
"step_deployment_package",
]

try:
from finn.transformation.fpgadataflow.infer_doublepacked_dsp import InferDoublePackedConv
folding_config_file="folding_config/U250_folding_config.json"
print("DoublePackedConv detected")
except:
warn(" FINN Experimental not available. Using non-packed folded down convolution. This is 16 times slower per MHz ")
folding_config_file="folding_config/U250_folding_config_no_doublepack_pe_folded_16.json"

cfg = build_cfg.DataflowBuildConfig(
steps=resnet50_build_steps,
output_dir="output_%s_%s" % (model_name, board),
synth_clk_period_ns=synth_clk_period_ns,
board=board,
shell_flow_type=build_cfg.ShellFlowType.VITIS_ALVEO,
vitis_platform=vitis_platform,
# throughput parameters (auto-folding)
mvau_wwidth_max = 24,
target_fps = target_fps,
folding_config_file = folding_config_file,
# enable extra performance optimizations (physopt)
vitis_opt_strategy=build_cfg.VitisOptStrategyCfg.PERFORMANCE_BEST,
generate_outputs=[
build_cfg.DataflowOutputType.PYNQ_DRIVER,
build_cfg.DataflowOutputType.ESTIMATE_REPORTS,
build_cfg.DataflowOutputType.BITFILE,
build_cfg.DataflowOutputType.DEPLOYMENT_PACKAGE,
],
)

model_file = "models/%s_exported.onnx" % model_name
build.build_dataflow_cfg(model_file, cfg)
Loading

0 comments on commit 8e659a4

Please sign in to comment.