Skip to content

Commit

Permalink
Merge pull request #86 from Xilinx/bugfix/rn50_fifo
Browse files Browse the repository at this point in the history
[RN50]: use standard set fifo depth
  • Loading branch information
auphelia authored May 3, 2024
2 parents e18241a + 77fe591 commit d69dd7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 75 deletions.
8 changes: 4 additions & 4 deletions build/resnet50/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
from custom_steps import (
step_resnet50_tidy,
step_resnet50_streamline,
step_resnet50_convert_to_hls,
step_resnet50_set_fifo_depths,
step_resnet50_convert_to_hw,
step_resnet50_slr_floorplan,
)

Expand All @@ -52,15 +51,15 @@
resnet50_build_steps = [
step_resnet50_tidy,
step_resnet50_streamline,
step_resnet50_convert_to_hls,
step_resnet50_convert_to_hw,
"step_create_dataflow_partition",
"step_specialize_layers",
"step_apply_folding_config",
"step_minimize_bit_width",
"step_generate_estimate_reports",
"step_hw_codegen",
"step_hw_ipgen",
step_resnet50_set_fifo_depths,
"step_set_fifo_depths",
step_resnet50_slr_floorplan,
"step_synthesize_bitfile",
"step_make_pynq_driver",
Expand Down Expand Up @@ -110,6 +109,7 @@ def platform_to_shell(platform):
synth_clk_period_ns=synth_clk_period_ns,
board=board,
shell_flow_type=build_cfg.ShellFlowType.VITIS_ALVEO,
split_large_fifos=True,
specialize_layers_config_file="specialize_layers_config.json",
vitis_platform=vitis_platform,
# throughput parameters (auto-folding)
Expand Down
83 changes: 12 additions & 71 deletions build/resnet50/custom_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
from qonnx.transformation.infer_datatypes import InferDataTypes
from qonnx.transformation.infer_data_layouts import InferDataLayouts
from qonnx.transformation.insert_topk import InsertTopK
import finn.transformation.fpgadataflow.convert_to_hw_layers as to_hls
import finn.transformation.fpgadataflow.convert_to_hw_layers as to_hw
from qonnx.transformation.lower_convs_to_matmul import LowerConvsToMatMul

from finn.builder.build_dataflow_config import (
Expand Down Expand Up @@ -188,28 +188,28 @@ def step_resnet50_streamline(model: ModelWrapper, cfg: DataflowBuildConfig):
return model


def step_resnet50_convert_to_hls(model: ModelWrapper, cfg: DataflowBuildConfig):
def step_resnet50_convert_to_hw(model: ModelWrapper, cfg: DataflowBuildConfig):
model.set_tensor_datatype(model.graph.input[0].name, DataType["UINT8"])
model = model.transform(InferDataLayouts())
model = model.transform(DoubleToSingleFloat())
model = model.transform(InferDataTypes())
model = model.transform(SortGraph())

to_hls_transformations = [
to_hls.InferAddStreamsLayer,
to_hw_transformations = [
to_hw.InferAddStreamsLayer,
LowerConvsToMatMul,
to_hls.InferChannelwiseLinearLayer,
to_hls.InferPool,
to_hw.InferChannelwiseLinearLayer,
to_hw.InferPool,
AbsorbTransposeIntoMultiThreshold,
RoundAndClipThresholds,
to_hls.InferQuantizedMatrixVectorActivation,
to_hls.InferThresholdingLayer,
to_hw.InferQuantizedMatrixVectorActivation,
to_hw.InferThresholdingLayer,
AbsorbConsecutiveTransposes,
to_hls.InferConvInpGen,
to_hls.InferDuplicateStreamsLayer,
to_hls.InferLabelSelectLayer,
to_hw.InferConvInpGen,
to_hw.InferDuplicateStreamsLayer,
to_hw.InferLabelSelectLayer,
]
for trn in to_hls_transformations:
for trn in to_hw_transformations:
model = model.transform(trn())
model = model.transform(InferDataLayouts())
model = model.transform(GiveUniqueNodeNames())
Expand All @@ -222,65 +222,6 @@ def step_resnet50_convert_to_hls(model: ModelWrapper, cfg: DataflowBuildConfig):

return model


def step_resnet50_set_fifo_depths(model: ModelWrapper, cfg: DataflowBuildConfig):
"""
Depending on the auto_fifo_depths setting, do one of the following:
* if auto_fifo_depths=True: Run the `InsertAndSetFIFODepths` transformation
to attempt to determine the FIFO sizes that provide full throughput. Involves
running stitched-IP rtlsim and may take a long time.
* if auto_fifo_depths=False: Assume the folding config file contains FIFO
sizes as well. Runs the `InsertFIFO` transformation, then
`ApplyConfig(cfg.folding_config_file)`, and finally `RemoveShallowFIFOs`.
Coherency with config file node naming is ensured by calling
`GiveUniqueNodeNames`.
"""

if cfg.auto_fifo_depths:
model = model.transform(
InsertAndSetFIFODepths(
cfg._resolve_fpga_part(),
cfg._resolve_hls_clk_period(),
vivado_ram_style=cfg.large_fifo_mem_style.value,
)
)
else:
# assume folding cfg json contains FIFO sizes too
# insert DWCs, FIFOs and run ApplyConfig once more
model = model.transform(InsertDWC())
# need to make sure all FIFOs are created so that their depth can be
# set by ApplyConfig, so create_shallow_fifos=True
model = model.transform(InsertFIFO(create_shallow_fifos=True))
model = model.transform(GiveUniqueNodeNames())
model = model.transform(GiveReadableTensorNames())
if cfg.folding_config_file is not None:
model = model.transform(ApplyConfig(cfg.folding_config_file))
# split large FIFOs into multiple FIFOs
model = model.transform(SplitLargeFIFOs())
# remove any shallow FIFOs
model = model.transform(RemoveShallowFIFOs())

# extract the final configuration and save it as json
hw_attrs = [
"PE",
"SIMD",
"ram_style",
"depth",
"impl_style",
"resType",
"mem_mode",
"runtime_writeable_weights",
]
extract_model_config_to_json(model, cfg.output_dir + "/final_hw_config.json", hw_attrs)

# after FIFOs are ready to go, call PrepareIP and HLSSynthIP again
# this will only run for the new nodes (e.g. FIFOs and DWCs)
model = model.transform(PrepareIP(cfg._resolve_fpga_part(), cfg._resolve_hls_clk_period()))
model = model.transform(HLSSynthIP())
model = model.transform(ReplaceVerilogRelPaths())
return model


def step_resnet50_slr_floorplan(model: ModelWrapper, cfg: DataflowBuildConfig):
if cfg.shell_flow_type == ShellFlowType.VITIS_ALVEO:
try:
Expand Down

0 comments on commit d69dd7d

Please sign in to comment.