Skip to content

Commit 6e5cc6a

Browse files
authored
Merge pull request #1951 from RapidSilicon/switch_segments_builder
Add APIs rr_switch and rr_segment() to RRGraphBuilder
2 parents 8c524bd + 6587aed commit 6e5cc6a

17 files changed

+180
-50
lines changed

utils/route_diag/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static void do_one_route(int source_node, int sink_node,
104104
device_ctx.rr_nodes,
105105
&device_ctx.rr_graph,
106106
device_ctx.rr_rc_data,
107-
device_ctx.rr_switch_inf,
107+
device_ctx.rr_graph.rr_switch(),
108108
g_vpr_ctx.mutable_routing().rr_node_route_inf);
109109
enable_router_debug(router_opts, ClusterNetId(), sink_node, 1, &router);
110110
bool found_path;

vpr/src/base/stats.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ void routing_stats(bool full_stats, enum e_route_type route_type, std::vector<t_
4646
float area, used_area;
4747

4848
auto& device_ctx = g_vpr_ctx.device();
49+
auto& rr_graph = device_ctx.rr_graph;
4950
auto& cluster_ctx = g_vpr_ctx.clustering();
5051

51-
int num_rr_switch = device_ctx.rr_switch_inf.size();
52+
int num_rr_switch = rr_graph.num_rr_switches();
5253

5354
length_and_bends_stats();
5455
print_channel_stats();

vpr/src/base/vpr_context.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,7 @@ struct DeviceContext : public Context {
168168
/* A read-only view of routing resource graph to be the ONLY database
169169
* for client functions: GUI, placer, router, timing analyzer etc.
170170
*/
171-
RRGraphView rr_graph{rr_nodes, rr_graph_builder.node_lookup(), rr_indexed_data, rr_segments, rr_switch_inf};
172-
173-
///@brief Autogenerated in build_rr_graph based on switch fan-in. [0..(num_rr_switches-1)]
174-
vtr::vector<RRSwitchId, t_rr_switch_inf> rr_switch_inf;
175-
176-
///@brief Wire segment types in RR graph
177-
vtr::vector<RRSegmentId, t_segment_inf> rr_segments;
178-
171+
RRGraphView rr_graph{rr_nodes, rr_graph_builder.node_lookup(), rr_indexed_data, rr_graph_builder.rr_segments(), rr_graph_builder.rr_switch()};
179172
int num_arch_switches;
180173
t_arch_switch_inf* arch_switch_inf; // [0..(num_arch_switches-1)]
181174

vpr/src/device/rr_graph_builder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void RRGraphBuilder::add_node_to_all_locs(RRNodeId node) {
5959

6060
void RRGraphBuilder::clear() {
6161
node_lookup_.clear();
62+
rr_segments_.clear();
63+
rr_switch_inf_.clear();
6264
}
6365

6466
void RRGraphBuilder::reorder_nodes(e_rr_node_reorder_algorithm reorder_rr_graph_nodes_algorithm,

vpr/src/device/rr_graph_builder.h

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,47 @@ class RRGraphBuilder {
4040
t_rr_graph_storage& node_storage();
4141
/** @brief Return a writable object for update the fast look-up of rr_node */
4242
RRSpatialLookup& node_lookup();
43+
44+
/** @brief Add a rr_segment to the routing resource graph. Return an valid id if successful.
45+
* - Each rr_segment contains the detailed information of a routing track, which is denoted by a node in CHANX or CHANY type.
46+
* - It is frequently used by client functions in timing and routability prediction.
47+
*/
48+
inline RRSegmentId add_rr_segment(const t_segment_inf& segment_info) {
49+
//Allocate an ID
50+
RRSegmentId segment_id = RRSegmentId(segment_ids_.size());
51+
segment_ids_.push_back(segment_id);
52+
53+
rr_segments_.push_back(segment_info);
54+
55+
return segment_id;
56+
}
57+
/** TODO @brief Return a writable list of all the rr_segments
58+
* .. warning:: It is not recommended to use this API unless you have to. The API may be deprecated later, and future APIs will designed to return a specific data from the rr_segments.
59+
*/
60+
inline vtr::vector<RRSegmentId, t_segment_inf>& rr_segments() {
61+
return rr_segments_;
62+
}
63+
64+
/** @brief Add a rr_switch to the routing resource graph. Return an valid id if successful.
65+
* - Each rr_switch contains the detailed information of a routing switch interconnecting two routing resource nodes.
66+
* - It is frequently used by client functions in timing prediction.
67+
*/
68+
inline RRSwitchId add_rr_switch(const t_rr_switch_inf& switch_info) {
69+
//Allocate an ID
70+
RRSwitchId switch_id = RRSwitchId(switch_ids_.size());
71+
switch_ids_.push_back(switch_id);
72+
73+
rr_switch_inf_.push_back(switch_info);
74+
75+
return switch_id;
76+
}
77+
/** TODO @brief Return a writable list of all the rr_switches
78+
* .. warning:: It is not recommended to use this API unless you have to. The API may be deprecated later, and future APIs will designed to return a specific data from the rr_switches.
79+
*/
80+
inline vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switch() {
81+
return rr_switch_inf_;
82+
}
83+
4384
/** @brief Set the type of a node with a given valid id */
4485
inline void set_node_type(RRNodeId id, t_rr_type type) {
4586
node_storage_.set_node_type(id, type);
@@ -185,15 +226,29 @@ class RRGraphBuilder {
185226
return node_storage_.count_rr_switches(num_arch_switches, arch_switch_inf, arch_switch_fanins);
186227
}
187228

188-
/** @brief This function reserve storage for RR nodes. */
229+
/** @brief Reserve the lists of nodes, edges, switches etc. to be memory efficient.
230+
* This function is mainly used to reserve memory space inside RRGraph,
231+
* when adding a large number of nodes/edge/switches/segments,
232+
* in order to avoid memory fragements */
189233
inline void reserve_nodes(size_t size) {
190234
node_storage_.reserve(size);
191235
}
192-
236+
inline void reserve_segments(size_t num_segments) {
237+
this->segment_ids_.reserve(num_segments);
238+
this->rr_segments_.reserve(num_segments);
239+
}
240+
inline void reserve_switches(size_t num_switches) {
241+
this->switch_ids_.reserve(num_switches);
242+
this->rr_switch_inf_.reserve(num_switches);
243+
}
193244
/** @brief This function resize node storage to accomidate size RR nodes. */
194245
inline void resize_nodes(size_t size) {
195246
node_storage_.resize(size);
196247
}
248+
/** @brief This function resize rr_switch to accomidate size RR Switch. */
249+
inline void resize_switches(size_t size) {
250+
rr_switch_inf_.resize(size);
251+
}
197252

198253
/** brief Validate that edge data is partitioned correctly
199254
* @note This function is used to validate the correctness of the routing resource graph in terms
@@ -235,6 +290,20 @@ class RRGraphBuilder {
235290
/* Fast look-up for rr nodes */
236291
RRSpatialLookup node_lookup_;
237292

293+
/** Wire segment types in RR graph
294+
* - Each rr_segment contains the detailed information of a routing track, which is denoted by a node in CHANX or CHANY type.
295+
* - We use a fly-weight data structure here, in the same philosophy as the rr_indexed_data. See detailed explanation in the t_segment_inf data structure
296+
*/
297+
vtr::vector<RRSegmentId, t_segment_inf> rr_segments_; /* detailed information about the segments, which are used in the RRGraph */
298+
vtr::vector<RRSegmentId, RRSegmentId> segment_ids_; /* unique identifiers for routing segments which are used in the RRGraph */
299+
/* Autogenerated in build_rr_graph based on switch fan-in.
300+
* - Each rr_switch contains the detailed information of a routing switch interconnecting two routing resource nodes.
301+
* - We use a fly-weight data structure here, in the same philosophy as the rr_indexed_data. See detailed explanation in the t_rr_switch_inf data structure
302+
*/
303+
vtr::vector<RRSwitchId, RRSwitchId> switch_ids_;
304+
/* Detailed information about the switches, which are used in the RRGraph */
305+
vtr::vector<RRSwitchId, t_rr_switch_inf> rr_switch_inf_;
306+
238307
/* Metadata is an extra data on rr-nodes and edges, respectively, that is not used by vpr
239308
* but simply passed through the flow so that it can be used by downstream tools.
240309
* The main (perhaps only) current use of this metadata is the fasm tool of symbiflow,

vpr/src/device/rr_graph_view.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,15 @@ class RRGraphView {
379379
inline const t_segment_inf& rr_segments(RRSegmentId seg_id) const {
380380
return rr_segments_[seg_id];
381381
}
382+
/** @brief Return the number of rr_segments in the routing resource graph */
383+
inline size_t num_rr_segments() const {
384+
return rr_segments_.size();
385+
}
386+
/** @brief Return a read-only list of rr_segments for queries from client functions */
387+
inline const vtr::vector<RRSegmentId, t_segment_inf>& rr_segments() const {
388+
return rr_segments_;
389+
}
390+
382391
/** @brief Return the switch information that is categorized in the rr_switch_inf with a given id
383392
* rr_switch_inf is created to minimize memory footprint of RRGraph classs
384393
* While the RRG could contain millions (even much larger) of edges, there are only
@@ -397,6 +406,14 @@ class RRGraphView {
397406
inline const t_rr_switch_inf& rr_switch_inf(RRSwitchId switch_id) const {
398407
return rr_switch_inf_[switch_id];
399408
}
409+
/** @brief Return the number of rr_segments in the routing resource graph */
410+
inline size_t num_rr_switches() const {
411+
return rr_switch_inf_.size();
412+
}
413+
/** @brief Return the rr_switch_inf_ structure for queries from client functions */
414+
inline const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switch() const {
415+
return rr_switch_inf_;
416+
}
400417

401418
/** @brief Return the fast look-up data structure for queries from client functions */
402419
const RRSpatialLookup& node_lookup() const {

vpr/src/power/power_sizing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static double power_count_transistors_switchbox() {
379379

380380
auto& device_ctx = g_vpr_ctx.device();
381381
const auto& rr_graph = device_ctx.rr_graph;
382-
for (size_t seg_idx = 0; seg_idx < device_ctx.rr_segments.size(); seg_idx++) {
382+
for (size_t seg_idx = 0; seg_idx < rr_graph.num_rr_segments(); seg_idx++) {
383383
/* In each switchbox, the different types of segments occur with relative freqencies.
384384
* Thus the total number of wires of each segment type is (#tracks * freq * 2).
385385
* The (x2) factor accounts for vertical and horizontal tracks.

vpr/src/route/check_route.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void check_route(enum e_route_type route_type, e_check_route_option check_route_
5656
auto& cluster_ctx = g_vpr_ctx.clustering();
5757
auto& route_ctx = g_vpr_ctx.routing();
5858

59-
const int num_switches = device_ctx.rr_switch_inf.size();
59+
const int num_switches = rr_graph.num_rr_switches();
6060

6161
VTR_LOG("\n");
6262
VTR_LOG("Checking to ensure routing is legal...\n");

vpr/src/route/check_rr_graph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void check_rr_graph(const t_graph_type graph_type,
5252

5353
auto total_edges_to_node = std::vector<int>(device_ctx.rr_nodes.size());
5454
auto switch_types_from_current_to_node = std::vector<unsigned char>(device_ctx.rr_nodes.size());
55-
const int num_rr_switches = device_ctx.rr_switch_inf.size();
55+
const int num_rr_switches = rr_graph.num_rr_switches();
5656

5757
std::vector<std::pair<int, int>> edges;
5858

vpr/src/route/route_timing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ bool try_timing_driven_route_tmpl(const t_router_opts& router_opts,
342342
device_ctx.rr_nodes,
343343
&device_ctx.rr_graph,
344344
device_ctx.rr_rc_data,
345-
device_ctx.rr_switch_inf,
345+
device_ctx.rr_graph.rr_switch(),
346346
route_ctx.rr_node_route_inf);
347347

348348
// Make sure template type ConnectionRouter is a ConnectionRouterInterface.

vpr/src/route/router_delay_profiling.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RouterDelayProfiler::RouterDelayProfiler(
1919
g_vpr_ctx.device().rr_nodes,
2020
&g_vpr_ctx.device().rr_graph,
2121
g_vpr_ctx.device().rr_rc_data,
22-
g_vpr_ctx.device().rr_switch_inf,
22+
g_vpr_ctx.device().rr_graph.rr_switch(),
2323
g_vpr_ctx.mutable_routing().rr_node_route_inf) {}
2424

2525
bool RouterDelayProfiler::calculate_delay(int source_node, int sink_node, const t_router_opts& router_opts, float* net_delay) {
@@ -124,7 +124,7 @@ std::vector<float> calculate_all_path_delays_from_rr_node(int src_rr_node, const
124124
device_ctx.rr_nodes,
125125
&g_vpr_ctx.device().rr_graph,
126126
device_ctx.rr_rc_data,
127-
device_ctx.rr_switch_inf,
127+
device_ctx.rr_graph.rr_switch(),
128128
routing_ctx.rr_node_route_inf);
129129
RouterStats router_stats;
130130

0 commit comments

Comments
 (0)