33//
44
55#include < sstream>
6- #include " lookahead_profiler.h"
7- #include " vtr_error.h"
8- #include " vtr_log.h"
6+
97#include " globals.h"
8+ #include " lookahead_profiler.h"
9+ #include " re_cluster_util.h"
1010#include " router_lookahead_map_utils.h"
1111#include " vpr_utils.h"
12- #include " re_cluster_util.h"
13-
14- LookaheadProfiler::LookaheadProfiler ()
15- : is_empty(true ) {
16- lookahead_verifier_csv.open (" lookahead_verifier_info.csv" , std::ios::out);
17-
18- if (!lookahead_verifier_csv.is_open ()) {
19- VTR_LOG_WARN (" Could not open lookahead_verifier_info.csv" );
20- return ;
21- }
22- }
12+ #include " vtr_error.h"
13+ #include " vtr_log.h"
2314
2415void LookaheadProfiler::record (int iteration,
2516 int target_net_pin_index,
@@ -32,10 +23,14 @@ void LookaheadProfiler::record(int iteration,
3223 const auto & rr_graph = device_ctx.rr_graph ;
3324 auto & route_ctx = g_vpr_ctx.routing ();
3425
35- if (!lookahead_verifier_csv.is_open ())
36- return ;
37-
26+ // If csv file hasn't been opened, open it and write out column headers
3827 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" );
32+ }
33+
3934 lookahead_verifier_csv
4035 << " iteration no."
4136 << " ,source node"
@@ -63,72 +58,96 @@ void LookaheadProfiler::record(int iteration,
6358 is_empty = false ;
6459 }
6560
61+ if (!lookahead_verifier_csv.is_open ())
62+ return ;
63+
64+ // The default value in RouteTree::update_from_heap() is -1; only calls which descend from route_net()
65+ // pass in an iteration value, which is the only context in which we want to profile.
6666 if (iteration < 1 )
6767 return ;
6868
69- for (size_t i = 2 ; i < branch_inodes.size (); ++i) { /* Distance one node away is always 0.0 (IPIN->SINK) */
70- RRNodeId source_inode = branch_inodes.back ();
71- RRNodeId sink_inode = branch_inodes.front ();
72- RRNodeId curr_inode = branch_inodes[i];
69+ RRNodeId source_inode = branch_inodes.back ();
70+ RRNodeId sink_inode = branch_inodes.front ();
7371
74- float total_backward_cost = route_ctx.rr_node_route_inf [sink_inode].backward_path_cost ;
75- float total_backward_delay = route_ctx.rr_node_route_inf [sink_inode].backward_path_delay ;
76- float total_backward_congestion = route_ctx.rr_node_route_inf [sink_inode].backward_path_congestion ;
72+ VTR_ASSERT (rr_graph.node_type (source_inode) == SOURCE);
73+ VTR_ASSERT (rr_graph.node_type (sink_inode) == SINK);
7774
78- auto current_node = route_ctx.rr_node_route_inf [curr_inode];
79- float current_backward_cost = current_node.backward_path_cost ;
80- float current_backward_delay = current_node.backward_path_delay ;
81- float current_backward_congestion = current_node.backward_path_congestion ;
75+ /* Get sink node attributes (atom block name, atom block model, cluster type, tile dimensions) */
8276
83- auto [from_x, from_y] = util::get_adjusted_rr_position (curr_inode);
84- auto [to_x, to_y] = util::get_adjusted_rr_position (sink_inode);
77+ if (atom_block_names.find (sink_inode) == atom_block_names.end ()) {
78+ if (net_id != ParentNetId::INVALID () && target_net_pin_index != OPEN) {
79+ atom_block_names[sink_inode] = net_list.block_name (net_list.net_pin_block (net_id, target_net_pin_index));
8580
86- int delta_x = to_x - from_x ;
87- int delta_y = to_y - from_y ;
81+ AtomBlockId atom_block_id = g_vpr_ctx. atom (). nlist . find_block (atom_block_names[sink_inode]) ;
82+ atom_block_models[sink_inode] = g_vpr_ctx. atom (). nlist . block_model (atom_block_id)-> name ;
8883
89- float djikstra_cost = total_backward_cost - current_backward_cost;
90- float djikstra_delay = total_backward_delay - current_backward_delay;
91- float djikstra_congestion = total_backward_congestion - current_backward_congestion;
84+ ClusterBlockId cluster_block_id = atom_to_cluster (atom_block_id);
9285
93- float lookahead_cost = router_lookahead.get_expected_cost (curr_inode, sink_inode, cost_params, 0.0 );
94- auto [lookahead_delay, lookahead_congestion] = router_lookahead.get_expected_delay_and_cong (curr_inode, sink_inode, cost_params, 0.0 );
86+ cluster_block_types[sink_inode] = g_vpr_ctx.clustering ().clb_nlist .block_type (cluster_block_id)->name ;
87+
88+ auto tile_type = physical_tile_type (cluster_block_id);
89+ tile_dimensions[sink_inode] = std::pair (std::to_string (tile_type->width ), std::to_string (tile_type->height ));
90+ } else {
91+ atom_block_names[sink_inode] = " --" ;
92+ atom_block_models[sink_inode] = " --" ;
93+ cluster_block_types[sink_inode] = " --" ;
94+ tile_dimensions[sink_inode] = {" --" , " --" };
95+ }
96+ }
9597
96- if (atom_block_names .find (sink_inode) == atom_block_names .end ()) {
97- if (net_id != ParentNetId::INVALID () && target_net_pin_index != OPEN) {
98- atom_block_names[ sink_inode] = net_list. block_name (net_list. net_pin_block (net_id, target_net_pin_index ));
98+ VTR_ASSERT_SAFE (atom_block_models .find (sink_inode) != atom_block_models .end ());
99+ VTR_ASSERT_SAFE (cluster_block_types. find (sink_inode) != cluster_block_types. end ());
100+ VTR_ASSERT_SAFE (tile_dimensions. find ( sink_inode) != tile_dimensions. end ( ));
99101
100- AtomBlockId atom_block_id = g_vpr_ctx.atom ().nlist .find_block (atom_block_names[sink_inode]);
101- atom_block_models[sink_inode] = g_vpr_ctx.atom ().nlist .block_model (atom_block_id)->name ;
102+ std::string block_name = atom_block_names[sink_inode];
103+ std::string atom_block_model = atom_block_models[sink_inode];
104+ std::string cluster_block_type = cluster_block_types[sink_inode];
105+ auto [tile_width, tile_height] = tile_dimensions[sink_inode];
102106
103- ClusterBlockId cluster_block_id = atom_to_cluster (atom_block_id);
107+ /* Iterate through the given path and record information for each node */
108+ for (size_t i = 2 ; i < branch_inodes.size (); ++i) { // Distance one node away is always 0. (IPIN->SINK)
109+ RRNodeId curr_inode = branch_inodes[i];
104110
105- cluster_block_types[sink_inode] = g_vpr_ctx.clustering ().clb_nlist .block_type (cluster_block_id)->name ;
111+ // Get backwards path cost, delay, and congestion from sink node
112+ t_rr_node_route_inf sink_node_info = route_ctx.rr_node_route_inf [sink_inode];
113+ float total_backward_cost = sink_node_info.backward_path_cost ;
114+ float total_backward_delay = sink_node_info.backward_path_delay ;
115+ float total_backward_congestion = sink_node_info.backward_path_congestion ;
116+
117+ // Get backwards path cost, delay, and congestion from current node
118+ t_rr_node_route_inf curr_node_info = route_ctx.rr_node_route_inf [curr_inode];
119+ float current_backward_cost = curr_node_info.backward_path_cost ;
120+ float current_backward_delay = curr_node_info.backward_path_delay ;
121+ float current_backward_congestion = curr_node_info.backward_path_congestion ;
122+
123+ // Get the difference in the coordinates in the current and sink nodes.
124+ // Note: we are not using util::get_xy_deltas() because this always gives positive values
125+ // unless the current node is the source node. Using util::get_adjusted_rr_position therefore
126+ // gives us more information.
127+ auto [from_x, from_y] = util::get_adjusted_rr_position (curr_inode);
128+ auto [to_x, to_y] = util::get_adjusted_rr_position (sink_inode);
106129
107- auto tile_type = physical_tile_type (cluster_block_id);
108- tile_dimensions[sink_inode] = std::pair (std::to_string (tile_type->width ), std::to_string (tile_type->height ));
109- } else {
110- atom_block_names[sink_inode] = " --" ;
111- atom_block_models[sink_inode] = " --" ;
112- cluster_block_types[sink_inode] = " --" ;
113- tile_dimensions[sink_inode] = {" --" , " --" };
114- }
115- }
130+ int delta_x = to_x - from_x;
131+ int delta_y = to_y - from_y;
116132
117- VTR_ASSERT_SAFE (atom_block_names. find (sink_inode) != atom_block_names. end ());
118- VTR_ASSERT_SAFE (atom_block_models. find (sink_inode) != atom_block_models. end ()) ;
119- VTR_ASSERT_SAFE (cluster_block_types. find (sink_inode) != cluster_block_types. end ()) ;
120- VTR_ASSERT_SAFE (tile_dimensions. find (sink_inode) != tile_dimensions. end ()) ;
133+ // Calculate the actual cost, delay, and congestion from the current node to the sink.
134+ float actual_cost = total_backward_cost - current_backward_cost ;
135+ float actual_delay = total_backward_delay - current_backward_delay ;
136+ float actual_congestion = total_backward_congestion - current_backward_congestion ;
121137
122- std::string block_name = atom_block_names[sink_inode];
123- std::string atom_block_model = atom_block_models[sink_inode];
124- std::string cluster_block_type = cluster_block_types[ sink_inode] ;
125- auto [tile_width, tile_height ] = tile_dimensions[ sink_inode] ;
138+ // Get the cost, delay, and congestion estimates made by the lookahead.
139+ // Note: lookahead_cost = lookahead_delay * criticality + lookahead_congestion * (1. - criticality)
140+ float lookahead_cost = router_lookahead. get_expected_cost (curr_inode, sink_inode, cost_params, 0.0 ) ;
141+ auto [lookahead_delay, lookahead_congestion ] = router_lookahead. get_expected_delay_and_cong (curr_inode, sink_inode, cost_params, 0.0 ) ;
126142
143+ // Get the current node's type and length
127144 std::string node_type_str = rr_graph.node_type_string (curr_inode);
128145 std::string node_length = (node_type_str == " CHANX" || node_type_str == " CHANX" )
129146 ? std::to_string (rr_graph.node_length (curr_inode))
130147 : " --" ;
131148
149+ /* Write out all info */
150+
132151 lookahead_verifier_csv << iteration << " ," ; // iteration no.
133152 lookahead_verifier_csv << source_inode << " ," ; // source node
134153 lookahead_verifier_csv << sink_inode << " ," ; // sink node
@@ -143,9 +162,9 @@ void LookaheadProfiler::record(int iteration,
143162 lookahead_verifier_csv << i << " ," ; // num. nodes from sink
144163 lookahead_verifier_csv << delta_x << " ," ; // delta x
145164 lookahead_verifier_csv << delta_y << " ," ; // delta y
146- lookahead_verifier_csv << djikstra_cost << " ," ; // actual cost
147- lookahead_verifier_csv << djikstra_delay << " ," ; // actual delay
148- lookahead_verifier_csv << djikstra_congestion << " ," ; // actual congestion
165+ lookahead_verifier_csv << actual_cost << " ," ; // actual cost
166+ lookahead_verifier_csv << actual_delay << " ," ; // actual delay
167+ lookahead_verifier_csv << actual_congestion << " ," ; // actual congestion
149168 lookahead_verifier_csv << lookahead_cost << " ," ; // predicted cost
150169 lookahead_verifier_csv << lookahead_delay << " ," ; // predicted delay
151170 lookahead_verifier_csv << lookahead_congestion << " ," ; // predicted congestion
0 commit comments