22#include " arch_util.h"
33#include " globals.h"
44
5+ /* *
6+ * @brief Creates a compressed grid from the given locations.
7+ *
8+ *
9+ * @param locations The location of logical blocks of a specific type.
10+ * [0...layer-1][0...num_instances_on_layer-1] --> (x, y)
11+ * @param num_layers The number of dice.
12+ * @return t_compressed_block_grid The compressed grid created from the given locations.
13+ */
14+ static t_compressed_block_grid create_compressed_block_grid (const std::vector<std::vector<vtr::Point<int >>>& locations,
15+ int num_layers);
16+
17+
518std::vector<t_compressed_block_grid> create_compressed_block_grids () {
619 auto & device_ctx = g_vpr_ctx.device ();
720 auto & grid = device_ctx.grid ;
821 const int num_layers = grid.get_num_layers ();
922
10- // Collect the set of x/y locations for each instace of a block type
11- std::vector<std::vector<std::vector<vtr::Point<int >>>> block_locations (device_ctx.logical_block_types .size ()); // [logical_block_type][layer_num][0...num_instance_on_layer] -> (x, y)
12- for (int block_type_num = 0 ; block_type_num < (int )device_ctx.logical_block_types .size (); block_type_num++) {
13- block_locations[block_type_num].resize (num_layers);
23+ // Collect the set of x/y locations for each instance of a block type
24+ // [logical_block_type][layer_num][0...num_instance_on_layer] -> (x, y)
25+ std::vector<std::vector<std::vector<vtr::Point<int >>>> block_locations (device_ctx.logical_block_types .size ());
26+
27+ for (const auto & block_type : device_ctx.logical_block_types ) {
28+ block_locations[block_type.index ].resize (num_layers);
1429 }
1530
1631 for (int layer_num = 0 ; layer_num < num_layers; layer_num++) {
1732 for (int x = 0 ; x < (int )grid.width (); ++x) {
1833 for (int y = 0 ; y < (int )grid.height (); ++y) {
1934 int width_offset = grid.get_width_offset ({x, y, layer_num});
2035 int height_offset = grid.get_height_offset (t_physical_tile_loc (x, y, layer_num));
21- if (width_offset == 0 && height_offset == 0 ) {
36+
37+ if (width_offset == 0 && height_offset == 0 ) { // the bottom left corner of a tile
2238 const auto & type = grid.get_physical_type ({x, y, layer_num});
2339 auto equivalent_sites = get_equivalent_sites_set (type);
2440
25- for (auto & block : equivalent_sites) {
41+ for (t_logical_block_type_ptr block_type : equivalent_sites) {
2642 // Only record at block root location
27- block_locations[block ->index ][layer_num].emplace_back (x, y);
43+ block_locations[block_type ->index ][layer_num].emplace_back (x, y);
2844 }
2945 }
3046 }
3147 }
3248 }
3349
50+ // each logical block type has its own compressed grid
3451 std::vector<t_compressed_block_grid> compressed_type_grids (device_ctx.logical_block_types .size ());
52+
3553 for (const auto & logical_block : device_ctx.logical_block_types ) {
3654 auto compressed_block_grid = create_compressed_block_grid (block_locations[logical_block.index ], num_layers);
3755
@@ -62,22 +80,22 @@ std::vector<t_compressed_block_grid> create_compressed_block_grids() {
6280}
6381
6482// Given a set of locations, returns a 2D matrix in a compressed space
65- t_compressed_block_grid create_compressed_block_grid (const std::vector<std::vector<vtr::Point<int >>>& locations, int num_layers) {
83+ static t_compressed_block_grid create_compressed_block_grid (const std::vector<std::vector<vtr::Point<int >>>& locations,
84+ int num_layers) {
6685 t_compressed_block_grid compressed_grid;
6786
6887 if (locations.empty ()) {
6988 return compressed_grid;
7089 }
7190
7291 {
73- std::vector<std::vector<int >> x_locs (num_layers);
74- std::vector<std::vector<int >> y_locs (num_layers);
7592 compressed_grid.compressed_to_grid_x .resize (num_layers);
7693 compressed_grid.compressed_to_grid_y .resize (num_layers);
94+
7795 for (int layer_num = 0 ; layer_num < num_layers; layer_num++) {
78- auto & layer_x_locs = x_locs[layer_num] ;
79- auto & layer_y_locs = y_locs[layer_num] ;
80- // Record all the x/y locations seperately
96+ std::vector< int > layer_x_locs;
97+ std::vector< int > layer_y_locs;
98+ // Record all the x/y locations separately
8199 for (auto point : locations[layer_num]) {
82100 layer_x_locs.emplace_back (point.x ());
83101 layer_y_locs.emplace_back (point.y ());
@@ -97,6 +115,9 @@ t_compressed_block_grid create_compressed_block_grid(const std::vector<std::vect
97115 }
98116 compressed_grid.compressed_to_grid_x [layer_num] = std::move (layer_x_locs);
99117 compressed_grid.compressed_to_grid_y [layer_num] = std::move (layer_y_locs);
118+
119+ layer_x_locs.clear ();
120+ layer_y_locs.clear ();
100121 }
101122 }
102123
@@ -142,7 +163,7 @@ t_compressed_block_grid create_compressed_block_grid(const std::vector<std::vect
142163}
143164
144165/* Print the contents of the compressed grids to an echo file*/
145- void echo_compressed_grids (char * filename, const std::vector<t_compressed_block_grid>& comp_grids) {
166+ void echo_compressed_grids (const char * filename, const std::vector<t_compressed_block_grid>& comp_grids) {
146167 FILE* fp;
147168 fp = vtr::fopen (filename, " w" );
148169
@@ -161,14 +182,14 @@ void echo_compressed_grids(char* filename, const std::vector<t_compressed_block_
161182 fprintf (fp, " \n\n Grid type: %s \n " , device_ctx.logical_block_types [i].name );
162183
163184 fprintf (fp, " X coordinates: \n " );
164- for (int j = 0 ; j < (int )comp_grids[i].compressed_to_grid_x .size (); j++) {
185+ for (int j = 0 ; j < (int )comp_grids[i].compressed_to_grid_x [layer_num] .size (); j++) {
165186 auto grid_loc = comp_grids[i].compressed_loc_to_grid_loc ({j, 0 , layer_num});
166187 fprintf (fp, " %d " , grid_loc.x );
167188 }
168189 fprintf (fp, " \n " );
169190
170191 fprintf (fp, " Y coordinates: \n " );
171- for (int k = 0 ; k < (int )comp_grids[i].compressed_to_grid_y .size (); k++) {
192+ for (int k = 0 ; k < (int )comp_grids[i].compressed_to_grid_y [layer_num] .size (); k++) {
172193 auto grid_loc = comp_grids[i].compressed_loc_to_grid_loc ({0 , k, layer_num});
173194 fprintf (fp, " %d " , grid_loc.y );
174195 }
0 commit comments