Skip to content

Commit d406c57

Browse files
author
Nathan Shreve
committed
Refactor
1 parent c88364a commit d406c57

13 files changed

+287
-410
lines changed

vpr/src/base/vpr_context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#ifndef NO_SERVER
3838

3939
#include "gateio.h"
40+
# include "lookahead_profiler.h"
4041
#include "taskresolver.h"
4142

4243
class SetupHoldTimingInfo;
@@ -496,6 +497,8 @@ struct RoutingContext : public Context {
496497
* @brief User specified routing constraints
497498
*/
498499
UserRouteConstraints constraints;
500+
501+
LookaheadProfiler lookahead_profiler;
499502
};
500503

501504
/**

vpr/src/route/connection_router.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,8 @@ float ConnectionRouter<Heap>::compute_node_cost_using_rcv(const t_conn_cost_para
660660
const t_conn_delay_budget* delay_budget = cost_params.delay_budget;
661661
// TODO: This function is not tested for is_flat == true
662662
VTR_ASSERT(is_flat_ != true);
663-
std::tie(expected_delay, expected_cong) = router_lookahead_.get_expected_delay_and_cong(to_node, target_node, cost_params, R_upstream, false);
663+
std::tie(expected_delay, expected_cong) = router_lookahead_.get_expected_delay_and_cong(to_node, target_node, cost_params, R_upstream);
664+
router_lookahead_.scale_delay_and_cong_by_criticality(expected_delay, expected_cong, cost_params);
664665

665666
float expected_total_delay_cost;
666667
float expected_total_cong_cost;

vpr/src/route/lookahead_profiler.cpp

Lines changed: 77 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "vpr_utils.h"
1212
#include "re_cluster_util.h"
1313

14-
LookaheadProfiler lookahead_profiler = LookaheadProfiler();
15-
1614
LookaheadProfiler::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
}

vpr/src/route/lookahead_profiler.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,7 @@ class LookaheadProfiler {
1515
public:
1616
LookaheadProfiler();
1717

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);
18+
void record(int iteration, int target_net_pin_index, const t_conn_cost_params& cost_params, const RouterLookahead& router_lookahead, const ParentNetId& net_id, const Netlist<>& net_list, std::vector<RRNodeId> branch_inodes);
2819

2920
private:
3021
std::ofstream lookahead_verifier_csv;
@@ -34,6 +25,4 @@ class LookaheadProfiler {
3425
std::unordered_map<RRNodeId, std::pair<std::string, std::string>> tile_dimensions;
3526
};
3627

37-
extern LookaheadProfiler lookahead_profiler;
38-
3928
#endif //VTR_LOOKAHEAD_PROFILER_H

vpr/src/route/route_tree.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -549,23 +549,12 @@ RouteTree::add_subtree_from_heap(t_heap* hptr, int target_net_pin_index, bool is
549549
}
550550
new_branch_iswitches.push_back(new_iswitch);
551551

552-
/*
553-
* ROUTER LOOKAHEAD VERIFIER
554-
*/
555-
if (itry >= 1) {
556-
for (size_t i = 2; i < new_branch_inodes.size(); ++i) { /* Distance one node away is always 0.0 */
557-
lookahead_profiler.record(itry,
558-
target_net_pin_index,
559-
new_branch_inodes.back(),
560-
new_branch_inodes.front(),
561-
new_branch_inodes[i],
562-
i,
563-
cost_params,
564-
router_lookahead,
565-
net_id,
566-
net_list);
567-
}
568-
}
552+
g_vpr_ctx.mutable_routing().lookahead_profiler.record(itry,
553+
target_net_pin_index,
554+
cost_params,
555+
router_lookahead,
556+
net_id,
557+
net_list, std::vector<RRNodeId>());
569558

570559
/* Build the new tree branch starting from the existing node we found */
571560
RouteTreeNode* last_node = _rr_node_to_rt_node[new_inode];

vpr/src/route/router_lookahead.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,19 @@ std::unique_ptr<RouterLookahead> make_router_lookahead(const t_det_routing_arch&
6161
return router_lookahead;
6262
}
6363

64+
void RouterLookahead::scale_delay_and_cong_by_criticality(float& delay, float& cong, const t_conn_cost_params& params) const {
65+
delay *= params.criticality;
66+
cong *= 1. - params.criticality;
67+
}
68+
6469
float ClassicLookahead::get_expected_cost(RRNodeId current_node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const {
65-
auto [delay_cost, cong_cost] = get_expected_delay_and_cong(current_node, target_node, params, R_upstream, false);
70+
auto [delay_cost, cong_cost] = get_expected_delay_and_cong(current_node, target_node, params, R_upstream);
71+
scale_delay_and_cong_by_criticality(delay_cost, cong_cost, params);
6672

6773
return delay_cost + cong_cost;
6874
}
6975

70-
std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream, bool ignore_criticality) const {
76+
std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& /*params*/, float R_upstream) const {
7177
auto& device_ctx = g_vpr_ctx.device();
7278
const auto& rr_graph = device_ctx.rr_graph;
7379

@@ -96,11 +102,7 @@ std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId n
96102
+ R_upstream * (num_segs_same_dir * same_data.C_load + num_segs_ortho_dir * ortho_data.C_load)
97103
+ ipin_data.T_linear;
98104

99-
if (ignore_criticality) {
100-
return std::make_pair(Tdel, cong_cost);
101-
} else {
102-
return std::make_pair(params.criticality * Tdel, (1 - params.criticality) * cong_cost);
103-
}
105+
return std::make_pair(Tdel, cong_cost);
104106
} else if (rr_type == IPIN) { /* Change if you're allowing route-throughs */
105107
return std::make_pair(0., device_ctx.rr_indexed_data[RRIndexedDataId(SINK_COST_INDEX)].base_cost);
106108

@@ -113,7 +115,7 @@ float NoOpLookahead::get_expected_cost(RRNodeId /*current_node*/, RRNodeId /*tar
113115
return 0.;
114116
}
115117

116-
std::pair<float, float> NoOpLookahead::get_expected_delay_and_cong(RRNodeId, RRNodeId, const t_conn_cost_params&, float, bool /*ignore_criticality*/) const {
118+
std::pair<float, float> NoOpLookahead::get_expected_delay_and_cong(RRNodeId, RRNodeId, const t_conn_cost_params&, float) const {
117119
return std::make_pair(0., 0.);
118120
}
119121

0 commit comments

Comments
 (0)