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

Enable analysis report of post synthesis resource utilization in json #965

Merged
merged 6 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/finn/analysis/fpgadataflow/post_synth_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ 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,
"FF": 6,
"BRAM_36K": 7,
"BRAM_18K": 8,
"DSP48": 9,
"DSP": 10,
auphelia marked this conversation as resolved.
Show resolved Hide resolved
}
restype_to_ind_vitis = {
"LUT": 4,
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/finn/builder/build_dataflow_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
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,
Expand Down Expand Up @@ -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"
Expand All @@ -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)
Expand Down
Loading