Skip to content

Commit 973fd2a

Browse files
committed
mods based on Vaughn's comments
1 parent 74b7375 commit 973fd2a

11 files changed

+65
-31
lines changed

vpr/src/base/echo_files.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ void alloc_and_load_echo_file_info() {
8080
//Packing
8181
setEchoFileName(E_ECHO_CLUSTERS, "clusters.echo");
8282

83+
//Legalizer
84+
setEchoFileName(E_ECHO_FLAT_PLACE, "post_legalizer_flat_placement.echo");
85+
8386
//Intra-block routing
8487
setEchoFileName(E_ECHO_INTRA_LB_FAILED_ROUTE, "intra_lb_failed_route.echo");
8588

vpr/src/base/echo_files.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ enum e_echo_files {
1616
//Packing
1717
E_ECHO_CLUSTERS,
1818

19+
//Legalizer
20+
E_ECHO_FLAT_PLACE,
21+
1922
// Intra-block routing
2023
E_ECHO_INTRA_LB_FAILED_ROUTE,
2124

vpr/src/base/load_flat_place.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ void print_flat_placement(const char* flat_place_file) {
4444
}
4545

4646
/* ingests and legalizes a flat placement file */
47-
bool load_flat_placement(t_vpr_setup& vpr_setup, const char* architecture_id) {
47+
bool load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch) {
4848
VTR_LOG("load_flat_placement(); when implemented, this function:");
4949
VTR_LOG("\n\tLoads flat placement file: %s, ", vpr_setup.FileNameOpts.FlatPlaceFile.c_str());
50-
VTR_LOG("\n\tArch id: %s, ", architecture_id);
50+
VTR_LOG("\n\tArch id: %s, ", arch.architecture_id);
5151
VTR_LOG("\n\tPrints clustered netlist file: %s, ", vpr_setup.FileNameOpts.NetFile.c_str());
5252
VTR_LOG("\n\tPrints fix clusters file: %s\n", vpr_setup.FileNameOpts.write_constraints_file.c_str());
5353

vpr/src/base/load_flat_place.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ void print_flat_placement(const char* flat_place_file);
1111
/**
1212
* @brief A function that loads and legalizes a flat placement file
1313
*/
14-
bool load_flat_placement(t_vpr_setup& vpr_setup, const char* archi_id);
14+
bool load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch);
1515

1616
#endif

vpr/src/base/read_options.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
13111311
.default_value("off");
13121312

13131313
stage_grp.add_argument<bool, ParseOnOff>(args.do_legalize, "--legalize")
1314-
.help("Legalize a flat placement")
1314+
.help("Legalize a flat placement, i.e. reconstruct and place clusters based on a flat placement file, which lists cluster and intra-cluster placement coordinates for each primitive.")
13151315
.action(argparse::Action::STORE_TRUE)
13161316
.default_value("off");
13171317

@@ -1596,7 +1596,7 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
15961596
.show_in(argparse::ShowIn::HELP_ONLY);
15971597

15981598
file_grp.add_argument(args.FlatPlaceFile, "--flat_place_file")
1599-
.help("Path to flat placement file")
1599+
.help("Path to input flat placement file")
16001600
.show_in(argparse::ShowIn::HELP_ONLY);
16011601

16021602
file_grp.add_argument(args.PlaceFile, "--place_file")
@@ -1638,14 +1638,13 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
16381638

16391639
file_grp.add_argument(args.write_constraints_file, "--write_fix_clusters")
16401640
.help(
1641-
"Output file containing fixed locations of legalized input clusters.")
1641+
"Output file containing fixed locations of legalized input clusters - does not include clusters without placement coordinates; this file is used during post-legalization placement in order to hold input placement coordinates fixed while VPR places legalizer-generated orphan clusters.")
16421642
.default_value("fix_clusters.out")
16431643
.show_in(argparse::ShowIn::HELP_ONLY);
16441644

16451645
file_grp.add_argument(args.write_flat_place_file, "--write_flat_place")
16461646
.help(
1647-
"VPR's placement solution in flat placement file format.")
1648-
.default_value("flat_place.out")
1647+
"VPR's (or reconstructed external) placement solution in flat placement file format; this file lists cluster and intra-cluster placement coordinates for each atom and can be used to reconstruct a clustering and placement solution.")
16491648
.show_in(argparse::ShowIn::HELP_ONLY);
16501649

16511650
file_grp.add_argument(args.read_router_lookahead, "--read_router_lookahead")

vpr/src/base/read_place.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ void print_place(const char* net_file,
331331
if (!place_ctx.block_locs.empty()) { //Only if placement exists
332332
for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {
333333
// if block is not placed, skip (useful for printing legalizer output)
334-
if (!is_place_file && (place_ctx.block_locs[blk_id].loc.x == -1)) {
334+
if (!is_place_file && (place_ctx.block_locs[blk_id].loc.x == INVALID_X)) {
335335
continue;
336336
}
337337
fprintf(fp, "%s\t", cluster_ctx.clb_nlist.block_pb(blk_id)->name);

vpr/src/base/read_place.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ void read_constraints(const char* constraints_file);
2222
* @param is_place_file: defaults to true. If false, does not print file header; this is useful if
2323
* the output will be used as a constraints file. If is_place_file is false,
2424
* net_file and net_id parameters are not used and can be set to nullptr.
25+
* Note: if false, only placed clusters are printed - clusters without
26+
* placement coordinates (e.g. orphan clusters created during legalization
27+
* will not be included; this file is used as a placement constraints
28+
* file when running placement in order to place orphan clusters.
2529
*/
2630
void print_place(const char* net_file,
2731
const char* net_id,

vpr/src/base/vpr_api.cpp

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -615,24 +615,8 @@ bool vpr_pack_flow(t_vpr_setup& vpr_setup, const t_arch& arch) {
615615
// generate a .net file by legalizing an input flat placement file
616616
if (packer_opts.load_flat_placement) {
617617

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.architecture_id);
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-
}
618+
//Load and legalizer flat placement file
619+
vpr_load_flat_placement(vpr_setup, arch);
636620

637621
//Load the result from the .net file
638622
vpr_load_packing(vpr_setup, arch);
@@ -747,6 +731,37 @@ void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch) {
747731
}
748732
}
749733

734+
bool vpr_load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch) {
735+
736+
// set up the device grid for the legalizer
737+
auto& device_ctx = g_vpr_ctx.mutable_device();
738+
device_ctx.arch = &arch;
739+
device_ctx.grid = create_device_grid(vpr_setup.device_layout, arch.grid_layouts);
740+
if (device_ctx.grid.get_num_layers() > 1) {
741+
VPR_FATAL_ERROR(VPR_ERROR_PACK, "Legalizer currently only supports single layer devices.\n");
742+
}
743+
744+
// load and legalize flat placement file, print .net and fix clusters files
745+
bool status = load_flat_placement(vpr_setup, arch);
746+
if (!status) {
747+
return status;
748+
}
749+
750+
// echo flat placement (orphan clusters will have -1 for X, Y, subtile coordinates)
751+
if (getEchoEnabled() && isEchoFileEnabled(E_ECHO_FLAT_PLACE)) {
752+
print_flat_placement(getEchoFileName(E_ECHO_FLAT_PLACE));
753+
}
754+
755+
// reset the device grid
756+
device_ctx.grid.clear();
757+
758+
// if running placement, use the fix clusters file produced by the legalizer
759+
if (vpr_setup.PlacerOpts.doPlacement) {
760+
vpr_setup.PlacerOpts.constraints_file = vpr_setup.FileNameOpts.write_constraints_file;
761+
}
762+
return true;
763+
}
764+
750765
bool vpr_place_flow(const Netlist<>& net_list, t_vpr_setup& vpr_setup, const t_arch& arch) {
751766
VTR_LOG("\n");
752767
const auto& placer_opts = vpr_setup.PlacerOpts;
@@ -775,6 +790,13 @@ bool vpr_place_flow(const Netlist<>& net_list, t_vpr_setup& vpr_setup, const t_a
775790
placer_opts.floorplan_num_horizontal_partitions, placer_opts.floorplan_num_vertical_partitions);
776791
}
777792

793+
// Write out a flat placement file if the option is specified
794+
// A flat placement file includes cluster and intra-cluster placement coordinates for
795+
// each primitive and can be used to reconstruct a clustering and placement solution.
796+
if (!filename_opts.write_flat_place_file.empty()) {
797+
print_flat_placement(vpr_setup.FileNameOpts.write_flat_place_file.c_str());
798+
}
799+
778800
return true;
779801
}
780802

vpr/src/base/vpr_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ bool vpr_pack(t_vpr_setup& vpr_setup, const t_arch& arch);
6565
///@brief Loads a previous packing
6666
void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch);
6767

68+
///@brief Reconstructs a packing and placement solution from a flat placement file
69+
bool vpr_load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch);
70+
6871
/* Placement */
6972

7073
///@brief Perform, load or skip the placement stage

vpr/src/base/vpr_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ struct hash<t_pl_offset> {
715715
};
716716
} // namespace std
717717

718+
/// @brief Sentinel value for indicating that a block does not have a valid x location, used to check whether a block has been placed
719+
static constexpr int INVALID_X = -1;
720+
718721
/**
719722
* @brief A placement location coordinate
720723
*

vpr/src/place/initial_placement.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "move_utils.h"
1313
#include "region.h"
1414
#include "directed_moves_util.h"
15-
15+
#include "vpr_types.h"
1616
#include "echo_files.h"
1717

1818
#include <ctime>
@@ -23,9 +23,6 @@
2323
void print_clb_placement(const char* fname);
2424
#endif
2525

26-
/// @brief Sentinel value for indicating that a block does not have a valid x location, used to check whether a block has been placed
27-
static constexpr int INVALID_X = -1;
28-
2926
// Number of iterations that initial placement tries to place all blocks before throwing an error
3027
static constexpr int MAX_INIT_PLACE_ATTEMPTS = 2;
3128

0 commit comments

Comments
 (0)