diff --git a/tests/fpgadataflow/test_split_large_fifos.py b/tests/fpgadataflow/test_split_large_fifos.py index ab9230ad398866433bfb500bb974b85cf04273da..eab8072fc80410df91addb2a21cc470feb932ab2 100644 --- a/tests/fpgadataflow/test_split_large_fifos.py +++ b/tests/fpgadataflow/test_split_large_fifos.py @@ -32,10 +32,12 @@ import pytest import json import shutil from brevitas.export.onnx.generic.manager import BrevitasONNXManager -from math import ceil +from qonnx.core.modelwrapper import ModelWrapper +from qonnx.custom_op.registry import getCustomOp import finn.builder.build_dataflow as build import finn.builder.build_dataflow_config as build_cfg +from finn.transformation.fpgadataflow.set_fifo_depths import get_fifo_split_configs from finn.util.basic import make_build_dir from finn.util.test import get_trained_network_and_ishape @@ -53,7 +55,7 @@ def get_folding_cfg(depth=65536): cfg["Defaults"] = dict() for i in range(3): key = "StreamingFIFO_" + str(i) - cfg[key] = {"depth": depth, "ram_style": "auto", "impl_style": "rtl"} + cfg[key] = {"depth": depth, "ram_style": "auto", "impl_style": "vivado"} return cfg @@ -93,12 +95,32 @@ def test_split_large_fifos(depth): / float(est_data["estimated_throughput_fps"]) > 0.9 ) - with open(tmp_output_dir + "/final_hw_config.json") as f: - hw_config = json.load(f) - n = 0 - for key in hw_config: - if "StreamingFIFO" in key: - n += 1 - assert n == 3 * ceil(depth / 32768) + 1 + model = ModelWrapper( + tmp_output_dir + "/intermediate_models/step_set_fifo_depths.onnx" + ) + # exclude final FIFO node (output FIFO, not part of test) + fifo_nodes = model.get_nodes_by_op_type("StreamingFIFO")[:-1] + golden_cfg = get_fifo_split_configs(depth, 256, 32768) + for i, fifo_node in enumerate(fifo_nodes): + inst = getCustomOp(fifo_node) + fifo_depth = inst.get_nodeattr("depth") + assert fifo_depth == golden_cfg[i % len(golden_cfg)][0] shutil.rmtree(tmp_output_dir) + + +def test_split_large_fifo_configs(): + ret0 = get_fifo_split_configs(513, 256, 32768) + assert ret0 == [(512, "vivado"), (1, "rtl")] + ret1 = get_fifo_split_configs(1200, 256, 32768) + assert ret1 == [(1024, "vivado"), (176, "rtl")] + ret2 = get_fifo_split_configs(45000, 256, 32768) + assert ret2 == [ + (32768, "vivado"), + (8192, "vivado"), + (2048, "vivado"), + (1024, "vivado"), + (512, "vivado"), + (256, "rtl"), + (200, "rtl"), + ]