-
Notifications
You must be signed in to change notification settings - Fork 446
Add --flat_place_verbosity to control annotation in flat placement files #3787
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
base: master
Are you sure you want to change the base?
Changes from all commits
ad66c9c
7f23ad3
48f7812
a9dce13
3303338
42d1c3e
20b13be
8ac91cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,16 +31,23 @@ | |
| * | ||
| * @param fp | ||
| * File pointer to the file the cluster is printed to. | ||
| * @param flat_place_verbosity | ||
| * How much annotation the file carries; decides which columns the | ||
| * header announces. See write_flat_placement(). | ||
| */ | ||
| static void print_flat_placement_file_header(FILE* fp) { | ||
| static void print_flat_placement_file_header(FILE* fp, int flat_place_verbosity) { | ||
| fprintf(fp, "# Flat Placement File\n"); | ||
| fprintf(fp, "# Auto-generated by VPR %s\n", | ||
| vtr::VERSION); | ||
| fprintf(fp, "# Created: %s\n", | ||
| vtr::BUILD_TIMESTAMP); | ||
| fprintf(fp, "#\n"); | ||
| fprintf(fp, "# This file prints the following information for each atom in the netlist:\n"); | ||
| fprintf(fp, "# <atom_name> <x> <y> <layer> <atom_sub_tile> #<clb_blk_id> <atom_pb_type>\n"); | ||
| if (flat_place_verbosity >= 2) { | ||
| fprintf(fp, "# <atom_name> <x> <y> <layer> <atom_sub_tile> #<clb_blk_id> <atom_pb_type> <site_path>\n"); | ||
| } else { | ||
| fprintf(fp, "# <atom_name> <x> <y> <layer> <atom_sub_tile> #<clb_blk_id> <atom_pb_type>\n"); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be written slightly cleaner (and easier) by printing the common part first, then the uncommon part in an if, and then print the |
||
| fprintf(fp, "\n"); | ||
| } | ||
|
|
||
|
|
@@ -57,36 +64,54 @@ static void print_flat_placement_file_header(FILE* fp) { | |
| * @param atoms_lookup | ||
| * A lookup between all clusters and the atom blocks that they | ||
| * contain. | ||
| * @param flat_place_verbosity | ||
| * How much annotation to append to each atom's line. See | ||
| * write_flat_placement(). | ||
| */ | ||
| static void print_flat_cluster(FILE* fp, | ||
| ClusterBlockId blk_id, | ||
| const vtr::vector_map<ClusterBlockId, t_block_loc>& block_locs, | ||
| const vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup) { | ||
| // Atom context used to get the atom_pb for each atom in the cluster. | ||
| const vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup, | ||
| int flat_place_verbosity) { | ||
| const AtomContext& atom_ctx = g_vpr_ctx.atom(); | ||
|
|
||
| // Get the location of this cluster. | ||
| const t_pl_loc& blk_loc = block_locs[blk_id].loc; | ||
|
|
||
| // Print a line for each atom. | ||
| for (AtomBlockId atom : atoms_lookup[blk_id]) { | ||
| // Get the atom pb graph node. | ||
| t_pb_graph_node* atom_pbgn = atom_ctx.lookup().atom_pb_bimap().atom_pb(atom)->pb_graph_node; | ||
|
|
||
| // Print the flat placement information for this atom. | ||
| fprintf(fp, "%s %d %d %d %d #%zu %s\n", | ||
| // Print the placement of this atom. These are the only columns the | ||
| // flat placement reader parses; everything below is annotation. | ||
| fprintf(fp, "%s %d %d %d %d", | ||
| atom_ctx.netlist().block_name(atom).c_str(), | ||
| blk_loc.x, blk_loc.y, blk_loc.layer, | ||
| blk_loc.sub_tile, | ||
| static_cast<size_t>(blk_id), | ||
| atom_pbgn->pb_type->name); | ||
| blk_loc.sub_tile); | ||
|
|
||
| if (flat_place_verbosity >= 1) { | ||
| // Get the atom pb graph node, which holds the primitive the atom | ||
| // was placed on. | ||
| t_pb_graph_node* atom_pbgn = atom_ctx.lookup().atom_pb_bimap().atom_pb(atom)->pb_graph_node; | ||
|
|
||
| fprintf(fp, " #%zu %s", | ||
| static_cast<size_t>(blk_id), | ||
| atom_pbgn->pb_type->name); | ||
|
|
||
| if (flat_place_verbosity >= 2) { | ||
| // The hierarchical path of the primitive this atom was placed | ||
| // on, e.g. "clb[0][default]/lab[0][default]/fle[3][n1_lut6]". | ||
| fprintf(fp, " %s", atom_pbgn->hierarchical_type_name().c_str()); | ||
| } | ||
| } | ||
|
|
||
| fprintf(fp, "\n"); | ||
| } | ||
| } | ||
|
|
||
| void write_flat_placement(const char* flat_place_file_path, | ||
| const ClusteredNetlist& cluster_netlist, | ||
| const vtr::vector_map<ClusterBlockId, t_block_loc>& block_locs, | ||
| const vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup) { | ||
| const vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup, | ||
| int flat_place_verbosity) { | ||
| // Writes the flat placement to the given flat_place_file_path. | ||
|
|
||
| // Only print a flat placement if the clusters have been placed. | ||
|
|
@@ -96,13 +121,16 @@ void write_flat_placement(const char* flat_place_file_path, | |
| // Create a file in write mode for the flat placement. | ||
| FILE* fp = fopen(flat_place_file_path, "w"); | ||
|
|
||
| // Add a header to the flat placement file. | ||
| print_flat_placement_file_header(fp); | ||
| // Add a header to the flat placement file. The header is itself a comment, | ||
| // so it is omitted when no annotation was asked for. | ||
| if (flat_place_verbosity >= 1) { | ||
| print_flat_placement_file_header(fp, flat_place_verbosity); | ||
| } | ||
|
|
||
| // For each cluster, write out the atoms in the cluster at this cluster's | ||
| // location. | ||
| for (ClusterBlockId iblk : cluster_netlist.blocks()) { | ||
| print_flat_cluster(fp, iblk, block_locs, atoms_lookup); | ||
| print_flat_cluster(fp, iblk, block_locs, atoms_lookup, flat_place_verbosity); | ||
| } | ||
|
|
||
| // Close the file. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2066,6 +2066,19 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio | |
| "VPR's (or reconstructed external) placement solution after legalization and before anneal in flat placement file format; this file lists (x, y, layer) coordinates and subtile for each atom and can be used to reconstruct a clustering and placement solution.") | ||
| .show_in(argparse::ShowIn::HELP_ONLY); | ||
|
|
||
| file_grp.add_argument<int>(args.flat_place_verbosity, "--flat_place_verbosity") | ||
| .help( | ||
| "Controls how much annotation is written into flat placement files." | ||
| " Annotations are informational only; the flat placement reader ignores" | ||
| " everything past the sub-tile column." | ||
| " 0: no annotations and no header comments, i.e. only the columns the reader parses." | ||
| " 1: header comments, plus the cluster block id and primitive type of each atom." | ||
| " 2: additionally the site_path of each atom, the hierarchical path of the" | ||
| " primitive it was placed on within its cluster." | ||
| " Larger values produce more detail.") | ||
| .default_value("1") | ||
| .show_in(argparse::ShowIn::HELP_ONLY); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above about making this an integer instead of a bool. |
||
|
|
||
| file_grp.add_argument(args.read_router_lookahead, "--read_router_lookahead") | ||
| .help( | ||
| "Reads the lookahead data from the specified file instead of computing it.") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would update this text to make it clear that anything after the pound symbol (
#) is a comment and is not parsed by VPR when read; it is only for the user to better understand and interpret the file. Your new argument allows us to select how verbose we want it.I really like the idea of adding a verbosity 0 since printing the CLB number and the primitive was always weird to me. This was grandfathered in by the first implementation of the flat placement file, which was not made by me.