Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Shreve committed Aug 12, 2024
1 parent c88364a commit d406c57
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 410 deletions.
3 changes: 3 additions & 0 deletions vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#ifndef NO_SERVER

#include "gateio.h"
# include "lookahead_profiler.h"
#include "taskresolver.h"

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

LookaheadProfiler lookahead_profiler;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion vpr/src/route/connection_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ float ConnectionRouter<Heap>::compute_node_cost_using_rcv(const t_conn_cost_para
const t_conn_delay_budget* delay_budget = cost_params.delay_budget;
// 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, false);
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
188 changes: 77 additions & 111 deletions vpr/src/route/lookahead_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "vpr_utils.h"
#include "re_cluster_util.h"

LookaheadProfiler lookahead_profiler = LookaheadProfiler();

LookaheadProfiler::LookaheadProfiler() {
lookahead_verifier_csv.open("lookahead_verifier_info.csv", std::ios::out);

Expand Down Expand Up @@ -45,136 +43,104 @@ LookaheadProfiler::LookaheadProfiler() {
<< std::endl;
}

void LookaheadProfiler::record(const int iteration,
const int target_net_pin_index,
const RRNodeId source_inode,
const RRNodeId sink_inode,
const RRNodeId curr_inode,
const size_t nodes_from_sink,
void LookaheadProfiler::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) {
const Netlist<>& net_list,
std::vector<RRNodeId> branch_inodes) {
auto& device_ctx = g_vpr_ctx.device();
const auto& rr_graph = device_ctx.rr_graph;
auto& route_ctx = g_vpr_ctx.routing();

float total_backward_cost = route_ctx.rr_node_route_inf[sink_inode].backward_path_cost;
float total_backward_delay = route_ctx.rr_node_route_inf[sink_inode].backward_path_delay;
float total_backward_congestion = route_ctx.rr_node_route_inf[sink_inode].backward_path_congestion;
if (iteration < 1)
return;

auto current_node = route_ctx.rr_node_route_inf[curr_inode];
float current_backward_cost = current_node.backward_path_cost;
float current_backward_delay = current_node.backward_path_delay;
float current_backward_congestion = current_node.backward_path_congestion;
for (size_t i = 2; i < branch_inodes.size(); ++i) { /* Distance one node away is always 0.0 (IPIN->SINK) */
RRNodeId source_inode = branch_inodes.back();
RRNodeId sink_inode = branch_inodes.front();
RRNodeId curr_inode = branch_inodes[i];

auto [from_x, from_y] = util::get_adjusted_rr_position(curr_inode);
auto [to_x, to_y] = util::get_adjusted_rr_position(sink_inode);
float total_backward_cost = route_ctx.rr_node_route_inf[sink_inode].backward_path_cost;
float total_backward_delay = route_ctx.rr_node_route_inf[sink_inode].backward_path_delay;
float total_backward_congestion = route_ctx.rr_node_route_inf[sink_inode].backward_path_congestion;

int delta_x = to_x - from_x;
int delta_y = to_y - from_y;
auto current_node = route_ctx.rr_node_route_inf[curr_inode];
float current_backward_cost = current_node.backward_path_cost;
float current_backward_delay = current_node.backward_path_delay;
float current_backward_congestion = current_node.backward_path_congestion;

float djikstra_cost = total_backward_cost - current_backward_cost;
float djikstra_delay = total_backward_delay - current_backward_delay;
float djikstra_congestion = total_backward_congestion - current_backward_congestion;
auto [from_x, from_y] = util::get_adjusted_rr_position(curr_inode);
auto [to_x, to_y] = util::get_adjusted_rr_position(sink_inode);

float lookahead_cost = router_lookahead.get_expected_cost(curr_inode, sink_inode, cost_params,
0.0);
float lookahead_delay, lookahead_congestion;
std::tie(lookahead_delay, lookahead_congestion) = router_lookahead.get_expected_delay_and_cong(curr_inode, sink_inode, cost_params, 0.0, true);
int delta_x = to_x - from_x;
int delta_y = to_y - from_y;

std::string block_name = "--";
std::string atom_block_model = "--";
std::string cluster_block_type = "--";
std::string tile_height = "--";
std::string tile_width = "--";
float djikstra_cost = total_backward_cost - current_backward_cost;
float djikstra_delay = total_backward_delay - current_backward_delay;
float djikstra_congestion = total_backward_congestion - current_backward_congestion;

if (atom_block_names.find(sink_inode) != atom_block_names.end()) {
VTR_ASSERT_SAFE(atom_block_models.find(sink_inode) != atom_block_models.end());
VTR_ASSERT_SAFE(cluster_block_types.find(sink_inode) != cluster_block_types.end());
VTR_ASSERT_SAFE(tile_dimensions.find(sink_inode) != tile_dimensions.end());
float lookahead_cost = router_lookahead.get_expected_cost(curr_inode, sink_inode, cost_params, 0.0);
auto [lookahead_delay, lookahead_congestion] = router_lookahead.get_expected_delay_and_cong(curr_inode, sink_inode, cost_params, 0.0);

block_name = atom_block_names[sink_inode];
atom_block_model = atom_block_models[sink_inode];
cluster_block_type = cluster_block_types[sink_inode];
std::tie(tile_width, tile_height) = tile_dimensions[sink_inode];
} else {
if (net_id != ParentNetId::INVALID() && target_net_pin_index != OPEN) {
block_name = net_list.block_name(net_list.net_pin_block(net_id, target_net_pin_index));
if (atom_block_names.find(sink_inode) == atom_block_names.end()) {
if (net_id != ParentNetId::INVALID() && target_net_pin_index != OPEN) {
atom_block_names[sink_inode] = net_list.block_name(net_list.net_pin_block(net_id, target_net_pin_index));

AtomBlockId atom_block_id = g_vpr_ctx.atom().nlist.find_block(block_name);
atom_block_model = g_vpr_ctx.atom().nlist.block_model(atom_block_id)->name;
AtomBlockId atom_block_id = g_vpr_ctx.atom().nlist.find_block(atom_block_names[sink_inode]);
atom_block_models[sink_inode] = g_vpr_ctx.atom().nlist.block_model(atom_block_id)->name;

ClusterBlockId cluster_block_id = atom_to_cluster(atom_block_id);
ClusterBlockId cluster_block_id = atom_to_cluster(atom_block_id);

cluster_block_type = g_vpr_ctx.clustering().clb_nlist.block_type(cluster_block_id)->name;
cluster_block_types[sink_inode] = g_vpr_ctx.clustering().clb_nlist.block_type(cluster_block_id)->name;

auto tile_type = physical_tile_type(cluster_block_id);
tile_height = std::to_string(tile_type->height);
tile_width = std::to_string(tile_type->width);
auto tile_type = physical_tile_type(cluster_block_id);
tile_dimensions[sink_inode] = std::pair(std::to_string(tile_type->width), std::to_string(tile_type->height));
} else {
atom_block_names[sink_inode] = "--";
atom_block_models[sink_inode] = "--";
cluster_block_types[sink_inode] = "--";
tile_dimensions[sink_inode] = {"--", "--"};
}
}

atom_block_names[sink_inode] = block_name;
atom_block_models[sink_inode] = atom_block_model;
cluster_block_types[sink_inode] = cluster_block_type;
tile_dimensions[sink_inode] = {tile_width, tile_height};
}
VTR_ASSERT_SAFE(atom_block_names.find(sink_inode) != atom_block_names.end());
VTR_ASSERT_SAFE(atom_block_models.find(sink_inode) != atom_block_models.end());
VTR_ASSERT_SAFE(cluster_block_types.find(sink_inode) != cluster_block_types.end());
VTR_ASSERT_SAFE(tile_dimensions.find(sink_inode) != tile_dimensions.end());

auto node_type = rr_graph.node_type(curr_inode);
std::string node_type_str;
std::string node_length;

switch (node_type) {
case SOURCE:
node_type_str = "SOURCE";
node_length = "--";
break;
case SINK:
node_type_str = "SINK";
node_length = "--";
break;
case IPIN:
node_type_str = "IPIN";
node_length = "--";
break;
case OPIN:
node_type_str = "OPIN";
node_length = "--";
break;
case CHANX:
node_type_str = "CHANX";
node_length = std::to_string(rr_graph.node_length(curr_inode));
break;
case CHANY:
node_type_str = "CHANY";
node_length = std::to_string(rr_graph.node_length(curr_inode));
break;
default:
node_type_str = "--";
node_length = "--";
break;
std::string block_name = atom_block_names[sink_inode];
std::string atom_block_model = atom_block_models[sink_inode];
std::string cluster_block_type = cluster_block_types[sink_inode];
auto [tile_width, tile_height] = tile_dimensions[sink_inode];

std::string node_type_str = rr_graph.node_type_string(curr_inode);
std::string node_length = (node_type_str == "CHANX" || node_type_str == "CHANX")
? std::to_string(rr_graph.node_length(curr_inode))
: "--";

lookahead_verifier_csv << iteration << ","; // iteration no.
lookahead_verifier_csv << source_inode << ","; // source node
lookahead_verifier_csv << sink_inode << ","; // sink node
lookahead_verifier_csv << block_name << ","; // sink block name
lookahead_verifier_csv << atom_block_model << ","; // sink atom block model
lookahead_verifier_csv << cluster_block_type << ","; // sink cluster block type
lookahead_verifier_csv << tile_height << ","; // sink cluster tile height
lookahead_verifier_csv << tile_width << ","; // sink cluster tile width
lookahead_verifier_csv << curr_inode << ","; // current node
lookahead_verifier_csv << node_type_str << ","; // node type
lookahead_verifier_csv << node_length << ","; // node length
lookahead_verifier_csv << i << ","; // num. nodes from sink
lookahead_verifier_csv << delta_x << ","; // delta x
lookahead_verifier_csv << delta_y << ","; // delta y
lookahead_verifier_csv << djikstra_cost << ","; // actual cost
lookahead_verifier_csv << djikstra_delay << ","; // actual delay
lookahead_verifier_csv << djikstra_congestion << ","; // actual congestion
lookahead_verifier_csv << lookahead_cost << ","; // predicted cost
lookahead_verifier_csv << lookahead_delay << ","; // predicted delay
lookahead_verifier_csv << lookahead_congestion << ","; // predicted congestion
lookahead_verifier_csv << cost_params.criticality; // criticality
lookahead_verifier_csv << std::endl;
}

lookahead_verifier_csv << iteration << ","; // iteration no.
lookahead_verifier_csv << source_inode << ","; // source node
lookahead_verifier_csv << sink_inode << ","; // sink node
lookahead_verifier_csv << block_name << ","; // sink block name
lookahead_verifier_csv << atom_block_model << ","; // sink atom block model
lookahead_verifier_csv << cluster_block_type << ","; // sink cluster block type
lookahead_verifier_csv << tile_height << ","; // sink cluster tile height
lookahead_verifier_csv << tile_width << ","; // sink cluster tile width
lookahead_verifier_csv << curr_inode << ","; // current node
lookahead_verifier_csv << node_type_str << ","; // node type
lookahead_verifier_csv << node_length << ","; // node length
lookahead_verifier_csv << nodes_from_sink << ","; // num. nodes from sink
lookahead_verifier_csv << delta_x << ","; // delta x
lookahead_verifier_csv << delta_y << ","; // delta y
lookahead_verifier_csv << djikstra_cost << ","; // actual cost
lookahead_verifier_csv << djikstra_delay << ","; // actual delay
lookahead_verifier_csv << djikstra_congestion << ","; // actual congestion
lookahead_verifier_csv << lookahead_cost << ","; // predicted cost
lookahead_verifier_csv << lookahead_delay << ","; // predicted delay
lookahead_verifier_csv << lookahead_congestion << ","; // predicted congestion
lookahead_verifier_csv << cost_params.criticality; // criticality
lookahead_verifier_csv << std::endl;
}
13 changes: 1 addition & 12 deletions vpr/src/route/lookahead_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ class LookaheadProfiler {
public:
LookaheadProfiler();

void record(int iteration,
int target_net_pin_index,
RRNodeId source_inode,
RRNodeId sink_inode,
RRNodeId curr_inode,
size_t nodes_from_sink,
const t_conn_cost_params& cost_params,
const RouterLookahead& router_lookahead,
const ParentNetId& net_id,
const Netlist<>& net_list);
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;
Expand All @@ -34,6 +25,4 @@ class LookaheadProfiler {
std::unordered_map<RRNodeId, std::pair<std::string, std::string>> tile_dimensions;
};

extern LookaheadProfiler lookahead_profiler;

#endif //VTR_LOOKAHEAD_PROFILER_H
23 changes: 6 additions & 17 deletions vpr/src/route/route_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,23 +549,12 @@ RouteTree::add_subtree_from_heap(t_heap* hptr, int target_net_pin_index, bool is
}
new_branch_iswitches.push_back(new_iswitch);

/*
* ROUTER LOOKAHEAD VERIFIER
*/
if (itry >= 1) {
for (size_t i = 2; i < new_branch_inodes.size(); ++i) { /* Distance one node away is always 0.0 */
lookahead_profiler.record(itry,
target_net_pin_index,
new_branch_inodes.back(),
new_branch_inodes.front(),
new_branch_inodes[i],
i,
cost_params,
router_lookahead,
net_id,
net_list);
}
}
g_vpr_ctx.mutable_routing().lookahead_profiler.record(itry,
target_net_pin_index,
cost_params,
router_lookahead,
net_id,
net_list, std::vector<RRNodeId>());

/* Build the new tree branch starting from the existing node we found */
RouteTreeNode* last_node = _rr_node_to_rt_node[new_inode];
Expand Down
18 changes: 10 additions & 8 deletions vpr/src/route/router_lookahead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ std::unique_ptr<RouterLookahead> make_router_lookahead(const t_det_routing_arch&
return router_lookahead;
}

void RouterLookahead::scale_delay_and_cong_by_criticality(float& delay, float& cong, const t_conn_cost_params& params) const {
delay *= params.criticality;
cong *= 1. - params.criticality;
}

float ClassicLookahead::get_expected_cost(RRNodeId current_node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const {
auto [delay_cost, cong_cost] = get_expected_delay_and_cong(current_node, target_node, params, R_upstream, false);
auto [delay_cost, cong_cost] = get_expected_delay_and_cong(current_node, target_node, params, R_upstream);
scale_delay_and_cong_by_criticality(delay_cost, cong_cost, params);

return delay_cost + cong_cost;
}

std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream, bool ignore_criticality) const {
std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& /*params*/, float R_upstream) const {
auto& device_ctx = g_vpr_ctx.device();
const auto& rr_graph = device_ctx.rr_graph;

Expand Down Expand Up @@ -96,11 +102,7 @@ std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId n
+ R_upstream * (num_segs_same_dir * same_data.C_load + num_segs_ortho_dir * ortho_data.C_load)
+ ipin_data.T_linear;

if (ignore_criticality) {
return std::make_pair(Tdel, cong_cost);
} else {
return std::make_pair(params.criticality * Tdel, (1 - params.criticality) * cong_cost);
}
return std::make_pair(Tdel, cong_cost);
} else if (rr_type == IPIN) { /* Change if you're allowing route-throughs */
return std::make_pair(0., device_ctx.rr_indexed_data[RRIndexedDataId(SINK_COST_INDEX)].base_cost);

Expand All @@ -113,7 +115,7 @@ float NoOpLookahead::get_expected_cost(RRNodeId /*current_node*/, RRNodeId /*tar
return 0.;
}

std::pair<float, float> NoOpLookahead::get_expected_delay_and_cong(RRNodeId, RRNodeId, const t_conn_cost_params&, float, bool /*ignore_criticality*/) const {
std::pair<float, float> NoOpLookahead::get_expected_delay_and_cong(RRNodeId, RRNodeId, const t_conn_cost_params&, float) const {
return std::make_pair(0., 0.);
}

Expand Down
Loading

0 comments on commit d406c57

Please sign in to comment.