Skip to content

Commit ab9dc4e

Browse files
committed
[VPR] Reworked RRSpatialLookup: added a private API find_nodes() to avoid duplicated codes
1 parent d4a76f6 commit ab9dc4e

File tree

2 files changed

+38
-57
lines changed

2 files changed

+38
-57
lines changed

vpr/src/device/rr_spatial_lookup.cpp

Lines changed: 26 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,18 @@ RRNodeId RRSpatialLookup::find_node(int x,
7474
return RRNodeId(rr_node_indices_[type][node_x][node_y][node_side][ptc]);
7575
}
7676

77-
std::vector<RRNodeId> RRSpatialLookup::find_channel_nodes(int x,
78-
int y,
79-
t_rr_type type) const {
77+
std::vector<RRNodeId> RRSpatialLookup::find_nodes(int x,
78+
int y,
79+
t_rr_type type,
80+
e_side side) const {
8081
/* TODO: The implementation of this API should be worked
8182
* when rr_node_indices adapts RRNodeId natively!
8283
*/
83-
std::vector<RRNodeId> channel_nodes;
84+
std::vector<RRNodeId> nodes;
8485

8586
/* Pre-check: the x, y, type are valid! Otherwise, return an empty vector */
86-
if ((x < 0 || y < 0) && (type == CHANX || type == CHANY)) {
87-
return channel_nodes;
87+
if (x < 0 || y < 0) {
88+
return nodes;
8889
}
8990

9091
/* Currently need to swap x and y for CHANX because of chan, seg convention
@@ -106,76 +107,44 @@ std::vector<RRNodeId> RRSpatialLookup::find_channel_nodes(int x,
106107
* - Return an empty list if any out-of-range is detected
107108
*/
108109
if (size_t(type) >= rr_node_indices_.size()) {
109-
return channel_nodes;
110+
return nodes;
110111
}
111112

112113
if (node_x >= rr_node_indices_[type].dim_size(0)) {
113-
return channel_nodes;
114+
return nodes;
114115
}
115116

116117
if (node_y >= rr_node_indices_[type].dim_size(1)) {
117-
return channel_nodes;
118+
return nodes;
118119
}
119120

120-
/* By default, we always added the channel nodes to the TOP side (to save memory) */
121-
e_side node_side = TOP;
122-
if (node_side >= rr_node_indices_[type].dim_size(2)) {
123-
return channel_nodes;
121+
if (side >= rr_node_indices_[type].dim_size(2)) {
122+
return nodes;
124123
}
125124

126-
for (const auto& node : rr_node_indices_[type][node_x][node_y][node_side]) {
125+
for (const auto& node : rr_node_indices_[type][node_x][node_y][side]) {
127126
if (RRNodeId(node)) {
128-
channel_nodes.push_back(RRNodeId(node));
127+
nodes.push_back(RRNodeId(node));
129128
}
130129
}
131130

132-
return channel_nodes;
131+
return nodes;
133132
}
134133

135-
std::vector<RRNodeId> RRSpatialLookup::find_sink_nodes(int x,
136-
int y) const {
137-
/* TODO: The implementation of this API should be worked
138-
* when rr_node_indices adapts RRNodeId natively!
139-
*/
140-
std::vector<RRNodeId> sink_nodes;
141-
142-
/* Pre-check: the x, y, type are valid! Otherwise, return an empty vector */
143-
if (x < 0 || y < 0) {
144-
return sink_nodes;
145-
}
146-
147-
VTR_ASSERT_SAFE(3 == rr_node_indices_[SINK].ndims());
148-
149-
/* Sanity check to ensure the x, y, side are in range
150-
* - Return a list of valid ids by searching in look-up when all the parameters are in range
151-
* - Return an empty list if any out-of-range is detected
152-
*/
153-
if (size_t(SINK) >= rr_node_indices_.size()) {
154-
return sink_nodes;
155-
}
156-
157-
if (size_t(x) >= rr_node_indices_[SINK].dim_size(0)) {
158-
return sink_nodes;
159-
}
160-
161-
if (size_t(y) >= rr_node_indices_[SINK].dim_size(1)) {
162-
return sink_nodes;
163-
}
164-
165-
/* By default, we always added the sink nodes to the TOP side (to save memory) */
166-
e_side node_side = TOP;
167-
if (node_side >= rr_node_indices_[SINK].dim_size(2)) {
168-
return sink_nodes;
134+
std::vector<RRNodeId> RRSpatialLookup::find_channel_nodes(int x,
135+
int y,
136+
t_rr_type type) const {
137+
/* Pre-check: node type should be routing tracks! */
138+
if (type != CHANX && type != CHANY) {
139+
return std::vector<RRNodeId>();
169140
}
170141

171-
/* Only insert valid ids in the returned vector */
172-
for (const auto& node : rr_node_indices_[SINK][x][y][node_side]) {
173-
if (RRNodeId(node)) {
174-
sink_nodes.push_back(RRNodeId(node));
175-
}
176-
}
142+
return find_nodes(x, y, type);
143+
}
177144

178-
return sink_nodes;
145+
std::vector<RRNodeId> RRSpatialLookup::find_sink_nodes(int x,
146+
int y) const {
147+
return find_nodes(x, y, SINK);
179148
}
180149

181150
std::vector<RRNodeId> RRSpatialLookup::find_nodes_at_all_sides(int x,

vpr/src/device/rr_spatial_lookup.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ class RRSpatialLookup {
180180
t_rr_type type,
181181
e_side side);
182182

183+
/* -- Internal data queries -- */
184+
private:
185+
/* An internal API to find all the nodes in a specific location with a given type
186+
* For OPIN/IPIN nodes that may exist on multiple sides, a specific side must be provided
187+
* This API is NOT public because its too powerful for developers with very limited sanity checks
188+
* But it is used to build the public APIs find_channel_nodes() etc., where sufficient sanity checks are applied
189+
*/
190+
std::vector<RRNodeId> find_nodes(int x,
191+
int y,
192+
t_rr_type type,
193+
e_side side = SIDES[0]) const;
194+
183195
/* -- Internal data storage -- */
184196
private:
185197
/* TODO: When the refactoring effort finishes,

0 commit comments

Comments
 (0)