@@ -24,14 +24,17 @@ void LookaheadProfiler::record(int iteration,
2424 auto & route_ctx = g_vpr_ctx.routing ();
2525
2626 // If csv file hasn't been opened, open it and write out column headers
27- if (is_empty) {
28- lookahead_verifier_csv.open (" lookahead_verifier_info.csv" , std::ios::out);
29-
30- if (!lookahead_verifier_csv.is_open ()) {
31- VTR_LOG_ERROR (" Could not open lookahead_verifier_info.csv" , " error" );
27+ if (is_empty_) {
28+ lookahead_verifier_csv_.open (" lookahead_verifier_info.csv" , std::ios::out);
29+
30+ if (!lookahead_verifier_csv_.is_open ()) {
31+ VTR_LOG_ERROR (" Could not open lookahead_verifier_info.csv" );
32+ throw vtr::VtrError (" Could not open lookahead_verifier_info.csv" ,
33+ " lookahead_profiler.cpp" ,
34+ 32 );
3235 }
3336
34- lookahead_verifier_csv
37+ lookahead_verifier_csv_
3538 << " iteration no."
3639 << " ,source node"
3740 << " ,sink node"
@@ -53,13 +56,21 @@ void LookaheadProfiler::record(int iteration,
5356 << " ,predicted delay"
5457 << " ,predicted congestion"
5558 << " ,criticality"
56- << std::endl ;
59+ << " \n " ;
5760
58- is_empty = false ;
61+ is_empty_ = false ;
5962 }
6063
61- if (!lookahead_verifier_csv.is_open ())
64+ if (!lookahead_verifier_csv_.is_open ()) {
65+ if (toggle_warn_) {
66+ VTR_LOG_WARN (" lookahead_verifier_info.csv is not open" );
67+ toggle_warn_ = false ;
68+ }
69+
6270 return ;
71+ } else {
72+ toggle_warn_ = true ;
73+ }
6374
6475 // The default value in RouteTree::update_from_heap() is -1; only calls which descend from route_net()
6576 // pass in an iteration value, which is the only context in which we want to profile.
@@ -73,51 +84,52 @@ void LookaheadProfiler::record(int iteration,
7384
7485 /* Get sink node attributes (atom block name, atom block model, cluster type, tile dimensions) */
7586
76- if (atom_block_names .find (sink_inode) == atom_block_names .end ()) {
87+ if (atom_block_names_ .find (sink_inode) == atom_block_names_ .end ()) {
7788 if (net_id != ParentNetId::INVALID () && target_net_pin_index != OPEN) {
78- atom_block_names [sink_inode] = net_list.block_name (net_list.net_pin_block (net_id, target_net_pin_index));
89+ atom_block_names_ [sink_inode] = net_list.block_name (net_list.net_pin_block (net_id, target_net_pin_index));
7990
80- AtomBlockId atom_block_id = g_vpr_ctx.atom ().nlist .find_block (atom_block_names [sink_inode]);
81- atom_block_models [sink_inode] = g_vpr_ctx.atom ().nlist .block_model (atom_block_id)->name ;
91+ AtomBlockId atom_block_id = g_vpr_ctx.atom ().nlist .find_block (atom_block_names_ [sink_inode]);
92+ atom_block_models_ [sink_inode] = g_vpr_ctx.atom ().nlist .block_model (atom_block_id)->name ;
8293
8394 ClusterBlockId cluster_block_id = atom_to_cluster (atom_block_id);
8495
85- cluster_block_types [sink_inode] = g_vpr_ctx.clustering ().clb_nlist .block_type (cluster_block_id)->name ;
96+ cluster_block_types_ [sink_inode] = g_vpr_ctx.clustering ().clb_nlist .block_type (cluster_block_id)->name ;
8697
8798 auto tile_type = physical_tile_type (cluster_block_id);
88- tile_dimensions [sink_inode] = std::pair (std::to_string (tile_type->width ), std::to_string (tile_type->height ));
99+ tile_dimensions_ [sink_inode] = std::pair (std::to_string (tile_type->width ), std::to_string (tile_type->height ));
89100 } else {
90- atom_block_names [sink_inode] = " --" ;
91- atom_block_models [sink_inode] = " --" ;
92- cluster_block_types [sink_inode] = " --" ;
93- tile_dimensions [sink_inode] = {" --" , " --" };
101+ atom_block_names_ [sink_inode] = " --" ;
102+ atom_block_models_ [sink_inode] = " --" ;
103+ cluster_block_types_ [sink_inode] = " --" ;
104+ tile_dimensions_ [sink_inode] = {" --" , " --" };
94105 }
95106 }
96107
97- VTR_ASSERT_SAFE (atom_block_models .find (sink_inode) != atom_block_models .end ());
98- VTR_ASSERT_SAFE (cluster_block_types .find (sink_inode) != cluster_block_types .end ());
99- VTR_ASSERT_SAFE (tile_dimensions .find (sink_inode) != tile_dimensions .end ());
108+ VTR_ASSERT_SAFE (atom_block_models_ .find (sink_inode) != atom_block_models_ .end ());
109+ VTR_ASSERT_SAFE (cluster_block_types_ .find (sink_inode) != cluster_block_types_ .end ());
110+ VTR_ASSERT_SAFE (tile_dimensions_ .find (sink_inode) != tile_dimensions_ .end ());
100111
101- std::string block_name = atom_block_names [sink_inode];
102- std::string atom_block_model = atom_block_models [sink_inode];
103- std::string cluster_block_type = cluster_block_types [sink_inode];
104- auto [tile_width, tile_height] = tile_dimensions [sink_inode];
112+ const std::string& block_name = atom_block_names_ [sink_inode];
113+ const std::string& atom_block_model = atom_block_models_ [sink_inode];
114+ const std::string& cluster_block_type = cluster_block_types_ [sink_inode];
115+ const auto & [tile_width, tile_height] = tile_dimensions_ [sink_inode];
105116
106117 /* Iterate through the given path and record information for each node */
107- for (size_t i = 2 ; i < branch_inodes.size (); ++i ) { // Distance one node away is always 0. (IPIN->SINK)
108- RRNodeId curr_inode = branch_inodes[i ];
118+ for (size_t nodes_from_sink = 2 ; nodes_from_sink < branch_inodes.size (); ++nodes_from_sink ) { // Distance one node away is always 0. (IPIN->SINK)
119+ RRNodeId curr_inode = branch_inodes[nodes_from_sink ];
109120
110- // Get backwards path cost, delay, and congestion from sink node
111- t_rr_node_route_inf sink_node_info = route_ctx.rr_node_route_inf [sink_inode];
112- float total_backward_cost = sink_node_info.backward_path_cost ;
113- float total_backward_delay = sink_node_info.backward_path_delay ;
114- float total_backward_congestion = sink_node_info.backward_path_congestion ;
121+ // Calculate the actual cost, delay, and congestion from the current node to the sink.
122+ const t_rr_node_route_inf& curr_node_info = route_ctx.rr_node_route_inf [curr_inode];
123+ const t_rr_node_route_inf& sink_node_info = route_ctx.rr_node_route_inf [sink_inode];
115124
116- // Get backwards path cost, delay, and congestion from current node
117- t_rr_node_route_inf curr_node_info = route_ctx.rr_node_route_inf [curr_inode];
118- float current_backward_cost = curr_node_info.backward_path_cost ;
119- float current_backward_delay = curr_node_info.backward_path_delay ;
120- float current_backward_congestion = curr_node_info.backward_path_congestion ;
125+ float actual_cost = sink_node_info.backward_path_cost - curr_node_info.backward_path_cost ;
126+ float actual_delay = sink_node_info.backward_path_delay - curr_node_info.backward_path_delay ;
127+ float actual_congestion = sink_node_info.backward_path_congestion - curr_node_info.backward_path_congestion ;
128+
129+ // Get the cost, delay, and congestion estimates made by the lookahead.
130+ // Note: lookahead_cost = lookahead_delay * criticality + lookahead_congestion * (1. - criticality)
131+ float lookahead_cost = router_lookahead.get_expected_cost (curr_inode, sink_inode, cost_params, 0.0 );
132+ auto [lookahead_delay, lookahead_congestion] = router_lookahead.get_expected_delay_and_cong_ignore_criticality (curr_inode, sink_inode, cost_params, 0.0 );
121133
122134 // Get the difference in the coordinates in the current and sink nodes.
123135 // Note: we are not using util::get_xy_deltas() because this always gives positive values
@@ -129,45 +141,35 @@ void LookaheadProfiler::record(int iteration,
129141 int delta_x = to_x - from_x;
130142 int delta_y = to_y - from_y;
131143
132- // Calculate the actual cost, delay, and congestion from the current node to the sink.
133- float actual_cost = total_backward_cost - current_backward_cost;
134- float actual_delay = total_backward_delay - current_backward_delay;
135- float actual_congestion = total_backward_congestion - current_backward_congestion;
136-
137- // Get the cost, delay, and congestion estimates made by the lookahead.
138- // Note: lookahead_cost = lookahead_delay * criticality + lookahead_congestion * (1. - criticality)
139- float lookahead_cost = router_lookahead.get_expected_cost (curr_inode, sink_inode, cost_params, 0.0 );
140- auto [lookahead_delay, lookahead_congestion] = router_lookahead.get_expected_delay_and_cong (curr_inode, sink_inode, cost_params, 0.0 );
141-
142144 // Get the current node's type and length
143145 std::string node_type_str = rr_graph.node_type_string (curr_inode);
144- std::string node_length = (node_type_str == " CHANX" || node_type_str == " CHANX " )
146+ std::string node_length = (node_type_str == " CHANX" || node_type_str == " CHANY " )
145147 ? std::to_string (rr_graph.node_length (curr_inode))
146148 : " --" ;
147149
148150 /* Write out all info */
149151
150- lookahead_verifier_csv << iteration << " ," ; // iteration no.
151- lookahead_verifier_csv << source_inode << " ," ; // source node
152- lookahead_verifier_csv << sink_inode << " ," ; // sink node
153- lookahead_verifier_csv << block_name << " ," ; // sink block name
154- lookahead_verifier_csv << atom_block_model << " ," ; // sink atom block model
155- lookahead_verifier_csv << cluster_block_type << " ," ; // sink cluster block type
156- lookahead_verifier_csv << tile_height << " ," ; // sink cluster tile height
157- lookahead_verifier_csv << tile_width << " ," ; // sink cluster tile width
158- lookahead_verifier_csv << curr_inode << " ," ; // current node
159- lookahead_verifier_csv << node_type_str << " ," ; // node type
160- lookahead_verifier_csv << node_length << " ," ; // node length
161- lookahead_verifier_csv << i << " ," ; // num. nodes from sink
162- lookahead_verifier_csv << delta_x << " ," ; // delta x
163- lookahead_verifier_csv << delta_y << " ," ; // delta y
164- lookahead_verifier_csv << actual_cost << " ," ; // actual cost
165- lookahead_verifier_csv << actual_delay << " ," ; // actual delay
166- lookahead_verifier_csv << actual_congestion << " ," ; // actual congestion
167- lookahead_verifier_csv << lookahead_cost << " ," ; // predicted cost
168- lookahead_verifier_csv << lookahead_delay << " ," ; // predicted delay
169- lookahead_verifier_csv << lookahead_congestion << " ," ; // predicted congestion
170- lookahead_verifier_csv << cost_params.criticality ; // criticality
171- lookahead_verifier_csv << std::endl ;
152+ lookahead_verifier_csv_ << iteration << " ," ; // iteration no.
153+ lookahead_verifier_csv_ << source_inode << " ," ; // source node
154+ lookahead_verifier_csv_ << sink_inode << " ," ; // sink node
155+ lookahead_verifier_csv_ << block_name << " ," ; // sink block name
156+ lookahead_verifier_csv_ << atom_block_model << " ," ; // sink atom block model
157+ lookahead_verifier_csv_ << cluster_block_type << " ," ; // sink cluster block type
158+ lookahead_verifier_csv_ << tile_height << " ," ; // sink cluster tile height
159+ lookahead_verifier_csv_ << tile_width << " ," ; // sink cluster tile width
160+ lookahead_verifier_csv_ << curr_inode << " ," ; // current node
161+ lookahead_verifier_csv_ << node_type_str << " ," ; // node type
162+ lookahead_verifier_csv_ << node_length << " ," ; // node length
163+ lookahead_verifier_csv_ << nodes_from_sink << " ," ; // num. nodes from sink
164+ lookahead_verifier_csv_ << delta_x << " ," ; // delta x
165+ lookahead_verifier_csv_ << delta_y << " ," ; // delta y
166+ lookahead_verifier_csv_ << actual_cost << " ," ; // actual cost
167+ lookahead_verifier_csv_ << actual_delay << " ," ; // actual delay
168+ lookahead_verifier_csv_ << actual_congestion << " ," ; // actual congestion
169+ lookahead_verifier_csv_ << lookahead_cost << " ," ; // predicted cost
170+ lookahead_verifier_csv_ << lookahead_delay << " ," ; // predicted delay
171+ lookahead_verifier_csv_ << lookahead_congestion << " ," ; // predicted congestion
172+ lookahead_verifier_csv_ << cost_params.criticality ; // criticality
173+ lookahead_verifier_csv_ << " \n " ;
172174 }
173175}
0 commit comments