Skip to content

Commit 9117490

Browse files
committed
[VPR] Remove the legacy data structure rr_node_indices from DeviceContext, as it is now fully shadowed by the data structure RRSpatialLookup
1 parent ba0eebd commit 9117490

File tree

8 files changed

+53
-55
lines changed

8 files changed

+53
-55
lines changed

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_view.h

Lines changed: 1 addition & 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

vpr/src/device/rr_spatial_lookup.cpp

Lines changed: 25 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,27 @@ 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+
294+
void RRSpatialLookup::clear() {
295+
for (auto& data : rr_node_indices_) {
296+
data.clear();
297+
}
298+
}

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/route/rr_graph.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,12 +1342,10 @@ void free_rr_graph() {
13421342

13431343
device_ctx.read_rr_graph_filename.clear();
13441344

1345-
for (auto& data : device_ctx.rr_node_indices) {
1346-
data.clear();
1347-
}
1348-
13491345
device_ctx.rr_nodes.clear();
13501346

1347+
device_ctx.rr_graph_builder.clear();
1348+
13511349
device_ctx.rr_indexed_data.clear();
13521350

13531351
device_ctx.rr_switch_inf.clear();

vpr/src/route/rr_graph_util.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,7 @@ void reorder_rr_graph_nodes(const t_router_opts& router_opts) {
156156

157157
graph.reorder(dest_order, src_order);
158158

159-
// update rr_node_indices, a map to optimize rr_index lookups
160-
for (auto& grid : device_ctx.rr_node_indices) {
161-
for (size_t x = 0; x < grid.dim_size(0); x++) {
162-
for (size_t y = 0; y < grid.dim_size(1); y++) {
163-
for (size_t s = 0; s < grid.dim_size(2); s++) {
164-
for (auto& node : grid[x][y][s]) {
165-
if (node != OPEN) {
166-
node = size_t(dest_order[RRNodeId(node)]);
167-
}
168-
}
169-
}
170-
}
171-
}
172-
}
159+
device_ctx.rr_graph_builder.node_lookup().reorder(dest_order);
173160

174161
device_ctx.rr_node_metadata.remap_keys([&](int node) { return size_t(dest_order[RRNodeId(node)]); });
175162
device_ctx.rr_edge_metadata.remap_keys([&](std::tuple<int, int, short> edge) {

0 commit comments

Comments
 (0)