Skip to content

Commit 739029b

Browse files
author
Nathan Shreve
committed
Created lookahead profiler (restored changes from previous branch)
1 parent 62d1243 commit 739029b

28 files changed

+524
-194
lines changed

utils/route_diag/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static void profile_source(const Netlist<>& net_list,
209209
RRNodeId(sink_rr_node),
210210
router_opts,
211211
&delays[sink_x][sink_y],
212-
layer_num);
212+
layer_num, net_list);
213213
}
214214

215215
if (successfully_routed) {

vpr/src/base/vpr_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,8 @@ struct t_rr_node_route_inf {
17461746
float acc_cost;
17471747
float path_cost;
17481748
float backward_path_cost;
1749+
float backward_path_delay;
1750+
float backward_path_congestion;
17491751

17501752
public: //Accessors
17511753
short occ() const { return occ_; }

vpr/src/place/timing_place_lookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ static void add_delay_to_matrix(
441441
}
442442

443443
static void generic_compute_matrix_dijkstra_expansion(
444-
RouterDelayProfiler& /*route_profiler*/,
444+
RouterDelayProfiler& route_profiler,
445445
vtr::Matrix<std::vector<float>>& matrix,
446446
int layer_num,
447447
int source_x,
@@ -489,7 +489,7 @@ static void generic_compute_matrix_dijkstra_expansion(
489489
RRNodeId source_rr_node = device_ctx.rr_graph.node_lookup().find_node(layer_num, source_x, source_y, SOURCE, driver_ptc);
490490

491491
VTR_ASSERT(source_rr_node != RRNodeId::INVALID());
492-
auto delays = calculate_all_path_delays_from_rr_node(source_rr_node, router_opts, is_flat);
492+
auto delays = calculate_all_path_delays_from_rr_node(source_rr_node, router_opts, is_flat, route_profiler.get_net_list());
493493

494494
bool path_to_all_sinks = true;
495495
for (int sink_x = start_x; sink_x <= end_x; sink_x++) {

vpr/src/route/connection_router.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ t_heap* ConnectionRouter<Heap>::timing_driven_route_connection_from_heap(RRNodeI
230230
// This is then placed into the traceback so that the correct path is returned
231231
// TODO: This can be eliminated by modifying the actual traceback function in route_timing
232232
if (rcv_path_manager.is_enabled()) {
233-
rcv_path_manager.insert_backwards_path_into_traceback(cheapest->path_data, cheapest->cost, cheapest->backward_path_cost, route_ctx);
233+
rcv_path_manager.insert_backwards_path_into_traceback(cheapest->path_data, cheapest->cost, cheapest->backward_path_cost, cheapest->backward_path_delay, cheapest->backward_path_congestion, route_ctx);
234234
}
235235
VTR_LOGV_DEBUG(router_debug_, " Found target %8d (%s)\n", inode, describe_rr_node(device_ctx.rr_graph, device_ctx.grid, device_ctx.rr_indexed_data, inode, is_flat_).c_str());
236236
break;
@@ -549,6 +549,8 @@ void ConnectionRouter<Heap>::timing_driven_add_to_heap(const t_conn_cost_params&
549549
// Costs initialized to current
550550
next.cost = std::numeric_limits<float>::infinity(); //Not used directly
551551
next.backward_path_cost = current->backward_path_cost;
552+
next.backward_path_delay = current->backward_path_delay;
553+
next.backward_path_congestion = current->backward_path_congestion;
552554

553555
// path_data variables are initialized to current values
554556
if (rcv_path_manager.is_enabled() && current->path_data) {
@@ -594,6 +596,8 @@ void ConnectionRouter<Heap>::timing_driven_add_to_heap(const t_conn_cost_params&
594596
next_ptr->cost = next.cost;
595597
next_ptr->R_upstream = next.R_upstream;
596598
next_ptr->backward_path_cost = next.backward_path_cost;
599+
next_ptr->backward_path_delay = next.backward_path_delay;
600+
next_ptr->backward_path_congestion = next.backward_path_congestion;
597601
next_ptr->index = to_node;
598602
next_ptr->set_prev_edge(from_edge);
599603

@@ -653,7 +657,7 @@ float ConnectionRouter<Heap>::compute_node_cost_using_rcv(const t_conn_cost_para
653657
const t_conn_delay_budget* delay_budget = cost_params.delay_budget;
654658
// TODO: This function is not tested for is_flat == true
655659
VTR_ASSERT(is_flat_ != true);
656-
std::tie(expected_delay, expected_cong) = router_lookahead_.get_expected_delay_and_cong(to_node, target_node, cost_params, R_upstream);
660+
std::tie(expected_delay, expected_cong) = router_lookahead_.get_expected_delay_and_cong(to_node, target_node, cost_params, R_upstream, false);
657661

658662
float expected_total_delay_cost;
659663
float expected_total_cong_cost;
@@ -781,6 +785,8 @@ void ConnectionRouter<Heap>::evaluate_timing_driven_node_costs(t_heap* to,
781785
//Update the backward cost (upstream already included)
782786
to->backward_path_cost += (1. - cost_params.criticality) * cong_cost; //Congestion cost
783787
to->backward_path_cost += cost_params.criticality * Tdel; //Delay cost
788+
to->backward_path_delay += Tdel;
789+
to->backward_path_congestion += cong_cost;
784790

785791
if (cost_params.bend_cost != 0.) {
786792
t_rr_type from_type = rr_graph_->node_type(from_node);
@@ -829,6 +835,8 @@ void ConnectionRouter<Heap>::empty_heap_annotating_node_route_inf() {
829835

830836
rr_node_route_inf_[tmp->index].path_cost = tmp->cost;
831837
rr_node_route_inf_[tmp->index].backward_path_cost = tmp->backward_path_cost;
838+
rr_node_route_inf_[tmp->index].backward_path_delay = tmp->backward_path_delay;
839+
rr_node_route_inf_[tmp->index].backward_path_congestion = tmp->backward_path_congestion;
832840
modified_rr_node_inf_.push_back(tmp->index);
833841

834842
rcv_path_manager.free_path_struct(tmp->path_data);
@@ -892,6 +900,8 @@ void ConnectionRouter<Heap>::add_route_tree_node_to_heap(
892900
const auto& device_ctx = g_vpr_ctx.device();
893901
const RRNodeId inode = rt_node.inode;
894902
float backward_path_cost = cost_params.criticality * rt_node.Tdel;
903+
float backward_path_delay = rt_node.Tdel;
904+
float backward_path_congestion = 0.0;
895905
float R_upstream = rt_node.R_upstream;
896906

897907
/* Don't push to heap if not in bounding box: no-op for serial router, important for parallel router */
@@ -919,7 +929,7 @@ void ConnectionRouter<Heap>::add_route_tree_node_to_heap(
919929

920930
push_back_node(&heap_, rr_node_route_inf_,
921931
inode, tot_cost, RREdgeId::INVALID(),
922-
backward_path_cost, R_upstream);
932+
backward_path_cost, backward_path_delay, backward_path_congestion, R_upstream);
923933
} else {
924934
float expected_total_cost = compute_node_cost_using_rcv(cost_params, inode, target_node, rt_node.Tdel, 0, R_upstream);
925935

vpr/src/route/connection_router.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ class ConnectionRouter : public ConnectionRouterInterface {
127127
// Ensure route budgets have been calculated before enabling this
128128
void set_rcv_enabled(bool enable) final;
129129

130+
const RouterLookahead& get_router_lookahead() const {
131+
return router_lookahead_;
132+
}
133+
130134
private:
131135
// Mark that data associated with rr_node "inode" has been modified, and
132136
// needs to be reset in reset_path_costs.
@@ -148,6 +152,8 @@ class ConnectionRouter : public ConnectionRouterInterface {
148152
route_inf->prev_edge = cheapest->prev_edge();
149153
route_inf->path_cost = cheapest->cost;
150154
route_inf->backward_path_cost = cheapest->backward_path_cost;
155+
route_inf->backward_path_delay = cheapest->backward_path_delay;
156+
route_inf->backward_path_congestion = cheapest->backward_path_congestion;
151157
}
152158

153159
/** Common logic from timing_driven_route_connection_from_route_tree and

vpr/src/route/heap_type.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ HeapStorage::alloc() {
2626
temp_ptr->set_next_heap_item(nullptr);
2727
temp_ptr->cost = 0.;
2828
temp_ptr->backward_path_cost = 0.;
29+
temp_ptr->backward_path_delay = 0.;
30+
temp_ptr->backward_path_congestion = 0.;
2931
temp_ptr->R_upstream = 0.;
3032
temp_ptr->index = RRNodeId::INVALID();
3133
temp_ptr->path_data = nullptr;

vpr/src/route/heap_type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
struct t_heap {
3838
float cost = 0.;
3939
float backward_path_cost = 0.;
40+
float backward_path_delay = 0.;
41+
float backward_path_congestion = 0.;
4042
float R_upstream = 0.;
4143

4244
RRNodeId index = RRNodeId::INVALID();

vpr/src/route/lookahead_profiler.cpp

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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+
}

vpr/src/route/lookahead_profiler.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Created by shrevena on 08/06/24.
3+
//
4+
5+
#ifndef VTR_LOOKAHEAD_PROFILER_H
6+
#define VTR_LOOKAHEAD_PROFILER_H
7+
8+
#include <fstream>
9+
#include <thread>
10+
#include "rr_graph_fwd.h"
11+
#include "connection_router_interface.h"
12+
#include "router_lookahead.h"
13+
14+
class LookaheadProfiler {
15+
public:
16+
LookaheadProfiler();
17+
18+
void record(int iteration,
19+
int target_net_pin_index,
20+
RRNodeId source_inode,
21+
RRNodeId sink_inode,
22+
RRNodeId curr_inode,
23+
size_t nodes_from_sink,
24+
const t_conn_cost_params& cost_params,
25+
const RouterLookahead& router_lookahead,
26+
const ParentNetId& net_id,
27+
const Netlist<>& net_list);
28+
29+
private:
30+
std::ofstream lookahead_verifier_csv;
31+
};
32+
33+
extern LookaheadProfiler lookahead_profiler;
34+
35+
#endif //VTR_LOOKAHEAD_PROFILER_H

vpr/src/route/route_common.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ void reset_path_costs(const std::vector<RRNodeId>& visited_rr_nodes) {
286286
for (auto node : visited_rr_nodes) {
287287
route_ctx.rr_node_route_inf[node].path_cost = std::numeric_limits<float>::infinity();
288288
route_ctx.rr_node_route_inf[node].backward_path_cost = std::numeric_limits<float>::infinity();
289+
route_ctx.rr_node_route_inf[node].backward_path_delay = std::numeric_limits<float>::infinity();
290+
route_ctx.rr_node_route_inf[node].backward_path_congestion = std::numeric_limits<float>::infinity();
289291
route_ctx.rr_node_route_inf[node].prev_edge = RREdgeId::INVALID();
290292
}
291293
}
@@ -423,6 +425,8 @@ void reset_rr_node_route_structs() {
423425
node_inf.acc_cost = 1.0;
424426
node_inf.path_cost = std::numeric_limits<float>::infinity();
425427
node_inf.backward_path_cost = std::numeric_limits<float>::infinity();
428+
node_inf.backward_path_delay = std::numeric_limits<float>::infinity();
429+
node_inf.backward_path_congestion = std::numeric_limits<float>::infinity();
426430
node_inf.set_occ(0);
427431
}
428432
}
@@ -811,7 +815,7 @@ void reserve_locally_used_opins(HeapInterface* heap, float pres_fac, float acc_f
811815
cost = get_rr_cong_cost(to_node, pres_fac);
812816
add_node_to_heap(heap, route_ctx.rr_node_route_inf,
813817
to_node, cost, RREdgeId::INVALID(),
814-
0., 0.);
818+
0., 0., 0., 0.);
815819
}
816820

817821
for (ipin = 0; ipin < num_local_opin; ipin++) {

0 commit comments

Comments
 (0)