Skip to content

Commit 9a4c9bd

Browse files
author
Lukas Stasytis
committed
New Folding Optimizer based on cost functions and simulated annealing as the optimizer
1 parent 58fa637 commit 9a4c9bd

6 files changed

Lines changed: 1738 additions & 42 deletions

File tree

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ sigtools==4.0.1
1919
toposort==1.7.0
2020
vcdvcd==1.0.5
2121
wget==3.2
22+
wrapdisc==2.5.0

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ docs =
8383
sphinx_rtd_theme==0.5.0
8484
torchvision
8585
torch
86+
wrapdisc
8687
qonnx@git+https://github.com/fastmachinelearning/qonnx@main#egg=qonnx
8788
brevitas@git+https://github.com/Xilinx/brevitas@master#egg=brevitas_examples
8889

src/finn/builder/build_dataflow_config.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,50 @@ class DataflowBuildConfig:
197197
#: useful for decreasing the latency (even though throughput won't increase).
198198
folding_two_pass_relaxation: Optional[bool] = True
199199

200+
#: (Optional) Control the maximum width of the per-PE MVAU stream while
201+
#: exploring the parallelization attributes to reach target_fps
202+
#: Only relevant if target_fps is specified.
203+
#: Set this to a large value (e.g. 10000) if targeting full unfolding or
204+
#: very high performance.
205+
mvau_wwidth_max: Optional[int] = 1024
206+
207+
# (Optional) which SetFolding optimizer to use (naive, optimized)
208+
folding_style: Optional[str] = "naive"
209+
210+
# (Optional) How much padding to allow for enabling more fine-grain folding
211+
# parameters (generally, more than 6 is unnecessary)
212+
# Enabling this flag requires the generalized datawidthconverter in your finn branch
213+
folding_maximum_padding: Optional[int] = 0
214+
215+
# (Optional) Whether to allow padding IO nodes during folding
216+
# If set to True, the model IO npy arrays would also need to be
217+
# padded by the user on host side!
218+
folding_pad_io_nodes: Optional[bool] = False
219+
220+
# (Optional) Heuristic to consider dwc LUT cost when performing folding
221+
# this will make the folding optimizer avoid mismatching stream widths
222+
enable_folding_dwc_heuristic: Optional[bool] = True
223+
224+
# (Optional) Heuristic to consider FIFO sizing cost when performing folding
225+
# this heuristic might help with not over-sizing fifos
226+
# Highly recommended to NOT enable this flag unless analytic fifo sizing is
227+
# also being used and so RTLSIM is never called for folding
228+
enable_folding_fifo_heuristic: Optional[bool] = False
229+
230+
# (Optional) How much effort to put into automatic folding
231+
# minimizer function. Typical ranges are between 50 and 500
232+
folding_effort: Optional[int] = 50
233+
234+
# (Optional) How many times to attempt to optimize throughput
235+
# (binary search steps)
236+
# 1: only attempts the target throughput
237+
# >1: attempt to increase the throughput to the maximum possible
238+
# for a given device. Increasing the value by one doubles the
239+
# precision towards reaching maximal throughput possible
240+
# 2 attempts: at worst half of the maximum throughput
241+
# 6 attempts: at worst 93.75% of maximum throughput
242+
folding_max_attempts: Optional[int] = 1
243+
200244
#: (Optional) At which steps the generated intermediate output model
201245
#: will be verified. See documentation of VerificationStepType for
202246
#: available options.
@@ -227,12 +271,10 @@ class DataflowBuildConfig:
227271
#: to the design: e.g. Customer signature, application signature, version
228272
signature: Optional[List[int]] = None
229273

230-
#: (Optional) Control the maximum width of the per-PE MVAU stream while
231-
#: exploring the parallelization attributes to reach target_fps
232-
#: Only relevant if target_fps is specified.
233-
#: Set this to a large value (e.g. 10000) if targeting full unfolding or
234-
#: very high performance.
235-
mvau_wwidth_max: Optional[int] = 36
274+
# (Optional) Flag for generating a hw config json in set_fifo_sizes
275+
# this should be turned off during setFolding optimization's call
276+
# to the set_fifo_sizes step
277+
extract_hw_config: Optional[bool] = True
236278

237279
#: (Optional) Whether thresholding layers (which implement quantized
238280
#: activations in FINN) will be implemented as stand-alone HW layers,

src/finn/builder/build_dataflow_steps.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,15 @@ def step_target_fps_parallelization(model: ModelWrapper, cfg: DataflowBuildConfi
421421
target_cycles_per_frame,
422422
mvau_wwidth_max=cfg.mvau_wwidth_max,
423423
two_pass_relaxation=cfg.folding_two_pass_relaxation,
424+
style=cfg.folding_style,
425+
folding_maximum_padding=cfg.folding_maximum_padding,
426+
enable_folding_dwc_heuristic=cfg.enable_folding_dwc_heuristic,
427+
enable_folding_fifo_heuristic=cfg.enable_folding_fifo_heuristic,
428+
folding_effort=cfg.folding_effort,
429+
folding_max_attempts=cfg.folding_max_attempts,
430+
folding_pad_io_nodes=cfg.folding_pad_io_nodes,
431+
platform=cfg.board,
432+
auto_fifo_strategy=cfg.auto_fifo_strategy,
424433
)
425434
)
426435
# extract the suggested configuration and save it as json

0 commit comments

Comments
 (0)