Skip to content

Commit 9a5aa94

Browse files
helper functions for add_edges_opin_chanz_per_side()
1 parent 2d833bf commit 9a5aa94

File tree

1 file changed

+83
-29
lines changed

1 file changed

+83
-29
lines changed

vpr/src/route/rr_graph_generation/rr_graph_sg.cpp

Lines changed: 83 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,72 @@
77
#include "globals.h"
88
#include "get_parallel_segs.h"
99

10+
//
11+
// Static Function Declarations
12+
//
13+
14+
/// @brief Collect CHANZ nodes (and their switches) for one switch-block and segment index.
15+
static void collect_chanz_nodes_for_seg(const RRSpatialLookup& node_lookup,
16+
const vtr::NdMatrix<std::vector<t_bottleneck_link>, 2>& interdie_3d_links,
17+
const t_physical_tile_loc& sb_loc,
18+
int layer,
19+
int seg_index,
20+
std::vector<std::pair<RRNodeId, short>>& out_nodes);
21+
22+
/// @brief Pick the next CHANZ node from the less-used side and update Fc_zofs.
23+
static std::pair<RRNodeId, short> next_chanz_node_for_seg(const std::array<t_physical_tile_loc, 2>& sb_locs,
24+
int seg_index,
25+
vtr::NdMatrix<int, 3>& Fc_zofs,
26+
std::vector<std::pair<RRNodeId, short>>& nodes0,
27+
std::vector<std::pair<RRNodeId, short>>& nodes1);
28+
29+
//
30+
// Static Function Definitions
31+
//
32+
33+
static void collect_chanz_nodes_for_seg(const RRSpatialLookup& node_lookup,
34+
const vtr::NdMatrix<std::vector<t_bottleneck_link>, 2>& interdie_3d_links,
35+
const t_physical_tile_loc& sb_loc,
36+
int layer,
37+
int seg_index,
38+
std::vector<std::pair<RRNodeId, short>>& out_nodes) {
39+
out_nodes.clear();
40+
41+
const std::vector<t_bottleneck_link>& links_at_sb = interdie_3d_links[sb_loc.x][sb_loc.y];
42+
for (size_t track_num = 0; track_num < links_at_sb.size(); ++track_num) {
43+
const t_bottleneck_link& bottleneck_link = links_at_sb[track_num];
44+
if (bottleneck_link.parallel_segment_index == seg_index && bottleneck_link.gather_loc.layer_num == layer) {
45+
RRNodeId node_id = node_lookup.find_node(sb_loc.layer_num,
46+
sb_loc.x,
47+
sb_loc.y,
48+
e_rr_type::CHANZ,
49+
track_num);
50+
out_nodes.emplace_back(node_id, bottleneck_link.arch_wire_switch);
51+
}
52+
}
53+
}
54+
55+
static std::pair<RRNodeId, short> next_chanz_node_for_seg(const std::array<t_physical_tile_loc, 2>& sb_locs,
56+
int seg_index,
57+
vtr::NdMatrix<int, 3>& Fc_zofs,
58+
std::vector<std::pair<RRNodeId, short>>& nodes0,
59+
std::vector<std::pair<RRNodeId, short>>& nodes1) {
60+
61+
VTR_ASSERT_SAFE(!nodes0.empty());
62+
VTR_ASSERT_SAFE(!nodes1.empty());
63+
64+
int& offset0 = Fc_zofs[sb_locs[0].x][sb_locs[0].y][seg_index];
65+
int& offset1 = Fc_zofs[sb_locs[1].x][sb_locs[1].y][seg_index];
66+
67+
if (offset0 < offset1) {
68+
const int idx = offset0++;
69+
return nodes0[idx % nodes0.size()];
70+
} else {
71+
const int idx = offset1++;
72+
return nodes1[idx % nodes1.size()];
73+
}
74+
}
75+
1076
void add_inter_die_3d_edges(RRGraphBuilder& rr_graph_builder,
1177
int x_coord,
1278
int y_coord,
@@ -18,27 +84,36 @@ void add_inter_die_3d_edges(RRGraphBuilder& rr_graph_builder,
1884
const RRSpatialLookup& node_lookup = rr_graph_builder.node_lookup();
1985
const int num_tracks = interdie_3d_links.size();
2086

87+
// Process each inter-die 3D link / CHANZ track at this switch block
2188
for (int track = 0; track < num_tracks; track++) {
2289
const t_bottleneck_link& link = interdie_3d_links[track];
90+
91+
// Sanity check: this link must be anchored at the given (x_coord, y_coord)
2392
VTR_ASSERT_SAFE(x_coord == link.gather_loc.x && y_coord == link.gather_loc.y);
2493
VTR_ASSERT_SAFE(x_coord == link.scatter_loc.x && y_coord == link.scatter_loc.y);
2594

95+
// Find the CHANZ node that represents this 3D link (track index = ptc)
2696
RRNodeId chanz_node = node_lookup.find_node(0, x_coord, y_coord, e_rr_type::CHANZ, track);
2797

98+
// 1) Add edges from all gather (fanin) wires to the CHANZ node
2899
for (const t_sg_candidate& gather_wire : link.gather_fanin_connections) {
100+
// Find the source CHAN RR node
29101
const t_physical_tile_loc& chan_loc = gather_wire.chan_loc.location;
30102
e_rr_type chan_type = gather_wire.chan_loc.chan_type;
31103
RRNodeId gather_node = node_lookup.find_node(chan_loc.layer_num, chan_loc.x, chan_loc.y, chan_type, gather_wire.wire_switchpoint.wire);
32104

33105
interdie_3d_rr_edges_to_create.emplace_back(gather_node, chanz_node, link.arch_wire_switch, false);
34106
}
35107

108+
// 2) Add edges from the CHANZ node to all scatter (fanout) wires
36109
for (const t_sg_candidate& scatter_wire : link.scatter_fanout_connections) {
110+
// Find the sink CHAN RR node
37111
const t_physical_tile_loc& chan_loc = scatter_wire.chan_loc.location;
38112
e_rr_type chan_type = scatter_wire.chan_loc.chan_type;
39113
const t_chan_details& chan_details = (chan_type == e_rr_type::CHANX) ? chan_details_x : chan_details_y;
40114
RRNodeId scatter_node = node_lookup.find_node(chan_loc.layer_num, chan_loc.x, chan_loc.y, chan_type, scatter_wire.wire_switchpoint.wire);
41115

116+
// Look up the switch used to drive this track
42117
int switch_index = chan_details[chan_loc.x][chan_loc.y][scatter_wire.wire_switchpoint.wire].arch_wire_switch();
43118
interdie_3d_rr_edges_to_create.emplace_back(chanz_node, scatter_node, switch_index, false);
44119
}
@@ -164,45 +239,24 @@ void add_edges_opin_chanz_per_side(const RRGraphView& rr_graph,
164239
continue;
165240
}
166241

167-
selected_chanz_nodes0.clear();
168-
for (size_t track_num = 0; track_num < interdie_3d_links[adjacent_sb_loc[0].x][adjacent_sb_loc[0].y].size(); track_num++) {
169-
const t_bottleneck_link& bottleneck_link = interdie_3d_links[adjacent_sb_loc[0].x][adjacent_sb_loc[0].y][track_num];
170-
if (bottleneck_link.parallel_segment_index == seg_index && bottleneck_link.gather_loc.layer_num == layer) {
171-
RRNodeId node_id = node_lookup.find_node(adjacent_sb_loc[0].layer_num, adjacent_sb_loc[0].x, adjacent_sb_loc[0].y, e_rr_type::CHANZ, track_num);
172-
selected_chanz_nodes0.emplace_back(node_id, bottleneck_link.arch_wire_switch);
173-
}
174-
}
242+
// Collect candidate CHANZ nodes on both adjacent switch blocks
243+
collect_chanz_nodes_for_seg(node_lookup, interdie_3d_links, adjacent_sb_loc[0],
244+
layer, seg_index, selected_chanz_nodes0);
175245

176-
selected_chanz_nodes1.clear();
177-
for (size_t track_num = 0; track_num < interdie_3d_links[adjacent_sb_loc[1].x][adjacent_sb_loc[1].y].size(); track_num++) {
178-
const t_bottleneck_link& bottleneck_link = interdie_3d_links[adjacent_sb_loc[1].x][adjacent_sb_loc[1].y][track_num];
179-
if (bottleneck_link.parallel_segment_index == seg_index && bottleneck_link.gather_loc.layer_num == layer) {
180-
RRNodeId node_id = node_lookup.find_node(adjacent_sb_loc[1].layer_num, adjacent_sb_loc[1].x, adjacent_sb_loc[1].y, e_rr_type::CHANZ, track_num);
181-
selected_chanz_nodes1.emplace_back(node_id, bottleneck_link.arch_wire_switch);
182-
}
183-
}
246+
collect_chanz_nodes_for_seg(node_lookup, interdie_3d_links, adjacent_sb_loc[1],
247+
layer, seg_index, selected_chanz_nodes1);
184248

185249
for (RRNodeId opin_node_id : opin_nodes) {
186250
int pin_number = rr_graph.node_pin_num(opin_node_id);
187251
int fc = Fc_out[type->index][pin_number][iseg];
188252

189253
for (int i = 0; i < fc; i++) {
190254

191-
RRNodeId chanz_node_id;
192-
short switch_id;
193-
if (Fc_zofs[adjacent_sb_loc[0].x][adjacent_sb_loc[0].y][seg_index] < Fc_zofs[adjacent_sb_loc[1].x][adjacent_sb_loc[1].y][seg_index]) {
194-
int chanz_idx = Fc_zofs[adjacent_sb_loc[0].x][adjacent_sb_loc[0].y][seg_index];
195-
chanz_node_id = selected_chanz_nodes0[chanz_idx % selected_chanz_nodes0.size()].first;
196-
switch_id = selected_chanz_nodes0[chanz_idx % selected_chanz_nodes0.size()].second;
197-
Fc_zofs[adjacent_sb_loc[0].x][adjacent_sb_loc[0].y][seg_index]++;
198-
} else {
199-
int chanz_idx = Fc_zofs[adjacent_sb_loc[1].x][adjacent_sb_loc[1].y][seg_index];
200-
chanz_node_id = selected_chanz_nodes1[chanz_idx % selected_chanz_nodes1.size()].first;
201-
switch_id = selected_chanz_nodes1[chanz_idx % selected_chanz_nodes1.size()].second;
202-
Fc_zofs[adjacent_sb_loc[1].x][adjacent_sb_loc[1].y][seg_index]++;
203-
}
255+
auto [chanz_node_id, switch_id] = next_chanz_node_for_seg(adjacent_sb_loc, seg_index, Fc_zofs,
256+
selected_chanz_nodes0, selected_chanz_nodes1);
204257

205258
rr_edges_to_create.emplace_back(opin_node_id, chanz_node_id, switch_id, false);
259+
206260
}
207261
}
208262
}

0 commit comments

Comments
 (0)