|
8 | 8 |
|
9 | 9 | #include "load_flat_place.h" |
10 | 10 |
|
| 11 | +#include <fstream> |
11 | 12 | #include <unordered_set> |
| 13 | +#include "atom_netlist.h" |
12 | 14 | #include "clustered_netlist.h" |
| 15 | +#include "FlatPlacementInfo.h" |
13 | 16 | #include "globals.h" |
14 | 17 | #include "vpr_context.h" |
| 18 | +#include "vpr_error.h" |
15 | 19 | #include "vpr_types.h" |
| 20 | +#include "vtr_log.h" |
16 | 21 |
|
17 | 22 | /** |
18 | 23 | * @brief Prints flat placement file entries for the atoms in one placed |
@@ -45,9 +50,10 @@ static void print_flat_cluster(FILE* fp, |
45 | 50 | t_pb_graph_node* atom_pbgn = atom_ctx.lookup.atom_pb(atom)->pb_graph_node; |
46 | 51 |
|
47 | 52 | // Print the flat placement information for this atom. |
48 | | - fprintf(fp, "%s %d %d %d %d #%zu %s\n", |
| 53 | + fprintf(fp, "%s %d %d %d %d %d #%zu %s\n", |
49 | 54 | atom_ctx.nlist.block_name(atom).c_str(), |
50 | | - blk_loc.x, blk_loc.y, blk_loc.sub_tile, |
| 55 | + blk_loc.x, blk_loc.y, blk_loc.layer, |
| 56 | + blk_loc.sub_tile, |
51 | 57 | atom_pbgn->flat_site_index, |
52 | 58 | static_cast<size_t>(blk_id), |
53 | 59 | atom_pbgn->pb_type->name); |
@@ -77,6 +83,86 @@ void write_flat_placement(const char* flat_place_file_path, |
77 | 83 | fclose(fp); |
78 | 84 | } |
79 | 85 |
|
| 86 | +FlatPlacementInfo read_flat_placement(const std::string& read_flat_place_file_path, |
| 87 | + const AtomNetlist& atom_netlist) { |
| 88 | + // Try to open the file, crash if we cannot open the file. |
| 89 | + std::ifstream flat_place_file(read_flat_place_file_path); |
| 90 | + if (!flat_place_file.is_open()) { |
| 91 | + VPR_ERROR(VPR_ERROR_OTHER, "Unable to open flat placement file: %s\n", |
| 92 | + read_flat_place_file_path.c_str()); |
| 93 | + } |
| 94 | + |
| 95 | + // Create a FlatPlacementInfo object to hold the flat placement. |
| 96 | + FlatPlacementInfo flat_placement_info(atom_netlist); |
| 97 | + |
| 98 | + // Read each line of the flat placement file. |
| 99 | + unsigned line_num = 0; |
| 100 | + std::string line; |
| 101 | + while (std::getline(flat_place_file, line)) { |
| 102 | + // Split the line into tokens (using spaces, tabs, etc. as delimiters). |
| 103 | + std::vector<std::string> tokens = vtr::split(line); |
| 104 | + // Skip empty lines |
| 105 | + if (tokens.empty()) |
| 106 | + continue; |
| 107 | + // Skip lines that are only comments. |
| 108 | + if (tokens[0][0] == '#') |
| 109 | + continue; |
| 110 | + // Skip lines with too few arguments. |
| 111 | + // Required arguments: |
| 112 | + // - Atom name |
| 113 | + // - Atom x-pos |
| 114 | + // - Atom y-pos |
| 115 | + // - Atom layer |
| 116 | + // - Atom sub-tile |
| 117 | + if (tokens.size() < 5) { |
| 118 | + VTR_LOG_WARN("Flat placement file, line %d has too few arguments. " |
| 119 | + "Requires at least: <atom_name> <x> <y> <layer> <sub_tile>\n", |
| 120 | + line_num); |
| 121 | + continue; |
| 122 | + } |
| 123 | + |
| 124 | + // Get the atom name, which should be the first argument. |
| 125 | + AtomBlockId atom_blk_id = atom_netlist.find_block(tokens[0]); |
| 126 | + if (!atom_blk_id.is_valid()) { |
| 127 | + VTR_LOG_WARN("Flat placement file, line %d atom name does not match " |
| 128 | + "any atoms in the atom netlist.\n", |
| 129 | + line_num); |
| 130 | + continue; |
| 131 | + } |
| 132 | + |
| 133 | + // Check if this atom already has a flat placement |
| 134 | + // Using the x_pos and y_pos as identifiers. |
| 135 | + if (flat_placement_info.blk_x_pos[atom_blk_id] != FlatPlacementInfo::UNDEFINED_POS || |
| 136 | + flat_placement_info.blk_y_pos[atom_blk_id] != FlatPlacementInfo::UNDEFINED_POS) { |
| 137 | + VTR_LOG_WARN("Flat placement file, line %d, atom %s has multiple " |
| 138 | + "placement definitions in the flat placement file.\n", |
| 139 | + line_num, atom_netlist.block_name(atom_blk_id).c_str()); |
| 140 | + continue; |
| 141 | + } |
| 142 | + |
| 143 | + // Get the (x, y, layer) position of the atom. These functions have |
| 144 | + // error checking built in. We parse these as floats to allow for |
| 145 | + // reading in more global atom positions. |
| 146 | + flat_placement_info.blk_x_pos[atom_blk_id] = vtr::atof(tokens[1]); |
| 147 | + flat_placement_info.blk_y_pos[atom_blk_id] = vtr::atof(tokens[2]); |
| 148 | + flat_placement_info.blk_layer[atom_blk_id] = vtr::atof(tokens[3]); |
| 149 | + |
| 150 | + // Parse the sub-tile as an integer. |
| 151 | + flat_placement_info.blk_sub_tile[atom_blk_id] = vtr::atoi(tokens[4]); |
| 152 | + |
| 153 | + // If a site index is given, parse the site index as an integer. |
| 154 | + if (tokens.size() >= 6 && tokens[5][0] != '#') |
| 155 | + flat_placement_info.blk_site_idx[atom_blk_id] = vtr::atoi(tokens[5]); |
| 156 | + |
| 157 | + // Ignore any further tokens. |
| 158 | + |
| 159 | + line_num++; |
| 160 | + } |
| 161 | + |
| 162 | + // Return the flat placement info loaded from the file. |
| 163 | + return flat_placement_info; |
| 164 | +} |
| 165 | + |
80 | 166 | /* ingests and legalizes a flat placement file */ |
81 | 167 | bool load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch) { |
82 | 168 | VTR_LOG("load_flat_placement(); when implemented, this function:"); |
|
0 commit comments