Skip to content

Commit b7cba40

Browse files
committed
WIP: Allow source node query in rr graph view.
1 parent efa5787 commit b7cba40

File tree

2 files changed

+52
-34
lines changed

2 files changed

+52
-34
lines changed

libs/librrgraph/src/base/rr_graph_storage.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ struct alignas(16) t_rr_node_data {
6363
t_rr_type type_ = NUM_RR_TYPES;
6464

6565
/* The character is a hex number which is a 4-bit truth table for node sides
66-
* The 4-bits in serial represent 4 sides on which a node could appear
67-
* It follows a fixed sequence, which is (LEFT, BOTTOM, RIGHT, TOP) whose indices are (3, 2, 1, 0)
66+
* The 4-bits in serial represent 4 sides on which a node could appear
67+
* It follows a fixed sequence, which is (LEFT, BOTTOM, RIGHT, TOP) whose indices are (3, 2, 1, 0)
6868
* - When a node appears on a given side, it is set to "1"
6969
* - When a node does not appear on a given side, it is set to "0"
7070
* For example,
71-
* - '1' means '0001' in hex number, which means the node appears on TOP
72-
* - 'A' means '1100' in hex number, which means the node appears on LEFT and BOTTOM sides,
71+
* - '1' means '0001' in hex number, which means the node appears on TOP
72+
* - 'A' means '1100' in hex number, which means the node appears on LEFT and BOTTOM sides,
7373
*/
7474
union {
7575
Direction direction; //Valid only for CHANX/CHANY
@@ -252,6 +252,7 @@ class t_rr_graph_storage {
252252
* - num_non_configurable_edges(RRNodeId)
253253
* - edge_id(RRNodeId, t_edge_size)
254254
* - edge_sink_node(RRNodeId, t_edge_size)
255+
* - edge_source_node(RRNodeId, t_edge_size)
255256
* - edge_switch(RRNodeId, t_edge_size)
256257
*
257258
* Only call these methods after partition_edges has been invoked. */
@@ -316,6 +317,11 @@ class t_rr_graph_storage {
316317
return edge_dest_node_[edge];
317318
}
318319

320+
// Get the source node for the specified edge.
321+
RRNodeId edge_source_node(const RREdgeId& edge) const {
322+
return edge_src_node_[edge];
323+
}
324+
319325
// Call the `apply` function with the edge id, source, and sink nodes of every edge.
320326
void for_each_edge(std::function<void(RREdgeId, RRNodeId, RRNodeId)> apply) const {
321327
for (size_t i = 0; i < edge_dest_node_.size(); i++) {
@@ -332,6 +338,11 @@ class t_rr_graph_storage {
332338
return edge_sink_node(edge_id(id, iedge));
333339
}
334340

341+
// Get the source node for the iedge'th edge from specified RRNodeId.
342+
RRNodeId edge_source_node(const RRNodeId& id, t_edge_size iedge) const {
343+
return edge_source_node(edge_id(id, iedge));
344+
}
345+
335346
// Get the switch used for the specified edge.
336347
short edge_switch(const RREdgeId& edge) const {
337348
return edge_switch_[edge];

libs/librrgraph/src/base/rr_graph_view.h

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
* - This avoids massive changes for each client on using the APIs
2626
* as each frame view provides adhoc APIs for each client
2727
*
28-
* TODO: more compact frame views will be created, e.g.,
28+
* TODO: more compact frame views will be created, e.g.,
2929
* - a mini frame view: contains only node and edges, representing the connectivity of the graph
30-
* - a geometry frame view: an extended mini frame view with node-level attributes,
30+
* - a geometry frame view: an extended mini frame view with node-level attributes,
3131
* in particular geometry information (type, x, y etc).
3232
*
3333
*/
@@ -45,29 +45,29 @@ class RRGraphView {
4545
const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switch_inf);
4646

4747
/* Disable copy constructors and copy assignment operator
48-
* This is to avoid accidental copy because it could be an expensive operation considering that the
48+
* This is to avoid accidental copy because it could be an expensive operation considering that the
4949
* memory footprint of the data structure could ~ Gb
50-
* Using the following syntax, we prohibit accidental 'pass-by-value' which can be immediately caught
50+
* Using the following syntax, we prohibit accidental 'pass-by-value' which can be immediately caught
5151
* by compiler
5252
*/
5353
RRGraphView(const RRGraphView&) = delete;
5454
void operator=(const RRGraphView&) = delete;
5555

5656
/* -- Accessors -- */
57-
/* TODO: The accessors may be turned into private later if they are replacable by 'questionin'
57+
/* TODO: The accessors may be turned into private later if they are replacable by 'questionin'
5858
* kind of accessors
5959
*/
6060
public:
6161
/* Aggregates: create range-based loops for nodes
62-
* To iterate over the nodes in a RRGraph,
63-
* using a range-based loop is suggested.
64-
* -----------------------------------------------------------------
65-
* Example: iterate over all the nodes
66-
* // Strongly suggest to use a read-only rr_graph object
67-
* const RRGraph& rr_graph;
68-
* for (const RRNodeId& node : rr_graph.nodes()) {
69-
* // Do something with each node
70-
* }
62+
* To iterate over the nodes in a RRGraph,
63+
* using a range-based loop is suggested.
64+
* -----------------------------------------------------------------
65+
* Example: iterate over all the nodes
66+
* // Strongly suggest to use a read-only rr_graph object
67+
* const RRGraph& rr_graph;
68+
* for (const RRNodeId& node : rr_graph.nodes()) {
69+
* // Do something with each node
70+
* }
7171
*/
7272
inline vtr::StrongIdRange<RRNodeId> nodes() const {
7373
return vtr::StrongIdRange<RRNodeId>(RRNodeId(0), RRNodeId(num_nodes()));
@@ -188,7 +188,7 @@ class RRGraphView {
188188
&& (node_xhigh(node) == -1) && (node_yhigh(node) == -1));
189189
}
190190

191-
/** @brief Check if two routing resource nodes are adjacent (must be a CHANX and a CHANY).
191+
/** @brief Check if two routing resource nodes are adjacent (must be a CHANX and a CHANY).
192192
* This function is used for error checking; it checks if two nodes are physically adjacent (could be connected) based on their geometry.
193193
* It does not check the routing edges to see if they are, in fact, possible to connect in the current routing graph.
194194
* This function is inlined for runtime optimization. */
@@ -203,7 +203,7 @@ class RRGraphView {
203203
return true;
204204
}
205205

206-
/** @brief Check if node is within bounding box.
206+
/** @brief Check if node is within bounding box.
207207
* To return true, the RRNode must be completely contained within the specified bounding box, with the edges of the bounding box being inclusive.
208208
*This function is inlined for runtime optimization. */
209209
inline bool node_is_inside_bounding_box(RRNodeId node, vtr::Rect<int> bounding_box) const {
@@ -307,6 +307,13 @@ class RRGraphView {
307307
return node_storage_.edge_sink_node(id, iedge);
308308
}
309309

310+
/** @brief Get the source node for the iedge'th edge from specified RRNodeId.
311+
* This method should generally not be used, and instead first_edge and
312+
* last_edge should be used.*/
313+
inline RRNodeId edge_source_node(RRNodeId id, t_edge_size iedge) const {
314+
return node_storage_.edge_source_node(id, iedge);
315+
}
316+
310317
/** @brief Detect if the edge is a configurable edge (controlled by a programmable routing multipler or a tri-state switch). */
311318
inline bool edge_is_configurable(RRNodeId id, t_edge_size iedge) const {
312319
return node_storage_.edge_is_configurable(id, iedge, rr_switch_inf_);
@@ -322,16 +329,16 @@ class RRGraphView {
322329
return node_storage_.num_non_configurable_edges(node, rr_switch_inf_);
323330
}
324331

325-
/** @brief A configurable edge represents a programmable switch between routing resources, which could be
332+
/** @brief A configurable edge represents a programmable switch between routing resources, which could be
326333
* a multiplexer
327334
* a tri-state buffer
328-
* a pass gate
335+
* a pass gate
329336
* This API gets ID range for configurable edges. This function is inlined for runtime optimization. */
330337
inline edge_idx_range configurable_edges(RRNodeId node) const {
331338
return vtr::make_range(edge_idx_iterator(0), edge_idx_iterator(node_storage_.num_edges(node) - num_non_configurable_edges(node)));
332339
}
333340

334-
/** @brief A non-configurable edge represents a hard-wired connection between routing resources, which could be
341+
/** @brief A non-configurable edge represents a hard-wired connection between routing resources, which could be
335342
* a non-configurable buffer that can not be turned off
336343
* a short metal connection that can not be turned off
337344
* This API gets ID range for non-configurable edges. This function is inlined for runtime optimization. */
@@ -357,26 +364,26 @@ class RRGraphView {
357364
return node_storage_.num_edges(node);
358365
}
359366

360-
/** @brief The ptc_num carries different meanings for different node types
361-
* (true in VPR RRG that is currently supported, may not be true in customized RRG)
362-
* CHANX or CHANY: the track id in routing channels
363-
* OPIN or IPIN: the index of pins in the logic block data structure
364-
* SOURCE and SINK: the class id of a pin (indicating logic equivalence of pins) in the logic block data structure
365-
* @note
366-
* This API is very powerful and developers should not use it unless it is necessary,
367-
* e.g the node type is unknown. If the node type is known, the more specific routines, `node_pin_num()`,
367+
/** @brief The ptc_num carries different meanings for different node types
368+
* (true in VPR RRG that is currently supported, may not be true in customized RRG)
369+
* CHANX or CHANY: the track id in routing channels
370+
* OPIN or IPIN: the index of pins in the logic block data structure
371+
* SOURCE and SINK: the class id of a pin (indicating logic equivalence of pins) in the logic block data structure
372+
* @note
373+
* This API is very powerful and developers should not use it unless it is necessary,
374+
* e.g the node type is unknown. If the node type is known, the more specific routines, `node_pin_num()`,
368375
* `node_track_num()`and `node_class_num()`, for different types of nodes should be used.*/
369376
inline short node_ptc_num(RRNodeId node) const {
370377
return node_storage_.node_ptc_num(node);
371378
}
372379

373-
/** @brief Get the pin num of a routing resource node. This is designed for logic blocks,
380+
/** @brief Get the pin num of a routing resource node. This is designed for logic blocks,
374381
* which are IPIN and OPIN nodes. This function is inlined for runtime optimization. */
375382
inline short node_pin_num(RRNodeId node) const {
376383
return node_storage_.node_pin_num(node);
377384
}
378385

379-
/** @brief Get the track num of a routing resource node. This is designed for routing tracks,
386+
/** @brief Get the track num of a routing resource node. This is designed for routing tracks,
380387
* which are CHANX and CHANY nodes. This function is inlined for runtime optimization. */
381388
inline short node_track_num(RRNodeId node) const {
382389
return node_storage_.node_track_num(node);
@@ -498,7 +505,7 @@ class RRGraphView {
498505
/* rr_indexed_data_ and rr_segments_ are needed to lookup the segment information in node_coordinate_to_string() */
499506
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data_;
500507

501-
/* RC data for nodes. This is a flyweight data */
508+
/* RC data for nodes. This is a flyweight data */
502509
const std::vector<t_rr_rc_data>& rr_rc_data_;
503510

504511
/* Segment info for rr nodes */

0 commit comments

Comments
 (0)