Skip to content

[WIP] Router Lookahead Profiler #2683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
739029b
Created lookahead profiler (restored changes from previous branch)
Jun 26, 2024
aa5570b
LookaheadProfiler now saves sink node info for efficiency
Jun 26, 2024
c88364a
Merge branch 'master' into feature_router_lookahead_verifier
Aug 12, 2024
d406c57
Refactor
Aug 12, 2024
c86ff7c
Added command-line option for profiler
Aug 12, 2024
ddf34eb
Commented LookaheadProfiler
Aug 12, 2024
0826ad7
More comments
Aug 12, 2024
e8ea974
Moved parse_lookahead_data.py
Aug 12, 2024
0b5a752
Moved, refactored, and commented parse_lookahead_data.py
Aug 12, 2024
cbe1334
Fixed multithreading in parsing script
Aug 13, 2024
80086ff
More refactoring, commenting
Aug 13, 2024
c747096
Fixed linting errors in python script
Aug 14, 2024
e753094
Refactored LookaheadProfiler
Aug 14, 2024
d9f4ee3
Eliminated profile_lookahead parameter in update_from_heap
Aug 14, 2024
dfab0a8
Allowed users to enter a file name for profiler output
Aug 14, 2024
c9801b7
Improved multiprocessing efficiency in script
Aug 14, 2024
7fe0b55
Cleaned a few function calls
Aug 15, 2024
c8b196e
LookaheadProfiler::clear() now uses vtr::release_memory()
Aug 15, 2024
ed4460d
Requirements for script added to requirements.txt
Aug 15, 2024
ab2c731
Updated some regtest seeds and golden results
Aug 15, 2024
2db5325
Merge branch 'master' into feature_router_lookahead_verifier
Aug 15, 2024
17ab565
#ifdef-ed extra heap data and added CI test
Aug 20, 2024
595af59
Merge branch 'master' into feature_router_lookahead_verifier
Aug 20, 2024
2f10ec5
Fixed compilation warnings
Aug 20, 2024
9bcad70
Fixed error in record()
Aug 20, 2024
c05e498
Updated golden results
Aug 21, 2024
643811b
Merge branch 'master' into feature_router_lookahead_verifier
Aug 22, 2024
1c9bb58
More updated golden results
Aug 23, 2024
deddc8a
Disabled RCV support for RouterLookahead, comments
Aug 28, 2024
971eebc
Merge branch 'master' into feature_router_lookahead_verifier
Aug 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the user should be able to specify the file name.

.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
4 changes: 4 additions & 0 deletions vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "gateio.h"
#include "taskresolver.h"

# include "lookahead_profiler.h"

class SetupHoldTimingInfo;
class PostClusterDelayCalculator;

Expand Down Expand Up @@ -496,6 +498,8 @@ struct RoutingContext : public Context {
* @brief User specified routing constraints
*/
UserRouteConstraints constraints;

LookaheadProfiler lookahead_profiler;
};

/**
Expand Down
3 changes: 3 additions & 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 Expand Up @@ -1756,6 +1757,8 @@ struct t_rr_node_route_inf {
float acc_cost;
float path_cost;
float backward_path_cost;
float backward_path_delay;
float backward_path_congestion;

public: //Accessors
short occ() const { return occ_; }
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/place/timing_place_lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ static void add_delay_to_matrix(
}

static void generic_compute_matrix_dijkstra_expansion(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a doxygen comment for this, detailing what you know about the function and its arguments (and for sure what the route_profiler does).

RouterDelayProfiler& /*route_profiler*/,
RouterDelayProfiler& route_profiler,
vtr::Matrix<std::vector<float>>& matrix,
int layer_num,
int source_x,
Expand Down Expand Up @@ -490,7 +490,7 @@ static void generic_compute_matrix_dijkstra_expansion(
RRNodeId source_rr_node = device_ctx.rr_graph.node_lookup().find_node(layer_num, source_x, source_y, SOURCE, driver_ptc);

VTR_ASSERT(source_rr_node != RRNodeId::INVALID());
auto delays = calculate_all_path_delays_from_rr_node(source_rr_node, router_opts, is_flat);
auto delays = calculate_all_path_delays_from_rr_node(source_rr_node, router_opts, is_flat, route_profiler.get_net_list());

bool path_to_all_sinks = true;
for (int sink_x = start_x; sink_x <= end_x; sink_x++) {
Expand Down
25 changes: 21 additions & 4 deletions vpr/src/route/connection_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ t_heap* ConnectionRouter<Heap>::timing_driven_route_connection_from_heap(RRNodeI
// This is then placed into the traceback so that the correct path is returned
// TODO: This can be eliminated by modifying the actual traceback function in route_timing
if (rcv_path_manager.is_enabled()) {
rcv_path_manager.insert_backwards_path_into_traceback(cheapest->path_data, cheapest->cost, cheapest->backward_path_cost, route_ctx);
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

long line
consider breaking it to multiple lines

}
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());
break;
Expand Down Expand Up @@ -552,6 +552,8 @@ void ConnectionRouter<Heap>::timing_driven_add_to_heap(const t_conn_cost_params&
// Costs initialized to current
next.cost = std::numeric_limits<float>::infinity(); //Not used directly
next.backward_path_cost = current->backward_path_cost;
next.backward_path_delay = current->backward_path_delay;
next.backward_path_congestion = current->backward_path_congestion;

// path_data variables are initialized to current values
if (rcv_path_manager.is_enabled() && current->path_data) {
Expand Down Expand Up @@ -597,6 +599,8 @@ void ConnectionRouter<Heap>::timing_driven_add_to_heap(const t_conn_cost_params&
next_ptr->cost = next.cost;
next_ptr->R_upstream = next.R_upstream;
next_ptr->backward_path_cost = next.backward_path_cost;
next_ptr->backward_path_delay = next.backward_path_delay;
next_ptr->backward_path_congestion = next.backward_path_congestion;
next_ptr->index = to_node;
next_ptr->set_prev_edge(from_edge);

Expand Down Expand Up @@ -657,6 +661,7 @@ float ConnectionRouter<Heap>::compute_node_cost_using_rcv(const t_conn_cost_para
// TODO: This function is not tested for is_flat == true
VTR_ASSERT(is_flat_ != true);
std::tie(expected_delay, expected_cong) = router_lookahead_.get_expected_delay_and_cong(to_node, target_node, cost_params, R_upstream);
router_lookahead_.scale_delay_and_cong_by_criticality(expected_delay, expected_cong, cost_params);

float expected_total_delay_cost;
float expected_total_cong_cost;
Expand Down Expand Up @@ -784,6 +789,8 @@ void ConnectionRouter<Heap>::evaluate_timing_driven_node_costs(t_heap* to,
//Update the backward cost (upstream already included)
to->backward_path_cost += (1. - cost_params.criticality) * cong_cost; //Congestion cost
to->backward_path_cost += cost_params.criticality * Tdel; //Delay cost
to->backward_path_delay += Tdel;
to->backward_path_congestion += cong_cost;

if (cost_params.bend_cost != 0.) {
t_rr_type from_type = rr_graph_->node_type(from_node);
Expand Down Expand Up @@ -832,6 +839,8 @@ void ConnectionRouter<Heap>::empty_heap_annotating_node_route_inf() {

rr_node_route_inf_[tmp->index].path_cost = tmp->cost;
rr_node_route_inf_[tmp->index].backward_path_cost = tmp->backward_path_cost;
rr_node_route_inf_[tmp->index].backward_path_delay = tmp->backward_path_delay;
rr_node_route_inf_[tmp->index].backward_path_congestion = tmp->backward_path_congestion;
modified_rr_node_inf_.push_back(tmp->index);

rcv_path_manager.free_path_struct(tmp->path_data);
Expand Down Expand Up @@ -892,6 +901,8 @@ void ConnectionRouter<Heap>::add_route_tree_node_to_heap(
const auto& device_ctx = g_vpr_ctx.device();
const RRNodeId inode = rt_node.inode;
float backward_path_cost = cost_params.criticality * rt_node.Tdel;
float backward_path_delay = rt_node.Tdel;
float backward_path_congestion = 0.0;
float R_upstream = rt_node.R_upstream;

/* Don't push to heap if not in bounding box: no-op for serial router, important for parallel router */
Expand All @@ -913,9 +924,15 @@ void ConnectionRouter<Heap>::add_route_tree_node_to_heap(
tot_cost,
describe_rr_node(device_ctx.rr_graph, device_ctx.grid, device_ctx.rr_indexed_data, inode, is_flat_).c_str());

push_back_node(&heap_, rr_node_route_inf_,
inode, tot_cost, RREdgeId::INVALID(),
backward_path_cost, R_upstream);
push_back_node(&heap_,
rr_node_route_inf_,
inode,
tot_cost,
RREdgeId::INVALID(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

named parameter comment for RREdgeId::INVALID()

backward_path_cost,
backward_path_delay,
backward_path_congestion,
R_upstream);
} else {
float expected_total_cost = compute_node_cost_using_rcv(cost_params, inode, target_node, rt_node.Tdel, 0, R_upstream);

Expand Down
7 changes: 7 additions & 0 deletions vpr/src/route/connection_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class ConnectionRouter : public ConnectionRouterInterface {
// Ensure route budgets have been calculated before enabling this
void set_rcv_enabled(bool enable) final;

// Get a const reference to the router's lookahead
const RouterLookahead& get_router_lookahead() const {
return router_lookahead_;
}

private:
// Mark that data associated with rr_node "inode" has been modified, and
// needs to be reset in reset_path_costs.
Expand All @@ -148,6 +153,8 @@ class ConnectionRouter : public ConnectionRouterInterface {
route_inf->prev_edge = cheapest->prev_edge();
route_inf->path_cost = cheapest->cost;
route_inf->backward_path_cost = cheapest->backward_path_cost;
route_inf->backward_path_delay = cheapest->backward_path_delay;
route_inf->backward_path_congestion = cheapest->backward_path_congestion;
}

/** Common logic from timing_driven_route_connection_from_route_tree and
Expand Down
2 changes: 2 additions & 0 deletions vpr/src/route/heap_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ HeapStorage::alloc() {
temp_ptr->set_next_heap_item(nullptr);
temp_ptr->cost = 0.;
temp_ptr->backward_path_cost = 0.;
temp_ptr->backward_path_delay = 0.;
temp_ptr->backward_path_congestion = 0.;
temp_ptr->R_upstream = 0.;
temp_ptr->index = RRNodeId::INVALID();
temp_ptr->path_data = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions vpr/src/route/heap_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct t_heap {
///@brief The "known" cost of the path up to and including this node. Used only by the timing-driven router. In this case, the
///.cost member contains not only the known backward cost but also an expected cost to the target.
float backward_path_cost = 0.;
float backward_path_delay = 0.;
float backward_path_congestion = 0.;
///@brief Used only by the timing-driven router. Stores the upstream resistance to ground from this node, including the resistance
/// of the node itself (device_ctx.rr_nodes[index].R).
float R_upstream = 0.;
Expand Down
Loading
Loading