1+ //
2+ // Created by shrevena on 08/06/24.
3+ //
4+
5+ #include < sstream>
6+ #include " lookahead_profiler.h"
7+ #include " vtr_error.h"
8+ #include " vtr_log.h"
9+ #include " globals.h"
10+ #include " router_lookahead_map_utils.h"
11+ #include " vpr_utils.h"
12+ #include " re_cluster_util.h"
13+
14+ LookaheadProfiler lookahead_profiler = LookaheadProfiler();
15+
16+ LookaheadProfiler::LookaheadProfiler () {
17+ lookahead_verifier_csv.open (" lookahead_verifier_info.csv" , std::ios::out);
18+
19+ if (!lookahead_verifier_csv.is_open ()) {
20+ VTR_LOG_ERROR (" Could not open lookahead_verifier_info.csv" , " error" );
21+ }
22+
23+ lookahead_verifier_csv
24+ << " iteration no."
25+ << " ,source node"
26+ << " ,sink node"
27+ << " ,sink block name"
28+ << " ,sink atom block model"
29+ << " ,sink cluster block type"
30+ << " ,sink cluster tile height"
31+ << " ,sink cluster tile width"
32+ << " ,current node"
33+ << " ,node type"
34+ << " ,node length"
35+ << " ,num. nodes from sink"
36+ << " ,delta x"
37+ << " ,delta y"
38+ << " ,actual cost"
39+ << " ,actual delay"
40+ << " ,actual congestion"
41+ << " ,predicted cost"
42+ << " ,predicted delay"
43+ << " ,predicted congestion"
44+ << " ,criticality"
45+ << std::endl;
46+ }
47+
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,
54+ const t_conn_cost_params& cost_params,
55+ const RouterLookahead& router_lookahead,
56+ const ParentNetId& net_id,
57+ const Netlist<>& net_list) {
58+ auto & device_ctx = g_vpr_ctx.device ();
59+ const auto & rr_graph = device_ctx.rr_graph ;
60+ auto & route_ctx = g_vpr_ctx.routing ();
61+
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 ;
65+
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 ;
70+
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);
73+
74+ int delta_x = to_x - from_x;
75+ int delta_y = to_y - from_y;
76+
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;
80+
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 );
85+
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 = " --" ;
91+
92+ if (net_id != ParentNetId::INVALID () && target_net_pin_index != OPEN) {
93+ block_name = net_list.block_name (net_list.net_pin_block (net_id, target_net_pin_index));
94+
95+ AtomBlockId atom_block_id = g_vpr_ctx.atom ().nlist .find_block (block_name);
96+ atom_block_model = g_vpr_ctx.atom ().nlist .block_model (atom_block_id)->name ;
97+
98+ ClusterBlockId cluster_block_id = atom_to_cluster (atom_block_id);
99+
100+ cluster_block_type = g_vpr_ctx.clustering ().clb_nlist .block_type (cluster_block_id)->name ;
101+
102+ auto tile_type = physical_tile_type (cluster_block_id);
103+ tile_height = std::to_string (tile_type->height );
104+ tile_width = std::to_string (tile_type->width );
105+ }
106+
107+ auto node_type = rr_graph.node_type (curr_inode);
108+ std::string node_type_str;
109+ std::string node_length;
110+
111+ switch (node_type) {
112+ case SOURCE:
113+ node_type_str = " SOURCE" ;
114+ node_length = " --" ;
115+ break ;
116+ case SINK:
117+ node_type_str = " SINK" ;
118+ node_length = " --" ;
119+ break ;
120+ case IPIN:
121+ node_type_str = " IPIN" ;
122+ node_length = " --" ;
123+ break ;
124+ case OPIN:
125+ node_type_str = " OPIN" ;
126+ node_length = " --" ;
127+ break ;
128+ case CHANX:
129+ node_type_str = " CHANX" ;
130+ node_length = std::to_string (rr_graph.node_length (curr_inode));
131+ break ;
132+ case CHANY:
133+ node_type_str = " CHANY" ;
134+ node_length = std::to_string (rr_graph.node_length (curr_inode));
135+ break ;
136+ default :
137+ node_type_str = " --" ;
138+ node_length = " --" ;
139+ break ;
140+ }
141+
142+ lookahead_verifier_csv << iteration << " ," ; // iteration no.
143+ lookahead_verifier_csv << source_inode << " ," ; // source node
144+ lookahead_verifier_csv << sink_inode << " ," ; // sink node
145+ lookahead_verifier_csv << block_name << " ," ; // sink block name
146+ lookahead_verifier_csv << atom_block_model << " ," ; // sink atom block model
147+ lookahead_verifier_csv << cluster_block_type << " ," ; // sink cluster block type
148+ lookahead_verifier_csv << tile_height << " ," ; // sink cluster tile height
149+ lookahead_verifier_csv << tile_width << " ," ; // sink cluster tile width
150+ lookahead_verifier_csv << curr_inode << " ," ; // current node
151+ lookahead_verifier_csv << node_type_str << " ," ; // node type
152+ lookahead_verifier_csv << node_length << " ," ; // node length
153+ lookahead_verifier_csv << nodes_from_sink << " ," ; // num. nodes from sink
154+ lookahead_verifier_csv << delta_x << " ," ; // delta x
155+ lookahead_verifier_csv << delta_y << " ," ; // delta y
156+ lookahead_verifier_csv << djikstra_cost << " ," ; // actual cost
157+ lookahead_verifier_csv << djikstra_delay << " ," ; // actual delay
158+ lookahead_verifier_csv << djikstra_congestion << " ," ; // actual congestion
159+ lookahead_verifier_csv << lookahead_cost << " ," ; // predicted cost
160+ lookahead_verifier_csv << lookahead_delay << " ," ; // predicted delay
161+ lookahead_verifier_csv << lookahead_congestion << " ," ; // predicted congestion
162+ lookahead_verifier_csv << cost_params.criticality ; // criticality
163+ lookahead_verifier_csv << std::endl;
164+ }
0 commit comments