Skip to content

Commit 438c4c8

Browse files
committed
[vpr][base] fix formatting in read_route.cpp and simplify the logic in update_rr_switch_id
1 parent 4d9b098 commit 438c4c8

File tree

2 files changed

+141
-57
lines changed

2 files changed

+141
-57
lines changed

vpr/src/base/read_options.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,11 +1639,11 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
16391639

16401640
gen_grp.add_argument<bool, ParseOnOff>(args.verify_rr_switch_id, "--verify_rr_switch_id")
16411641
.help(
1642-
"Verify that the switch IDs in the routing file are consistent with those in the RR Graph."
1643-
"Set this to false when switch IDs in the routing file may differ from the RR Graph."
1644-
"For example, when analyzing different timing corners using the same netlist, placement, and routing files,"
1645-
"the RR switch IDs in the RR Graph may differ due to changes in delays."
1646-
"In such cases, set this option to false so that the switch IDs from the RR Graph are used, and those in the routing file are ignored.")
1642+
"Verify that the switch IDs in the routing file are consistent with those in the RR Graph. "
1643+
"Set this to false when switch IDs in the routing file may differ from the RR Graph. "
1644+
"For example, when analyzing different timing corners using the same netlist, placement, and routing files, "
1645+
"the RR switch IDs in the RR Graph may differ due to changes in delays. "
1646+
"In such cases, set this option to false so that the switch IDs from the RR Graph are used, and those in the routing file are ignored.\n")
16471647
.default_value("on")
16481648
.show_in(argparse::ShowIn::HELP_ONLY);
16491649

vpr/src/base/read_route.cpp

Lines changed: 136 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,53 @@
3939
#include "old_traceback.h"
4040

4141
/*************Functions local to this module*************/
42+
43+
/**
44+
* @brief Read the routing file and create the routing tree for each net.
45+
*
46+
* @param net_list The netlist to process.
47+
* @param fp The file stream to read from.
48+
* @param filename The name of the file to read from.
49+
* @param lineno The line number currently being processed.
50+
* @param verify_rr_switch_id Whether to verify the RR switch IDs in the routing file.
51+
* @param is_flat Whether flat-router is enabled.
52+
*/
4253
static void process_route(const Netlist<>& net_list,
4354
std::ifstream& fp,
4455
const char* filename,
4556
int& lineno,
4657
bool verify_rr_switch_id,
4758
bool is_flat);
4859

60+
/**
61+
* @brief Create the routing tree for the net at the given line number in the routing file.
62+
*
63+
* @param net_list The netlist to process.
64+
* @param fp The file stream to read from.
65+
* @param inet The net ID to process.
66+
* @param filename The name of the file to read from.
67+
* @param verify_rr_switch_id Whether to verify the RR switch IDs in the routing file.
68+
*/
4969
static void process_nodes(const Netlist<>& net_list,
5070
std::ifstream& fp,
5171
ClusterNetId inet,
5272
const char* filename,
5373
bool verify_rr_switch_id,
5474
int& lineno);
5575

76+
/**
77+
* @brief Process the net at the given line number in the routing file.
78+
*
79+
* @param net_list The netlist to process.
80+
* @param fp The file stream to read from.
81+
* @param inet The net ID to process.
82+
* @param name The name of the net.
83+
* @param input_tokens The tokens of the net.
84+
* @param filename The name of the file to read from.
85+
* @param lineno The line number currently being processed.
86+
* @param verify_rr_switch_id Whether to verify the RR switch IDs in the routing file.
87+
* @param is_flat Whether flat-router is enabled.
88+
*/
5689
static void process_nets(const Netlist<>& net_list,
5790
std::ifstream& fp,
5891
ClusterNetId inet,
@@ -63,14 +96,49 @@ static void process_nets(const Netlist<>& net_list,
6396
bool verify_rr_switch_id,
6497
bool is_flat);
6598

66-
static void update_rr_switch_id(t_trace* trace, std::set<int>& seen_rr_nodes);
99+
/**
100+
* @brief Update the switch IDs in the routing trace to match the RR Graph.
101+
*
102+
* @note This function is called recursively to update the switch IDs in the routing trace.
103+
*
104+
* @param trace Pointer to the head of the routing trace of the net to update.
105+
* @param seen_rr_nodes A set of seen RR nodes to avoid duplicate updates.
106+
*/
107+
static void update_rr_switch_id(t_trace* trace,
108+
std::set<int>& seen_rr_nodes);
109+
110+
/**
111+
* @brief This function goes through all the blocks in a global net and verify
112+
* it with the clustered netlist and the placement
113+
*/
114+
static void process_global_blocks(const Netlist<>& net_list,
115+
std::ifstream& fp,
116+
ClusterNetId inet,
117+
const char* filename,
118+
int& lineno,
119+
bool is_flat);
120+
121+
static void format_coordinates(int& layer_num,
122+
int& x,
123+
int& y,
124+
std::string coord,
125+
ClusterNetId net,
126+
const char* filename,
127+
const int lineno);
128+
129+
static void format_pin_info(std::string& pb_name,
130+
std::string& port_name,
131+
int& pb_pin_num,
132+
const std::string& input);
67133

68-
static void process_global_blocks(const Netlist<>& net_list, std::ifstream& fp, ClusterNetId inet, const char* filename, int& lineno, bool is_flat);
69-
static void format_coordinates(int& layer_num, int& x, int& y, std::string coord, ClusterNetId net, const char* filename, const int lineno);
70-
static void format_pin_info(std::string& pb_name, std::string& port_name, int& pb_pin_num, const std::string& input);
71134
static std::string format_name(std::string name);
72-
static bool check_rr_graph_connectivity(RRNodeId prev_node, RRNodeId node);
73-
void print_route(const Netlist<>& net_list, FILE* fp, bool is_flat);
135+
136+
static bool check_rr_graph_connectivity(RRNodeId prev_node,
137+
RRNodeId node);
138+
139+
void print_route(const Netlist<>& net_list,
140+
FILE* fp,
141+
bool is_flat);
74142

75143
/*************Global Functions****************************/
76144

@@ -80,7 +148,10 @@ void print_route(const Netlist<>& net_list, FILE* fp, bool is_flat);
80148
* Perform a series of verification tests to ensure the netlist,
81149
* placement, and routing files match
82150
*/
83-
bool read_route(const char* route_file, const t_router_opts& router_opts, bool verify_file_digests, bool is_flat) {
151+
bool read_route(const char* route_file,
152+
const t_router_opts& router_opts,
153+
bool verify_file_digests,
154+
bool is_flat) {
84155
auto& device_ctx = g_vpr_ctx.mutable_device();
85156
auto& place_ctx = g_vpr_ctx.placement();
86157
bool flat_router = router_opts.flat_routing;
@@ -167,7 +238,6 @@ bool read_route(const char* route_file, const t_router_opts& router_opts, bool v
167238
return is_feasible;
168239
}
169240

170-
///@brief Walks through every net and add the routing appropriately
171241
static void process_route(const Netlist<>& net_list,
172242
std::ifstream& fp,
173243
const char* filename,
@@ -186,15 +256,30 @@ static void process_route(const Netlist<>& net_list,
186256
continue; //Skip commented lines
187257
} else if (tokens[0] == "Net") {
188258
ClusterNetId inet(atoi(tokens[1].c_str()));
189-
process_nets(net_list, fp, inet, tokens[2], tokens, filename, lineno, verify_rr_switch_id, is_flat);
259+
process_nets(net_list,
260+
fp,
261+
inet,
262+
tokens[2],
263+
tokens,
264+
filename,
265+
lineno,
266+
verify_rr_switch_id,
267+
is_flat);
190268
}
191269
}
192270

193271
tokens.clear();
194272
}
195273

196-
///@brief Check if the net is global or not, and process appropriately
197-
static void process_nets(const Netlist<>& net_list, std::ifstream& fp, ClusterNetId inet, std::string name, std::vector<std::string> input_tokens, const char* filename, int& lineno, bool verify_rr_switch_id, bool is_flat) {
274+
static void process_nets(const Netlist<>& net_list,
275+
std::ifstream& fp,
276+
ClusterNetId inet,
277+
std::string name,
278+
std::vector<std::string> input_tokens,
279+
const char* filename,
280+
int& lineno,
281+
bool verify_rr_switch_id,
282+
bool is_flat) {
198283
if (input_tokens.size() > 3 && input_tokens[3] == "global"
199284
&& input_tokens[4] == "net" && input_tokens[5] == "connecting:") {
200285
/* Global net. Never routed. */
@@ -227,12 +312,22 @@ static void process_nets(const Netlist<>& net_list, std::ifstream& fp, ClusterNe
227312
name.c_str(), size_t(inet), net_list.net_name(inet).c_str());
228313
}
229314

230-
process_nodes(net_list, fp, inet, filename, verify_rr_switch_id, lineno);
315+
process_nodes(net_list,
316+
fp,
317+
inet,
318+
filename,
319+
verify_rr_switch_id,
320+
lineno);
231321
}
232322
input_tokens.clear();
233323
}
234324

235-
static void process_nodes(const Netlist<>& net_list, std::ifstream& fp, ClusterNetId inet, const char* filename, bool verify_rr_switch_id, int& lineno) {
325+
static void process_nodes(const Netlist<>& net_list,
326+
std::ifstream& fp,
327+
ClusterNetId inet,
328+
const char* filename,
329+
bool verify_rr_switch_id,
330+
int& lineno) {
236331
/* Not a global net. Goes through every node and add it into trace.head*/
237332
auto& device_ctx = g_vpr_ctx.mutable_device();
238333
const auto& rr_graph = device_ctx.rr_graph;
@@ -437,58 +532,47 @@ static void process_nodes(const Netlist<>& net_list, std::ifstream& fp, ClusterN
437532
}
438533

439534
static void update_rr_switch_id(t_trace* trace, std::set<int>& seen_rr_nodes) {
440-
if (!trace) {
535+
if (trace == nullptr) {
441536
return;
442537
}
443538

444539
seen_rr_nodes.insert(trace->index);
445540

446541
t_trace* next = trace->next;
447542

448-
if (next) {
449-
if (trace->iswitch == OPEN) { //End of a branch
543+
if (next == nullptr) {
544+
return;
545+
}
450546

451-
//Verify that the next element (branch point) has been already seen in the traceback so far
452-
if (!seen_rr_nodes.count(next->index)) {
453-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback branch point %d not found", next->index);
454-
} else {
455-
//Recurse along the new branch
456-
update_rr_switch_id(next, seen_rr_nodes);
457-
return;
458-
}
459-
} else { //Midway along branch
460-
461-
//Check there is an edge connecting trace and next
462-
463-
auto& device_ctx = g_vpr_ctx.device();
464-
const auto& rr_graph = device_ctx.rr_graph;
465-
bool found = false;
466-
for (t_edge_size iedge = 0; iedge < rr_graph.num_edges(RRNodeId(trace->index)); ++iedge) {
467-
int to_node = size_t(rr_graph.edge_sink_node(RRNodeId(trace->index), iedge));
468-
if (to_node == next->index) {
469-
found = true;
470-
471-
//Verify that the switch matches
472-
int rr_iswitch = rr_graph.edge_switch(RRNodeId(trace->index), iedge);
473-
trace->iswitch = rr_iswitch;
474-
break;
475-
}
476-
}
477-
if (!found) {
478-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback no RR edge between RR nodes %d -> %d\n", trace->index, next->index);
547+
if (trace->iswitch == OPEN) { //End of a branch
548+
//Verify that the next element (branch point) has been already seen in the traceback so far
549+
if (!seen_rr_nodes.count(next->index)) {
550+
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback branch point %d not found", next->index);
551+
}
552+
} else { //Midway along branch
553+
//Check there is an edge connecting trace and next
554+
auto& device_ctx = g_vpr_ctx.device();
555+
const auto& rr_graph = device_ctx.rr_graph;
556+
bool found = false;
557+
for (t_edge_size iedge = 0; iedge < rr_graph.num_edges(RRNodeId(trace->index)); ++iedge) {
558+
int to_node = size_t(rr_graph.edge_sink_node(RRNodeId(trace->index), iedge));
559+
if (to_node == next->index) {
560+
found = true;
561+
562+
//Verify that the switch matches
563+
int rr_iswitch = rr_graph.edge_switch(RRNodeId(trace->index), iedge);
564+
trace->iswitch = rr_iswitch;
565+
break;
479566
}
480-
//Recurse
481-
update_rr_switch_id(next, seen_rr_nodes);
482-
return;
567+
}
568+
if (!found) {
569+
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback no RR edge between RR nodes %d -> %d\n", trace->index, next->index);
483570
}
484571
}
485-
VTR_ASSERT(!next);
572+
//Recurse
573+
update_rr_switch_id(next, seen_rr_nodes);
486574
}
487575

488-
/**
489-
* @brief This function goes through all the blocks in a global net and verify
490-
* it with the clustered netlist and the placement
491-
*/
492576
static void process_global_blocks(const Netlist<>& net_list, std::ifstream& fp, ClusterNetId inet, const char* filename, int& lineno, bool is_flat) {
493577
std::string block, bnum_str;
494578
int layer_num, x, y;

0 commit comments

Comments
 (0)