Skip to content

Commit 0dcb2fa

Browse files
add add_edges_opin_chanz_per_side()
1 parent 78afdc2 commit 0dcb2fa

File tree

3 files changed

+151
-26
lines changed

3 files changed

+151
-26
lines changed

vpr/src/route/rr_graph_generation/rr_graph.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,8 @@ static std::function<void(t_chan_width*)> alloc_and_load_rr_graph(RRGraphBuilder
14711471
vtr::NdMatrix<int, 3> Fc_xofs({grid.height() - 1, grid.width() - 1, num_seg_types_x}, 0);
14721472
vtr::NdMatrix<int, 3> Fc_yofs({grid.width() - 1, grid.height() - 1, num_seg_types_y}, 0);
14731473

1474+
vtr::NdMatrix<int, 3> Fc_zofs({grid.width(), grid.height(), num_seg_types_y}, 0);
1475+
14741476
// Build opins
14751477
int rr_edges_before_directs = 0;
14761478
for (size_t layer = 0; layer < grid.get_num_layers(); layer++) {
@@ -1495,15 +1497,17 @@ static std::function<void(t_chan_width*)> alloc_and_load_rr_graph(RRGraphBuilder
14951497
*Fc_clipped = true;
14961498
}
14971499
}
1498-
}
14991500

1500-
add_edges_opin_chanz(rr_graph,
1501-
layer, i, j,
1502-
Fc_out,
1503-
seg_index_map,
1504-
num_seg_types,
1505-
rr_edges_to_create,
1506-
interdie_3d_links[i][j]);
1501+
add_edges_opin_chanz_per_side(rr_graph,
1502+
layer, i, j,
1503+
side,
1504+
Fc_out,
1505+
seg_index_map,
1506+
num_seg_types,
1507+
Fc_zofs,
1508+
rr_edges_to_create,
1509+
interdie_3d_links);
1510+
}
15071511

15081512
// Create the actual OPIN->CHANX/CHANY edges
15091513
uniquify_edges(rr_edges_to_create);
@@ -1512,6 +1516,8 @@ static std::function<void(t_chan_width*)> alloc_and_load_rr_graph(RRGraphBuilder
15121516
rr_edges_to_create.clear();
15131517
}
15141518
}
1519+
1520+
Fc_zofs.fill(0);
15151521
}
15161522

15171523
VTR_LOGV(route_verbosity > 1, "OPIN->CHANX/CHANY edge count before creating direct connections: %d\n", rr_edges_before_directs);

vpr/src/route/rr_graph_generation/rr_graph_sg.cpp

Lines changed: 116 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,122 @@ void build_inter_die_3d_rr_chan(RRGraphBuilder& rr_graph_builder,
100100
}
101101
}
102102

103-
void add_edges_opin_chanz(const RRGraphView& rr_graph,
104-
int layer,
105-
int x,
106-
int y,
107-
const std::vector<vtr::Matrix<int>>& Fc_out,
108-
const t_unified_to_parallel_seg_index& seg_index_map,
109-
int num_seg_types,
110-
t_rr_edge_info_set& rr_edges_to_create,
111-
const std::vector<t_bottleneck_link>& interdie_3d_links) {
103+
void add_edges_opin_chanz_per_side(const RRGraphView& rr_graph,
104+
int layer,
105+
int x,
106+
int y,
107+
e_side side,
108+
const std::vector<vtr::Matrix<int>>& Fc_out,
109+
const t_unified_to_parallel_seg_index& seg_index_map,
110+
int num_seg_types,
111+
vtr::NdMatrix<int, 3>& Fc_zofs,
112+
t_rr_edge_info_set& rr_edges_to_create,
113+
const vtr::NdMatrix<std::vector<t_bottleneck_link>, 2>& interdie_3d_links) {
114+
const RRSpatialLookup& node_lookup = rr_graph.node_lookup();
115+
const DeviceGrid& grid = g_vpr_ctx.device().grid;
116+
117+
t_physical_tile_type_ptr type = grid.get_physical_type({x, y, layer});
118+
119+
std::vector<RRNodeId> opin_nodes = node_lookup.find_pin_nodes_at_side(layer, x, y, e_rr_type::OPIN, side);
120+
121+
t_physical_tile_loc sb_loc0, sb_loc1;
122+
switch (side) {
123+
case TOP:
124+
sb_loc0 = {x, y, layer};
125+
sb_loc1 = {x - 1, y, layer};
126+
break;
127+
128+
case BOTTOM:
129+
sb_loc0 = {x, y - 1, layer};
130+
sb_loc1 = {x - 1, y - 1, layer};
131+
break;
132+
133+
case RIGHT:
134+
sb_loc0 = {x, y, layer};
135+
sb_loc1 = {x , y - 1, layer};
136+
break;
137+
138+
case LEFT:
139+
sb_loc0 = {x - 1, y, layer};
140+
sb_loc1 = {x - 1 , y - 1, layer};
141+
break;
142+
143+
default:
144+
VTR_ASSERT_SAFE(false);
145+
}
146+
147+
const int grid_width = grid.width();
148+
const int grid_height = grid.height();
149+
150+
sb_loc0.x = std::clamp(sb_loc0.x, 0, grid_width - 1);
151+
sb_loc0.y = std::clamp(sb_loc0.y, 0, grid_height - 1);
152+
153+
sb_loc1.x = std::clamp(sb_loc1.x, 0, grid_width - 1);
154+
sb_loc1.y = std::clamp(sb_loc1.y, 0, grid_height - 1);
155+
156+
std::vector<std::pair<RRNodeId, short>> selected_chanz_nodes0;
157+
std::vector<std::pair<RRNodeId, short>> selected_chanz_nodes1;
158+
159+
for (int iseg = 0; iseg < num_seg_types; iseg++) {
160+
int seg_index = get_parallel_seg_index(iseg, seg_index_map, e_parallel_axis::Z_AXIS);
161+
if (seg_index < 0) {
162+
continue;
163+
}
164+
165+
selected_chanz_nodes0.clear();
166+
for (size_t track_num = 0; track_num < interdie_3d_links[sb_loc0.x][sb_loc0.y].size(); track_num++) {
167+
const t_bottleneck_link& bottleneck_link = interdie_3d_links[sb_loc0.x][sb_loc0.y][track_num];
168+
if (bottleneck_link.parallel_segment_index == seg_index && bottleneck_link.gather_loc.layer_num == layer) {
169+
RRNodeId node_id = node_lookup.find_node(sb_loc0.layer_num, sb_loc0.x, sb_loc0.y, e_rr_type::CHANZ, track_num);
170+
selected_chanz_nodes0.push_back({node_id, bottleneck_link.arch_wire_switch});
171+
}
172+
}
173+
174+
selected_chanz_nodes1.clear();
175+
for (size_t track_num = 0; track_num < interdie_3d_links[sb_loc1.x][sb_loc1.y].size(); track_num++) {
176+
const t_bottleneck_link& bottleneck_link = interdie_3d_links[sb_loc1.x][sb_loc1.y][track_num];
177+
if (bottleneck_link.parallel_segment_index == seg_index && bottleneck_link.gather_loc.layer_num == layer) {
178+
RRNodeId node_id = node_lookup.find_node(sb_loc1.layer_num, sb_loc1.x, sb_loc1.y, e_rr_type::CHANZ, track_num);
179+
selected_chanz_nodes1.push_back({node_id, bottleneck_link.arch_wire_switch});
180+
}
181+
}
182+
183+
for (RRNodeId opin_node_id : opin_nodes) {
184+
int pin_number = rr_graph.node_pin_num(opin_node_id);
185+
int fc = Fc_out[type->index][pin_number][iseg];
186+
187+
for (int i = 0; i < fc; i++) {
188+
189+
RRNodeId chanz_node_id;
190+
short switch_id;
191+
if (Fc_zofs[sb_loc0.x][sb_loc0.y][seg_index] < Fc_zofs[sb_loc1.x][sb_loc1.y][seg_index]) {
192+
int chanz_idx = Fc_zofs[sb_loc0.x][sb_loc0.y][seg_index];
193+
chanz_node_id = selected_chanz_nodes0[chanz_idx % selected_chanz_nodes0.size()].first;
194+
switch_id = selected_chanz_nodes0[chanz_idx % selected_chanz_nodes0.size()].second;
195+
Fc_zofs[sb_loc0.x][sb_loc0.y][seg_index]++;
196+
} else {
197+
int chanz_idx = Fc_zofs[sb_loc1.x][sb_loc1.y][seg_index];
198+
chanz_node_id = selected_chanz_nodes1[chanz_idx % selected_chanz_nodes1.size()].first;
199+
switch_id = selected_chanz_nodes1[chanz_idx % selected_chanz_nodes1.size()].second;
200+
Fc_zofs[sb_loc1.x][sb_loc1.y][seg_index]++;
201+
}
202+
203+
rr_edges_to_create.emplace_back(opin_node_id, chanz_node_id, switch_id, false);
204+
}
205+
}
206+
}
207+
208+
}
209+
210+
void add_edges_opin_chanz_per_block(const RRGraphView& rr_graph,
211+
int layer,
212+
int x,
213+
int y,
214+
const std::vector<vtr::Matrix<int>>& Fc_out,
215+
const t_unified_to_parallel_seg_index& seg_index_map,
216+
int num_seg_types,
217+
t_rr_edge_info_set& rr_edges_to_create,
218+
const std::vector<t_bottleneck_link>& interdie_3d_links) {
112219
const RRSpatialLookup& node_lookup = rr_graph.node_lookup();
113220
const DeviceGrid& grid = g_vpr_ctx.device().grid;
114221

vpr/src/route/rr_graph_generation/rr_graph_sg.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,27 @@ void add_inter_die_3d_edges(RRGraphBuilder& rr_graph_builder,
3131
const std::vector<t_bottleneck_link>& interdie_3d_links,
3232
t_rr_edge_info_set& interdie_3d_rr_edges_to_create);
3333

34-
void add_edges_opin_chanz(const RRGraphView& rr_graph,
35-
int layer,
36-
int x,
37-
int y,
38-
const std::vector<vtr::Matrix<int>>& Fc_out,
39-
const t_unified_to_parallel_seg_index& seg_index_map,
40-
int num_seg_types,
41-
t_rr_edge_info_set& rr_edges_to_create,
42-
const std::vector<t_bottleneck_link>& interdie_3d_links);
34+
void add_edges_opin_chanz_per_side(const RRGraphView& rr_graph,
35+
int layer,
36+
int x,
37+
int y,
38+
e_side side,
39+
const std::vector<vtr::Matrix<int>>& Fc_out,
40+
const t_unified_to_parallel_seg_index& seg_index_map,
41+
int num_seg_types,
42+
vtr::NdMatrix<int, 3>& Fc_zofs,
43+
t_rr_edge_info_set& rr_edges_to_create,
44+
const vtr::NdMatrix<std::vector<t_bottleneck_link>, 2>& interdie_3d_links);
45+
46+
void add_edges_opin_chanz_per_block(const RRGraphView& rr_graph,
47+
int layer,
48+
int x,
49+
int y,
50+
const std::vector<vtr::Matrix<int>>& Fc_out,
51+
const t_unified_to_parallel_seg_index& seg_index_map,
52+
int num_seg_types,
53+
t_rr_edge_info_set& rr_edges_to_create,
54+
const std::vector<t_bottleneck_link>& interdie_3d_links);
4355

4456
/**
4557
* @brief Adds and connects non-3D scatter–gather (SG) links to the RR graph.

0 commit comments

Comments
 (0)