Skip to content

Commit c86ff7c

Browse files
author
Nathan Shreve
committed
Added command-line option for profiler
1 parent d406c57 commit c86ff7c

13 files changed

+159
-52
lines changed

utils/route_diag/src/main.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,14 @@ 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, OPEN, nullptr, router_opts.flat_routing, router.get_router_lookahead(), cost_params, -1, net_list, conn_params.net_id_);
133+
std::tie(std::ignore, rt_node_of_sink) = tree.update_from_heap(&cheapest,
134+
OPEN,
135+
nullptr,
136+
router_opts.flat_routing,
137+
router.get_router_lookahead(),
138+
cost_params,
139+
net_list,
140+
conn_params.net_id_);
134141

135142
//find delay
136143
float net_delay = rt_node_of_sink.value().Tdel;

vpr/src/base/SetupVPR.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ static void SetupRouterOpts(const t_options& Options, t_router_opts* RouterOpts)
473473
RouterOpts->router_debug_sink_rr = Options.router_debug_sink_rr;
474474
RouterOpts->router_debug_iteration = Options.router_debug_iteration;
475475
RouterOpts->lookahead_type = Options.router_lookahead_type;
476+
RouterOpts->router_lookahead_profiling = Options.router_lookahead_profiler;
476477
RouterOpts->max_convergence_count = Options.router_max_convergence_count;
477478
RouterOpts->reconvergence_cpd_threshold = Options.router_reconvergence_cpd_threshold;
478479
RouterOpts->initial_timing = Options.router_initial_timing;

vpr/src/base/read_options.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,6 +2626,14 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
26262626
.default_value("map")
26272627
.show_in(argparse::ShowIn::HELP_ONLY);
26282628

2629+
route_timing_grp.add_argument<bool, ParseOnOff>(args.router_lookahead_profiler, "--router_lookahead_profiler")
2630+
.help(
2631+
"For every routed sink, records the cost, delay, and congestion estimated by the router lookahead and the "
2632+
"actual cost, delay, and congestion, from every node along each route to the sink. These results, along with many "
2633+
"other attributes of the node, are recorded into lookahead_verifier_info.csv.")
2634+
.default_value("off")
2635+
.show_in(argparse::ShowIn::HELP_ONLY);
2636+
26292637
route_timing_grp.add_argument(args.router_max_convergence_count, "--router_max_convergence_count")
26302638
.help(
26312639
"Controls how many times the router is allowed to converge to a legal routing before halting."

vpr/src/base/read_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ struct t_options {
238238
argparse::ArgValue<int> router_debug_sink_rr;
239239
argparse::ArgValue<int> router_debug_iteration;
240240
argparse::ArgValue<e_router_lookahead> router_lookahead_type;
241+
argparse::ArgValue<bool> router_lookahead_profiler;
241242
argparse::ArgValue<int> router_max_convergence_count;
242243
argparse::ArgValue<float> router_reconvergence_cpd_threshold;
243244
argparse::ArgValue<bool> router_update_lower_bound_delays;

vpr/src/base/vpr_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ struct t_router_opts {
14581458
int router_debug_sink_rr;
14591459
int router_debug_iteration;
14601460
e_router_lookahead lookahead_type;
1461+
bool router_lookahead_profiling;
14611462
int max_convergence_count;
14621463
float reconvergence_cpd_threshold;
14631464
e_router_initial_timing initial_timing;

vpr/src/route/lookahead_profiler.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,14 @@
1111
#include "vpr_utils.h"
1212
#include "re_cluster_util.h"
1313

14-
LookaheadProfiler::LookaheadProfiler() {
14+
LookaheadProfiler::LookaheadProfiler()
15+
: is_empty(true) {
1516
lookahead_verifier_csv.open("lookahead_verifier_info.csv", std::ios::out);
1617

1718
if (!lookahead_verifier_csv.is_open()) {
18-
VTR_LOG_ERROR("Could not open lookahead_verifier_info.csv", "error");
19+
VTR_LOG_WARN("Could not open lookahead_verifier_info.csv");
20+
return;
1921
}
20-
21-
lookahead_verifier_csv
22-
<< "iteration no."
23-
<< ",source node"
24-
<< ",sink node"
25-
<< ",sink block name"
26-
<< ",sink atom block model"
27-
<< ",sink cluster block type"
28-
<< ",sink cluster tile height"
29-
<< ",sink cluster tile width"
30-
<< ",current node"
31-
<< ",node type"
32-
<< ",node length"
33-
<< ",num. nodes from sink"
34-
<< ",delta x"
35-
<< ",delta y"
36-
<< ",actual cost"
37-
<< ",actual delay"
38-
<< ",actual congestion"
39-
<< ",predicted cost"
40-
<< ",predicted delay"
41-
<< ",predicted congestion"
42-
<< ",criticality"
43-
<< std::endl;
4422
}
4523

4624
void LookaheadProfiler::record(int iteration,
@@ -54,6 +32,37 @@ void LookaheadProfiler::record(int iteration,
5432
const auto& rr_graph = device_ctx.rr_graph;
5533
auto& route_ctx = g_vpr_ctx.routing();
5634

35+
if (!lookahead_verifier_csv.is_open())
36+
return;
37+
38+
if (is_empty) {
39+
lookahead_verifier_csv
40+
<< "iteration no."
41+
<< ",source node"
42+
<< ",sink node"
43+
<< ",sink block name"
44+
<< ",sink atom block model"
45+
<< ",sink cluster block type"
46+
<< ",sink cluster tile height"
47+
<< ",sink cluster tile width"
48+
<< ",current node"
49+
<< ",node type"
50+
<< ",node length"
51+
<< ",num. nodes from sink"
52+
<< ",delta x"
53+
<< ",delta y"
54+
<< ",actual cost"
55+
<< ",actual delay"
56+
<< ",actual congestion"
57+
<< ",predicted cost"
58+
<< ",predicted delay"
59+
<< ",predicted congestion"
60+
<< ",criticality"
61+
<< std::endl;
62+
63+
is_empty = false;
64+
}
65+
5766
if (iteration < 1)
5867
return;
5968

vpr/src/route/lookahead_profiler.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
//
2-
// Created by shrevena on 08/06/24.
3-
//
4-
51
#ifndef VTR_LOOKAHEAD_PROFILER_H
62
#define VTR_LOOKAHEAD_PROFILER_H
73

@@ -15,10 +11,17 @@ class LookaheadProfiler {
1511
public:
1612
LookaheadProfiler();
1713

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

2022
private:
2123
std::ofstream lookahead_verifier_csv;
24+
bool is_empty;
2225
std::unordered_map<RRNodeId, std::string> atom_block_names;
2326
std::unordered_map<RRNodeId, std::string> atom_block_models;
2427
std::unordered_map<RRNodeId, std::string> cluster_block_types;

vpr/src/route/route_net.tpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ inline NetResultFlags route_net(ConnectionRouter& router,
190190
spatial_route_tree_lookup,
191191
router_stats,
192192
is_flat,
193-
itry);
193+
itry,
194+
router_opts);
194195

195196
if (flags.success == false)
196197
return flags;
@@ -298,7 +299,8 @@ inline NetResultFlags pre_route_to_clock_root(ConnectionRouter& router,
298299
SpatialRouteTreeLookup& spatial_rt_lookup,
299300
RouterStats& router_stats,
300301
bool is_flat,
301-
int itry) {
302+
int itry,
303+
const t_router_opts& router_opts) {
302304
const auto& device_ctx = g_vpr_ctx.device();
303305
auto& route_ctx = g_vpr_ctx.mutable_routing();
304306
auto& m_route_ctx = g_vpr_ctx.mutable_routing();
@@ -354,8 +356,16 @@ inline NetResultFlags pre_route_to_clock_root(ConnectionRouter& router,
354356
* points. Therefore, we can set the net pin index of the sink node to *
355357
* OPEN (meaning illegal) as it is not meaningful for this sink. */
356358
vtr::optional<const RouteTreeNode&> new_branch, new_sink;
357-
std::tie(new_branch, new_sink) = tree.update_from_heap(&cheapest, OPEN, ((high_fanout) ? &spatial_rt_lookup : nullptr), is_flat, router.get_router_lookahead(), cost_params, itry, net_list,
358-
conn_params.net_id_);
359+
std::tie(new_branch, new_sink) = tree.update_from_heap(&cheapest,
360+
OPEN,
361+
((high_fanout) ? &spatial_rt_lookup : nullptr),
362+
is_flat,
363+
router.get_router_lookahead(),
364+
cost_params,
365+
net_list,
366+
conn_params.net_id_,
367+
itry,
368+
router_opts.router_lookahead_profiling);
359369

360370
VTR_ASSERT_DEBUG(!high_fanout || validate_route_tree_spatial_lookup(tree.root(), spatial_rt_lookup));
361371

@@ -483,7 +493,16 @@ inline NetResultFlags route_sink(ConnectionRouter& router,
483493
profiling::sink_criticality_end(cost_params.criticality);
484494

485495
vtr::optional<const RouteTreeNode&> new_branch, new_sink;
486-
std::tie(new_branch, new_sink) = tree.update_from_heap(&cheapest, target_pin, ((high_fanout) ? &spatial_rt_lookup : nullptr), is_flat, router.get_router_lookahead(), cost_params, itry, net_list, conn_params.net_id_);
496+
std::tie(new_branch, new_sink) = tree.update_from_heap(&cheapest,
497+
target_pin,
498+
((high_fanout) ? &spatial_rt_lookup : nullptr),
499+
is_flat,
500+
router.get_router_lookahead(),
501+
cost_params,
502+
net_list,
503+
conn_params.net_id_,
504+
itry,
505+
router_opts.router_lookahead_profiling);
487506

488507
VTR_ASSERT_DEBUG(!high_fanout || validate_route_tree_spatial_lookup(tree.root(), spatial_rt_lookup));
489508

vpr/src/route/route_tree.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,22 @@ void RouteTree::print(void) const {
486486
* This routine returns a tuple: RouteTreeNode of the branch it adds to the route tree and
487487
* RouteTreeNode of the SINK it adds to the routing. */
488488
std::tuple<vtr::optional<const RouteTreeNode&>, vtr::optional<const RouteTreeNode&>>
489-
RouteTree::update_from_heap(t_heap* hptr, int target_net_pin_index, SpatialRouteTreeLookup* spatial_rt_lookup, bool is_flat, const RouterLookahead& router_lookahead, const t_conn_cost_params cost_params, const int itry, const Netlist<>& net_list, const ParentNetId& net_id) {
489+
RouteTree::update_from_heap(t_heap* hptr,
490+
int target_net_pin_index,
491+
SpatialRouteTreeLookup* spatial_rt_lookup,
492+
bool is_flat,
493+
const RouterLookahead& router_lookahead,
494+
const t_conn_cost_params cost_params,
495+
const Netlist<>& net_list,
496+
const ParentNetId& net_id,
497+
const int itry,
498+
bool profile_lookahead) {
490499
/* Lock the route tree for writing. At least on Linux this shouldn't have an impact on single-threaded code */
491500
std::unique_lock<std::mutex> write_lock(_write_mutex);
492501

493502
//Create a new subtree from the target in hptr to existing routing
494503
vtr::optional<RouteTreeNode&> start_of_new_subtree_rt_node, sink_rt_node;
495-
std::tie(start_of_new_subtree_rt_node, sink_rt_node) = add_subtree_from_heap(hptr, target_net_pin_index, is_flat, router_lookahead, cost_params, itry, net_list, net_id);
504+
std::tie(start_of_new_subtree_rt_node, sink_rt_node) = add_subtree_from_heap(hptr, target_net_pin_index, is_flat, router_lookahead, cost_params, itry, net_list, net_id, profile_lookahead);
496505

497506
if (!start_of_new_subtree_rt_node)
498507
return {vtr::nullopt, *sink_rt_node};
@@ -515,7 +524,15 @@ RouteTree::update_from_heap(t_heap* hptr, int target_net_pin_index, SpatialRoute
515524
* to the SINK indicated by hptr. Returns the first (most upstream) new rt_node,
516525
* and the rt_node of the new SINK. Traverses up from SINK */
517526
std::tuple<vtr::optional<RouteTreeNode&>, vtr::optional<RouteTreeNode&>>
518-
RouteTree::add_subtree_from_heap(t_heap* hptr, int target_net_pin_index, bool is_flat, const RouterLookahead& router_lookahead, const t_conn_cost_params cost_params, const int itry, const Netlist<>& net_list, const ParentNetId& net_id) {
527+
RouteTree::add_subtree_from_heap(t_heap* hptr,
528+
int target_net_pin_index,
529+
bool is_flat,
530+
const RouterLookahead& router_lookahead,
531+
const t_conn_cost_params cost_params,
532+
const int itry,
533+
const Netlist<>& net_list,
534+
const ParentNetId& net_id,
535+
bool profile_lookahead) {
519536
auto& device_ctx = g_vpr_ctx.device();
520537
const auto& rr_graph = device_ctx.rr_graph;
521538
auto& route_ctx = g_vpr_ctx.routing();
@@ -549,12 +566,15 @@ RouteTree::add_subtree_from_heap(t_heap* hptr, int target_net_pin_index, bool is
549566
}
550567
new_branch_iswitches.push_back(new_iswitch);
551568

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>());
569+
if (profile_lookahead) {
570+
g_vpr_ctx.mutable_routing().lookahead_profiler.record(itry,
571+
target_net_pin_index,
572+
cost_params,
573+
router_lookahead,
574+
net_id,
575+
net_list,
576+
new_branch_inodes);
577+
}
558578

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

vpr/src/route/route_tree.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,16 @@ class RouteTree {
358358
* RouteTreeNode of the SINK it adds to the routing.
359359
* Locking operation: only one thread can update_from_heap() a RouteTree at a time. */
360360
std::tuple<vtr::optional<const RouteTreeNode&>, vtr::optional<const RouteTreeNode&>>
361-
update_from_heap(t_heap* hptr, int target_net_pin_index, SpatialRouteTreeLookup* spatial_rt_lookup, bool is_flat, const RouterLookahead& router_lookahead, const t_conn_cost_params cost_params, const int itry, const Netlist<>& net_list, const ParentNetId& net_id);
361+
update_from_heap(t_heap* hptr,
362+
int target_net_pin_index,
363+
SpatialRouteTreeLookup* spatial_rt_lookup,
364+
bool is_flat,
365+
const RouterLookahead& router_lookahead,
366+
t_conn_cost_params cost_params,
367+
const Netlist<>& net_list,
368+
const ParentNetId& net_id,
369+
int itry = -1,
370+
bool profile_lookahead = false);
362371

363372
/** Reload timing values (R_upstream, C_downstream, Tdel).
364373
* Can take a RouteTreeNode& to do an incremental update.
@@ -492,7 +501,15 @@ class RouteTree {
492501

493502
private:
494503
std::tuple<vtr::optional<RouteTreeNode&>, vtr::optional<RouteTreeNode&>>
495-
add_subtree_from_heap(t_heap* hptr, int target_net_pin_index, bool is_flat, const RouterLookahead& router_lookahead, const t_conn_cost_params cost_params, const int itry, const Netlist<>& net_list, const ParentNetId& net_id);
504+
add_subtree_from_heap(t_heap* hptr,
505+
int target_net_pin_index,
506+
bool is_flat,
507+
const RouterLookahead& router_lookahead,
508+
const t_conn_cost_params cost_params,
509+
const int itry,
510+
const Netlist<>& net_list,
511+
const ParentNetId& net_id,
512+
bool profile_lookahead);
496513

497514
void add_non_configurable_nodes(RouteTreeNode* rt_node,
498515
bool reached_by_non_configurable_edge,

vpr/src/route/router_delay_profiling.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,14 @@ bool RouterDelayProfiler::calculate_delay(RRNodeId source_node,
121121
VTR_ASSERT(cheapest.index == sink_node);
122122

123123
vtr::optional<const RouteTreeNode&> rt_node_of_sink;
124-
std::tie(std::ignore, rt_node_of_sink) = tree.update_from_heap(&cheapest, OPEN, nullptr, is_flat_, router_.get_router_lookahead(), cost_params, -1, net_list_, conn_params.net_id_);
124+
std::tie(std::ignore, rt_node_of_sink) = tree.update_from_heap(&cheapest,
125+
OPEN,
126+
nullptr,
127+
is_flat_,
128+
router_.get_router_lookahead(),
129+
cost_params,
130+
net_list_,
131+
conn_params.net_id_);
125132

126133
//find delay
127134
*net_delay = rt_node_of_sink->Tdel;
@@ -208,7 +215,14 @@ vtr::vector<RRNodeId, float> calculate_all_path_delays_from_rr_node(RRNodeId src
208215
//Build the routing tree to get the delay
209216
tree = RouteTree(RRNodeId(src_rr_node));
210217
vtr::optional<const RouteTreeNode&> rt_node_of_sink;
211-
std::tie(std::ignore, rt_node_of_sink) = tree.update_from_heap(&shortest_paths[sink_rr_node], OPEN, nullptr, router_opts.flat_routing, router.get_router_lookahead(), cost_params, -1, net_list, conn_params.net_id_);
218+
std::tie(std::ignore, rt_node_of_sink) = tree.update_from_heap(&shortest_paths[sink_rr_node],
219+
OPEN,
220+
nullptr,
221+
router_opts.flat_routing,
222+
router.get_router_lookahead(),
223+
cost_params,
224+
net_list,
225+
conn_params.net_id_);
212226

213227
VTR_ASSERT(rt_node_of_sink->inode == RRNodeId(sink_rr_node));
214228

0 commit comments

Comments
 (0)