@@ -1264,7 +1264,9 @@ def _generate_pr_flow(self, model):
12641264 pr_config .append ("launch_runs synth_1 -jobs 4" )
12651265 pr_config .append ("wait_on_run synth_1" )
12661266
1267- pr_config .append ("open_run synth_1 -name synth_1" )
1267+ # Collect pblock info for every PR SDP before choosing the mode.
1268+ # Each entry is (sdp_name, pblock_string_or_empty, pr_nodecontainer_inst).
1269+ pr_sdp_pblock_info = []
12681270 for pr_sdp in pr_sdp_nodes :
12691271 pr_sdp_inst = getCustomOp (pr_sdp )
12701272 sdp_name = pr_sdp .name
@@ -1277,15 +1279,57 @@ def _generate_pr_flow(self, model):
12771279 ][0 ]
12781280 pr_nodecontainer_inst = getCustomOp (pr_nodecontainer )
12791281 pblock = pr_nodecontainer_inst .get_nodeattr ("pblock" )
1280- assert pblock , "NodeContainer %s has no 'pblock' attribute set" % sdp_name
1281- pblock_name = "pblock_Hier_%s" % sdp_name
1282- cell_path = "top_i/Hier_%s" % sdp_name
1283- pr_config .append ("create_pblock %s" % pblock_name )
1282+ pr_sdp_pblock_info .append ((sdp_name , pblock ))
1283+
1284+ pblocks_specified = [pblock for _ , pblock in pr_sdp_pblock_info ]
1285+ all_empty = all (p == "" for p in pblocks_specified )
1286+ all_specified = all (p != "" for p in pblocks_specified )
1287+
1288+ if not all_empty and not all_specified :
1289+ raise FINNError (
1290+ "Mixed pblock specification: either ALL PR regions must have an explicit "
1291+ "'pblock' string, or ALL must omit it (auto-floorplanning mode). "
1292+ "Found a mix of specified and empty pblock attributes."
1293+ )
1294+
1295+ pr_config .append ("open_run synth_1 -name synth_1" )
1296+
1297+ if all_empty :
1298+ # ----------------------------------------------------------------
1299+ # Auto-floorplanning mode: query per-cell resource usage from the
1300+ # synthesised netlist and let generate_multi_dfx_pblocks size and
1301+ # place the pblocks automatically.
1302+ # ----------------------------------------------------------------
1303+ dfx_tcl_path = str (
1304+ Path (__file__ ).parent .parent .parent
1305+ / "util"
1306+ / "vivado_scripts"
1307+ / "dfx_auto_floorplanning.tcl"
1308+ )
1309+ pr_config .append ("source {%s}" % dfx_tcl_path )
1310+
1311+ cell_names = ["top_i/Hier_%s" % sdp_name for sdp_name , _ in pr_sdp_pblock_info ]
1312+ pblock_names = ["pblock_Hier_%s" % sdp_name for sdp_name , _ in pr_sdp_pblock_info ]
1313+
12841314 pr_config .append (
1285- "add_cells_to_pblock [get_pblocks %s] [get_cells %s]" % (pblock_name , cell_path )
1315+ "auto_floorplan_from_synthesis {%s} {%s}"
1316+ % (" " .join (cell_names ), " " .join (pblock_names ))
12861317 )
1287- pr_config .append ("resize_pblock [get_pblocks %s] -add {%s}" % (pblock_name , pblock ))
1288- pr_config .append ("set_property SNAPPING_MODE ON [get_pblocks %s]" % pblock_name )
1318+ else :
1319+ # ----------------------------------------------------------------
1320+ # Manual mode: use the pblock strings already set on each
1321+ # NodeContainer (existing behaviour).
1322+ # ----------------------------------------------------------------
1323+ for sdp_name , pblock in pr_sdp_pblock_info :
1324+ pblock_name = "pblock_Hier_%s" % sdp_name
1325+ cell_path = "top_i/Hier_%s" % sdp_name
1326+ pr_config .append ("create_pblock %s" % pblock_name )
1327+ pr_config .append (
1328+ "add_cells_to_pblock [get_pblocks %s] [get_cells %s]" % (pblock_name , cell_path )
1329+ )
1330+ pr_config .append ("resize_pblock [get_pblocks %s] -add {%s}" % (pblock_name , pblock ))
1331+ pr_config .append ("set_property SNAPPING_MODE ON [get_pblocks %s]" % pblock_name )
1332+
12891333 pr_config .append ("save_constraints -force" )
12901334 pr_config .append ("close_design" )
12911335
@@ -1297,6 +1341,16 @@ def _generate_pr_flow(self, model):
12971341
12981342 pr_config .append ("launch_runs impl_1 -to_step write_bitstream -jobs 4" )
12991343 pr_config .append ("wait_on_run impl_1" )
1344+
1345+ if all_empty :
1346+ # Auto mode: query post-implementation utilisation and write the JSON report.
1347+ pr_config .append ("open_run impl_1 -name impl_1" )
1348+ pr_config .append (
1349+ "write_pr_resource_report {%s} {%s}"
1350+ % (" " .join (cell_names ), " " .join (pblock_names ))
1351+ )
1352+ pr_config .append ("close_design" )
1353+
13001354 for body_id in range (1 , num_bodies ):
13011355 impl_run = "impl_body_%d" % body_id
13021356 pr_config .append ("launch_runs %s -to_step write_bitstream -jobs 4" % impl_run )
0 commit comments