Skip to content

Commit dfab0a8

Browse files
author
Nathan Shreve
committed
Allowed users to enter a file name for profiler output
1 parent d9f4ee3 commit dfab0a8

File tree

7 files changed

+61
-62
lines changed

7 files changed

+61
-62
lines changed

vpr/src/base/SetupVPR.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ 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;
477476
RouterOpts->max_convergence_count = Options.router_max_convergence_count;
478477
RouterOpts->reconvergence_cpd_threshold = Options.router_reconvergence_cpd_threshold;
479478
RouterOpts->initial_timing = Options.router_initial_timing;
@@ -487,6 +486,8 @@ static void SetupRouterOpts(const t_options& Options, t_router_opts* RouterOpts)
487486
RouterOpts->write_intra_cluster_router_lookahead = Options.write_intra_cluster_router_lookahead;
488487
RouterOpts->read_intra_cluster_router_lookahead = Options.read_intra_cluster_router_lookahead;
489488

489+
RouterOpts->lookahead_profiling_output = Options.lookahead_profiling_output;
490+
490491
RouterOpts->router_heap = Options.router_heap;
491492
RouterOpts->exit_after_first_routing_iteration = Options.exit_after_first_routing_iteration;
492493

vpr/src/base/read_options.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,13 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
16731673
.help("Writes the intra-cluster lookahead data to the specified file.")
16741674
.show_in(argparse::ShowIn::HELP_ONLY);
16751675

1676+
file_grp.add_argument(args.lookahead_profiling_output, "--profile_router_lookahead")
1677+
.help(
1678+
"For every routed sink, record the cost, delay, and congestion estimated by the router lookahead and the "
1679+
"actual cost, delay, and congestion, from every node along each route to the sink. These results, along with many "
1680+
"other attributes of the node, are recorded into the file name provided. File extension must be .csv.")
1681+
.show_in(argparse::ShowIn::HELP_ONLY);
1682+
16761683
file_grp.add_argument(args.read_placement_delay_lookup, "--read_placement_delay_lookup")
16771684
.help(
16781685
"Reads the placement delay lookup from the specified file instead of computing it.")
@@ -2626,14 +2633,6 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
26262633
.default_value("map")
26272634
.show_in(argparse::ShowIn::HELP_ONLY);
26282635

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-
26372636
route_timing_grp.add_argument(args.router_max_convergence_count, "--router_max_convergence_count")
26382637
.help(
26392638
"Controls how many times the router is allowed to converge to a legal routing before halting."

vpr/src/base/read_options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct t_options {
4444
argparse::ArgValue<std::string> write_intra_cluster_router_lookahead;
4545
argparse::ArgValue<std::string> read_intra_cluster_router_lookahead;
4646

47+
argparse::ArgValue<std::string> lookahead_profiling_output;
48+
4749
argparse::ArgValue<std::string> write_block_usage;
4850

4951
/* Stage Options */
@@ -238,7 +240,6 @@ struct t_options {
238240
argparse::ArgValue<int> router_debug_sink_rr;
239241
argparse::ArgValue<int> router_debug_iteration;
240242
argparse::ArgValue<e_router_lookahead> router_lookahead_type;
241-
argparse::ArgValue<bool> router_lookahead_profiler;
242243
argparse::ArgValue<int> router_max_convergence_count;
243244
argparse::ArgValue<float> router_reconvergence_cpd_threshold;
244245
argparse::ArgValue<bool> router_update_lower_bound_delays;

vpr/src/base/vpr_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,6 @@ 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;
14621461
int max_convergence_count;
14631462
float reconvergence_cpd_threshold;
14641463
e_router_initial_timing initial_timing;
@@ -1473,6 +1472,8 @@ struct t_router_opts {
14731472
std::string write_intra_cluster_router_lookahead;
14741473
std::string read_intra_cluster_router_lookahead;
14751474

1475+
std::string lookahead_profiling_output;
1476+
14761477
e_heap_type router_heap;
14771478
bool exit_after_first_routing_iteration;
14781479

vpr/src/route/lookahead_profiler.cpp

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,42 @@
88
#include "vtr_error.h"
99
#include "vtr_log.h"
1010

11-
void LookaheadProfiler::enable(bool should_enable) {
12-
enabled_ = should_enable;
11+
void LookaheadProfiler::set_file_name(const std::string& file_name) {
12+
enabled_ = !file_name.empty();
13+
if (!enabled_)
14+
return;
15+
16+
lookahead_verifier_csv_.open(file_name, std::ios::out);
17+
18+
if (!lookahead_verifier_csv_.is_open()) {
19+
std::string message = "Could not open " + file_name;
20+
VTR_LOG_ERROR(message.c_str());
21+
throw vtr::VtrError(message, "lookahead_profiler.cpp", 21);
22+
}
23+
24+
lookahead_verifier_csv_
25+
<< "iteration no."
26+
<< ",source node"
27+
<< ",sink node"
28+
<< ",sink block name"
29+
<< ",sink atom block model"
30+
<< ",sink cluster block type"
31+
<< ",sink cluster tile height"
32+
<< ",sink cluster tile width"
33+
<< ",current node"
34+
<< ",node type"
35+
<< ",node length"
36+
<< ",num. nodes from sink"
37+
<< ",delta x"
38+
<< ",delta y"
39+
<< ",actual cost"
40+
<< ",actual delay"
41+
<< ",actual congestion"
42+
<< ",predicted cost"
43+
<< ",predicted delay"
44+
<< ",predicted congestion"
45+
<< ",criticality"
46+
<< "\n";
1347
}
1448

1549
void LookaheadProfiler::record(int iteration,
@@ -26,49 +60,9 @@ void LookaheadProfiler::record(int iteration,
2660
if (!enabled_)
2761
return;
2862

29-
// If csv file hasn't been opened, open it and write out column headers
30-
if (is_empty_) {
31-
lookahead_verifier_csv_.open("lookahead_verifier_info.csv", std::ios::out);
32-
33-
if (!lookahead_verifier_csv_.is_open()) {
34-
VTR_LOG_ERROR("Could not open lookahead_verifier_info.csv");
35-
throw vtr::VtrError("Could not open lookahead_verifier_info.csv",
36-
"lookahead_profiler.cpp",
37-
28);
38-
}
39-
40-
lookahead_verifier_csv_
41-
<< "iteration no."
42-
<< ",source node"
43-
<< ",sink node"
44-
<< ",sink block name"
45-
<< ",sink atom block model"
46-
<< ",sink cluster block type"
47-
<< ",sink cluster tile height"
48-
<< ",sink cluster tile width"
49-
<< ",current node"
50-
<< ",node type"
51-
<< ",node length"
52-
<< ",num. nodes from sink"
53-
<< ",delta x"
54-
<< ",delta y"
55-
<< ",actual cost"
56-
<< ",actual delay"
57-
<< ",actual congestion"
58-
<< ",predicted cost"
59-
<< ",predicted delay"
60-
<< ",predicted congestion"
61-
<< ",criticality"
62-
<< "\n";
63-
64-
is_empty_ = false;
65-
}
66-
6763
if (!lookahead_verifier_csv_.is_open()) {
68-
VTR_LOG_ERROR("lookahead_verifier_info.csv is not open.");
69-
throw vtr::VtrError("lookahead_verifier_info.csv is not open.",
70-
"lookahead_profiler.cpp",
71-
62);
64+
VTR_LOG_ERROR("Output file is not open.");
65+
throw vtr::VtrError("Output file is not open.", "lookahead_profiler.cpp", 65);
7266
}
7367

7468
// The default value in RouteTree::update_from_heap() is -1; only calls which descend from route_net()

vpr/src/route/lookahead_profiler.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
class LookaheadProfiler {
1616
public:
1717
LookaheadProfiler()
18-
: is_empty_(true) {}
18+
: enabled_(false) {}
1919

2020
LookaheadProfiler(const LookaheadProfiler&) = delete;
2121
LookaheadProfiler& operator=(const LookaheadProfiler&) = delete;
2222

2323
/**
24-
* @brief Enable or disable the LookaheadProfiler.
24+
* @brief Set the name of the output file.
2525
*
26-
* @param should_enable Whether the profiler should be enabled.
26+
* @note
27+
* Passing in an empty string will disable the profiler.
28+
*
29+
* @param file_name The name of the output csv file.
2730
*/
28-
void enable(bool should_enable);
31+
void set_file_name(const std::string& file_name);
2932

3033
/**
3134
* @brief Record information on nodes on a path from a source to a sink.
@@ -59,8 +62,8 @@ class LookaheadProfiler {
5962
bool enabled_;
6063
///@brief The output filestream.
6164
std::ofstream lookahead_verifier_csv_;
62-
///@brief Whether the output file is empty/not yet opened.
63-
bool is_empty_;
65+
///@brief The output file name.
66+
std::string file_name_;
6467
///@brief A map from sink node IDs to their atom blocks' IDs.
6568
std::unordered_map<RRNodeId, ParentBlockId> net_pin_blocks_;
6669
///@brief A map from sink node IDs to a pointer to the model of their atom blocks.

vpr/src/route/route.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool route(const Netlist<>& net_list,
222222
is_flat);
223223

224224
// Enable lookahead profiling if command-line option used
225-
route_ctx.lookahead_profiler.enable(router_opts.router_lookahead_profiling);
225+
route_ctx.lookahead_profiler.set_file_name(router_opts.lookahead_profiling_output);
226226

227227
RouterStats router_stats;
228228
float prev_iter_cumm_time = 0;

0 commit comments

Comments
 (0)