Skip to content

Commit 5034a9f

Browse files
committed
[VPR] Add an API find_channel_nodes() to RRSpatialLookup, driven by the needs in client functions
1 parent e62a86a commit 5034a9f

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

vpr/src/device/rr_spatial_lookup.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,59 @@ 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 {
80+
std::vector<RRNodeId> channel_nodes;
81+
82+
/* Pre-check: the x, y, type are valid! Otherwise, return an empty vector */
83+
if ((0 > x || 0 > y) && (CHANX == type || CHANY == type)) {
84+
return channel_nodes;
85+
}
86+
87+
/* Currently need to swap x and y for CHANX because of chan, seg convention
88+
* This is due to that the fast look-up builders uses (y, x) coordinate when
89+
* registering a CHANX node in the look-up
90+
* TODO: Once the builders is reworked for use consistent (x, y) convention,
91+
* the following swapping can be removed
92+
*/
93+
size_t node_x = x;
94+
size_t node_y = y;
95+
if (CHANX == type) {
96+
std::swap(node_x, node_y);
97+
}
98+
99+
VTR_ASSERT_SAFE(3 == rr_node_indices_[type].ndims());
100+
101+
/* Sanity check to ensure the x, y, side are in range
102+
* - Return a list of valid ids by searching in look-up when all the parameters are in range
103+
* - Return an empty list if any out-of-range is detected
104+
*/
105+
if (size_t(type) >= rr_node_indices_.size()) {
106+
return channel_nodes;
107+
}
108+
109+
if (node_x >= rr_node_indices_[type].dim_size(0)) {
110+
return channel_nodes;
111+
}
112+
113+
if (node_y >= rr_node_indices_[type].dim_size(1)) {
114+
return channel_nodes;
115+
}
116+
117+
/* By default, we always added the channel nodes to the TOP side (to save memory) */
118+
e_side node_side = TOP;
119+
if (node_side >= rr_node_indices_[type].dim_size(2)) {
120+
return channel_nodes;
121+
}
122+
123+
for (const auto& node : rr_node_indices_[type][node_x][node_y][node_side]) {
124+
channel_nodes.push_back(RRNodeId(node));
125+
}
126+
127+
return channel_nodes;
128+
}
129+
77130
void RRSpatialLookup::add_node(RRNodeId node,
78131
int x,
79132
int y,

vpr/src/device/rr_spatial_lookup.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ class RRSpatialLookup {
6363
int ptc,
6464
e_side side = NUM_SIDES) const;
6565

66+
/**
67+
* Returns the indices of the specified routing resource nodes,
68+
* representing routing tracks in a channel.
69+
* - (x, y) are the coordinate of the routing channel within the FPGA
70+
* - rr_type specifies the type of routing channel, either x-direction or y-direction
71+
*
72+
* Note:
73+
* - Return an empty list if there are no routing channel at the given (x, y) location
74+
* - The node list returned may contain some holes (invalid ids), which means that
75+
* the routing track does not exist at a specific location
76+
* For example, if the 2nd element is an invalid id, it means the 2nd routing track does not exist
77+
* in a routing channel at (x, y) location
78+
*/
79+
std::vector<RRNodeId> find_channel_nodes(int x,
80+
int y,
81+
t_rr_type type) const;
82+
6683
/* -- Mutators -- */
6784
public:
6885
/**

0 commit comments

Comments
 (0)