Skip to content

Commit 8a26367

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

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
@@ -352,6 +352,8 @@ static void SetupRouterOpts(const t_options& Options, t_router_opts* RouterOpts)
352352
RouterOpts->fixed_channel_width = Options.RouteChanWidth;
353353
RouterOpts->min_channel_width_hint = Options.min_route_chan_width_hint;
354354
RouterOpts->read_rr_edge_metadata = Options.read_rr_edge_metadata;
355+
RouterOpts->reorder_rr_graph_nodes_algorithm = Options.reorder_rr_graph_nodes_algorithm;
356+
RouterOpts->reorder_rr_graph_nodes_threshold = Options.reorder_rr_graph_nodes_threshold;
355357

356358
//TODO document these?
357359
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
@@ -353,16 +353,17 @@ int binary_search_place_and_route(const t_placer_opts& placer_opts_ref,
353353
device_ctx.num_arch_switches,
354354
det_routing_arch,
355355
segment_inf,
356-
router_opts.base_cost_type,
357-
router_opts.trim_empty_channels,
358-
router_opts.trim_obs_channels,
359-
router_opts.clock_modeling,
356+
router_opts,
360357
arch->Directs, arch->num_directs,
361-
&warnings,
362-
router_opts.read_rr_edge_metadata,
363-
router_opts.do_check_rr_graph);
358+
&warnings);
364359

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

368369
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;
@@ -1865,6 +1896,21 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
18651896
.default_value("off")
18661897
.show_in(argparse::ShowIn::HELP_ONLY);
18671898

1899+
route_grp.add_argument<e_node_reorder_algorithm, ParseNodeReorderAlgorithm>(args.reorder_rr_graph_nodes_algorithm, "--reorder_rr_graph_nodes_algorithm")
1900+
.help(
1901+
"Specifies the node reordering algorithm to use.\n"
1902+
" * degree_bfs: sort by degree and then by BFS\n"
1903+
" * random_shuffle: a random shuffle\n")
1904+
.default_value("degree_bfs")
1905+
.choices({"degree_bfs", "random_shuffle"})
1906+
.show_in(argparse::ShowIn::HELP_ONLY);
1907+
1908+
route_grp.add_argument(args.reorder_rr_graph_nodes_threshold, "--reorder_rr_graph_nodes_threshold")
1909+
.help(
1910+
"Reorder rr_graph nodes to optimize memory layout above this number of nodes, or -1 to disable.")
1911+
.default_value("-1")
1912+
.show_in(argparse::ShowIn::HELP_ONLY);
1913+
18681914
auto& route_timing_grp = parser.add_argument_group("timing-driven routing options");
18691915

18701916
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
@@ -152,6 +152,8 @@ struct t_options {
152152
argparse::ArgValue<e_check_route_option> check_route;
153153
argparse::ArgValue<size_t> max_logged_overused_rr_nodes;
154154
argparse::ArgValue<bool> generate_rr_node_overuse_report;
155+
argparse::ArgValue<e_node_reorder_algorithm> reorder_rr_graph_nodes_algorithm;
156+
argparse::ArgValue<int> reorder_rr_graph_nodes_threshold;
155157

156158
/* Timing-driven router options only */
157159
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
@@ -888,14 +888,9 @@ void vpr_create_rr_graph(t_vpr_setup& vpr_setup, const t_arch& arch, int chan_wi
888888
device_ctx.num_arch_switches,
889889
det_routing_arch,
890890
vpr_setup.Segments,
891-
router_opts.base_cost_type,
892-
router_opts.trim_empty_channels,
893-
router_opts.trim_obs_channels,
894-
router_opts.clock_modeling,
891+
router_opts,
895892
arch.Directs, arch.num_directs,
896-
&warnings,
897-
router_opts.read_rr_edge_metadata,
898-
router_opts.do_check_rr_graph);
893+
&warnings);
899894
//Initialize drawing, now that we have an RR graph
900895
init_draw_coords(chan_width_fac);
901896
}

vpr/src/base/vpr_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,11 @@ enum e_router_algorithm {
991991
TIMING_DRIVEN,
992992
};
993993

994+
enum e_node_reorder_algorithm {
995+
DEGREE_BFS,
996+
RANDOM_SHUFFLE,
997+
};
998+
994999
enum e_base_cost_type {
9951000
DELAY_NORMALIZED,
9961001
DELAY_NORMALIZED_LENGTH,
@@ -1043,6 +1048,8 @@ enum class e_incr_reroute_delay_ripup {
10431048
constexpr int NO_FIXED_CHANNEL_WIDTH = -1;
10441049

10451050
struct t_router_opts {
1051+
e_node_reorder_algorithm reorder_rr_graph_nodes_algorithm = DEGREE_BFS;
1052+
int reorder_rr_graph_nodes_threshold = -1;
10461053
bool read_rr_edge_metadata = false;
10471054
bool do_check_rr_graph = true;
10481055
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
@@ -739,3 +739,68 @@ t_rr_graph_view t_rr_graph_storage::view() const {
739739
vtr::make_const_array_view_id(edge_dest_node_),
740740
vtr::make_const_array_view_id(edge_switch_));
741741
}
742+
743+
void t_rr_graph_storage::reorder(const vtr::vector<RRNodeId, RRNodeId>& order,
744+
const vtr::vector<RRNodeId, RRNodeId>& inverse_order) {
745+
{
746+
auto old_node_storage = node_storage_;
747+
748+
// Reorder nodes
749+
for (size_t i = 0; i < node_storage_.size(); i++) {
750+
auto n = RRNodeId(i);
751+
VTR_ASSERT(n == inverse_order[order[n]]);
752+
node_storage_[order[n]] = old_node_storage[n];
753+
}
754+
}
755+
{
756+
auto old_node_first_edge = node_first_edge_;
757+
auto old_edge_src_node = edge_src_node_;
758+
auto old_edge_dest_node = edge_dest_node_;
759+
auto old_edge_switch = edge_switch_;
760+
RREdgeId cur_edge(0);
761+
762+
// Reorder edges by source node
763+
for (size_t i = 0; i < node_storage_.size(); i++) {
764+
node_first_edge_[RRNodeId(i)] = cur_edge;
765+
auto n = inverse_order[RRNodeId(i)];
766+
for (auto e = old_node_first_edge[n];
767+
e < old_node_first_edge[RRNodeId(size_t(n) + 1)];
768+
e = RREdgeId(size_t(e) + 1)) {
769+
edge_src_node_[cur_edge] = order[old_edge_src_node[e]]; // == n?
770+
edge_dest_node_[cur_edge] = order[old_edge_dest_node[e]];
771+
edge_switch_[cur_edge] = old_edge_switch[e];
772+
cur_edge = RREdgeId(size_t(cur_edge) + 1);
773+
}
774+
}
775+
}
776+
{
777+
auto old_node_ptc = node_ptc_;
778+
for (size_t i = 0; i < node_ptc_.size(); i++) {
779+
node_ptc_[order[RRNodeId(i)]] = old_node_ptc[RRNodeId(i)];
780+
}
781+
}
782+
{
783+
auto old_node_fan_in = node_fan_in_;
784+
for (size_t i = 0; i < node_fan_in_.size(); i++) {
785+
node_fan_in_[order[RRNodeId(i)]] = old_node_fan_in[RRNodeId(i)];
786+
}
787+
}
788+
789+
// Check that edges are still partitioned
790+
if (partitioned_) {
791+
auto& device_ctx = g_vpr_ctx.device();
792+
for (size_t i = 0; i < size(); i++) {
793+
RRNodeId n(i);
794+
bool configurable_partition = true;
795+
for (auto e = first_edge(n);
796+
e < last_edge(n);
797+
e = RREdgeId(size_t(e) + 1)) {
798+
if (device_ctx.rr_switch_inf[edge_switch(e)].configurable()) {
799+
VTR_ASSERT(configurable_partition);
800+
} else {
801+
configurable_partition = false;
802+
}
803+
}
804+
}
805+
}
806+
}

vpr/src/route/rr_graph_storage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ class t_rr_graph_storage {
435435
node_storage_.emplace_back();
436436
node_ptc_.emplace_back();
437437
}
438+
void reorder(const vtr::vector<RRNodeId, RRNodeId>& order,
439+
const vtr::vector<RRNodeId, RRNodeId>& inverse_order);
438440

439441
/* PTC set methods */
440442
void set_node_ptc_num(RRNodeId id, short);

0 commit comments

Comments
 (0)