From de1f0247a9eadbb4d23c3bd10fb925c432d663d0 Mon Sep 17 00:00:00 2001 From: Christoph Berganski Date: Sun, 28 Jan 2024 16:28:34 +0100 Subject: [PATCH 1/6] Enable analysis report of post synthesis resource in json Note: This was already implemented, it was just not called from the step_synthesize_bitfile. --- src/finn/builder/build_dataflow_steps.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/finn/builder/build_dataflow_steps.py b/src/finn/builder/build_dataflow_steps.py index 443d2df54c..f94b191918 100644 --- a/src/finn/builder/build_dataflow_steps.py +++ b/src/finn/builder/build_dataflow_steps.py @@ -58,6 +58,7 @@ from finn.analysis.fpgadataflow.dataflow_performance import dataflow_performance from finn.analysis.fpgadataflow.exp_cycles_per_layer import exp_cycles_per_layer from finn.analysis.fpgadataflow.hls_synth_res_estimation import hls_synth_res_estimation +from finn.analysis.fpgadataflow.post_synth_res import post_synth_res from finn.analysis.fpgadataflow.op_and_param_counts import ( aggregate_dict_keys, op_and_param_counts, @@ -801,6 +802,11 @@ def step_synthesize_bitfile(model: ModelWrapper, cfg: DataflowBuildConfig): model.get_metadata_prop("vivado_synth_rpt"), report_dir + "/post_synth_resources.xml", ) + + post_synth_resources = model.analysis(post_synth_res) + with open(report_dir + "/post_synth_resources.json", "w") as f: + json.dump(post_synth_resources, f, indent=2) + vivado_pynq_proj_dir = model.get_metadata_prop("vivado_pynq_proj") timing_rpt = ( "%s/finn_zynq_link.runs/impl_1/top_wrapper_timing_summary_routed.rpt" @@ -825,6 +831,10 @@ def step_synthesize_bitfile(model: ModelWrapper, cfg: DataflowBuildConfig): model.get_metadata_prop("vivado_synth_rpt"), report_dir + "/post_synth_resources.xml", ) + + post_synth_resources = model.analysis(post_synth_res) + with open(report_dir + "/post_synth_resources.json", "w") as f: + json.dump(post_synth_resources, f, indent=2) else: raise Exception("Unrecognized shell_flow_type: " + str(cfg.shell_flow_type)) print("Bitfile written into " + bitfile_dir) From b435655ecd7eb2daaa12bb3c8e4cb69beea6e863 Mon Sep 17 00:00:00 2001 From: Christoph Berganski Date: Sun, 28 Jan 2024 16:31:43 +0100 Subject: [PATCH 2/6] Fix table row of the DSP48 post synthesis resource utilization report According to the last synthesis I ran using Vitis/Vivado 2022.2, the DSP48 utilization seems to be reported in row 10 of the XML table. --- src/finn/analysis/fpgadataflow/post_synth_res.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/finn/analysis/fpgadataflow/post_synth_res.py b/src/finn/analysis/fpgadataflow/post_synth_res.py index 7b65b60fa7..f10d83158f 100644 --- a/src/finn/analysis/fpgadataflow/post_synth_res.py +++ b/src/finn/analysis/fpgadataflow/post_synth_res.py @@ -65,7 +65,7 @@ def post_synth_res(model, override_synth_report_filename=None): "FF": 6, "BRAM_36K": 7, "BRAM_18K": 8, - "DSP48": 9, + "DSP48": 10, } restype_to_ind_vitis = { "LUT": 4, From 79a90158f6cd31776053917da44b57964dcd9fc3 Mon Sep 17 00:00:00 2001 From: Yaman Umuroglu Date: Tue, 28 Nov 2023 15:47:55 +0000 Subject: [PATCH 3/6] [Analysis] try to infer restype-to-index dynamically from report --- .../analysis/fpgadataflow/post_synth_res.py | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/finn/analysis/fpgadataflow/post_synth_res.py b/src/finn/analysis/fpgadataflow/post_synth_res.py index f10d83158f..d81153b977 100644 --- a/src/finn/analysis/fpgadataflow/post_synth_res.py +++ b/src/finn/analysis/fpgadataflow/post_synth_res.py @@ -58,7 +58,6 @@ def post_synth_res(model, override_synth_report_filename=None): else: raise Exception("Please run synthesis first") - # TODO build these indices based on table headers instead of harcoding restype_to_ind_default = { "LUT": 2, "SRL": 5, @@ -74,13 +73,36 @@ def post_synth_res(model, override_synth_report_filename=None): "BRAM_36K": 9, "BRAM_18K": 10, "URAM": 11, - "DSP48": 12, + "DSP": 12, } - if model.get_metadata_prop("platform") == "alveo": - restype_to_ind = restype_to_ind_vitis + # format: (human_readable_name_in_report, canonical_name) + res_types_to_search = [ + ("Total LUTs", "LUT"), + ("SRLs", "SRL"), + ("FFs", "FF"), + ("RAMB36", "BRAM_36K"), + ("RAMB18", "BRAM_18K"), + ("URAM", "URAM"), + ("DSP Blocks", "DSP"), + ] + + # try to infer resource type to table index by + # looking at the names in headings + header_row = root.findall(".//*[@contents='Instance']/..") + if header_row != []: + headers = [x.attrib["contents"] for x in list(header_row[0])] + restype_to_ind = {} + for res_type_name, res_type in res_types_to_search: + if res_type_name in headers: + restype_to_ind[res_type] = headers.index(res_type_name) else: - restype_to_ind = restype_to_ind_default + # could not infer resource types from header + # fall back to default indices + if model.get_metadata_prop("platform") == "alveo": + restype_to_ind = restype_to_ind_vitis + else: + restype_to_ind = restype_to_ind_default def get_instance_stats(inst_name): row = root.findall(".//*[@contents='%s']/.." % inst_name) From 5f1f80a91c03609341fd45dd08eb5507a51908ff Mon Sep 17 00:00:00 2001 From: Christoph Berganski Date: Fri, 9 Feb 2024 16:30:14 +0100 Subject: [PATCH 4/6] Address linting issues running pre-commit --- src/finn/builder/build_dataflow_steps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/finn/builder/build_dataflow_steps.py b/src/finn/builder/build_dataflow_steps.py index f94b191918..a842a3ce4e 100644 --- a/src/finn/builder/build_dataflow_steps.py +++ b/src/finn/builder/build_dataflow_steps.py @@ -58,11 +58,11 @@ from finn.analysis.fpgadataflow.dataflow_performance import dataflow_performance from finn.analysis.fpgadataflow.exp_cycles_per_layer import exp_cycles_per_layer from finn.analysis.fpgadataflow.hls_synth_res_estimation import hls_synth_res_estimation -from finn.analysis.fpgadataflow.post_synth_res import post_synth_res from finn.analysis.fpgadataflow.op_and_param_counts import ( aggregate_dict_keys, op_and_param_counts, ) +from finn.analysis.fpgadataflow.post_synth_res import post_synth_res from finn.analysis.fpgadataflow.res_estimation import ( res_estimation, res_estimation_complete, From f2aa4406e2caf0e018c09e73b3d2fb497e472f81 Mon Sep 17 00:00:00 2001 From: Christoph Berganski Date: Fri, 9 Feb 2024 16:39:20 +0100 Subject: [PATCH 5/6] DSP48 should simply be reported as DSP --- src/finn/analysis/fpgadataflow/post_synth_res.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/finn/analysis/fpgadataflow/post_synth_res.py b/src/finn/analysis/fpgadataflow/post_synth_res.py index d81153b977..f7a3e6e2ba 100644 --- a/src/finn/analysis/fpgadataflow/post_synth_res.py +++ b/src/finn/analysis/fpgadataflow/post_synth_res.py @@ -64,7 +64,7 @@ def post_synth_res(model, override_synth_report_filename=None): "FF": 6, "BRAM_36K": 7, "BRAM_18K": 8, - "DSP48": 10, + "DSP": 10, } restype_to_ind_vitis = { "LUT": 4, From 7dbd811388b9c5bb9f3b0d070dad71470fee0222 Mon Sep 17 00:00:00 2001 From: auphelia Date: Wed, 24 Apr 2024 14:40:56 +0100 Subject: [PATCH 6/6] [Test] Add check for post synthesis json report in build dataflow test --- tests/util/test_build_dataflow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/util/test_build_dataflow.py b/tests/util/test_build_dataflow.py index c8f80a8e1b..75ed8335c0 100644 --- a/tests/util/test_build_dataflow.py +++ b/tests/util/test_build_dataflow.py @@ -64,6 +64,7 @@ def test_end2end_build_dataflow_directory(): assert os.path.isfile(output_dir + "/bitfile/finn-accel.hwh") assert os.path.isfile(output_dir + "/report/post_synth_resources.xml") assert os.path.isfile(output_dir + "/report/post_route_timing.rpt") + assert os.path.isfile(output_dir + "/report/post_synth_resources.json") # verification outputs verif_batchsize = np.load(target_dir + "/input.npy").shape[0] for i in range(verif_batchsize):