1111#include  " vpr_utils.h" 
1212#include  " re_cluster_util.h" 
1313
14- LookaheadProfiler lookahead_profiler = LookaheadProfiler();
15- 
1614LookaheadProfiler::LookaheadProfiler () {
1715    lookahead_verifier_csv.open (" lookahead_verifier_info.csv"  , std::ios::out);
1816
@@ -45,136 +43,104 @@ LookaheadProfiler::LookaheadProfiler() {
4543        << std::endl;
4644}
4745
48- void  LookaheadProfiler::record (const  int  iteration,
49-                                const  int  target_net_pin_index,
50-                                const  RRNodeId source_inode,
51-                                const  RRNodeId sink_inode,
52-                                const  RRNodeId curr_inode,
53-                                const  size_t  nodes_from_sink,
46+ void  LookaheadProfiler::record (int  iteration,
47+                                int  target_net_pin_index,
5448                               const  t_conn_cost_params& cost_params,
5549                               const  RouterLookahead& router_lookahead,
5650                               const  ParentNetId& net_id,
57-                                const  Netlist<>& net_list) {
51+                                const  Netlist<>& net_list,
52+                                std::vector<RRNodeId> branch_inodes) {
5853    auto & device_ctx = g_vpr_ctx.device ();
5954    const  auto & rr_graph = device_ctx.rr_graph ;
6055    auto & route_ctx = g_vpr_ctx.routing ();
6156
62-     float  total_backward_cost = route_ctx.rr_node_route_inf [sink_inode].backward_path_cost ;
63-     float  total_backward_delay = route_ctx.rr_node_route_inf [sink_inode].backward_path_delay ;
64-     float  total_backward_congestion = route_ctx.rr_node_route_inf [sink_inode].backward_path_congestion ;
57+     if  (iteration < 1 )
58+         return ;
6559
66-     auto  current_node = route_ctx. rr_node_route_inf [curr_inode]; 
67-     float  current_backward_cost = current_node. backward_path_cost ;
68-     float  current_backward_delay = current_node. backward_path_delay ;
69-     float  current_backward_congestion = current_node. backward_path_congestion ;
60+     for  ( size_t  i =  2 ; i < branch_inodes. size (); ++i) {  /*  Distance one node away is always 0.0 (IPIN->SINK)  */ 
61+         RRNodeId source_inode = branch_inodes. back () ;
62+         RRNodeId sink_inode = branch_inodes. front () ;
63+         RRNodeId curr_inode = branch_inodes[i] ;
7064
71-     auto  [from_x, from_y] = util::get_adjusted_rr_position (curr_inode);
72-     auto  [to_x, to_y] = util::get_adjusted_rr_position (sink_inode);
65+         float  total_backward_cost = route_ctx.rr_node_route_inf [sink_inode].backward_path_cost ;
66+         float  total_backward_delay = route_ctx.rr_node_route_inf [sink_inode].backward_path_delay ;
67+         float  total_backward_congestion = route_ctx.rr_node_route_inf [sink_inode].backward_path_congestion ;
7368
74-     int  delta_x = to_x - from_x;
75-     int  delta_y = to_y - from_y;
69+         auto  current_node = route_ctx.rr_node_route_inf [curr_inode];
70+         float  current_backward_cost = current_node.backward_path_cost ;
71+         float  current_backward_delay = current_node.backward_path_delay ;
72+         float  current_backward_congestion = current_node.backward_path_congestion ;
7673
77-     float  djikstra_cost = total_backward_cost - current_backward_cost;
78-     float  djikstra_delay = total_backward_delay - current_backward_delay;
79-     float  djikstra_congestion = total_backward_congestion - current_backward_congestion;
74+         auto  [from_x, from_y] = util::get_adjusted_rr_position (curr_inode);
75+         auto  [to_x, to_y] = util::get_adjusted_rr_position (sink_inode);
8076
81-     float  lookahead_cost = router_lookahead.get_expected_cost (curr_inode, sink_inode, cost_params,
82-                                                               0.0 );
83-     float  lookahead_delay, lookahead_congestion;
84-     std::tie (lookahead_delay, lookahead_congestion) = router_lookahead.get_expected_delay_and_cong (curr_inode, sink_inode, cost_params, 0.0 , true );
77+         int  delta_x = to_x - from_x;
78+         int  delta_y = to_y - from_y;
8579
86-     std::string block_name = " --"  ;
87-     std::string atom_block_model = " --"  ;
88-     std::string cluster_block_type = " --"  ;
89-     std::string tile_height = " --"  ;
90-     std::string tile_width = " --"  ;
80+         float  djikstra_cost = total_backward_cost - current_backward_cost;
81+         float  djikstra_delay = total_backward_delay - current_backward_delay;
82+         float  djikstra_congestion = total_backward_congestion - current_backward_congestion;
9183
92-     if  (atom_block_names.find (sink_inode) != atom_block_names.end ()) {
93-         VTR_ASSERT_SAFE (atom_block_models.find (sink_inode) != atom_block_models.end ());
94-         VTR_ASSERT_SAFE (cluster_block_types.find (sink_inode) != cluster_block_types.end ());
95-         VTR_ASSERT_SAFE (tile_dimensions.find (sink_inode) != tile_dimensions.end ());
84+         float  lookahead_cost = router_lookahead.get_expected_cost (curr_inode, sink_inode, cost_params, 0.0 );
85+         auto  [lookahead_delay, lookahead_congestion] = router_lookahead.get_expected_delay_and_cong (curr_inode, sink_inode, cost_params, 0.0 );
9686
97-         block_name = atom_block_names[sink_inode];
98-         atom_block_model = atom_block_models[sink_inode];
99-         cluster_block_type = cluster_block_types[sink_inode];
100-         std::tie (tile_width, tile_height) = tile_dimensions[sink_inode];
101-     } else  {
102-         if  (net_id != ParentNetId::INVALID () && target_net_pin_index != OPEN) {
103-             block_name = net_list.block_name (net_list.net_pin_block (net_id, target_net_pin_index));
87+         if  (atom_block_names.find (sink_inode) == atom_block_names.end ()) {
88+             if  (net_id != ParentNetId::INVALID () && target_net_pin_index != OPEN) {
89+                 atom_block_names[sink_inode] = net_list.block_name (net_list.net_pin_block (net_id, target_net_pin_index));
10490
105-             AtomBlockId atom_block_id = g_vpr_ctx.atom ().nlist .find_block (block_name );
106-             atom_block_model  = 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 ;
10793
108-             ClusterBlockId cluster_block_id = atom_to_cluster (atom_block_id);
94+                  ClusterBlockId cluster_block_id = atom_to_cluster (atom_block_id);
10995
110-             cluster_block_type  = 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 ;
11197
112-             auto  tile_type = physical_tile_type (cluster_block_id);
113-             tile_height = std::to_string (tile_type->height );
114-             tile_width = std::to_string (tile_type->width );
98+                 auto  tile_type = physical_tile_type (cluster_block_id);
99+                 tile_dimensions[sink_inode] = std::pair (std::to_string (tile_type->width ), std::to_string (tile_type->height ));
100+             } else  {
101+                 atom_block_names[sink_inode] = " --"  ;
102+                 atom_block_models[sink_inode] = " --"  ;
103+                 cluster_block_types[sink_inode] = " --"  ;
104+                 tile_dimensions[sink_inode] = {" --"  , " --"  };
105+             }
115106        }
116107
117-         atom_block_names[sink_inode] = block_name;
118-         atom_block_models[sink_inode] = atom_block_model;
119-         cluster_block_types[sink_inode] = cluster_block_type;
120-         tile_dimensions[sink_inode] = {tile_width, tile_height};
121-     }
108+         VTR_ASSERT_SAFE (atom_block_names.find (sink_inode) != atom_block_names.end ());
109+         VTR_ASSERT_SAFE (atom_block_models.find (sink_inode) != atom_block_models.end ());
110+         VTR_ASSERT_SAFE (cluster_block_types.find (sink_inode) != cluster_block_types.end ());
111+         VTR_ASSERT_SAFE (tile_dimensions.find (sink_inode) != tile_dimensions.end ());
122112
123-     auto  node_type = rr_graph.node_type (curr_inode);
124-     std::string node_type_str;
125-     std::string node_length;
126- 
127-     switch  (node_type) {
128-         case  SOURCE:
129-             node_type_str = " SOURCE"  ;
130-             node_length = " --"  ;
131-             break ;
132-         case  SINK:
133-             node_type_str = " SINK"  ;
134-             node_length = " --"  ;
135-             break ;
136-         case  IPIN:
137-             node_type_str = " IPIN"  ;
138-             node_length = " --"  ;
139-             break ;
140-         case  OPIN:
141-             node_type_str = " OPIN"  ;
142-             node_length = " --"  ;
143-             break ;
144-         case  CHANX:
145-             node_type_str = " CHANX"  ;
146-             node_length = std::to_string (rr_graph.node_length (curr_inode));
147-             break ;
148-         case  CHANY:
149-             node_type_str = " CHANY"  ;
150-             node_length = std::to_string (rr_graph.node_length (curr_inode));
151-             break ;
152-         default :
153-             node_type_str = " --"  ;
154-             node_length = " --"  ;
155-             break ;
113+         std::string block_name = atom_block_names[sink_inode];
114+         std::string atom_block_model = atom_block_models[sink_inode];
115+         std::string cluster_block_type = cluster_block_types[sink_inode];
116+         auto  [tile_width, tile_height] = tile_dimensions[sink_inode];
117+ 
118+         std::string node_type_str = rr_graph.node_type_string (curr_inode);
119+         std::string node_length = (node_type_str == " CHANX"   || node_type_str == " CHANX"  )
120+                                       ? std::to_string (rr_graph.node_length (curr_inode))
121+                                       : " --"  ;
122+ 
123+         lookahead_verifier_csv << iteration << " ,"  ;            //  iteration no.
124+         lookahead_verifier_csv << source_inode << " ,"  ;         //  source node
125+         lookahead_verifier_csv << sink_inode << " ,"  ;           //  sink node
126+         lookahead_verifier_csv << block_name << " ,"  ;           //  sink block name
127+         lookahead_verifier_csv << atom_block_model << " ,"  ;     //  sink atom block model
128+         lookahead_verifier_csv << cluster_block_type << " ,"  ;   //  sink cluster block type
129+         lookahead_verifier_csv << tile_height << " ,"  ;          //  sink cluster tile height
130+         lookahead_verifier_csv << tile_width << " ,"  ;           //  sink cluster tile width
131+         lookahead_verifier_csv << curr_inode << " ,"  ;           //  current node
132+         lookahead_verifier_csv << node_type_str << " ,"  ;        //  node type
133+         lookahead_verifier_csv << node_length << " ,"  ;          //  node length
134+         lookahead_verifier_csv << i << " ,"  ;                    //  num. nodes from sink
135+         lookahead_verifier_csv << delta_x << " ,"  ;              //  delta x
136+         lookahead_verifier_csv << delta_y << " ,"  ;              //  delta y
137+         lookahead_verifier_csv << djikstra_cost << " ,"  ;        //  actual cost
138+         lookahead_verifier_csv << djikstra_delay << " ,"  ;       //  actual delay
139+         lookahead_verifier_csv << djikstra_congestion << " ,"  ;  //  actual congestion
140+         lookahead_verifier_csv << lookahead_cost << " ,"  ;       //  predicted cost
141+         lookahead_verifier_csv << lookahead_delay << " ,"  ;      //  predicted delay
142+         lookahead_verifier_csv << lookahead_congestion << " ,"  ; //  predicted congestion
143+         lookahead_verifier_csv << cost_params.criticality ;     //  criticality
144+         lookahead_verifier_csv << std::endl;
156145    }
157- 
158-     lookahead_verifier_csv << iteration << " ,"  ;            //  iteration no.
159-     lookahead_verifier_csv << source_inode << " ,"  ;         //  source node
160-     lookahead_verifier_csv << sink_inode << " ,"  ;           //  sink node
161-     lookahead_verifier_csv << block_name << " ,"  ;           //  sink block name
162-     lookahead_verifier_csv << atom_block_model << " ,"  ;     //  sink atom block model
163-     lookahead_verifier_csv << cluster_block_type << " ,"  ;   //  sink cluster block type
164-     lookahead_verifier_csv << tile_height << " ,"  ;          //  sink cluster tile height
165-     lookahead_verifier_csv << tile_width << " ,"  ;           //  sink cluster tile width
166-     lookahead_verifier_csv << curr_inode << " ,"  ;           //  current node
167-     lookahead_verifier_csv << node_type_str << " ,"  ;        //  node type
168-     lookahead_verifier_csv << node_length << " ,"  ;          //  node length
169-     lookahead_verifier_csv << nodes_from_sink << " ,"  ;      //  num. nodes from sink
170-     lookahead_verifier_csv << delta_x << " ,"  ;              //  delta x
171-     lookahead_verifier_csv << delta_y << " ,"  ;              //  delta y
172-     lookahead_verifier_csv << djikstra_cost << " ,"  ;        //  actual cost
173-     lookahead_verifier_csv << djikstra_delay << " ,"  ;       //  actual delay
174-     lookahead_verifier_csv << djikstra_congestion << " ,"  ;  //  actual congestion
175-     lookahead_verifier_csv << lookahead_cost << " ,"  ;       //  predicted cost
176-     lookahead_verifier_csv << lookahead_delay << " ,"  ;      //  predicted delay
177-     lookahead_verifier_csv << lookahead_congestion << " ,"  ; //  predicted congestion
178-     lookahead_verifier_csv << cost_params.criticality ;     //  criticality
179-     lookahead_verifier_csv << std::endl;
180146}
0 commit comments