|
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
|
@@ -77,6 +82,84 @@ void write_flat_placement(const char* flat_place_file_path,
|
77 | 82 | fclose(fp);
|
78 | 83 | }
|
79 | 84 |
|
| 85 | +FlatPlacementInfo read_flat_placement(const std::string& read_flat_place_file_path, |
| 86 | + const AtomNetlist& atom_netlist) { |
| 87 | + // Try to open the file, crash if we cannot open the file. |
| 88 | + std::ifstream flat_place_file(read_flat_place_file_path); |
| 89 | + if (!flat_place_file.is_open()) { |
| 90 | + VPR_ERROR(VPR_ERROR_OTHER, "Unable to open flat placement file: %s\n", |
| 91 | + read_flat_place_file_path.c_str()); |
| 92 | + } |
| 93 | + |
| 94 | + // Create a FlatPlacementInfo object to hold the flat placement. |
| 95 | + FlatPlacementInfo flat_placement_info(atom_netlist); |
| 96 | + |
| 97 | + // Read each line of the flat placement file. |
| 98 | + unsigned line_num = 0; |
| 99 | + std::string line; |
| 100 | + while (std::getline(flat_place_file, line)) { |
| 101 | + // Split the line into tokens (using spaces, tabs, etc. as delimiters). |
| 102 | + std::vector<std::string> tokens = vtr::split(line); |
| 103 | + // Skip empty lines |
| 104 | + if (tokens.empty()) |
| 105 | + continue; |
| 106 | + // Skip lines that are only comments. |
| 107 | + if (tokens[0][0] == '#') |
| 108 | + continue; |
| 109 | + // Skip lines with too few arguments. |
| 110 | + // Required arguments: |
| 111 | + // - Atom name |
| 112 | + // - Atom x-pos |
| 113 | + // - Atom y-pos |
| 114 | + if (tokens.size() < 3) { |
| 115 | + VTR_LOG_WARN("Flat placement file, line %d has too few arguments. " |
| 116 | + "Requires at least: <atom_name> <atom_x_pos> <atom_y_pos>\n", |
| 117 | + line_num); |
| 118 | + continue; |
| 119 | + } |
| 120 | + |
| 121 | + // Get the atom name, which should be the first argument. |
| 122 | + AtomBlockId atom_blk_id = atom_netlist.find_block(tokens[0]); |
| 123 | + if (!atom_blk_id.is_valid()) { |
| 124 | + VTR_LOG_WARN("Flat placement file, line %d atom name does not match " |
| 125 | + "any atoms in the atom netlist.\n", |
| 126 | + line_num); |
| 127 | + continue; |
| 128 | + } |
| 129 | + |
| 130 | + // Check if this atom already has a flat placement |
| 131 | + // Using the x_pos and y_pos as identifiers. |
| 132 | + if (flat_placement_info.blk_x_pos[atom_blk_id] != FlatPlacementInfo::UNDEFINED_POS || |
| 133 | + flat_placement_info.blk_y_pos[atom_blk_id] != FlatPlacementInfo::UNDEFINED_POS) { |
| 134 | + VTR_LOG_WARN("Flat placement file, line %d, atom %s has multiple " |
| 135 | + "placement definitions in the flat placement file.\n", |
| 136 | + line_num, atom_netlist.block_name(atom_blk_id).c_str()); |
| 137 | + continue; |
| 138 | + } |
| 139 | + |
| 140 | + // Get the x and y position of the atom. These functions have error |
| 141 | + // checking built in. We parse x and y as floats to allow for reading |
| 142 | + // in more global atom positions. |
| 143 | + flat_placement_info.blk_x_pos[atom_blk_id] = vtr::atof(tokens[1]); |
| 144 | + flat_placement_info.blk_y_pos[atom_blk_id] = vtr::atof(tokens[2]); |
| 145 | + |
| 146 | + // If a sub-tile is given, parse the sub-tile as an integer. |
| 147 | + if (tokens.size() >= 4 && tokens[3][0] != '#') |
| 148 | + flat_placement_info.blk_sub_tile[atom_blk_id] = vtr::atoi(tokens[3]); |
| 149 | + |
| 150 | + // If a site index is given, parse the site index as an integer. |
| 151 | + if (tokens.size() >= 5 && tokens[4][0] != '#') |
| 152 | + flat_placement_info.blk_site_idx[atom_blk_id] = vtr::atoi(tokens[4]); |
| 153 | + |
| 154 | + // Ignore any further tokens. |
| 155 | + |
| 156 | + line_num++; |
| 157 | + } |
| 158 | + |
| 159 | + // Return the flat placement info loaded from the file. |
| 160 | + return flat_placement_info; |
| 161 | +} |
| 162 | + |
80 | 163 | /* ingests and legalizes a flat placement file */
|
81 | 164 | bool load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch) {
|
82 | 165 | VTR_LOG("load_flat_placement(); when implemented, this function:");
|
|
0 commit comments