Skip to content

Commit 4e13cb5

Browse files
committed
[vpr][base] remove update_rr_switch_id and update validate_traceback to validate_and_update_traceback
1 parent d10f7dd commit 4e13cb5

File tree

5 files changed

+55
-111
lines changed

5 files changed

+55
-111
lines changed

vpr/src/base/SetupVPR.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ static void SetupRouterOpts(const t_options& Options, t_router_opts* RouterOpts)
517517
RouterOpts->custom_3d_sb_fanin_fanout = Options.custom_3d_sb_fanin_fanout;
518518
RouterOpts->with_timing_analysis = Options.timing_analysis;
519519

520-
RouterOpts->verify_route_file_switch_id = Options.verify_route_file_switch_id ;
520+
RouterOpts->verify_route_file_switch_id = Options.verify_route_file_switch_id;
521521

522522
RouterOpts->generate_router_lookahead_report = Options.generate_router_lookahead_report.value();
523523
}

vpr/src/base/old_traceback.cpp

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#include "route_common.h"
77

88
#include <vector>
9+
#include <stack>
910

1011
std::pair<t_trace*, t_trace*> traceback_from_route_tree_recurr(t_trace* head, t_trace* tail, const RouteTreeNode& node);
11-
bool validate_traceback_recurr(t_trace* trace, std::set<int>& seen_rr_nodes);
1212
void free_trace_data(t_trace* tptr);
1313

1414
/** Build a route tree from a traceback */
@@ -109,7 +109,7 @@ t_trace* TracebackCompat::traceback_from_route_tree(const RouteTree& tree) {
109109

110110
std::tie(head, tail) = traceback_from_route_tree_recurr(nullptr, nullptr, tree.root());
111111

112-
VTR_ASSERT(validate_traceback(head));
112+
VTR_ASSERT(validate_and_update_traceback(head));
113113

114114
return head;
115115
}
@@ -141,70 +141,64 @@ void print_traceback(const t_trace* trace) {
141141
VTR_LOG("\n");
142142
}
143143

144-
bool validate_traceback(t_trace* trace) {
145-
std::set<int> seen_rr_nodes;
146-
147-
return validate_traceback_recurr(trace, seen_rr_nodes);
148-
}
149-
150-
bool validate_traceback_recurr(t_trace* trace, std::set<int>& seen_rr_nodes) {
144+
bool validate_and_update_traceback(t_trace* trace, bool verify_switch_id /* = true */) {
151145
if (!trace) {
152146
return true;
153147
}
154148

155-
seen_rr_nodes.insert(trace->index);
149+
std::set<int> seen_rr_nodes;
150+
std::stack<t_trace*> trace_stack;
156151

157-
t_trace* next = trace->next;
152+
while (!trace_stack.empty()) {
153+
trace = trace_stack.top();
154+
trace_stack.pop();
155+
seen_rr_nodes.insert(trace->index);
156+
t_trace* next = trace->next;
158157

159-
if (next) {
160-
if (trace->iswitch == OPEN) { //End of a branch
158+
if (next == nullptr) {
159+
continue;
160+
}
161161

162+
if (trace->iswitch == OPEN) { //End of a branch
162163
//Verify that the next element (branch point) has been already seen in the traceback so far
163164
if (!seen_rr_nodes.count(next->index)) {
164165
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback branch point %d not found", next->index);
165-
} else {
166-
//Recurse along the new branch
167-
return validate_traceback_recurr(next, seen_rr_nodes);
168166
}
169167
} else { //Midway along branch
170-
171168
//Check there is an edge connecting trace and next
172-
173-
auto& device_ctx = g_vpr_ctx.device();
174-
const auto& rr_graph = device_ctx.rr_graph;
169+
const auto& rr_graph = g_vpr_ctx.device().rr_graph;
175170
bool found = false;
176171
for (t_edge_size iedge = 0; iedge < rr_graph.num_edges(RRNodeId(trace->index)); ++iedge) {
177172
int to_node = size_t(rr_graph.edge_sink_node(RRNodeId(trace->index), iedge));
178-
179173
if (to_node == next->index) {
180174
found = true;
181-
182-
//Verify that the switch matches
183175
int rr_iswitch = rr_graph.edge_switch(RRNodeId(trace->index), iedge);
184-
if (trace->iswitch != rr_iswitch) {
185-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback mismatched switch type: traceback %d rr_graph %d (RR nodes %d -> %d)\n",
186-
trace->iswitch, rr_iswitch,
187-
trace->index, to_node);
176+
if (verify_switch_id) {
177+
// Verify that the switch matches
178+
if (trace->iswitch != rr_iswitch) {
179+
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback mismatched switch type: traceback %d rr_graph %d (RR nodes %d -> %d)\n",
180+
trace->iswitch, rr_iswitch,
181+
trace->index, to_node);
182+
}
183+
} else {
184+
// Update the switch ID in the traceback to match the RR Graph
185+
trace->iswitch = rr_iswitch;
188186
}
189187
break;
190188
}
191189
}
192-
193190
if (!found) {
194191
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback no RR edge between RR nodes %d -> %d\n", trace->index, next->index);
195192
}
196-
197-
//Recurse
198-
return validate_traceback_recurr(next, seen_rr_nodes);
199193
}
194+
// Recurse
195+
trace_stack.push(next);
200196
}
201197

202-
VTR_ASSERT(!next);
203-
return true; //End of traceback
198+
return true;
204199
}
205200

206-
t_trace*
207-
alloc_trace_data() {
201+
t_trace* alloc_trace_data() {
208202
return (t_trace*)malloc(sizeof(t_trace));
209203
}
210204

vpr/src/base/old_traceback.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,14 @@ class TracebackCompat {
4646
t_trace* alloc_trace_data();
4747
void free_traceback(t_trace* trace);
4848
void print_traceback(const t_trace* trace);
49-
bool validate_traceback(t_trace* trace);
49+
50+
/**
51+
* @brief Validate the routing traceback if verify_switch_id is true, otherwise update the
52+
* switch IDs in the traceback to match the RR Graph.
53+
*
54+
* @param trace Pointer to the head of the routing trace of the net to validate and update.
55+
* @param verify_switch_id Whether to verify the switch IDs in the traceback.
56+
*
57+
* @return true if the traceback is valid, false otherwise.
58+
*/
59+
bool validate_and_update_traceback(t_trace* trace, bool verify_switch_id = true);

vpr/src/base/read_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
16371637
.default_value("on")
16381638
.show_in(argparse::ShowIn::HELP_ONLY);
16391639

1640-
gen_grp.add_argument<bool, ParseOnOff>(args.verify_route_file_switch_id , "--verify_route_file_switch_id")
1640+
gen_grp.add_argument<bool, ParseOnOff>(args.verify_route_file_switch_id, "--verify_route_file_switch_id")
16411641
.help(
16421642
"Verify that the switch IDs in the routing file are consistent with those in the RR Graph. "
16431643
"Set this to false when switch IDs in the routing file may differ from the RR Graph. "

vpr/src/base/read_route.cpp

Lines changed: 13 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@
4848
* @param fp The file stream to read from.
4949
* @param filename The name of the file to read from.
5050
* @param lineno The line number currently being processed.
51-
* @param verify_route_file_switch_id Whether to verify the RR switch IDs in the routing file.
51+
* @param verify_route_file_switch_id Whether to verify the RR switch IDs in the routing file.
5252
* @param is_flat Whether flat-router is enabled.
5353
*/
5454
static void process_route(const Netlist<>& net_list,
5555
std::ifstream& fp,
5656
const char* filename,
5757
int& lineno,
58-
bool verify_route_file_switch_id ,
58+
bool verify_route_file_switch_id,
5959
bool is_flat);
6060

6161
/**
@@ -65,13 +65,13 @@ static void process_route(const Netlist<>& net_list,
6565
* @param fp The file stream to read from.
6666
* @param inet The net ID to process.
6767
* @param filename The name of the file to read from.
68-
* @param verify_route_file_switch_id Whether to verify the RR switch IDs in the routing file.
68+
* @param verify_route_file_switch_id Whether to verify the RR switch IDs in the routing file.
6969
*/
7070
static void process_nodes(const Netlist<>& net_list,
7171
std::ifstream& fp,
7272
ClusterNetId inet,
7373
const char* filename,
74-
bool verify_route_file_switch_id ,
74+
bool verify_route_file_switch_id,
7575
int& lineno);
7676

7777
/**
@@ -84,7 +84,7 @@ static void process_nodes(const Netlist<>& net_list,
8484
* @param input_tokens The tokens of the net.
8585
* @param filename The name of the file to read from.
8686
* @param lineno The line number currently being processed.
87-
* @param verify_route_file_switch_id Whether to verify the RR switch IDs in the routing file.
87+
* @param verify_route_file_switch_id Whether to verify the RR switch IDs in the routing file.
8888
* @param is_flat Whether flat-router is enabled.
8989
*/
9090
static void process_nets(const Netlist<>& net_list,
@@ -94,16 +94,9 @@ static void process_nets(const Netlist<>& net_list,
9494
std::vector<std::string> input_tokens,
9595
const char* filename,
9696
int& lineno,
97-
bool verify_route_file_switch_id ,
97+
bool verify_route_file_switch_id,
9898
bool is_flat);
9999

100-
/**
101-
* @brief Update the switch IDs in the routing trace to match the RR Graph.
102-
*
103-
* @param trace Pointer to the head of the routing trace of the net to update.
104-
*/
105-
static void update_rr_switch_id(t_trace* trace);
106-
107100
/**
108101
* @brief This function goes through all the blocks in a global net and verify
109102
* it with the clustered netlist and the placement
@@ -203,7 +196,7 @@ bool read_route(const char* route_file,
203196
}
204197

205198
/* Read in every net */
206-
process_route(router_net_list, fp, route_file, lineno, router_opts.verify_route_file_switch_id , is_flat);
199+
process_route(router_net_list, fp, route_file, lineno, router_opts.verify_route_file_switch_id, is_flat);
207200

208201
fp.close();
209202

@@ -239,7 +232,7 @@ static void process_route(const Netlist<>& net_list,
239232
std::ifstream& fp,
240233
const char* filename,
241234
int& lineno,
242-
bool verify_route_file_switch_id ,
235+
bool verify_route_file_switch_id,
243236
bool is_flat) {
244237
std::string input;
245238
std::vector<std::string> tokens;
@@ -260,7 +253,7 @@ static void process_route(const Netlist<>& net_list,
260253
tokens,
261254
filename,
262255
lineno,
263-
verify_route_file_switch_id ,
256+
verify_route_file_switch_id,
264257
is_flat);
265258
}
266259
}
@@ -275,7 +268,7 @@ static void process_nets(const Netlist<>& net_list,
275268
std::vector<std::string> input_tokens,
276269
const char* filename,
277270
int& lineno,
278-
bool verify_route_file_switch_id ,
271+
bool verify_route_file_switch_id,
279272
bool is_flat) {
280273
if (input_tokens.size() > 3 && input_tokens[3] == "global"
281274
&& input_tokens[4] == "net" && input_tokens[5] == "connecting:") {
@@ -313,7 +306,7 @@ static void process_nets(const Netlist<>& net_list,
313306
fp,
314307
inet,
315308
filename,
316-
verify_route_file_switch_id ,
309+
verify_route_file_switch_id,
317310
lineno);
318311
}
319312
input_tokens.clear();
@@ -323,7 +316,7 @@ static void process_nodes(const Netlist<>& net_list,
323316
std::ifstream& fp,
324317
ClusterNetId inet,
325318
const char* filename,
326-
bool verify_route_file_switch_id ,
319+
bool verify_route_file_switch_id,
327320
int& lineno) {
328321
/* Not a global net. Goes through every node and add it into trace.head*/
329322
auto& device_ctx = g_vpr_ctx.mutable_device();
@@ -516,66 +509,13 @@ static void process_nodes(const Netlist<>& net_list,
516509
oldpos = fp.tellg();
517510
}
518511

519-
if (verify_route_file_switch_id ) {
520-
VTR_ASSERT(validate_traceback(head_ptr));
521-
} else {
522-
update_rr_switch_id(head_ptr);
523-
}
512+
VTR_ASSERT(validate_and_update_traceback(head_ptr, verify_route_file_switch_id));
524513

525514
/* Convert to route_tree after reading */
526515
route_ctx.route_trees[inet] = TracebackCompat::traceback_to_route_tree(head_ptr);
527516
free_traceback(head_ptr);
528517
}
529518

530-
static void update_rr_switch_id(t_trace* trace) {
531-
if (trace == nullptr) {
532-
return;
533-
}
534-
535-
std::set<int> seen_rr_nodes;
536-
537-
std::stack<t_trace*> trace_stack;
538-
trace_stack.push(trace);
539-
540-
541-
while (!trace_stack.empty()) {
542-
trace = trace_stack.top();
543-
trace_stack.pop();
544-
seen_rr_nodes.insert(trace->index);
545-
t_trace* next = trace->next;
546-
547-
if (next == nullptr) {
548-
continue;
549-
}
550-
551-
if (trace->iswitch == OPEN) { // End of a branch
552-
// Verify that the next element (branch point) has been already seen in the traceback so far
553-
if (!seen_rr_nodes.count(next->index)) {
554-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback branch point %d not found", next->index);
555-
}
556-
} else { // Midway along branch
557-
// Check there is an edge connecting trace and next
558-
const auto& rr_graph = g_vpr_ctx.device().rr_graph;
559-
bool found = false;
560-
for (t_edge_size iedge = 0; iedge < rr_graph.num_edges(RRNodeId(trace->index)); ++iedge) {
561-
int to_node = size_t(rr_graph.edge_sink_node(RRNodeId(trace->index), iedge));
562-
if (to_node == next->index) {
563-
found = true;
564-
565-
// Verify that the switch matches
566-
int rr_iswitch = rr_graph.edge_switch(RRNodeId(trace->index), iedge);
567-
trace->iswitch = rr_iswitch;
568-
break;
569-
}
570-
}
571-
if (!found) {
572-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback no RR edge between RR nodes %d -> %d\n", trace->index, next->index);
573-
}
574-
}
575-
trace_stack.push(next);
576-
}
577-
}
578-
579519
static void process_global_blocks(const Netlist<>& net_list, std::ifstream& fp, ClusterNetId inet, const char* filename, int& lineno, bool is_flat) {
580520
std::string block, bnum_str;
581521
int layer_num, x, y;

0 commit comments

Comments
 (0)