Skip to content

Commit 871b28a

Browse files
authored
Merge pull request #2509 from verilog-to-routing/round_comp_loc
Round compressed grid locations
2 parents 31f0fbb + c9e423f commit 871b28a

File tree

30 files changed

+3685
-3386
lines changed

30 files changed

+3685
-3386
lines changed

libs/libarchfpga/src/arch_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ std::unordered_set<t_logical_block_type_ptr> get_equivalent_sites_set(t_physical
550550
std::unordered_set<t_logical_block_type_ptr> equivalent_sites;
551551

552552
for (auto& sub_tile : type->sub_tiles) {
553-
for (auto& logical_block : sub_tile.equivalent_sites) {
553+
for (auto logical_block : sub_tile.equivalent_sites) {
554554
equivalent_sites.insert(logical_block);
555555
}
556556
}

libs/libarchfpga/src/device_grid.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ DeviceGrid::DeviceGrid(std::string grid_name, vtr::NdMatrix<t_grid_tile, 3> grid
88
count_instances();
99
}
1010

11-
DeviceGrid::DeviceGrid(std::string grid_name, vtr::NdMatrix<t_grid_tile, 3> grid, std::vector<t_logical_block_type_ptr> limiting_res)
11+
DeviceGrid::DeviceGrid(std::string grid_name,
12+
vtr::NdMatrix<t_grid_tile, 3> grid,
13+
std::vector<t_logical_block_type_ptr> limiting_res)
1214
: DeviceGrid(std::move(grid_name), std::move(grid)) {
1315
limiting_resources_ = std::move(limiting_res);
1416
}

libs/libarchfpga/src/device_grid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class DeviceGrid {
118118
* @note which can be used for indexing in the second dimension, allowing
119119
* @note traditional 2-d indexing to be used
120120
*/
121-
vtr::NdMatrix<t_grid_tile, 3> grid_; //This stores the grid of complex blocks. It is a a 3D matrix: [0..num_layers-1][0..grid.width()-1][0..grid_height()-1]
121+
vtr::NdMatrix<t_grid_tile, 3> grid_; //This stores the grid of complex blocks. It is a 3D matrix: [0..num_layers-1][0..grid.width()-1][0..grid_height()-1]
122122

123123
///@brief instance_counts_ stores the number of each tile type on each layer. It is initialized in count_instances().
124124
std::vector<std::map<t_physical_tile_type_ptr, size_t>> instance_counts_; /* [layer_num][physical_tile_type_ptr] */

vpr/src/place/compressed_grid.cpp

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,54 @@
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+
518
std::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\nGrid 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
}

vpr/src/place/compressed_grid.h

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,29 @@ struct t_compressed_block_grid {
6767
* the nearest compressed location to point by rounding it down
6868
*/
6969
inline t_physical_tile_loc grid_loc_to_compressed_loc_approx(t_physical_tile_loc grid_loc) const {
70-
int cx = OPEN;
71-
int cy = OPEN;
72-
int layer_num = grid_loc.layer_num;
73-
74-
auto itr_x = std::lower_bound(compressed_to_grid_x[layer_num].begin(), compressed_to_grid_x[layer_num].end(), grid_loc.x);
75-
if (itr_x == compressed_to_grid_x[layer_num].end())
76-
cx = std::distance(compressed_to_grid_x[layer_num].begin(), itr_x - 1);
77-
else
78-
cx = std::distance(compressed_to_grid_x[layer_num].begin(), itr_x);
79-
80-
auto itr_y = std::lower_bound(compressed_to_grid_y[layer_num].begin(), compressed_to_grid_y[layer_num].end(), grid_loc.y);
81-
if (itr_y == compressed_to_grid_y[layer_num].end())
82-
cy = std::distance(compressed_to_grid_y[layer_num].begin(), itr_y - 1);
83-
else
84-
cy = std::distance(compressed_to_grid_y[layer_num].begin(), itr_y);
70+
auto find_closest_compressed_point = [](int loc, const std::vector<int>& compressed_grid_dim) -> int {
71+
auto itr = std::lower_bound(compressed_grid_dim.begin(), compressed_grid_dim.end(), loc);
72+
int cx;
73+
if (itr < compressed_grid_dim.end() - 1) {
74+
int dist_prev = abs(loc - *itr);
75+
int dist_next = abs(loc - *(itr+1));
76+
if (dist_prev < dist_next) {
77+
cx = std::distance(compressed_grid_dim.begin(), itr);
78+
} else {
79+
cx = std::distance(compressed_grid_dim.begin(), itr + 1);
80+
}
81+
} else if (itr == compressed_grid_dim.end()) {
82+
cx = std::distance(compressed_grid_dim.begin(), itr - 1);
83+
} else {
84+
cx = std::distance(compressed_grid_dim.begin(), itr);
85+
}
86+
87+
return cx;
88+
};
89+
90+
const int layer_num = grid_loc.layer_num;
91+
const int cx = find_closest_compressed_point(grid_loc.x, compressed_to_grid_x[layer_num]);
92+
const int cy = find_closest_compressed_point(grid_loc.y, compressed_to_grid_y[layer_num]);
8593

8694
return {cx, cy, layer_num};
8795
}
@@ -111,15 +119,13 @@ typedef std::vector<t_compressed_block_grid> t_compressed_block_grids;
111119

112120
std::vector<t_compressed_block_grid> create_compressed_block_grids();
113121

114-
t_compressed_block_grid create_compressed_block_grid(const std::vector<std::vector<vtr::Point<int>>>& locations, int num_layers);
115-
116122
/**
117123
* @brief print the contents of the compressed grids to an echo file
118124
*
119125
* @param filename the name of the file to print to
120126
* @param comp_grids the compressed grids that are used during placement
121127
*
122128
*/
123-
void echo_compressed_grids(char* filename, const std::vector<t_compressed_block_grid>& comp_grids);
129+
void echo_compressed_grids(const char* filename, const std::vector<t_compressed_block_grid>& comp_grids);
124130

125131
#endif

vpr/src/place/directed_moves_util.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ void calculate_centroid_loc(ClusterBlockId b_from,
4242
//iterate over the from block pins
4343
for (ClusterPinId pin_id : cluster_ctx.clb_nlist.block_pins(b_from)) {
4444
ClusterNetId net_id = cluster_ctx.clb_nlist.pin_net(pin_id);
45+
46+
if (cluster_ctx.clb_nlist.net_is_ignored(net_id)) {
47+
continue;
48+
}
49+
4550
/* Ignore the special case nets which only connects a block to itself *
4651
* Experimentally, it was found that this case greatly degrade QoR */
4752
if (cluster_ctx.clb_nlist.net_sinks(net_id).size() == 1) {
@@ -122,9 +127,9 @@ void calculate_centroid_loc(ClusterBlockId b_from,
122127
}
123128

124129
//Calculate the centroid location
125-
centroid.x = acc_x / acc_weight;
126-
centroid.y = acc_y / acc_weight;
127-
centroid.layer = acc_layer / acc_weight;
130+
centroid.x = (int)std::round(acc_x / acc_weight);
131+
centroid.y = (int)std::round(acc_y / acc_weight);
132+
centroid.layer = (int)std::round(acc_layer / acc_weight);
128133
}
129134

130135
static std::map<std::string, e_reward_function> available_reward_function = {

0 commit comments

Comments
 (0)