1
1
#include " ../src/global.hh"
2
- #include " ../src/graph.hh"
3
2
#include " ../src/io.hh"
3
+ #include " ../src/timing.hh"
4
+ #include " ../src/thunder_io.hh"
4
5
#include < cstdio>
5
6
#include < fstream>
6
7
#include < iostream>
8
+ #include " argparse/argparse.hpp"
7
9
8
10
using namespace std ;
9
11
@@ -37,6 +39,73 @@ bool process_args(int argc, char *argv[], ::vector<::string> &args) {
37
39
return pd_aware;
38
40
}
39
41
42
+ void setup_argparse (argparse::ArgumentParser &parser) {
43
+ parser.add_argument (" --pd" ).help (" If set, will use PD-oriented routing strategy" ).default_value (
44
+ false ).implicit_value (true );
45
+ parser.add_argument (" -p" , " --packed" ).help (" Packed netlist file" ).required ();
46
+ parser.add_argument (" -P" , " --placement" ).help (" Placement file" ).required ();
47
+ parser.add_argument (" -o" , " -r" , " --route" ).help (" Routing result" ).required ();
48
+ parser.add_argument (" -g" ).help (" Routing graph information" ).required ().append ();
49
+ parser.add_argument (" -l" , " --layout" ).help (" Chip layout" ).default_value (" " );
50
+ parser.add_argument (" -t" , " --retime" ).help (
51
+ " Set timing file. Default is none, which turns off re-timing. Set to default to use the default timing information" ).default_value (
52
+ " none" );
53
+ }
54
+
55
+ struct RouterInput {
56
+ bool pd = false ;
57
+ std::string packed_filename;
58
+ std::string placement_filename;
59
+ std::string output_file;
60
+ std::vector<std::pair<uint32_t , std::string>> graph_info;
61
+ std::string timing_file;
62
+ std::string chip_layout;
63
+ };
64
+
65
+ std::optional<RouterInput> parse_args (int argc, char *argv[]) {
66
+ argparse::ArgumentParser parser (" CGRA Router" );
67
+ setup_argparse (parser);
68
+
69
+ try {
70
+ parser.parse_args (argc, argv);
71
+ }
72
+ catch (const std::runtime_error &err) {
73
+ std::cerr << err.what () << std::endl;
74
+ std::cerr << parser;
75
+ return std::nullopt;
76
+ }
77
+ // fill out information
78
+ RouterInput result;
79
+ result.pd = parser[" --pd" ] == true ;
80
+ result.packed_filename = parser.get <std::string>(" -p" );
81
+ result.placement_filename = parser.get <std::string>(" -P" );
82
+ result.output_file = parser.get <std::string>(" -o" );
83
+ auto values = parser.get <std::vector<std::string>>(" -g" );
84
+ if (values.size () % 2 != 0 ) {
85
+ std::cerr << " Incorrect number of graph args" << std::endl;
86
+ std::cerr << parser;
87
+ return std::nullopt;
88
+ }
89
+ for (auto i = 0u ; i < values.size (); i += 2 ) {
90
+ auto bit_width = std::stoul (values[i * 2 ]);
91
+ auto path = values[i * 2 + 1 ];
92
+ result.graph_info .emplace_back (std::make_pair (bit_width, path));
93
+ }
94
+
95
+ auto timing_file = parser.get <std::string>(" -t" );
96
+ if (timing_file != " none" ) {
97
+ auto layout = parser.get <std::string>(" -l" );
98
+ if (layout.empty ()) {
99
+ std::cerr << " When re-timing is specified, layout file is required" << std::endl;
100
+ std::cerr << parser << std::endl;
101
+ return std::nullopt;
102
+ }
103
+ result.chip_layout = layout;
104
+ }
105
+
106
+ return result;
107
+ }
108
+
40
109
void
41
110
adjust_node_cost_power_domain (RoutingGraph *graph,
42
111
const std::map<std::string, std::pair<int , int >> &placement_result) {
@@ -52,30 +121,43 @@ adjust_node_cost_power_domain(RoutingGraph *graph,
52
121
auto switchbox = tile.switchbox ;
53
122
for (uint32_t i = 0 ; i < 4 ; i++) {
54
123
auto sbs = switchbox.get_sbs_by_side (SwitchBoxSide (i));
55
- for (const auto & sb: sbs) {
124
+ for (const auto & sb: sbs) {
56
125
sb->delay = power_domain_cost;
57
126
}
58
127
}
59
128
}
60
129
}
61
130
}
62
131
132
+ void retime_router (Router &router, const RouterInput &args) {
133
+ const auto &timing_file = args.timing_file ;
134
+ if (timing_file == " none" ) {
135
+ return ;
136
+ } else if (timing_file == " default" ) {
137
+ auto const &layout_file = args.chip_layout ;
138
+ auto layout = load_layout (layout_file);
139
+ TimingAnalysis timing (router);
140
+ timing.set_timing_cost (get_default_timing_info ());
141
+ timing.retime ();
142
+ } else {
143
+ throw std::runtime_error (" Timing file not implemented" );
144
+ }
145
+ }
146
+
63
147
int main (int argc, char *argv[]) {
64
- if (argc < 6 ) {
65
- print_help (argv[ 0 ]);
148
+ auto args_opt = parse_args (argc, argv);
149
+ if (!args_opt) {
66
150
return EXIT_FAILURE;
67
151
}
68
- ::vector<::string> args;
69
- bool power_domain = process_args (argc, argv, args);
152
+ auto const &args = *args_opt;
70
153
71
- string packed_filename = args[1 ];
72
- string placement_filename = args[2 ];
73
- // reassign the size
74
- argc = args.size ();
154
+ bool power_domain = args.pd ;
155
+ const auto &packed_filename = args.packed_filename ;
156
+ auto const &placement_filename = args.placement_filename ;
75
157
76
158
auto [netlist, track_mode] = load_netlist (packed_filename);
77
159
auto placement = load_placement (placement_filename);
78
- auto output_file = args[argc - 1 ] ;
160
+ auto output_file = args. output_file ;
79
161
80
162
// delete the old file if exists
81
163
if (exists (output_file)) {
@@ -85,9 +167,7 @@ int main(int argc, char *argv[]) {
85
167
}
86
168
}
87
169
88
- for (int arg_index = 3 ; arg_index < argc - 1 ; arg_index += 2 ) {
89
- auto bit_width = static_cast <uint32_t >(stoi (args[arg_index]));
90
- string graph_filename = args[arg_index + 1 ];
170
+ for (auto const &[bit_width, graph_filename]: args.graph_info ) {
91
171
cout << " using bit_width " << bit_width << endl;
92
172
auto graph = load_routing_graph (graph_filename);
93
173
@@ -113,6 +193,8 @@ int main(int argc, char *argv[]) {
113
193
114
194
r.route ();
115
195
196
+ retime_router (r, args);
197
+
116
198
dump_routing_result (r, output_file);
117
199
}
118
200
return EXIT_SUCCESS;
0 commit comments