Skip to content

Commit 6bff4a4

Browse files
authored
Merge branch 'master' into yosys+odin
2 parents 2d6e53a + eea0df0 commit 6bff4a4

39 files changed

+581
-317
lines changed

utils/route_diag/src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static void do_one_route(int source_node, int sink_node,
102102
device_ctx.grid,
103103
*router_lookahead,
104104
device_ctx.rr_nodes,
105+
&device_ctx.rr_graph,
105106
device_ctx.rr_rc_data,
106107
device_ctx.rr_switch_inf,
107108
g_vpr_ctx.mutable_routing().rr_node_route_inf);

vpr/asan.supp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#AddressSanitizer suppression file for VPR
2+
3+
#Suppress known errors from the TBB library
4+
#These are some errors from the library that we can't fix and suspect are spurious
5+
interceptor_via_lib:libtbb.so

vpr/lsan.supp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#LeakSanitizer supporession file for VPR
1+
#LeakSanitizer suppression file for VPR
22

33
#Leak from graphics (ezgl/cairo) related to
44
# text processing
55
leak:libfontconfig.so
6+
#Leaks from TBB library, which
7+
#allows VPR to run with parallelism
8+
leak:libtbb.so

vpr/src/base/vpr_context.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,26 +160,15 @@ struct DeviceContext : public Context {
160160
///@brief Reverse look-up from RR node to non-configurably connected node set (index into rr_nonconf_node_sets)
161161
std::unordered_map<int, int> rr_node_to_non_config_node_set;
162162

163-
///@brief The indicies of rr nodes of a given type at a specific x,y grid location
164-
t_rr_node_indices rr_node_indices; // [0..NUM_RR_TYPES-1][0..grid.width()-1][0..grid.width()-1][0..size-1]
165-
166-
/* TODO: remove this interface from device_context once the code refactoring is completed
167-
* because it should be part of the rr_graph view
168-
* TODO: Currently, we use reference pointers to ensure that the rr_spatial_lookup is always
169-
* synchronized with the rr_node_indices but this causes a lot of confusion for developers
170-
* The temporary fix should be patched as soon as possible.
163+
/* A writeable view of routing resource graph to be the ONLY database
164+
* for routing resource graph builder functions.
171165
*/
172-
RRSpatialLookup rr_spatial_lookup{rr_node_indices};
166+
RRGraphBuilder rr_graph_builder{&rr_nodes};
173167

174168
/* A read-only view of routing resource graph to be the ONLY database
175169
* for client functions: GUI, placer, router, timing analyzer etc.
176170
*/
177-
RRGraphView rr_graph{rr_nodes, rr_spatial_lookup};
178-
179-
/* A writeable view of routing resource graph to be the ONLY database
180-
* for routing resource graph builder functions.
181-
*/
182-
RRGraphBuilder rr_graph_builder{&rr_nodes, &rr_spatial_lookup};
171+
RRGraphView rr_graph{rr_nodes, rr_graph_builder.node_lookup()};
183172

184173
///@brief Autogenerated in build_rr_graph based on switch fan-in. [0..(num_rr_switches-1)]
185174
std::vector<t_rr_switch_inf> rr_switch_inf;

vpr/src/device/rr_graph_builder.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#include "vtr_log.h"
22
#include "rr_graph_builder.h"
33

4-
RRGraphBuilder::RRGraphBuilder(t_rr_graph_storage* node_storage,
5-
RRSpatialLookup* node_lookup)
6-
: node_storage_(*node_storage)
7-
, node_lookup_(*node_lookup) {
4+
RRGraphBuilder::RRGraphBuilder(t_rr_graph_storage* node_storage)
5+
: node_storage_(*node_storage) {
86
}
97

108
t_rr_graph_storage& RRGraphBuilder::node_storage() {
@@ -48,3 +46,7 @@ void RRGraphBuilder::add_node_to_all_locs(RRNodeId node) {
4846
}
4947
}
5048
}
49+
50+
void RRGraphBuilder::clear() {
51+
node_lookup_.clear();
52+
}

vpr/src/device/rr_graph_builder.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class RRGraphBuilder {
1919
/* -- Constructors -- */
2020
public:
2121
/* See detailed comments about the data structures in the internal data storage section of this file */
22-
RRGraphBuilder(t_rr_graph_storage* node_storage,
23-
RRSpatialLookup* node_lookup);
22+
RRGraphBuilder(t_rr_graph_storage* node_storage);
2423

2524
/* Disable copy constructors and copy assignment operator
2625
* This is to avoid accidental copy because it could be an expensive operation considering that the
@@ -49,6 +48,9 @@ class RRGraphBuilder {
4948
*/
5049
void add_node_to_all_locs(RRNodeId node);
5150

51+
/* Clear all the underlying data storage */
52+
void clear();
53+
5254
/* -- Internal data storage -- */
5355
private:
5456
/* TODO: When the refactoring effort finishes,
@@ -63,7 +65,7 @@ class RRGraphBuilder {
6365
/* node-level storage including edge storages */
6466
t_rr_graph_storage& node_storage_;
6567
/* Fast look-up for rr nodes */
66-
RRSpatialLookup& node_lookup_;
68+
RRSpatialLookup node_lookup_;
6769
};
6870

6971
#endif

vpr/src/device/rr_graph_obj.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,6 @@ e_side RRGraph::node_side(const RRNodeId& node) const {
168168
return node_sides_[node];
169169
}
170170

171-
/* Get the resistance of a node */
172-
float RRGraph::node_R(const RRNodeId& node) const {
173-
VTR_ASSERT_SAFE(valid_node_id(node));
174-
return node_Rs_[node];
175-
}
176-
177-
/* Get the capacitance of a node */
178-
float RRGraph::node_C(const RRNodeId& node) const {
179-
VTR_ASSERT_SAFE(valid_node_id(node));
180-
return node_Cs_[node];
181-
}
182-
183171
/*
184172
* Get a segment id of a node in rr_graph
185173
*/

vpr/src/device/rr_graph_obj.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,6 @@ class RRGraph {
434434
*/
435435
e_side node_side(const RRNodeId& node) const;
436436

437-
/* Get resistance of a node, used to built RC tree for timing analysis */
438-
float node_R(const RRNodeId& node) const;
439-
440-
/* Get capacitance of a node, used to built RC tree for timing analysis */
441-
float node_C(const RRNodeId& node) const;
442-
443437
/* Get segment id of a node, containing the information of the routing
444438
* segment that the node represents. See more details in the data structure t_segment_inf
445439
*/

vpr/src/device/rr_graph_view.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#ifndef RR_GRAPH_VIEW_H
22
#define RR_GRAPH_VIEW_H
33

4-
#include "rr_graph_storage.h"
5-
#include "rr_spatial_lookup.h"
4+
#include "rr_graph_builder.h"
65

76
/* An read-only routing resource graph
87
* which is an unified object including pointors to
@@ -77,6 +76,21 @@ class RRGraphView {
7776
return node_storage_.node_direction_string(node);
7877
}
7978

79+
/* Get the capacitance of a routing resource node. This function is inlined for runtime optimization. */
80+
inline float node_C(RRNodeId node) const {
81+
return node_storage_.node_C(node);
82+
}
83+
84+
/* Get the resistance of a routing resource node. This function is inlined for runtime optimization. */
85+
inline float node_R(RRNodeId node) const {
86+
return node_storage_.node_R(node);
87+
}
88+
89+
/* Get the rc_index of a routing resource node. This function is inlined for runtime optimization. */
90+
inline int16_t node_rc_index(RRNodeId node) const {
91+
return node_storage_.node_rc_index(node);
92+
}
93+
8094
/* Get the fan in of a routing resource node. This function is inlined for runtime optimization. */
8195
inline t_edge_size node_fan_in(RRNodeId node) const {
8296
return node_storage_.fan_in(node);

vpr/src/device/rr_spatial_lookup.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "vtr_assert.h"
22
#include "rr_spatial_lookup.h"
33

4-
RRSpatialLookup::RRSpatialLookup(t_rr_node_indices& rr_node_indices)
5-
: rr_node_indices_(rr_node_indices) {
4+
RRSpatialLookup::RRSpatialLookup() {
65
}
76

87
RRNodeId RRSpatialLookup::find_node(int x,
@@ -273,3 +272,26 @@ void RRSpatialLookup::resize_nodes(int x,
273272
std::max(rr_node_indices_[type].dim_size(2), size_t(side) + 1)});
274273
}
275274
}
275+
276+
void RRSpatialLookup::reorder(const vtr::vector<RRNodeId, RRNodeId> dest_order) {
277+
// update rr_node_indices, a map to optimize rr_index lookups
278+
for (auto& grid : rr_node_indices_) {
279+
for (size_t x = 0; x < grid.dim_size(0); x++) {
280+
for (size_t y = 0; y < grid.dim_size(1); y++) {
281+
for (size_t s = 0; s < grid.dim_size(2); s++) {
282+
for (auto& node : grid[x][y][s]) {
283+
if (node != OPEN) {
284+
node = size_t(dest_order[RRNodeId(node)]);
285+
}
286+
}
287+
}
288+
}
289+
}
290+
}
291+
}
292+
293+
void RRSpatialLookup::clear() {
294+
for (auto& data : rr_node_indices_) {
295+
data.clear();
296+
}
297+
}

vpr/src/device/rr_spatial_lookup.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RR_SPATIAL_LOOKUP_H
33

44
#include "vtr_geometry.h"
5+
#include "vtr_vector.h"
56
#include "vpr_types.h"
67

78
/********************************************************************
@@ -17,7 +18,7 @@ class RRSpatialLookup {
1718
/* -- Constructors -- */
1819
public:
1920
/* Explicitly define the only way to create an object */
20-
explicit RRSpatialLookup(t_rr_node_indices& rr_node_indices);
21+
explicit RRSpatialLookup();
2122

2223
/* Disable copy constructors and copy assignment operator
2324
* This is to avoid accidental copy because it could be an expensive operation considering that the
@@ -185,6 +186,12 @@ class RRSpatialLookup {
185186
t_rr_type type,
186187
e_side side);
187188

189+
/* Reorder the internal look up to be more memory efficient */
190+
void reorder(const vtr::vector<RRNodeId, RRNodeId> dest_order);
191+
192+
/* Clear all the data inside */
193+
void clear();
194+
188195
/* -- Internal data queries -- */
189196
private:
190197
/* An internal API to find all the nodes in a specific location with a given type
@@ -199,17 +206,8 @@ class RRSpatialLookup {
199206

200207
/* -- Internal data storage -- */
201208
private:
202-
/* TODO: When the refactoring effort finishes,
203-
* the data structure will be the owner of the data storages.
204-
* That is why the reference is used here.
205-
* It can avoid a lot of code changes once the refactoring is finished
206-
* (there is no function get data directly through the rr_node_indices in DeviceContext).
207-
* If pointers are used, it may cause many codes in client functions
208-
* or inside the data structures to be changed later.
209-
* That explains why the reference is used here temporarily
210-
*/
211209
/* Fast look-up: TODO: Should rework the data type. Currently it is based on a 3-dimensional arrqay mater where some dimensions must always be accessed with a specific index. Such limitation should be overcome */
212-
t_rr_node_indices& rr_node_indices_;
210+
t_rr_node_indices rr_node_indices_;
213211
};
214212

215213
#endif

vpr/src/place/grid_tile_lookup.cpp

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#include "grid_tile_lookup.h"
2+
3+
void GridTileLookup::initialize_grid_tile_matrices() {
4+
auto& device_ctx = g_vpr_ctx.device();
5+
6+
//Will store the max number of tile locations for each logical block type
7+
max_placement_locations.resize(device_ctx.logical_block_types.size());
8+
9+
for (const auto& type : device_ctx.logical_block_types) {
10+
vtr::NdMatrix<int, 2> type_count({device_ctx.grid.width(), device_ctx.grid.height()});
11+
fill_type_matrix(&type, type_count);
12+
block_type_matrices.push_back(type_count);
13+
}
14+
}
15+
16+
void GridTileLookup::fill_type_matrix(t_logical_block_type_ptr block_type, vtr::NdMatrix<int, 2>& type_count) {
17+
auto& device_ctx = g_vpr_ctx.device();
18+
19+
int num_rows = device_ctx.grid.height();
20+
int num_cols = device_ctx.grid.width();
21+
22+
/*
23+
* Iterating through every location on the grid to store the number of subtiles of
24+
* the correct type at each location. For each location, we store the cumulative
25+
* number of tiles of the type up to that location - meaning we store the number of
26+
* subtiles at the location, plus the number of subtiles at the locations above and to
27+
* the right of it.
28+
*/
29+
for (int i_col = type_count.dim_size(0) - 1; i_col >= 0; i_col--) {
30+
for (int j_row = type_count.dim_size(1) - 1; j_row >= 0; j_row--) {
31+
auto& tile = device_ctx.grid[i_col][j_row].type;
32+
type_count[i_col][j_row] = 0;
33+
34+
if (is_tile_compatible(tile, block_type)) {
35+
for (const auto& sub_tile : tile->sub_tiles) {
36+
if (is_sub_tile_compatible(tile, block_type, sub_tile.capacity.low)) {
37+
type_count[i_col][j_row] = sub_tile.capacity.total();
38+
}
39+
}
40+
}
41+
42+
if (i_col < num_cols - 1) {
43+
type_count[i_col][j_row] += type_count[i_col + 1][j_row];
44+
}
45+
if (j_row < num_rows - 1) {
46+
type_count[i_col][j_row] += type_count[i_col][j_row + 1];
47+
}
48+
if (i_col < (num_cols - 1) && j_row < (num_rows - 1)) {
49+
type_count[i_col][j_row] -= type_count[i_col + 1][j_row + 1];
50+
}
51+
}
52+
}
53+
54+
//The total number of subtiles for the block type will be at [0][0]
55+
max_placement_locations[block_type->index] = type_count[0][0];
56+
}
57+
58+
vtr::NdMatrix<int, 2>& GridTileLookup::get_type_grid(t_logical_block_type_ptr block_type) {
59+
return block_type_matrices[block_type->index];
60+
}
61+
62+
int GridTileLookup::total_type_tiles(t_logical_block_type_ptr block_type) {
63+
return max_placement_locations[block_type->index];
64+
}
65+
66+
/*
67+
* This routine uses pre-computed values from the grids for each block type to get the number of grid tiles
68+
* covered by a region.
69+
* For a region with no subtiles specified, the number of grid tiles can be calculated by adding
70+
* and subtracting four values from within/at the edge of the region.
71+
* The region with subtile case is taken care of by a helper routine, region_with_subtile_count().
72+
*/
73+
int GridTileLookup::region_tile_count(const Region& reg, t_logical_block_type_ptr block_type) {
74+
vtr::Rect<int> reg_rect = reg.get_region_rect();
75+
int subtile = reg.get_sub_tile();
76+
77+
int xmin = reg_rect.xmin();
78+
int ymin = reg_rect.ymin();
79+
int xmax = reg_rect.xmax();
80+
int ymax = reg_rect.ymax();
81+
auto& type_grid = block_type_matrices[block_type->index];
82+
83+
int xdim = type_grid.dim_size(0);
84+
int ydim = type_grid.dim_size(1);
85+
86+
int num_tiles = 0;
87+
88+
if (subtile == NO_SUBTILE) {
89+
num_tiles = type_grid[xmin][ymin];
90+
91+
if ((ymax + 1) < ydim) {
92+
num_tiles -= type_grid[xmin][ymax + 1];
93+
}
94+
95+
if ((xmax + 1) < xdim) {
96+
num_tiles -= type_grid[xmax + 1][ymin];
97+
}
98+
99+
if ((xmax + 1) < xdim && (ymax + 1) < ydim) {
100+
num_tiles += type_grid[xmax + 1][ymax + 1];
101+
}
102+
} else {
103+
num_tiles = region_with_subtile_count(reg, block_type);
104+
}
105+
106+
return num_tiles;
107+
}
108+
109+
/*
110+
* This routine is for the subtile specified case; an O(region_size) scan needs to be done to check whether each grid
111+
* location in the region is compatible for the block at the subtile specified.
112+
*/
113+
int GridTileLookup::region_with_subtile_count(const Region& reg, t_logical_block_type_ptr block_type) {
114+
auto& device_ctx = g_vpr_ctx.device();
115+
int num_sub_tiles = 0;
116+
vtr::Rect<int> reg_rect = reg.get_region_rect();
117+
int subtile = reg.get_sub_tile();
118+
119+
int xmin = reg_rect.xmin();
120+
int ymin = reg_rect.ymin();
121+
int xmax = reg_rect.xmax();
122+
int ymax = reg_rect.ymax();
123+
124+
for (int i = xmax; i >= xmin; i--) {
125+
for (int j = ymax; j >= ymin; j--) {
126+
auto& tile = device_ctx.grid[i][j].type;
127+
if (is_sub_tile_compatible(tile, block_type, subtile)) {
128+
num_sub_tiles++;
129+
}
130+
}
131+
}
132+
133+
return num_sub_tiles;
134+
}
135+
136+
void GridTileLookup::print_type_matrix(vtr::NdMatrix<int, 2>& type_count) {
137+
for (int i_col = type_count.dim_size(0) - 1; i_col >= 0; i_col--) {
138+
for (int j_row = type_count.dim_size(1) - 1; j_row >= 0; j_row--) {
139+
VTR_LOG("%d ", type_count[i_col][j_row]);
140+
}
141+
VTR_LOG("\n");
142+
}
143+
}

0 commit comments

Comments
 (0)