Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor modifications to SetFoldingExhaustive #438

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
23 changes: 23 additions & 0 deletions src/finn/builder/build_dataflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,29 @@ class DataflowBuildConfig:
#: that will override the target_fps setting here.
target_fps: Optional[int] = None

#: (Optional) Fraction that indicates what part of the LUTs of the targeted
#: FPGA board are set available for user's network.
#: If parallelization attributes are specified as part of folding_config_file
#: that will override the resource_frac setting here.
resource_frac: Optional[float] = 0.7

#: (Optional) Maximum number of LUTs available to be used.
#: If max_luts is specified with folding_mode="resources", the network is
#: folded while ensuring to stay under the budget of the specified
#: maximum number of LUTs. If not specified, the resource_frac and board
#: attributes will be used to determine the LUT budget.
max_luts: Optional[int] = None

#: (Optional) Indicate whether the network should be explored based on
#: either target_fps requirement or the resource limit on the board scaled
#: by resource_frac. If invalid folding_mode specified, then folding is
#: is done according to target_fps.
#: If target_fps is specified, the network is folded either until the resource
#: budget is reached or until the target_fps is met. If target_fps is not
#: specified, the network is folded until the resource budget is reached.
#: Expected: ["frames", "resources"]
folding_mode: Optional[str] = "frames"

#: (Optional) Use two-pass relaxation for folding, only relevant if target_fps
#: is set. If enabled, parallelization will internally run a second time if the
#: target cycles from the first pass could not be achieved, instead using the
Expand Down
52 changes: 47 additions & 5 deletions src/finn/builder/build_dataflow_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
RemoveShallowFIFOs,
)
from finn.transformation.fpgadataflow.set_folding import SetFolding
from finn.transformation.fpgadataflow.set_folding_exhaustive import SetFoldingExhaustive
from finn.transformation.fpgadataflow.synth_ooc import SynthOutOfContext
from finn.transformation.fpgadataflow.vitis_build import VitisBuild
from finn.transformation.general import (
Expand All @@ -103,6 +104,7 @@
from finn.transformation.streamline.reorder import MakeMaxPoolNHWC
from finn.util.basic import get_rtlsim_trace_depth
from finn.util.config import extract_model_config_to_json
from finn.util.platforms import platforms
from finn.util.pyverilator import pyverilate_get_liveness_threshold_cycles
from finn.util.test import execute_parent

Expand Down Expand Up @@ -330,15 +332,55 @@ def step_target_fps_parallelization(model: ModelWrapper, cfg: DataflowBuildConfi
auto_folding_config.json under the outputs, which can serve as a basis for
customizing the folding factors further."""

target_cycles_per_frame = cfg._resolve_cycles_per_frame()
if target_cycles_per_frame is not None:
folding_mode = cfg.folding_mode
if folding_mode == "resources":
print(
"Folding the network based on the resource budget of {}x \
of the available LUTs!".format(
cfg.resource_frac
)
)
if cfg.max_luts is not None:
max_luts = cfg.max_luts
elif cfg.board is not None:
try:
board_resources = platforms[cfg.board]().compute_resources
max_luts = sum(res[0] for res in board_resources)
except KeyError:
print("Board {} not found in finn.util.platforms!".format(cfg.board))
raise
else:
raise Exception(
"Please specify either the maximum number of LUTs available or board"
)
target_cycles_per_frame = cfg._resolve_cycles_per_frame()
model = model.transform(
SetFolding(
SetFoldingExhaustive(
target_cycles_per_frame,
mvau_wwidth_max=cfg.mvau_wwidth_max,
two_pass_relaxation=cfg.folding_two_pass_relaxation,
cfg.mvau_wwidth_max,
scale_ratio=cfg.resource_frac,
max_luts=max_luts,
)
)
elif folding_mode == "frames":
print("Folding the network based on target frames per second!")
target_cycles_per_frame = cfg._resolve_cycles_per_frame()
if target_cycles_per_frame is not None:
model = model.transform(
SetFolding(
target_cycles_per_frame,
mvau_wwidth_max=cfg.mvau_wwidth_max,
two_pass_relaxation=cfg.folding_two_pass_relaxation,
)
)
else:
raise (
"Folding mode {} not recognized! Please choose either 'frames'\
or 'resources'.".format(
folding_mode
)
)

# extract the suggested configuration and save it as json
hw_attrs = [
"PE",
Expand Down
Loading