Skip to content

Commit

Permalink
Added command-line option for profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Shreve committed Aug 12, 2024
1 parent d406c57 commit c86ff7c
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 52 deletions.
9 changes: 8 additions & 1 deletion utils/route_diag/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ static void do_one_route(const Netlist<>& net_list,
VTR_ASSERT(cheapest.index == sink_node);

vtr::optional<const RouteTreeNode&> rt_node_of_sink;
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_);
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,
net_list,
conn_params.net_id_);

//find delay
float net_delay = rt_node_of_sink.value().Tdel;
Expand Down
1 change: 1 addition & 0 deletions vpr/src/base/SetupVPR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ 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 Down
8 changes: 8 additions & 0 deletions vpr/src/base/read_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,14 @@ 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
1 change: 1 addition & 0 deletions vpr/src/base/read_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ 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
1 change: 1 addition & 0 deletions vpr/src/base/vpr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ 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 Down
61 changes: 35 additions & 26 deletions vpr/src/route/lookahead_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,14 @@
#include "vpr_utils.h"
#include "re_cluster_util.h"

LookaheadProfiler::LookaheadProfiler() {
LookaheadProfiler::LookaheadProfiler()
: is_empty(true) {
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", "error");
VTR_LOG_WARN("Could not open lookahead_verifier_info.csv");
return;
}

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"
<< std::endl;
}

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

if (!lookahead_verifier_csv.is_open())
return;

if (is_empty) {
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"
<< std::endl;

is_empty = false;
}

if (iteration < 1)
return;

Expand Down
13 changes: 8 additions & 5 deletions vpr/src/route/lookahead_profiler.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//
// Created by shrevena on 08/06/24.
//

#ifndef VTR_LOOKAHEAD_PROFILER_H
#define VTR_LOOKAHEAD_PROFILER_H

Expand All @@ -15,10 +11,17 @@ class LookaheadProfiler {
public:
LookaheadProfiler();

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);
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);

private:
std::ofstream lookahead_verifier_csv;
bool is_empty;
std::unordered_map<RRNodeId, std::string> atom_block_names;
std::unordered_map<RRNodeId, std::string> atom_block_models;
std::unordered_map<RRNodeId, std::string> cluster_block_types;
Expand Down
29 changes: 24 additions & 5 deletions vpr/src/route/route_net.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ inline NetResultFlags route_net(ConnectionRouter& router,
spatial_route_tree_lookup,
router_stats,
is_flat,
itry);
itry,
router_opts);

if (flags.success == false)
return flags;
Expand Down Expand Up @@ -298,7 +299,8 @@ inline NetResultFlags pre_route_to_clock_root(ConnectionRouter& router,
SpatialRouteTreeLookup& spatial_rt_lookup,
RouterStats& router_stats,
bool is_flat,
int itry) {
int itry,
const t_router_opts& router_opts) {
const auto& device_ctx = g_vpr_ctx.device();
auto& route_ctx = g_vpr_ctx.mutable_routing();
auto& m_route_ctx = g_vpr_ctx.mutable_routing();
Expand Down Expand Up @@ -354,8 +356,16 @@ inline NetResultFlags pre_route_to_clock_root(ConnectionRouter& router,
* points. Therefore, we can set the net pin index of the sink node to *
* OPEN (meaning illegal) as it is not meaningful for this sink. */
vtr::optional<const RouteTreeNode&> new_branch, new_sink;
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,
conn_params.net_id_);
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,
net_list,
conn_params.net_id_,
itry,
router_opts.router_lookahead_profiling);

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

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

vtr::optional<const RouteTreeNode&> new_branch, new_sink;
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_);
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,
net_list,
conn_params.net_id_,
itry,
router_opts.router_lookahead_profiling);

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

Expand Down
38 changes: 29 additions & 9 deletions vpr/src/route/route_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,22 @@ void RouteTree::print(void) const {
* This routine returns a tuple: RouteTreeNode of the branch it adds to the route tree and
* RouteTreeNode of the SINK it adds to the routing. */
std::tuple<vtr::optional<const RouteTreeNode&>, vtr::optional<const RouteTreeNode&>>
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) {
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 Netlist<>& net_list,
const ParentNetId& net_id,
const int itry,
bool profile_lookahead) {
/* Lock the route tree for writing. At least on Linux this shouldn't have an impact on single-threaded code */
std::unique_lock<std::mutex> write_lock(_write_mutex);

//Create a new subtree from the target in hptr to existing routing
vtr::optional<RouteTreeNode&> start_of_new_subtree_rt_node, sink_rt_node;
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);
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);

if (!start_of_new_subtree_rt_node)
return {vtr::nullopt, *sink_rt_node};
Expand All @@ -515,7 +524,15 @@ RouteTree::update_from_heap(t_heap* hptr, int target_net_pin_index, SpatialRoute
* to the SINK indicated by hptr. Returns the first (most upstream) new rt_node,
* and the rt_node of the new SINK. Traverses up from SINK */
std::tuple<vtr::optional<RouteTreeNode&>, vtr::optional<RouteTreeNode&>>
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) {
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,
bool profile_lookahead) {
auto& device_ctx = g_vpr_ctx.device();
const auto& rr_graph = device_ctx.rr_graph;
auto& route_ctx = g_vpr_ctx.routing();
Expand Down Expand Up @@ -549,12 +566,15 @@ RouteTree::add_subtree_from_heap(t_heap* hptr, int target_net_pin_index, bool is
}
new_branch_iswitches.push_back(new_iswitch);

g_vpr_ctx.mutable_routing().lookahead_profiler.record(itry,
target_net_pin_index,
cost_params,
router_lookahead,
net_id,
net_list, std::vector<RRNodeId>());
if (profile_lookahead) {
g_vpr_ctx.mutable_routing().lookahead_profiler.record(itry,
target_net_pin_index,
cost_params,
router_lookahead,
net_id,
net_list,
new_branch_inodes);
}

/* Build the new tree branch starting from the existing node we found */
RouteTreeNode* last_node = _rr_node_to_rt_node[new_inode];
Expand Down
21 changes: 19 additions & 2 deletions vpr/src/route/route_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,16 @@ class RouteTree {
* RouteTreeNode of the SINK it adds to the routing.
* Locking operation: only one thread can update_from_heap() a RouteTree at a time. */
std::tuple<vtr::optional<const RouteTreeNode&>, vtr::optional<const RouteTreeNode&>>
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);
update_from_heap(t_heap* hptr,
int target_net_pin_index,
SpatialRouteTreeLookup* spatial_rt_lookup,
bool is_flat,
const RouterLookahead& router_lookahead,
t_conn_cost_params cost_params,
const Netlist<>& net_list,
const ParentNetId& net_id,
int itry = -1,
bool profile_lookahead = false);

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

private:
std::tuple<vtr::optional<RouteTreeNode&>, vtr::optional<RouteTreeNode&>>
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);
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,
bool profile_lookahead);

void add_non_configurable_nodes(RouteTreeNode* rt_node,
bool reached_by_non_configurable_edge,
Expand Down
18 changes: 16 additions & 2 deletions vpr/src/route/router_delay_profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ bool RouterDelayProfiler::calculate_delay(RRNodeId source_node,
VTR_ASSERT(cheapest.index == sink_node);

vtr::optional<const RouteTreeNode&> rt_node_of_sink;
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_);
std::tie(std::ignore, rt_node_of_sink) = tree.update_from_heap(&cheapest,
OPEN,
nullptr,
is_flat_,
router_.get_router_lookahead(),
cost_params,
net_list_,
conn_params.net_id_);

//find delay
*net_delay = rt_node_of_sink->Tdel;
Expand Down Expand Up @@ -208,7 +215,14 @@ vtr::vector<RRNodeId, float> calculate_all_path_delays_from_rr_node(RRNodeId src
//Build the routing tree to get the delay
tree = RouteTree(RRNodeId(src_rr_node));
vtr::optional<const RouteTreeNode&> rt_node_of_sink;
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_);
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,
net_list,
conn_params.net_id_);

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

Expand Down
Loading

0 comments on commit c86ff7c

Please sign in to comment.