9696#include " log.h"
9797#include " iostream"
9898
99+ #include " load_flat_place.h"
100+
99101#ifdef VPR_USE_TBB
100102# define TBB_PREVIEW_GLOBAL_CONTROL 1 /* Needed for compatibility with old TBB versions */
101103# include < tbb/task_arena.h>
@@ -393,6 +395,7 @@ bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) {
393395 return false ; // Unimplementable
394396 }
395397 }
398+
396399 // For the time being, we decided to create the flat graph after placement is done. Thus, the is_flat parameter for this function
397400 // , since it is called before routing, should be false.
398401 vpr_create_device (vpr_setup, arch, false );
@@ -410,6 +413,7 @@ bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) {
410413 std::cout << " failed placement" << std::endl;
411414 return false ; // Unimplementable
412415 }
416+ print_flat_placement (vpr_setup.FileNameOpts .write_flat_place_file .c_str ());
413417 }
414418 bool is_flat = vpr_setup.RouterOpts .flat_routing ;
415419 const Netlist<>& router_net_list = is_flat ? (const Netlist<>&)g_vpr_ctx.atom ().nlist : (const Netlist<>&)g_vpr_ctx.clustering ().clb_nlist ;
@@ -595,6 +599,9 @@ bool vpr_pack_flow(t_vpr_setup& vpr_setup, const t_arch& arch) {
595599 if (packer_opts.doPacking == STAGE_DO) {
596600 // Do the actual packing
597601 status = vpr_pack (vpr_setup, arch);
602+ if (!status) {
603+ return status;
604+ }
598605
599606 // TODO: to be consistent with placement/routing vpr_pack should really
600607 // load the netlist data structures itself, instead of re-loading
@@ -604,10 +611,41 @@ bool vpr_pack_flow(t_vpr_setup& vpr_setup, const t_arch& arch) {
604611 vpr_load_packing (vpr_setup, arch);
605612 } else {
606613 VTR_ASSERT (packer_opts.doPacking == STAGE_LOAD);
607- // Load a previous packing from the .net file
608- vpr_load_packing (vpr_setup, arch);
609- // Load cluster_constraints data structure here since loading pack file
610- load_cluster_constraints ();
614+
615+ // generate a .net file by legalizing an input flat placement file
616+ if (packer_opts.load_flat_placement ) {
617+
618+ // set up the device grid for the legalizer
619+ auto & device_ctx = g_vpr_ctx.mutable_device ();
620+ device_ctx.arch = &arch;
621+ device_ctx.grid = create_device_grid (vpr_setup.device_layout , arch.grid_layouts );
622+
623+ // load and legalize flat placement file, print .net and fix clusters files
624+ status = load_flat_placement (vpr_setup, arch);
625+ if (!status) {
626+ return status;
627+ }
628+
629+ // reset the device grid
630+ device_ctx.grid .clear ();
631+
632+ // if running placement, use the fix clusters file produced by the legalizer
633+ if (vpr_setup.PlacerOpts .doPlacement ) {
634+ vpr_setup.PlacerOpts .constraints_file = vpr_setup.FileNameOpts .write_constraints_file ;
635+ }
636+
637+ // Load the result from the .net file
638+ vpr_load_packing (vpr_setup, arch);
639+
640+ } else {
641+
642+ // Load a previous packing from the .net file
643+ vpr_load_packing (vpr_setup, arch);
644+
645+ // Load cluster_constraints data structure here since loading pack file
646+ load_cluster_constraints ();
647+ }
648+
611649 }
612650
613651 /* Sanity check the resulting netlist */
0 commit comments