Skip to content

Commit 80086ff

Browse files
author
Nathan Shreve
committed
More refactoring, commenting
1 parent cbe1334 commit 80086ff

23 files changed

+208
-146
lines changed

utils/route_diag/src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ static void do_one_route(const Netlist<>& net_list,
130130
VTR_ASSERT(cheapest.index == sink_node);
131131

132132
vtr::optional<const RouteTreeNode&> rt_node_of_sink;
133-
std::tie(std::ignore, rt_node_of_sink) = tree.update_from_heap(&cheapest,
134-
OPEN,
135-
nullptr,
133+
std::tie(std::ignore, rt_node_of_sink) = tree.update_from_heap(/*htpr=*/&cheapest,
134+
/*target_net_pin_index=*/OPEN,
135+
/*spatial_rt_lookup=*/nullptr,
136136
router_opts.flat_routing,
137137
router.get_router_lookahead(),
138138
cost_params,

vpr/src/base/vpr_context.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@
3939
#include "gateio.h"
4040
#include "taskresolver.h"
4141

42-
# include "lookahead_profiler.h"
43-
4442
class SetupHoldTimingInfo;
4543
class PostClusterDelayCalculator;
4644

4745
#endif /* NO_SERVER */
4846

47+
// Forward declaration
48+
class LookaheadProfiler;
49+
4950
/**
5051
* @brief A Context is collection of state relating to a particular part of VPR
5152
*
@@ -499,6 +500,9 @@ struct RoutingContext : public Context {
499500
*/
500501
UserRouteConstraints constraints;
501502

503+
/**
504+
* @brief Writes out information used to profile the accuracy of the router lookahead.
505+
*/
502506
LookaheadProfiler lookahead_profiler;
503507
};
504508

vpr/src/base/vpr_types.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,16 +1740,20 @@ constexpr bool is_src_sink(e_rr_type type) { return (type == SOURCE || type == S
17401740
* @brief Extra information about each rr_node needed only during routing
17411741
* (i.e. during the maze expansion).
17421742
*
1743-
* @param prev_edge ID of the edge (globally unique edge ID in the RR Graph)
1744-
* that was used to reach this node from the previous node.
1745-
* If there is no predecessor, prev_edge = NO_PREVIOUS.
1746-
* @param acc_cost Accumulated cost term from previous Pathfinder iterations.
1747-
* @param path_cost Total cost of the path up to and including this node +
1748-
* the expected cost to the target if the timing_driven router
1749-
* is being used.
1750-
* @param backward_path_cost Total cost of the path up to and including this
1751-
* node.
1752-
* @param occ The current occupancy of the associated rr node
1743+
* @param prev_edge ID of the edge (globally unique edge ID in the RR Graph)
1744+
* that was used to reach this node from the previous node.
1745+
* If there is no predecessor, prev_edge = NO_PREVIOUS.
1746+
* @param acc_cost Accumulated cost term from previous Pathfinder iterations.
1747+
* @param path_cost Total cost of the path up to and including this node +
1748+
* the expected cost to the target if the timing_driven router
1749+
* is being used.
1750+
* @param backward_path_cost Total cost of the path up to and including
1751+
* this node. Recorded for LookaheadProfiler.
1752+
* @param backward_path_delay Total delay in the path up to and including
1753+
* this node. Recorded for LookaheadProfiler.
1754+
* @param backward_path_congestion Total congestion in the path up to and
1755+
* including this node.
1756+
* @param occ The current occupancy of the associated rr node
17531757
*/
17541758
struct t_rr_node_route_inf {
17551759
RREdgeId prev_edge;

vpr/src/route/connection_router.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,12 @@ t_heap* ConnectionRouter<Heap>::timing_driven_route_connection_from_heap(RRNodeI
239239
// This is then placed into the traceback so that the correct path is returned
240240
// TODO: This can be eliminated by modifying the actual traceback function in route_timing
241241
if (rcv_path_manager.is_enabled()) {
242-
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);
242+
rcv_path_manager.insert_backwards_path_into_traceback(cheapest->path_data,
243+
cheapest->cost,
244+
cheapest->backward_path_cost,
245+
cheapest->backward_path_delay,
246+
cheapest->backward_path_congestion,
247+
route_ctx);
243248
}
244249
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());
245250
break;
@@ -661,7 +666,6 @@ float ConnectionRouter<Heap>::compute_node_cost_using_rcv(const t_conn_cost_para
661666
// TODO: This function is not tested for is_flat == true
662667
VTR_ASSERT(is_flat_ != true);
663668
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);
665669

666670
float expected_total_delay_cost;
667671
float expected_total_cong_cost;
@@ -928,7 +932,7 @@ void ConnectionRouter<Heap>::add_route_tree_node_to_heap(
928932
rr_node_route_inf_,
929933
inode,
930934
tot_cost,
931-
RREdgeId::INVALID(),
935+
/*prev_edge=*/RREdgeId::INVALID(),
932936
backward_path_cost,
933937
backward_path_delay,
934938
backward_path_congestion,

vpr/src/route/heap_type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ struct t_heap {
1818
///@brief The "known" cost of the path up to and including this node. Used only by the timing-driven router. In this case, the
1919
///.cost member contains not only the known backward cost but also an expected cost to the target.
2020
float backward_path_cost = 0.;
21+
///@brief The "known" delay in the path up to and including this node. Recorded for LookaheadProfiler during routing.
2122
float backward_path_delay = 0.;
23+
///@brief The "known" congestion in the path up to and including this node. Recorded for LookaheadProfiler during routing.
2224
float backward_path_congestion = 0.;
2325
///@brief Used only by the timing-driven router. Stores the upstream resistance to ground from this node, including the resistance
2426
/// of the node itself (device_ctx.rr_nodes[index].R).

vpr/src/route/lookahead_profiler.cpp

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ void LookaheadProfiler::record(int iteration,
2424
auto& route_ctx = g_vpr_ctx.routing();
2525

2626
// If csv file hasn't been opened, open it and write out column headers
27-
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");
27+
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");
32+
throw vtr::VtrError("Could not open lookahead_verifier_info.csv",
33+
"lookahead_profiler.cpp",
34+
32);
3235
}
3336

34-
lookahead_verifier_csv
37+
lookahead_verifier_csv_
3538
<< "iteration no."
3639
<< ",source node"
3740
<< ",sink node"
@@ -53,13 +56,21 @@ void LookaheadProfiler::record(int iteration,
5356
<< ",predicted delay"
5457
<< ",predicted congestion"
5558
<< ",criticality"
56-
<< std::endl;
59+
<< "\n";
5760

58-
is_empty = false;
61+
is_empty_ = false;
5962
}
6063

61-
if (!lookahead_verifier_csv.is_open())
64+
if (!lookahead_verifier_csv_.is_open()) {
65+
if (toggle_warn_) {
66+
VTR_LOG_WARN("lookahead_verifier_info.csv is not open");
67+
toggle_warn_ = false;
68+
}
69+
6270
return;
71+
} else {
72+
toggle_warn_ = true;
73+
}
6374

6475
// The default value in RouteTree::update_from_heap() is -1; only calls which descend from route_net()
6576
// pass in an iteration value, which is the only context in which we want to profile.
@@ -73,51 +84,52 @@ void LookaheadProfiler::record(int iteration,
7384

7485
/* Get sink node attributes (atom block name, atom block model, cluster type, tile dimensions) */
7586

76-
if (atom_block_names.find(sink_inode) == atom_block_names.end()) {
87+
if (atom_block_names_.find(sink_inode) == atom_block_names_.end()) {
7788
if (net_id != ParentNetId::INVALID() && target_net_pin_index != OPEN) {
78-
atom_block_names[sink_inode] = net_list.block_name(net_list.net_pin_block(net_id, target_net_pin_index));
89+
atom_block_names_[sink_inode] = net_list.block_name(net_list.net_pin_block(net_id, target_net_pin_index));
7990

80-
AtomBlockId atom_block_id = g_vpr_ctx.atom().nlist.find_block(atom_block_names[sink_inode]);
81-
atom_block_models[sink_inode] = 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;
8293

8394
ClusterBlockId cluster_block_id = atom_to_cluster(atom_block_id);
8495

85-
cluster_block_types[sink_inode] = 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;
8697

8798
auto tile_type = physical_tile_type(cluster_block_id);
88-
tile_dimensions[sink_inode] = std::pair(std::to_string(tile_type->width), std::to_string(tile_type->height));
99+
tile_dimensions_[sink_inode] = std::pair(std::to_string(tile_type->width), std::to_string(tile_type->height));
89100
} else {
90-
atom_block_names[sink_inode] = "--";
91-
atom_block_models[sink_inode] = "--";
92-
cluster_block_types[sink_inode] = "--";
93-
tile_dimensions[sink_inode] = {"--", "--"};
101+
atom_block_names_[sink_inode] = "--";
102+
atom_block_models_[sink_inode] = "--";
103+
cluster_block_types_[sink_inode] = "--";
104+
tile_dimensions_[sink_inode] = {"--", "--"};
94105
}
95106
}
96107

97-
VTR_ASSERT_SAFE(atom_block_models.find(sink_inode) != atom_block_models.end());
98-
VTR_ASSERT_SAFE(cluster_block_types.find(sink_inode) != cluster_block_types.end());
99-
VTR_ASSERT_SAFE(tile_dimensions.find(sink_inode) != tile_dimensions.end());
108+
VTR_ASSERT_SAFE(atom_block_models_.find(sink_inode) != atom_block_models_.end());
109+
VTR_ASSERT_SAFE(cluster_block_types_.find(sink_inode) != cluster_block_types_.end());
110+
VTR_ASSERT_SAFE(tile_dimensions_.find(sink_inode) != tile_dimensions_.end());
100111

101-
std::string block_name = atom_block_names[sink_inode];
102-
std::string atom_block_model = atom_block_models[sink_inode];
103-
std::string cluster_block_type = cluster_block_types[sink_inode];
104-
auto [tile_width, tile_height] = tile_dimensions[sink_inode];
112+
const std::string& block_name = atom_block_names_[sink_inode];
113+
const std::string& atom_block_model = atom_block_models_[sink_inode];
114+
const std::string& cluster_block_type = cluster_block_types_[sink_inode];
115+
const auto& [tile_width, tile_height] = tile_dimensions_[sink_inode];
105116

106117
/* Iterate through the given path and record information for each node */
107-
for (size_t i = 2; i < branch_inodes.size(); ++i) { // Distance one node away is always 0. (IPIN->SINK)
108-
RRNodeId curr_inode = branch_inodes[i];
118+
for (size_t nodes_from_sink = 2; nodes_from_sink < branch_inodes.size(); ++nodes_from_sink) { // Distance one node away is always 0. (IPIN->SINK)
119+
RRNodeId curr_inode = branch_inodes[nodes_from_sink];
109120

110-
// Get backwards path cost, delay, and congestion from sink node
111-
t_rr_node_route_inf sink_node_info = route_ctx.rr_node_route_inf[sink_inode];
112-
float total_backward_cost = sink_node_info.backward_path_cost;
113-
float total_backward_delay = sink_node_info.backward_path_delay;
114-
float total_backward_congestion = sink_node_info.backward_path_congestion;
121+
// Calculate the actual cost, delay, and congestion from the current node to the sink.
122+
const t_rr_node_route_inf& curr_node_info = route_ctx.rr_node_route_inf[curr_inode];
123+
const t_rr_node_route_inf& sink_node_info = route_ctx.rr_node_route_inf[sink_inode];
115124

116-
// Get backwards path cost, delay, and congestion from current node
117-
t_rr_node_route_inf curr_node_info = route_ctx.rr_node_route_inf[curr_inode];
118-
float current_backward_cost = curr_node_info.backward_path_cost;
119-
float current_backward_delay = curr_node_info.backward_path_delay;
120-
float current_backward_congestion = curr_node_info.backward_path_congestion;
125+
float actual_cost = sink_node_info.backward_path_cost - curr_node_info.backward_path_cost;
126+
float actual_delay = sink_node_info.backward_path_delay - curr_node_info.backward_path_delay;
127+
float actual_congestion = sink_node_info.backward_path_congestion - curr_node_info.backward_path_congestion;
128+
129+
// Get the cost, delay, and congestion estimates made by the lookahead.
130+
// Note: lookahead_cost = lookahead_delay * criticality + lookahead_congestion * (1. - criticality)
131+
float lookahead_cost = router_lookahead.get_expected_cost(curr_inode, sink_inode, cost_params, 0.0);
132+
auto [lookahead_delay, lookahead_congestion] = router_lookahead.get_expected_delay_and_cong_ignore_criticality(curr_inode, sink_inode, cost_params, 0.0);
121133

122134
// Get the difference in the coordinates in the current and sink nodes.
123135
// Note: we are not using util::get_xy_deltas() because this always gives positive values
@@ -129,45 +141,35 @@ void LookaheadProfiler::record(int iteration,
129141
int delta_x = to_x - from_x;
130142
int delta_y = to_y - from_y;
131143

132-
// Calculate the actual cost, delay, and congestion from the current node to the sink.
133-
float actual_cost = total_backward_cost - current_backward_cost;
134-
float actual_delay = total_backward_delay - current_backward_delay;
135-
float actual_congestion = total_backward_congestion - current_backward_congestion;
136-
137-
// Get the cost, delay, and congestion estimates made by the lookahead.
138-
// Note: lookahead_cost = lookahead_delay * criticality + lookahead_congestion * (1. - criticality)
139-
float lookahead_cost = router_lookahead.get_expected_cost(curr_inode, sink_inode, cost_params, 0.0);
140-
auto [lookahead_delay, lookahead_congestion] = router_lookahead.get_expected_delay_and_cong(curr_inode, sink_inode, cost_params, 0.0);
141-
142144
// Get the current node's type and length
143145
std::string node_type_str = rr_graph.node_type_string(curr_inode);
144-
std::string node_length = (node_type_str == "CHANX" || node_type_str == "CHANX")
146+
std::string node_length = (node_type_str == "CHANX" || node_type_str == "CHANY")
145147
? std::to_string(rr_graph.node_length(curr_inode))
146148
: "--";
147149

148150
/* Write out all info */
149151

150-
lookahead_verifier_csv << iteration << ","; // iteration no.
151-
lookahead_verifier_csv << source_inode << ","; // source node
152-
lookahead_verifier_csv << sink_inode << ","; // sink node
153-
lookahead_verifier_csv << block_name << ","; // sink block name
154-
lookahead_verifier_csv << atom_block_model << ","; // sink atom block model
155-
lookahead_verifier_csv << cluster_block_type << ","; // sink cluster block type
156-
lookahead_verifier_csv << tile_height << ","; // sink cluster tile height
157-
lookahead_verifier_csv << tile_width << ","; // sink cluster tile width
158-
lookahead_verifier_csv << curr_inode << ","; // current node
159-
lookahead_verifier_csv << node_type_str << ","; // node type
160-
lookahead_verifier_csv << node_length << ","; // node length
161-
lookahead_verifier_csv << i << ","; // num. nodes from sink
162-
lookahead_verifier_csv << delta_x << ","; // delta x
163-
lookahead_verifier_csv << delta_y << ","; // delta y
164-
lookahead_verifier_csv << actual_cost << ","; // actual cost
165-
lookahead_verifier_csv << actual_delay << ","; // actual delay
166-
lookahead_verifier_csv << actual_congestion << ","; // actual congestion
167-
lookahead_verifier_csv << lookahead_cost << ","; // predicted cost
168-
lookahead_verifier_csv << lookahead_delay << ","; // predicted delay
169-
lookahead_verifier_csv << lookahead_congestion << ","; // predicted congestion
170-
lookahead_verifier_csv << cost_params.criticality; // criticality
171-
lookahead_verifier_csv << std::endl;
152+
lookahead_verifier_csv_ << iteration << ","; // iteration no.
153+
lookahead_verifier_csv_ << source_inode << ","; // source node
154+
lookahead_verifier_csv_ << sink_inode << ","; // sink node
155+
lookahead_verifier_csv_ << block_name << ","; // sink block name
156+
lookahead_verifier_csv_ << atom_block_model << ","; // sink atom block model
157+
lookahead_verifier_csv_ << cluster_block_type << ","; // sink cluster block type
158+
lookahead_verifier_csv_ << tile_height << ","; // sink cluster tile height
159+
lookahead_verifier_csv_ << tile_width << ","; // sink cluster tile width
160+
lookahead_verifier_csv_ << curr_inode << ","; // current node
161+
lookahead_verifier_csv_ << node_type_str << ","; // node type
162+
lookahead_verifier_csv_ << node_length << ","; // node length
163+
lookahead_verifier_csv_ << nodes_from_sink << ","; // num. nodes from sink
164+
lookahead_verifier_csv_ << delta_x << ","; // delta x
165+
lookahead_verifier_csv_ << delta_y << ","; // delta y
166+
lookahead_verifier_csv_ << actual_cost << ","; // actual cost
167+
lookahead_verifier_csv_ << actual_delay << ","; // actual delay
168+
lookahead_verifier_csv_ << actual_congestion << ","; // actual congestion
169+
lookahead_verifier_csv_ << lookahead_cost << ","; // predicted cost
170+
lookahead_verifier_csv_ << lookahead_delay << ","; // predicted delay
171+
lookahead_verifier_csv_ << lookahead_congestion << ","; // predicted congestion
172+
lookahead_verifier_csv_ << cost_params.criticality; // criticality
173+
lookahead_verifier_csv_ << "\n";
172174
}
173175
}

0 commit comments

Comments
 (0)