Skip to content

Commit 7b78e57

Browse files
committed
[core] add methods to identify opins for connection blocks
1 parent 26bac8c commit 7b78e57

File tree

2 files changed

+111
-2
lines changed

2 files changed

+111
-2
lines changed

vpr/src/tileable_rr_graph/rr_gsb.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ RRGSB::RRGSB() {
2727
ipin_node_.clear();
2828

2929
opin_node_.clear();
30+
cb_opin_node_.clear();
3031
}
3132

3233
/************************************************************************
@@ -97,6 +98,31 @@ std::vector<enum e_side> RRGSB::get_cb_ipin_sides(const t_rr_type& cb_type) cons
9798
return ipin_sides;
9899
}
99100

101+
/* Get the sides of ipin_nodes belong to the cb */
102+
std::vector<enum e_side> RRGSB::get_cb_opin_sides(const t_rr_type& cb_type) const {
103+
VTR_ASSERT(validate_cb_type(cb_type));
104+
105+
std::vector<enum e_side> opin_sides;
106+
107+
/* Make sure a clean start */
108+
opin_sides.clear();
109+
110+
switch (cb_type) {
111+
case CHANX:
112+
case CHANY:
113+
opin_sides.push_back(TOP);
114+
opin_sides.push_back(RIGHT);
115+
opin_sides.push_back(BOTTOM);
116+
opin_sides.push_back(LEFT);
117+
break;
118+
default:
119+
VTR_LOG("Invalid type of connection block!\n");
120+
exit(1);
121+
}
122+
123+
return opin_sides;
124+
}
125+
100126
/* Get the direction of a rr_node at a given side and track_id */
101127
enum PORTS RRGSB::get_chan_node_direction(const e_side& side, const size_t& track_id) const {
102128
SideManager side_manager(side);
@@ -257,6 +283,29 @@ RRNodeId RRGSB::get_opin_node(const e_side& side, const size_t& node_id) const {
257283
return opin_node_[side_manager.to_size_t()][node_id];
258284
}
259285

286+
/* Get the number of OPIN rr_nodes on a side */
287+
size_t RRGSB::get_num_cb_opin_nodes(const t_rr_type& cb_type, const e_side& side) const {
288+
SideManager side_manager(side);
289+
VTR_ASSERT(side_manager.validate());
290+
size_t icb_type = get_cb_opin_type_id(cb_type);
291+
return cb_opin_node_[icb_type][side_manager.to_size_t()].size();
292+
}
293+
294+
/* get a opin_node at a given side and track_id */
295+
RRNodeId RRGSB::get_cb_opin_node(const t_rr_type& cb_type, const e_side& side, const size_t& node_id) const {
296+
SideManager side_manager(side);
297+
VTR_ASSERT(side_manager.validate());
298+
299+
/* Ensure the side is valid in the context of this switch block */
300+
VTR_ASSERT(validate_side(side));
301+
302+
/* Ensure the track is valid in the context of this switch block at a specific side */
303+
VTR_ASSERT(validate_cb_opin_node_id(cb_type, side, node_id));
304+
305+
size_t icb_type = get_cb_opin_type_id(cb_type);
306+
return cb_opin_node_[icb_type][side_manager.to_size_t()][node_id];
307+
}
308+
260309
/* Get the node index of a routing track of a connection block, return -1 if not found */
261310
int RRGSB::get_cb_chan_node_index(const t_rr_type& cb_type, const RRNodeId& node) const {
262311
enum e_side chan_side = get_cb_chan_side(cb_type);
@@ -921,6 +970,37 @@ void RRGSB::sort_ipin_node_in_edges(const RRGraphView& rr_graph) {
921970
}
922971
}
923972

973+
void RRGSB::build_cb_opin_nodes(const RRGraphView& rr_graph) {
974+
for (t_rr_type cb_type : {CHANX, CHANY}) {
975+
size_t icb_type = cb_type == CHANX ? 0 : 1;
976+
std::vector<enum e_side> cb_opin_sides = rr_gsb.get_cb_ipin_sides(cb_type);
977+
for (size_t iside = 0; iside < cb_ipin_sides.size(); ++iside) {
978+
enum e_side cb_ipin_side = cb_ipin_sides[iside];
979+
for (size_t inode = 0; inode < rr_gsb.get_num_ipin_nodes(cb_ipin_side);
980+
++inode) {
981+
std::vector<RREdgeId> driver_rr_edges =
982+
get_ipin_node_in_edges(rr_graph, cb_ipin_side, inode);
983+
for (const RREdgeId curr_edge : driver_rr_edges) {
984+
RRNodeId cand_node = rr_graph.edge_src_node(curr_edge);
985+
if (OPIN != rr_graph.node_type(cand_node)) {
986+
continue;
987+
}
988+
enum e_side cb_opin_side = NUM_SIDES;
989+
int cb_opin_index = -1;
990+
rr_gsb.get_node_side_and_index(rr_graph, cand_node, IN_PORT, cb_opin_side,
991+
cb_opin_index);
992+
VTR_ASSERT((-1 != cb_opin_index) && (NUM_SIDES != cb_opin_side));
993+
994+
if (cb_opin_node_[icb_type][size_t(cb_opin_side)].end() ==
995+
std::find(cb_opin_node_[icb_type][size_t(cb_opin_side)].begin(), cb_opin_node_[icb_type][size_t(cb_opin_side)].end(), cand_node)) {
996+
cb_opin_node_[icb_type][size_t(cb_opin_side)] = cand_node;
997+
}
998+
}
999+
}
1000+
}
1001+
}
1002+
}
1003+
9241004
/************************************************************************
9251005
* Public Mutators: clean-up functions
9261006
***********************************************************************/
@@ -1031,6 +1111,15 @@ bool RRGSB::validate_opin_node_id(const e_side& side, const size_t& node_id) con
10311111
return (node_id < opin_node_[size_t(side)].size());
10321112
}
10331113

1114+
/* Check the opin_node_id is valid for opin_node_ and opin_node_grid_side_ */
1115+
bool RRGSB::validate_cb_opin_node_id(const t_rr_type& cb_type, const e_side& side, const size_t& node_id) const {
1116+
if (false == validate_side(side)) {
1117+
return false;
1118+
}
1119+
size_t icb_type = get_cb_opin_type_id(cb_type);
1120+
return (node_id < cb_opin_node_[icb_type][size_t(side)].size());
1121+
}
1122+
10341123
/* Check the ipin_node_id is valid for opin_node_ and opin_node_grid_side_ */
10351124
bool RRGSB::validate_ipin_node_id(const e_side& side, const size_t& node_id) const {
10361125
if (false == validate_side(side)) {
@@ -1042,3 +1131,9 @@ bool RRGSB::validate_ipin_node_id(const e_side& side, const size_t& node_id) con
10421131
bool RRGSB::validate_cb_type(const t_rr_type& cb_type) const {
10431132
return ((CHANX == cb_type) || (CHANY == cb_type));
10441133
}
1134+
1135+
size_t RRGSB::get_cb_opin_type_id(const t_rr_type& cb_type) const {
1136+
VTR_ASSERT(validate_cb_type(cb_type));
1137+
return cb_type == CHANX ? 0 : 1;
1138+
}
1139+

vpr/src/tileable_rr_graph/rr_gsb.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class RRGSB {
7272

7373
/* Get the sides of CB ipins in the array */
7474
std::vector<enum e_side> get_cb_ipin_sides(const t_rr_type& cb_type) const;
75+
/* Get the sides of CB opins in the array, OPINs can only be at the same sides of IPINs. Differently, they are inputs to a connection block */
76+
std::vector<enum e_side> get_cb_opin_sides(const t_rr_type& cb_type) const;
7577

7678
/* Get the direction of a rr_node at a given side and track_id */
7779
enum PORTS get_chan_node_direction(const e_side& side, const size_t& track_id) const;
@@ -107,9 +109,13 @@ class RRGSB {
107109

108110
/* Get the number of OPIN rr_nodes on a side */
109111
size_t get_num_opin_nodes(const e_side& side) const;
112+
/* Get the number of OPIN rr_nodes on a side of a connection block */
113+
size_t get_num_cb_opin_nodes(const t_rr_type& cb_type, const e_side& side) const;
110114

111115
/* get a rr_node at a given side and track_id */
112-
RRNodeId get_opin_node(const e_side& side, const size_t& node_id) const;
116+
RRNodeId get_opin_node(const t_rr_type& cb_type, const e_side& side, const size_t& node_id) const;
117+
/* get a rr_node at a given side and track_id for a connection block */
118+
RRNodeId get_cb_opin_node(const t_rr_type& cb_type, const e_side& side, const size_t& node_id) const;
113119

114120
int get_cb_chan_node_index(const t_rr_type& cb_type, const RRNodeId& node) const;
115121

@@ -184,6 +190,8 @@ class RRGSB {
184190
void sort_chan_node_in_edges(const RRGraphView& rr_graph);
185191
/* Sort all the incoming edges for input pin rr_node */
186192
void sort_ipin_node_in_edges(const RRGraphView& rr_graph);
193+
/* Build the lists of opin node for connection blocks. This is required after adding all the nodes */
194+
void build_cb_opin_nodes(const RRGraphView& rr_graph);
187195

188196
public: /* Mutators: cleaners */
189197
void clear();
@@ -210,17 +218,18 @@ class RRGSB {
210218
void sort_ipin_node_in_edges(const RRGraphView& rr_graph,
211219
const e_side& chan_side,
212220
const size_t& ipin_id);
213-
214221
private: /* internal functions */
215222
size_t get_track_id_first_short_connection(const RRGraphView& rr_graph, const e_side& node_side) const;
216223

217224
private: /* internal validators */
218225
bool validate_num_sides() const;
219226
bool validate_side(const e_side& side) const;
220227
bool validate_track_id(const e_side& side, const size_t& track_id) const;
228+
bool validate_cb_opin_node_id(const t_rr_type& cb_type, const e_side& side, const size_t& node_id) const;
221229
bool validate_opin_node_id(const e_side& side, const size_t& node_id) const;
222230
bool validate_ipin_node_id(const e_side& side, const size_t& node_id) const;
223231
bool validate_cb_type(const t_rr_type& cb_type) const;
232+
size_t get_cb_opin_type_id(const t_rr_type& cb_type) const;
224233

225234
private: /* Internal Data */
226235
/* Coordinator */
@@ -255,6 +264,11 @@ class RRGSB {
255264

256265
/* Logic Block Outputs data */
257266
std::vector<std::vector<RRNodeId>> opin_node_;
267+
/* Logic block outputs which directly drive IPINs in connection block,
268+
* CBX -> array[0], CBY -> array[1]
269+
* Each CB may have OPINs from all sides
270+
*/
271+
std::array<std::array<std::vector<RRNodeId>, NUM_SIDES>, 2> cb_opin_node_;
258272
};
259273

260274
#endif

0 commit comments

Comments
 (0)