Skip to content

Commit 633193b

Browse files
authored
Merge pull request #2496 from verilog-to-routing/noc_turn_model_routing
NoC Turn Model Routing Algorithms
2 parents 5cfbaa0 + ccc5aa4 commit 633193b

File tree

76 files changed

+8903
-587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+8903
-587
lines changed

libs/EXTERNAL/libargparse/src/argparse.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <algorithm>
2-
#include <array>
32
#include <list>
43
#include <cassert>
54
#include <string>
65
#include <set>
76
#include <limits>
7+
#include <utility>
88

99
#include "argparse.hpp"
1010
#include "argparse_util.hpp"
@@ -16,16 +16,16 @@ namespace argparse {
1616
* ArgumentParser
1717
*/
1818

19-
ArgumentParser::ArgumentParser(std::string prog_name, std::string description_str, std::ostream& os)
20-
: description_(description_str)
19+
ArgumentParser::ArgumentParser(const std::string& prog_name, std::string description_str, std::ostream& os)
20+
: description_(std::move(description_str))
2121
, formatter_(new DefaultFormatter())
2222
, os_(os)
2323
{
2424
prog(prog_name);
2525
argument_groups_.push_back(ArgumentGroup("arguments"));
2626
}
2727

28-
ArgumentParser& ArgumentParser::prog(std::string prog_name, bool basename_only) {
28+
ArgumentParser& ArgumentParser::prog(const std::string& prog_name, bool basename_only) {
2929
if (basename_only) {
3030
prog_ = basename(prog_name);
3131
} else {
@@ -35,17 +35,17 @@ namespace argparse {
3535
}
3636

3737
ArgumentParser& ArgumentParser::version(std::string version_str) {
38-
version_ = version_str;
38+
version_ = std::move(version_str);
3939
return *this;
4040
}
4141

4242
ArgumentParser& ArgumentParser::epilog(std::string epilog_str) {
43-
epilog_ = epilog_str;
43+
epilog_ = std::move(epilog_str);
4444
return *this;
4545
}
4646

4747
ArgumentGroup& ArgumentParser::add_argument_group(std::string description_str) {
48-
argument_groups_.push_back(ArgumentGroup(description_str));
48+
argument_groups_.push_back(ArgumentGroup(std::move(description_str)));
4949
return argument_groups_[argument_groups_.size() - 1];
5050
}
5151

@@ -72,7 +72,7 @@ namespace argparse {
7272
void ArgumentParser::parse_args_throw(int argc, const char* const* argv) {
7373
std::vector<std::string> arg_strs;
7474
for (int i = 1; i < argc; ++i) {
75-
arg_strs.push_back(argv[i]);
75+
arg_strs.emplace_back(argv[i]);
7676
}
7777

7878
parse_args_throw(arg_strs);
@@ -241,7 +241,7 @@ namespace argparse {
241241
} else if (arg->nargs() == '+' || arg->nargs() == '*') {
242242
if (arg->nargs() == '+') {
243243
assert(nargs_read >= 1);
244-
assert(values.size() >= 1);
244+
assert(!values.empty());
245245
}
246246

247247
for (const auto& value : values) {
@@ -410,11 +410,11 @@ namespace argparse {
410410
* ArgumentGroup
411411
*/
412412
ArgumentGroup::ArgumentGroup(std::string name_str)
413-
: name_(name_str)
413+
: name_(std::move(name_str))
414414
{}
415415

416416
ArgumentGroup& ArgumentGroup::epilog(std::string str) {
417-
epilog_ = str;
417+
epilog_ = std::move(str);
418418
return *this;
419419
}
420420
std::string ArgumentGroup::name() const { return name_; }
@@ -425,10 +425,10 @@ namespace argparse {
425425
* Argument
426426
*/
427427
Argument::Argument(std::string long_opt, std::string short_opt)
428-
: long_opt_(long_opt)
429-
, short_opt_(short_opt) {
428+
: long_opt_(std::move(long_opt))
429+
, short_opt_(std::move(short_opt)) {
430430

431-
if (long_opt_.size() < 1) {
431+
if (long_opt_.empty()) {
432432
throw ArgParseError("Argument must be at least one character long");
433433
}
434434

@@ -445,7 +445,7 @@ namespace argparse {
445445
}
446446

447447
Argument& Argument::help(std::string help_str) {
448-
help_ = help_str;
448+
help_ = std::move(help_str);
449449
return *this;
450450
}
451451

@@ -476,12 +476,12 @@ namespace argparse {
476476
}
477477

478478
Argument& Argument::metavar(std::string metavar_str) {
479-
metavar_ = metavar_str;
479+
metavar_ = std::move(metavar_str);
480480
return *this;
481481
}
482482

483483
Argument& Argument::choices(std::vector<std::string> choice_values) {
484-
choices_ = choice_values;
484+
choices_ = std::move(choice_values);
485485
return *this;
486486
}
487487

@@ -536,7 +536,7 @@ namespace argparse {
536536
}
537537

538538
Argument& Argument::group_name(std::string grp) {
539-
group_name_ = grp;
539+
group_name_ = std::move(grp);
540540
return *this;
541541
}
542542

libs/EXTERNAL/libargparse/src/argparse.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ namespace argparse {
3434
class ArgumentParser {
3535
public:
3636
//Initializes an argument parser
37-
ArgumentParser(std::string prog_name, std::string description_str=std::string(), std::ostream& os=std::cout);
37+
ArgumentParser(const std::string& prog_name, std::string description_str=std::string(), std::ostream& os=std::cout);
3838

3939
//Overrides the program name
40-
ArgumentParser& prog(std::string prog, bool basename_only=true);
40+
ArgumentParser& prog(const std::string& prog, bool basename_only=true);
4141

4242
//Sets the program version
4343
ArgumentParser& version(std::string version);

libs/libvtrutil/src/vtr_util.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ std::string string_fmt(const char* fmt, ...) {
125125

126126
///@brief Returns a std::string formatted using a printf-style format string taking an explicit va_list
127127
std::string vstring_fmt(const char* fmt, va_list args) {
128-
// We need to copy the args so we don't change them before the true formating
128+
// We need to copy the args so we don't change them before the true formatting
129129
va_list va_args_copy;
130130
va_copy(va_args_copy, args);
131131

vpr/src/base/SetupVPR.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,12 @@ static void SetupNocOpts(const t_options& Options, t_noc_opts* NocOpts) {
735735
NocOpts->noc_flows_file = Options.noc_flows_file;
736736
NocOpts->noc_routing_algorithm = Options.noc_routing_algorithm;
737737
NocOpts->noc_placement_weighting = Options.noc_placement_weighting;
738+
NocOpts->noc_aggregate_bandwidth_weighting = Options.noc_agg_bandwidth_weighting;
738739
NocOpts->noc_latency_constraints_weighting = Options.noc_latency_constraints_weighting;
739740
NocOpts->noc_latency_weighting = Options.noc_latency_weighting;
740741
NocOpts->noc_congestion_weighting = Options.noc_congestion_weighting;
741742
NocOpts->noc_swap_percentage = Options.noc_swap_percentage;
742743
NocOpts->noc_placement_file_name = Options.noc_placement_file_name;
743-
744-
return;
745744
}
746745

747746
static void find_ipin_cblock_switch_index(const t_arch& Arch, int& wire_to_arch_ipin_switch, int& wire_to_arch_ipin_switch_between_dice) {

vpr/src/base/ShowSetup.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ static void ShowPlacerOpts(const t_placer_opts& PlacerOpts,
608608
}
609609

610610
VTR_LOG("PlacerOpts.constraints_file: ");
611-
if (PlacerOpts.constraints_file == "") {
611+
if (PlacerOpts.constraints_file.empty()) {
612612
VTR_LOG("No constraints file given\n");
613613
} else {
614614
VTR_LOG("Using constraints file '%s'\n", PlacerOpts.constraints_file.c_str());
@@ -795,6 +795,7 @@ static void ShowNocOpts(const t_noc_opts& NocOpts) {
795795
VTR_LOG("NocOpts.noc_flows_file: %s\n", NocOpts.noc_flows_file.c_str());
796796
VTR_LOG("NocOpts.noc_routing_algorithm: %s\n", NocOpts.noc_routing_algorithm.c_str());
797797
VTR_LOG("NocOpts.noc_placement_weighting: %f\n", NocOpts.noc_placement_weighting);
798+
VTR_LOG("NocOpts.noc_aggregate_bandwidth_weighting: %f\n", NocOpts.noc_aggregate_bandwidth_weighting);
798799
VTR_LOG("NocOpts.noc_latency_constraints_weighting: %f\n", NocOpts.noc_latency_constraints_weighting);
799800
VTR_LOG("NocOpts.noc_latency_weighting: %f\n", NocOpts.noc_latency_weighting);
800801
VTR_LOG("NocOpts.noc_congestion_weighting: %f\n", NocOpts.noc_congestion_weighting);

vpr/src/base/read_options.cpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "argparse.hpp"
77

8-
#include "vtr_memory.h"
98
#include "vtr_log.h"
109
#include "vtr_util.h"
1110
#include "vtr_path.h"
@@ -14,7 +13,7 @@
1413
using argparse::ConvertedValue;
1514
using argparse::Provenance;
1615

17-
///@brief Read and process VPR's command-line aruments
16+
///@brief Read and process VPR's command-line arguments
1817
t_options read_options(int argc, const char** argv) {
1918
t_options args = t_options(); //Explicitly initialize for zero initialization
2019

@@ -1259,7 +1258,7 @@ struct ParsePostSynthNetlistUnconnOutputHandling {
12591258
}
12601259
};
12611260

1262-
argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& args) {
1261+
argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_options& args) {
12631262
std::string description =
12641263
"Implements the specified circuit onto the target FPGA architecture"
12651264
" by performing packing/placement/routing, and analyzes the result.\n"
@@ -2807,10 +2806,15 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
28072806
.help(
28082807
"Controls the algorithm used by the NoC to route packets.\n"
28092808
"* xy_routing: Uses the direction oriented routing algorithm. This is recommended to be used with mesh NoC topologies.\n"
2810-
"* bfs_routing: Uses the breadth first search algorithm. The objective is to find a route that uses a minimum number of links.\n"
2811-
"This can be used with any NoC topology\n")
2809+
"* bfs_routing: Uses the breadth first search algorithm. The objective is to find a route that uses a minimum number of links."
2810+
" This algorithm is not guaranteed to generate deadlock-free traffic flow routes, but can be used with any NoC topology\n"
2811+
"* west_first_routing: Uses the west-first routing algorithm. This is recommended to be used with mesh NoC topologies.\n"
2812+
"* north_last_routing: Uses the north-last routing algorithm. This is recommended to be used with mesh NoC topologies.\n"
2813+
"* negative_first_routing: Uses the negative-first routing algorithm. This is recommended to be used with mesh NoC topologies.\n"
2814+
"* odd_even_routing: Uses the odd-even routing algorithm. This is recommended to be used with mesh NoC topologies.\n")
28122815
.default_value("bfs_routing")
2813-
.choices({"xy_routing", "bfs_routing"})
2816+
.choices({"xy_routing", "bfs_routing", "west_first_routing", "north_last_routing", "negative_first_routing",
2817+
"odd_even_routing"})
28142818
.show_in(argparse::ShowIn::HELP_ONLY);
28152819

28162820
noc_grp.add_argument<double>(args.noc_placement_weighting, "--noc_placement_weighting")
@@ -2822,6 +2826,16 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
28222826
.default_value("5.0")
28232827
.show_in(argparse::ShowIn::HELP_ONLY);
28242828

2829+
noc_grp.add_argument<double>(args.noc_agg_bandwidth_weighting, "--noc_aggregate_bandwidth_weighting")
2830+
.help(
2831+
"Controls the importance of minimizing the NoC aggregate bandwidth.\n"
2832+
"This value can be >=0, where 0 would mean the aggregate bandwidth has no relevance to placement.\n"
2833+
"Other positive numbers specify the importance of minimizing the NoC aggregate bandwidth to other NoC-related cost terms.\n"
2834+
"Weighting factors for NoC-related cost terms are normalized internally. Therefore, their absolute values are not important, and"
2835+
"only their relative ratios determine the importance of each cost term.")
2836+
.default_value("0.38")
2837+
.show_in(argparse::ShowIn::HELP_ONLY);
2838+
28252839
noc_grp.add_argument<double>(args.noc_latency_constraints_weighting, "--noc_latency_constraints_weighting")
28262840
.help(
28272841
"Controls the importance of meeting all the NoC traffic flow latency constraints.\n"
@@ -2849,7 +2863,7 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
28492863
"Other positive numbers specify the importance of minimizing congestion to other NoC-related cost terms.\n"
28502864
"Weighting factors for NoC-related cost terms are normalized internally. Therefore, their absolute values are not important, and"
28512865
"only their relative ratios determine the importance of each cost term.")
2852-
.default_value("0.00")
2866+
.default_value("0.25")
28532867
.show_in(argparse::ShowIn::HELP_ONLY);
28542868

28552869
noc_grp.add_argument<double>(args.noc_swap_percentage, "--noc_swap_percentage")

vpr/src/base/read_options.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ struct t_options {
153153
argparse::ArgValue<std::string> noc_flows_file;
154154
argparse::ArgValue<std::string> noc_routing_algorithm;
155155
argparse::ArgValue<double> noc_placement_weighting;
156+
argparse::ArgValue<double> noc_agg_bandwidth_weighting;
156157
argparse::ArgValue<double> noc_latency_constraints_weighting;
157158
argparse::ArgValue<double> noc_latency_weighting;
158159
argparse::ArgValue<double> noc_congestion_weighting;
@@ -241,7 +242,7 @@ struct t_options {
241242
argparse::ArgValue<std::string> write_timing_summary;
242243
};
243244

244-
argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& args);
245+
argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_options& args);
245246
t_options read_options(int argc, const char** argv);
246247
void set_conditional_defaults(t_options& args);
247248
bool verify_args(const t_options& args);

vpr/src/noc/bfs_routing.cpp

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
#
1+
2+
#include <queue>
23

34
#include "bfs_routing.h"
45

5-
BFSRouting::~BFSRouting() {}
6+
BFSRouting::~BFSRouting() = default;
67

7-
void BFSRouting::route_flow(NocRouterId src_router_id, NocRouterId sink_router_id, std::vector<NocLinkId>& flow_route, const NocStorage& noc_model) {
8+
void BFSRouting::route_flow(NocRouterId src_router_id,
9+
NocRouterId sink_router_id,
10+
NocTrafficFlowId /*traffic_flow_id*/,
11+
std::vector<NocLinkId>& flow_route,
12+
const NocStorage& noc_model) {
813
const NocRouter& src_router = noc_model.get_single_noc_router(src_router_id);
914
const NocRouter& sink_router = noc_model.get_single_noc_router(sink_router_id);
1015

@@ -15,7 +20,7 @@ void BFSRouting::route_flow(NocRouterId src_router_id, NocRouterId sink_router_i
1520
* Keeps track of which routers have been reached already
1621
* while traversing the NoC. This variable will help prevent
1722
* the algorithm from getting stuck visiting routers that
18-
* jave already been visited.
23+
* have already been visited.
1924
*
2025
*/
2126
std::unordered_set<NocRouterId> visited_routers;
@@ -46,7 +51,7 @@ void BFSRouting::route_flow(NocRouterId src_router_id, NocRouterId sink_router_i
4651
}
4752

4853
// Explore the NoC from the starting router and try to find a path to the destination router
49-
// We finish searching when there are no more routers to process or we found the destination router
54+
// We finish searching when there are no more routers to process, or we found the destination router
5055
while (!routers_to_process.empty() && !found_sink_router) {
5156
// get the next router to process
5257
NocRouterId processing_router = routers_to_process.front();
@@ -88,13 +93,17 @@ void BFSRouting::route_flow(NocRouterId src_router_id, NocRouterId sink_router_i
8893
generate_route(sink_router_id, flow_route, noc_model, router_parent_link);
8994
} else {
9095
// a path was not found so throw an error to the user
91-
VPR_FATAL_ERROR(VPR_ERROR_OTHER, "No route could be found from starting router with id:'%d' and the destination router with id:'%d' using the breadth-first search routing algorithm.", src_router.get_router_user_id(), sink_router.get_router_user_id());
96+
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
97+
"No route could be found from starting router with id:'%d' and the destination router with id:'%d' using the breadth-first search routing algorithm.",
98+
src_router.get_router_user_id(),
99+
sink_router.get_router_user_id());
92100
}
93-
94-
return;
95101
}
96102

97-
void BFSRouting::generate_route(NocRouterId start_router_id, std::vector<NocLinkId>& flow_route, const NocStorage& noc_model, const std::unordered_map<NocRouterId, NocLinkId>& router_parent_link) {
103+
void BFSRouting::generate_route(NocRouterId start_router_id,
104+
std::vector<NocLinkId>& flow_route,
105+
const NocStorage& noc_model,
106+
const std::unordered_map<NocRouterId, NocLinkId>& router_parent_link) {
98107
// The intermediate router being visited while tracing the path back from the destination router to the starting router in the flow.
99108
// Initially this is set to the router at the end of the path (destination router)
100109
NocRouterId curr_intermediate_router = start_router_id;
@@ -104,11 +113,11 @@ void BFSRouting::generate_route(NocRouterId start_router_id, std::vector<NocLink
104113
auto route_beginning = flow_route.begin();
105114

106115
// get the parent link of the start router
107-
std::unordered_map<NocRouterId, NocLinkId>::const_iterator curr_intermediate_router_parent_link = router_parent_link.find(curr_intermediate_router);
116+
auto curr_intermediate_router_parent_link = router_parent_link.find(curr_intermediate_router);
108117

109-
// keep tracking baackwards from each router in the path until a router doesn't have a parent link (this means we reached the starting router in the flow)
118+
// keep tracking backwards from each router in the path until a router doesn't have a parent link (this means we reached the starting router in the flow)
110119
while (curr_intermediate_router_parent_link != router_parent_link.end()) {
111-
// add the parent link to the path. Since we are tracing backwards we need to store the links in fron of the last link.
120+
// add the parent link to the path. Since we are tracing backwards we need to store the links in front of the last link.
112121
flow_route.emplace(route_beginning, curr_intermediate_router_parent_link->second);
113122

114123
// update the reference to the beginning of the route
@@ -119,6 +128,4 @@ void BFSRouting::generate_route(NocRouterId start_router_id, std::vector<NocLink
119128
// now get the parent of the router we moved to
120129
curr_intermediate_router_parent_link = router_parent_link.find(curr_intermediate_router);
121130
}
122-
123-
return;
124131
}

0 commit comments

Comments
 (0)