Skip to content

Commit fb381c0

Browse files
committed
Implemented two node reordering algorithms
Signed-off-by: Dusty DeWeese <[email protected]>
1 parent ce72d60 commit fb381c0

14 files changed

+233
-56
lines changed

vpr/src/base/SetupVPR.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ static void SetupRouterOpts(const t_options& Options, t_router_opts* RouterOpts)
343343
RouterOpts->fixed_channel_width = Options.RouteChanWidth;
344344
RouterOpts->min_channel_width_hint = Options.min_route_chan_width_hint;
345345
RouterOpts->read_rr_edge_metadata = Options.read_rr_edge_metadata;
346+
RouterOpts->reorder_rr_graph_nodes_algorithm = Options.reorder_rr_graph_nodes_algorithm;
347+
RouterOpts->reorder_rr_graph_nodes_threshold = Options.reorder_rr_graph_nodes_threshold;
346348

347349
//TODO document these?
348350
RouterOpts->trim_empty_channels = false; /* DEFAULT */

vpr/src/base/place_and_route.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,17 @@ int binary_search_place_and_route(const t_placer_opts& placer_opts_ref,
352352
device_ctx.num_arch_switches,
353353
det_routing_arch,
354354
segment_inf,
355-
router_opts.base_cost_type,
356-
router_opts.trim_empty_channels,
357-
router_opts.trim_obs_channels,
358-
router_opts.clock_modeling,
355+
router_opts,
359356
arch->Directs, arch->num_directs,
360-
&warnings,
361-
router_opts.read_rr_edge_metadata,
362-
router_opts.do_check_rr_graph);
357+
&warnings);
363358

364359
init_draw_coords(final);
360+
361+
/* Allocate and load additional rr_graph information needed only by the router. */
362+
alloc_and_load_rr_node_route_structs();
363+
364+
init_route_structs(router_opts.bb_factor);
365+
365366
restore_routing(best_routing, route_ctx.clb_opins_used_locally, saved_clb_opins_used_locally);
366367

367368
if (Fc_clipped) {

vpr/src/base/read_options.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,37 @@ struct ParseRouterAlgorithm {
163163
}
164164
};
165165

166+
struct ParseNodeReorderAlgorithm {
167+
ConvertedValue<e_node_reorder_algorithm> from_str(std::string str) {
168+
ConvertedValue<e_node_reorder_algorithm> conv_value;
169+
if (str == "degree_bfs")
170+
conv_value.set_value(DEGREE_BFS);
171+
else if (str == "random_shuffle")
172+
conv_value.set_value(RANDOM_SHUFFLE);
173+
else {
174+
std::stringstream msg;
175+
msg << "Invalid conversion from '" << str << "' to e_node_reorder_algorithm (expected one of: " << argparse::join(default_choices(), ", ") << ")";
176+
conv_value.set_error(msg.str());
177+
}
178+
return conv_value;
179+
}
180+
181+
ConvertedValue<std::string> to_str(e_node_reorder_algorithm val) {
182+
ConvertedValue<std::string> conv_value;
183+
if (val == DEGREE_BFS)
184+
conv_value.set_value("degree_bfs");
185+
else {
186+
VTR_ASSERT(val == RANDOM_SHUFFLE);
187+
conv_value.set_value("random_shuffle");
188+
}
189+
return conv_value;
190+
}
191+
192+
std::vector<std::string> default_choices() {
193+
return {"degree_bfs", "random_shuffle"};
194+
}
195+
};
196+
166197
struct RouteBudgetsAlgorithm {
167198
ConvertedValue<e_routing_budgets_algorithm> from_str(std::string str) {
168199
ConvertedValue<e_routing_budgets_algorithm> conv_value;
@@ -1735,6 +1766,21 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
17351766
.default_value("off")
17361767
.show_in(argparse::ShowIn::HELP_ONLY);
17371768

1769+
route_grp.add_argument<e_node_reorder_algorithm, ParseNodeReorderAlgorithm>(args.reorder_rr_graph_nodes_algorithm, "--reorder_rr_graph_nodes_algorithm")
1770+
.help(
1771+
"Specifies the node reordering algorithm to use.\n"
1772+
" * degree_bfs: sort by degree and then by BFS\n"
1773+
" * random_shuffle: a random shuffle\n")
1774+
.default_value("degree_bfs")
1775+
.choices({"degree_bfs", "random_shuffle"})
1776+
.show_in(argparse::ShowIn::HELP_ONLY);
1777+
1778+
route_grp.add_argument(args.reorder_rr_graph_nodes_threshold, "--reorder_rr_graph_nodes_threshold")
1779+
.help(
1780+
"Reorder rr_graph nodes to optimize memory layout above this number of nodes, or -1 to disable.")
1781+
.default_value("-1")
1782+
.show_in(argparse::ShowIn::HELP_ONLY);
1783+
17381784
auto& route_timing_grp = parser.add_argument_group("timing-driven routing options");
17391785

17401786
route_timing_grp.add_argument(args.astar_fac, "--astar_fac")

vpr/src/base/read_options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ struct t_options {
140140
argparse::ArgValue<int> min_incremental_reroute_fanout;
141141
argparse::ArgValue<bool> read_rr_edge_metadata;
142142
argparse::ArgValue<bool> exit_after_first_routing_iteration;
143+
argparse::ArgValue<e_node_reorder_algorithm> reorder_rr_graph_nodes_algorithm;
144+
argparse::ArgValue<int> reorder_rr_graph_nodes_threshold;
143145

144146
/* Timing-driven router options only */
145147
argparse::ArgValue<float> astar_fac;

vpr/src/base/vpr_api.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -866,14 +866,9 @@ void vpr_create_rr_graph(t_vpr_setup& vpr_setup, const t_arch& arch, int chan_wi
866866
device_ctx.num_arch_switches,
867867
det_routing_arch,
868868
vpr_setup.Segments,
869-
router_opts.base_cost_type,
870-
router_opts.trim_empty_channels,
871-
router_opts.trim_obs_channels,
872-
router_opts.clock_modeling,
869+
router_opts,
873870
arch.Directs, arch.num_directs,
874-
&warnings,
875-
router_opts.read_rr_edge_metadata,
876-
router_opts.do_check_rr_graph);
871+
&warnings);
877872
//Initialize drawing, now that we have an RR graph
878873
init_draw_coords(chan_width_fac);
879874
}

vpr/src/base/vpr_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,11 @@ enum e_router_algorithm {
910910
TIMING_DRIVEN,
911911
};
912912

913+
enum e_node_reorder_algorithm {
914+
DEGREE_BFS,
915+
RANDOM_SHUFFLE,
916+
};
917+
913918
enum e_base_cost_type {
914919
DELAY_NORMALIZED,
915920
DELAY_NORMALIZED_LENGTH,
@@ -946,6 +951,8 @@ enum class e_incr_reroute_delay_ripup {
946951
constexpr int NO_FIXED_CHANNEL_WIDTH = -1;
947952

948953
struct t_router_opts {
954+
e_node_reorder_algorithm reorder_rr_graph_nodes_algorithm = DEGREE_BFS;
955+
int reorder_rr_graph_nodes_threshold = -1;
949956
bool read_rr_edge_metadata = false;
950957
bool do_check_rr_graph = true;
951958
float first_iter_pres_fac;

vpr/src/route/route_common.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,9 @@ void try_graph(int width_fac, const t_router_opts& router_opts, t_det_routing_ar
227227
device_ctx.num_arch_switches,
228228
det_routing_arch,
229229
segment_inf,
230-
router_opts.base_cost_type,
231-
router_opts.trim_empty_channels,
232-
router_opts.trim_obs_channels,
233-
router_opts.clock_modeling,
230+
router_opts,
234231
directs, num_directs,
235-
&warning_count,
236-
router_opts.read_rr_edge_metadata,
237-
router_opts.do_check_rr_graph);
232+
&warning_count);
238233
}
239234

240235
bool try_route(int width_fac,
@@ -279,14 +274,9 @@ bool try_route(int width_fac,
279274
device_ctx.num_arch_switches,
280275
det_routing_arch,
281276
segment_inf,
282-
router_opts.base_cost_type,
283-
router_opts.trim_empty_channels,
284-
router_opts.trim_obs_channels,
285-
router_opts.clock_modeling,
277+
router_opts,
286278
directs, num_directs,
287-
&warning_count,
288-
router_opts.read_rr_edge_metadata,
289-
router_opts.do_check_rr_graph);
279+
&warning_count);
290280

291281
//Initialize drawing, now that we have an RR graph
292282
init_draw_coords(width_fac);

vpr/src/route/router_delay_profiling.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,9 @@ void alloc_routing_structs(t_chan_width chan_width,
221221
device_ctx.num_arch_switches,
222222
det_routing_arch,
223223
segment_inf,
224-
router_opts.base_cost_type,
225-
router_opts.trim_empty_channels,
226-
router_opts.trim_obs_channels,
227-
router_opts.clock_modeling,
224+
router_opts,
228225
directs, num_directs,
229-
&warnings,
230-
router_opts.read_rr_edge_metadata,
231-
router_opts.do_check_rr_graph);
226+
&warnings);
232227

233228
alloc_and_load_rr_node_route_structs();
234229

vpr/src/route/rr_graph.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,10 @@ void create_rr_graph(const t_graph_type graph_type,
317317
const int num_arch_switches,
318318
t_det_routing_arch* det_routing_arch,
319319
const std::vector<t_segment_inf>& segment_inf,
320-
const enum e_base_cost_type base_cost_type,
321-
const bool trim_empty_channels,
322-
const bool trim_obs_channels,
323-
const enum e_clock_modeling clock_modeling,
320+
const t_router_opts& router_opts,
324321
const t_direct_inf* directs,
325322
const int num_directs,
326-
int* Warnings,
327-
bool read_rr_edge_metadata,
328-
bool do_check_rr_graph) {
323+
int* Warnings) {
329324
const auto& device_ctx = g_vpr_ctx.device();
330325

331326
if (!det_routing_arch->read_rr_graph_filename.empty()) {
@@ -335,11 +330,12 @@ void create_rr_graph(const t_graph_type graph_type,
335330
load_rr_file(graph_type,
336331
grid,
337332
segment_inf,
338-
base_cost_type,
333+
router_opts.base_cost_type,
339334
&det_routing_arch->wire_to_rr_ipin_switch,
340335
det_routing_arch->read_rr_graph_filename.c_str(),
341-
read_rr_edge_metadata,
342-
do_check_rr_graph);
336+
router_opts.read_rr_edge_metadata,
337+
router_opts.do_check_rr_graph);
338+
reorder_rr_graph_nodes(router_opts);
343339
}
344340
} else {
345341
if (channel_widths_unchanged(device_ctx.chan_width, nodes_per_chan) && !device_ctx.rr_nodes.empty()) {
@@ -364,13 +360,14 @@ void create_rr_graph(const t_graph_type graph_type,
364360
det_routing_arch->delayless_switch,
365361
det_routing_arch->R_minW_nmos,
366362
det_routing_arch->R_minW_pmos,
367-
base_cost_type,
368-
clock_modeling,
369-
trim_empty_channels,
370-
trim_obs_channels,
363+
router_opts.base_cost_type,
364+
router_opts.clock_modeling,
365+
router_opts.trim_empty_channels,
366+
router_opts.trim_obs_channels,
371367
directs, num_directs,
372368
&det_routing_arch->wire_to_rr_ipin_switch,
373369
Warnings);
370+
reorder_rr_graph_nodes(router_opts);
374371
}
375372

376373
process_non_config_sets();

vpr/src/route/rr_graph.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,10 @@ void create_rr_graph(const t_graph_type graph_type,
3333
const int num_arch_switches,
3434
t_det_routing_arch* det_routing_arch,
3535
const std::vector<t_segment_inf>& segment_inf,
36-
const enum e_base_cost_type base_cost_type,
37-
const bool trim_empty_channels,
38-
const bool trim_obs_channels,
39-
const enum e_clock_modeling clock_modeling,
36+
const t_router_opts& router_opts,
4037
const t_direct_inf* directs,
4138
const int num_directs,
42-
int* Warnings,
43-
bool read_rr_edge_metadata,
44-
bool do_check_rr_graph);
39+
int* Warnings);
4540

4641
void free_rr_graph();
4742

vpr/src/route/rr_graph_storage.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,3 +709,68 @@ t_rr_graph_view t_rr_graph_storage::view() const {
709709
vtr::make_const_array_view_id(edge_dest_node_),
710710
vtr::make_const_array_view_id(edge_switch_));
711711
}
712+
713+
void t_rr_graph_storage::reorder(const vtr::vector<RRNodeId, RRNodeId>& order,
714+
const vtr::vector<RRNodeId, RRNodeId>& inverse_order) {
715+
{
716+
auto old_node_storage = node_storage_;
717+
718+
// Reorder nodes
719+
for (size_t i = 0; i < node_storage_.size(); i++) {
720+
auto n = RRNodeId(i);
721+
VTR_ASSERT(n == inverse_order[order[n]]);
722+
node_storage_[order[n]] = old_node_storage[n];
723+
}
724+
}
725+
{
726+
auto old_node_first_edge = node_first_edge_;
727+
auto old_edge_src_node = edge_src_node_;
728+
auto old_edge_dest_node = edge_dest_node_;
729+
auto old_edge_switch = edge_switch_;
730+
RREdgeId cur_edge(0);
731+
732+
// Reorder edges by source node
733+
for (size_t i = 0; i < node_storage_.size(); i++) {
734+
node_first_edge_[RRNodeId(i)] = cur_edge;
735+
auto n = inverse_order[RRNodeId(i)];
736+
for (auto e = old_node_first_edge[n];
737+
e < old_node_first_edge[RRNodeId(size_t(n) + 1)];
738+
e = RREdgeId(size_t(e) + 1)) {
739+
edge_src_node_[cur_edge] = order[old_edge_src_node[e]]; // == n?
740+
edge_dest_node_[cur_edge] = order[old_edge_dest_node[e]];
741+
edge_switch_[cur_edge] = old_edge_switch[e];
742+
cur_edge = RREdgeId(size_t(cur_edge) + 1);
743+
}
744+
}
745+
}
746+
{
747+
auto old_node_ptc = node_ptc_;
748+
for (size_t i = 0; i < node_ptc_.size(); i++) {
749+
node_ptc_[order[RRNodeId(i)]] = old_node_ptc[RRNodeId(i)];
750+
}
751+
}
752+
{
753+
auto old_node_fan_in = node_fan_in_;
754+
for (size_t i = 0; i < node_fan_in_.size(); i++) {
755+
node_fan_in_[order[RRNodeId(i)]] = old_node_fan_in[RRNodeId(i)];
756+
}
757+
}
758+
759+
// Check that edges are still partitioned
760+
if (partitioned_) {
761+
auto& device_ctx = g_vpr_ctx.device();
762+
for (size_t i = 0; i < size(); i++) {
763+
RRNodeId n(i);
764+
bool configurable_partition = true;
765+
for (auto e = first_edge(n);
766+
e < last_edge(n);
767+
e = RREdgeId(size_t(e) + 1)) {
768+
if (device_ctx.rr_switch_inf[edge_switch(e)].configurable()) {
769+
VTR_ASSERT(configurable_partition);
770+
} else {
771+
configurable_partition = false;
772+
}
773+
}
774+
}
775+
}
776+
}

vpr/src/route/rr_graph_storage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ class t_rr_graph_storage {
433433
node_storage_.emplace_back();
434434
node_ptc_.emplace_back();
435435
}
436+
void reorder(const vtr::vector<RRNodeId, RRNodeId>& order,
437+
const vtr::vector<RRNodeId, RRNodeId>& inverse_order);
436438

437439
/* PTC set methods */
438440
void set_node_ptc_num(RRNodeId id, short);

0 commit comments

Comments
 (0)