Skip to content

Commit

Permalink
Allowed users to enter a file name for profiler output
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Shreve committed Aug 14, 2024
1 parent d9f4ee3 commit dfab0a8
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 62 deletions.
3 changes: 2 additions & 1 deletion vpr/src/base/SetupVPR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ static void SetupRouterOpts(const t_options& Options, t_router_opts* RouterOpts)
RouterOpts->router_debug_sink_rr = Options.router_debug_sink_rr;
RouterOpts->router_debug_iteration = Options.router_debug_iteration;
RouterOpts->lookahead_type = Options.router_lookahead_type;
RouterOpts->router_lookahead_profiling = Options.router_lookahead_profiler;
RouterOpts->max_convergence_count = Options.router_max_convergence_count;
RouterOpts->reconvergence_cpd_threshold = Options.router_reconvergence_cpd_threshold;
RouterOpts->initial_timing = Options.router_initial_timing;
Expand All @@ -487,6 +486,8 @@ static void SetupRouterOpts(const t_options& Options, t_router_opts* RouterOpts)
RouterOpts->write_intra_cluster_router_lookahead = Options.write_intra_cluster_router_lookahead;
RouterOpts->read_intra_cluster_router_lookahead = Options.read_intra_cluster_router_lookahead;

RouterOpts->lookahead_profiling_output = Options.lookahead_profiling_output;

RouterOpts->router_heap = Options.router_heap;
RouterOpts->exit_after_first_routing_iteration = Options.exit_after_first_routing_iteration;

Expand Down
15 changes: 7 additions & 8 deletions vpr/src/base/read_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,13 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
.help("Writes the intra-cluster lookahead data to the specified file.")
.show_in(argparse::ShowIn::HELP_ONLY);

file_grp.add_argument(args.lookahead_profiling_output, "--profile_router_lookahead")
.help(
"For every routed sink, record the cost, delay, and congestion estimated by the router lookahead and the "
"actual cost, delay, and congestion, from every node along each route to the sink. These results, along with many "
"other attributes of the node, are recorded into the file name provided. File extension must be .csv.")
.show_in(argparse::ShowIn::HELP_ONLY);

file_grp.add_argument(args.read_placement_delay_lookup, "--read_placement_delay_lookup")
.help(
"Reads the placement delay lookup from the specified file instead of computing it.")
Expand Down Expand Up @@ -2626,14 +2633,6 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
.default_value("map")
.show_in(argparse::ShowIn::HELP_ONLY);

route_timing_grp.add_argument<bool, ParseOnOff>(args.router_lookahead_profiler, "--router_lookahead_profiler")
.help(
"For every routed sink, records the cost, delay, and congestion estimated by the router lookahead and the "
"actual cost, delay, and congestion, from every node along each route to the sink. These results, along with many "
"other attributes of the node, are recorded into lookahead_verifier_info.csv.")
.default_value("off")
.show_in(argparse::ShowIn::HELP_ONLY);

route_timing_grp.add_argument(args.router_max_convergence_count, "--router_max_convergence_count")
.help(
"Controls how many times the router is allowed to converge to a legal routing before halting."
Expand Down
3 changes: 2 additions & 1 deletion vpr/src/base/read_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ struct t_options {
argparse::ArgValue<std::string> write_intra_cluster_router_lookahead;
argparse::ArgValue<std::string> read_intra_cluster_router_lookahead;

argparse::ArgValue<std::string> lookahead_profiling_output;

argparse::ArgValue<std::string> write_block_usage;

/* Stage Options */
Expand Down Expand Up @@ -238,7 +240,6 @@ struct t_options {
argparse::ArgValue<int> router_debug_sink_rr;
argparse::ArgValue<int> router_debug_iteration;
argparse::ArgValue<e_router_lookahead> router_lookahead_type;
argparse::ArgValue<bool> router_lookahead_profiler;
argparse::ArgValue<int> router_max_convergence_count;
argparse::ArgValue<float> router_reconvergence_cpd_threshold;
argparse::ArgValue<bool> router_update_lower_bound_delays;
Expand Down
3 changes: 2 additions & 1 deletion vpr/src/base/vpr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,6 @@ struct t_router_opts {
int router_debug_sink_rr;
int router_debug_iteration;
e_router_lookahead lookahead_type;
bool router_lookahead_profiling;
int max_convergence_count;
float reconvergence_cpd_threshold;
e_router_initial_timing initial_timing;
Expand All @@ -1473,6 +1472,8 @@ struct t_router_opts {
std::string write_intra_cluster_router_lookahead;
std::string read_intra_cluster_router_lookahead;

std::string lookahead_profiling_output;

e_heap_type router_heap;
bool exit_after_first_routing_iteration;

Expand Down
82 changes: 38 additions & 44 deletions vpr/src/route/lookahead_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,42 @@
#include "vtr_error.h"
#include "vtr_log.h"

void LookaheadProfiler::enable(bool should_enable) {
enabled_ = should_enable;
void LookaheadProfiler::set_file_name(const std::string& file_name) {
enabled_ = !file_name.empty();
if (!enabled_)
return;

lookahead_verifier_csv_.open(file_name, std::ios::out);

if (!lookahead_verifier_csv_.is_open()) {
std::string message = "Could not open " + file_name;
VTR_LOG_ERROR(message.c_str());
throw vtr::VtrError(message, "lookahead_profiler.cpp", 21);
}

lookahead_verifier_csv_
<< "iteration no."
<< ",source node"
<< ",sink node"
<< ",sink block name"
<< ",sink atom block model"
<< ",sink cluster block type"
<< ",sink cluster tile height"
<< ",sink cluster tile width"
<< ",current node"
<< ",node type"
<< ",node length"
<< ",num. nodes from sink"
<< ",delta x"
<< ",delta y"
<< ",actual cost"
<< ",actual delay"
<< ",actual congestion"
<< ",predicted cost"
<< ",predicted delay"
<< ",predicted congestion"
<< ",criticality"
<< "\n";
}

void LookaheadProfiler::record(int iteration,
Expand All @@ -26,49 +60,9 @@ void LookaheadProfiler::record(int iteration,
if (!enabled_)
return;

// If csv file hasn't been opened, open it and write out column headers
if (is_empty_) {
lookahead_verifier_csv_.open("lookahead_verifier_info.csv", std::ios::out);

if (!lookahead_verifier_csv_.is_open()) {
VTR_LOG_ERROR("Could not open lookahead_verifier_info.csv");
throw vtr::VtrError("Could not open lookahead_verifier_info.csv",
"lookahead_profiler.cpp",
28);
}

lookahead_verifier_csv_
<< "iteration no."
<< ",source node"
<< ",sink node"
<< ",sink block name"
<< ",sink atom block model"
<< ",sink cluster block type"
<< ",sink cluster tile height"
<< ",sink cluster tile width"
<< ",current node"
<< ",node type"
<< ",node length"
<< ",num. nodes from sink"
<< ",delta x"
<< ",delta y"
<< ",actual cost"
<< ",actual delay"
<< ",actual congestion"
<< ",predicted cost"
<< ",predicted delay"
<< ",predicted congestion"
<< ",criticality"
<< "\n";

is_empty_ = false;
}

if (!lookahead_verifier_csv_.is_open()) {
VTR_LOG_ERROR("lookahead_verifier_info.csv is not open.");
throw vtr::VtrError("lookahead_verifier_info.csv is not open.",
"lookahead_profiler.cpp",
62);
VTR_LOG_ERROR("Output file is not open.");
throw vtr::VtrError("Output file is not open.", "lookahead_profiler.cpp", 65);
}

// The default value in RouteTree::update_from_heap() is -1; only calls which descend from route_net()
Expand Down
15 changes: 9 additions & 6 deletions vpr/src/route/lookahead_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
class LookaheadProfiler {
public:
LookaheadProfiler()
: is_empty_(true) {}
: enabled_(false) {}

LookaheadProfiler(const LookaheadProfiler&) = delete;
LookaheadProfiler& operator=(const LookaheadProfiler&) = delete;

/**
* @brief Enable or disable the LookaheadProfiler.
* @brief Set the name of the output file.
*
* @param should_enable Whether the profiler should be enabled.
* @note
* Passing in an empty string will disable the profiler.
*
* @param file_name The name of the output csv file.
*/
void enable(bool should_enable);
void set_file_name(const std::string& file_name);

/**
* @brief Record information on nodes on a path from a source to a sink.
Expand Down Expand Up @@ -59,8 +62,8 @@ class LookaheadProfiler {
bool enabled_;
///@brief The output filestream.
std::ofstream lookahead_verifier_csv_;
///@brief Whether the output file is empty/not yet opened.
bool is_empty_;
///@brief The output file name.
std::string file_name_;
///@brief A map from sink node IDs to their atom blocks' IDs.
std::unordered_map<RRNodeId, ParentBlockId> net_pin_blocks_;
///@brief A map from sink node IDs to a pointer to the model of their atom blocks.
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/route/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ bool route(const Netlist<>& net_list,
is_flat);

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

RouterStats router_stats;
float prev_iter_cumm_time = 0;
Expand Down

0 comments on commit dfab0a8

Please sign in to comment.