Skip to content

Add extended lookahead map followup #1536

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions vpr/src/route/connection_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ float ConnectionRouter<Heap>::compute_node_cost_using_rcv(const t_conn_cost_para

const t_conn_delay_budget* delay_budget = cost_params.delay_budget;

std::tie(expected_delay, expected_cong) = router_lookahead_.get_expected_delay_and_cong(to_node, target_node, cost_params, R_upstream);
std::tie(expected_delay, expected_cong) = router_lookahead_.get_expected_delay_and_cong(RRNodeId(to_node), RRNodeId(target_node), cost_params, R_upstream);

float expected_total_delay_cost;
float expected_total_cong_cost;
Expand Down Expand Up @@ -761,7 +761,7 @@ void ConnectionRouter<Heap>::evaluate_timing_driven_node_costs(t_heap* to,
total_cost = compute_node_cost_using_rcv(cost_params, to_node, target_node, to->path_data->backward_delay, to->path_data->backward_cong, to->R_upstream);
} else {
//Update total cost
float expected_cost = router_lookahead_.get_expected_cost(to_node, target_node, cost_params, to->R_upstream);
float expected_cost = router_lookahead_.get_expected_cost(RRNodeId(to_node), RRNodeId(target_node), cost_params, to->R_upstream);
VTR_LOGV_DEBUG(router_debug_ && !std::isfinite(expected_cost),
" Lookahead from %s (%s) to %s (%s) is non-finite, expected_cost = %f, to->R_upstream = %f\n",
rr_node_arch_name(to_node).c_str(), describe_rr_node(to_node).c_str(),
Expand Down Expand Up @@ -848,7 +848,7 @@ void ConnectionRouter<Heap>::add_route_tree_node_to_heap(
// tot_cost = backward_path_cost + cost_params.astar_fac * expected_cost;
float tot_cost = backward_path_cost
+ cost_params.astar_fac
* router_lookahead_.get_expected_cost(inode, target_node, cost_params, R_upstream);
* router_lookahead_.get_expected_cost(RRNodeId(inode), RRNodeId(target_node), cost_params, R_upstream);
VTR_LOGV_DEBUG(router_debug_, " Adding node %8d to heap from init route tree with cost %g (%s)\n", inode, tot_cost, describe_rr_node(inode).c_str());

push_back_node(&heap_, rr_node_route_inf_,
Expand Down
13 changes: 9 additions & 4 deletions vpr/src/route/route_timing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ struct RoutingMetrics {
* File-scope variables
*/

//Run-time flag to control when router debug information is printed
//Note only enables debug output if compiled with VTR_ENABLE_DEBUG_LOGGING defined
//f_router_debug is used to stop the router when a breakpoint is reached. When a breakpoint is reached, this flag is set to true.
/**
* @brief Run-time flag to control when router debug information is printed
* Note only enables debug output if compiled with VTR_ENABLE_DEBUG_LOGGING defined
* f_router_debug is used to stop the router when a breakpoint is reached. When a breakpoint is reached, this flag is set to true.
*
* In addition f_router_debug is used to print additional debug information during routing, for instance lookahead expected costs
* information.
*/
bool f_router_debug = false;

//Count the number of times the router has failed
Expand Down Expand Up @@ -2139,7 +2144,7 @@ static void init_net_delay_from_lookahead(const RouterLookahead& router_lookahea
for (size_t ipin = 1; ipin < cluster_ctx.clb_nlist.net_pins(net_id).size(); ++ipin) {
int sink_rr = route_ctx.net_rr_terminals[net_id][ipin];

float est_delay = router_lookahead.get_expected_cost(source_rr, sink_rr, cost_params, /*R_upstream=*/0.);
float est_delay = router_lookahead.get_expected_cost(RRNodeId(source_rr), RRNodeId(sink_rr), cost_params, /*R_upstream=*/0.);
VTR_ASSERT(std::isfinite(est_delay) && est_delay < std::numeric_limits<float>::max());

net_delay[net_id][ipin] = est_delay;
Expand Down
39 changes: 19 additions & 20 deletions vpr/src/route/router_lookahead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "globals.h"
#include "route_timing.h"

static int get_expected_segs_to_target(int inode, int target_node, int* num_segs_ortho_dir_ptr);
static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int* num_segs_ortho_dir_ptr);
static int round_up(float x);

static std::unique_ptr<RouterLookahead> make_router_lookahead_object(e_router_lookahead router_lookahead_type) {
Expand Down Expand Up @@ -44,25 +44,23 @@ std::unique_ptr<RouterLookahead> make_router_lookahead(
return router_lookahead;
}

float ClassicLookahead::get_expected_cost(int current_node, int target_node, const t_conn_cost_params& params, float R_upstream) const {
float ClassicLookahead::get_expected_cost(RRNodeId current_node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const {
float delay_cost, cong_cost;
std::tie(delay_cost, cong_cost) = get_expected_delay_and_cong(current_node, target_node, params, R_upstream);

return delay_cost + cong_cost;
}

std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(int node, int target_node, const t_conn_cost_params& params, float R_upstream) 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();

t_rr_type rr_type = device_ctx.rr_nodes[node].type();
t_rr_type rr_type = device_ctx.rr_nodes.node_type(node);

if (rr_type == CHANX || rr_type == CHANY) {
VTR_ASSERT_SAFE(device_ctx.rr_nodes[node].type() == CHANX || device_ctx.rr_nodes[node].type() == CHANY);

int num_segs_ortho_dir = 0;
int num_segs_same_dir = get_expected_segs_to_target(node, target_node, &num_segs_ortho_dir);

int cost_index = device_ctx.rr_nodes[node].cost_index();
int cost_index = device_ctx.rr_nodes.node_cost_index(node);
int ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;

const auto& same_data = device_ctx.rr_indexed_data[cost_index];
Expand Down Expand Up @@ -91,11 +89,11 @@ std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(int node,
}
}

float NoOpLookahead::get_expected_cost(int /*current_node*/, int /*target_node*/, const t_conn_cost_params& /*params*/, float /*R_upstream*/) const {
float NoOpLookahead::get_expected_cost(RRNodeId /*current_node*/, RRNodeId /*target_node*/, const t_conn_cost_params& /*params*/, float /*R_upstream*/) const {
return 0.;
}

std::pair<float, float> NoOpLookahead::get_expected_delay_and_cong(int /*node*/, int /*target_node*/, const t_conn_cost_params& /*params*/, float /*R_upstream*/) const {
std::pair<float, float> NoOpLookahead::get_expected_delay_and_cong(RRNodeId /*node*/, RRNodeId /*target_node*/, const t_conn_cost_params& /*params*/, float /*R_upstream*/) const {
return std::make_pair(0., 0.);
}

Expand All @@ -105,7 +103,7 @@ static int round_up(float x) {
return std::ceil(x - 0.001);
}

static int get_expected_segs_to_target(int inode, int target_node, int* num_segs_ortho_dir_ptr) {
static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int* num_segs_ortho_dir_ptr) {
/* Returns the number of segments the same type as inode that will be needed *
* to reach target_node (not including inode) in each direction (the same *
* direction (horizontal or vertical) as inode and the orthogonal direction).*/
Expand All @@ -117,18 +115,19 @@ static int get_expected_segs_to_target(int inode, int target_node, int* num_segs
int no_need_to_pass_by_clb;
float inv_length, ortho_inv_length, ylow, yhigh, xlow, xhigh;

target_x = device_ctx.rr_nodes[target_node].xlow();
target_y = device_ctx.rr_nodes[target_node].ylow();
cost_index = device_ctx.rr_nodes[inode].cost_index();
target_x = device_ctx.rr_nodes.node_xlow(target_node);
target_y = device_ctx.rr_nodes.node_ylow(target_node);

cost_index = device_ctx.rr_nodes.node_cost_index(inode);
inv_length = device_ctx.rr_indexed_data[cost_index].inv_length;
ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;
ortho_inv_length = device_ctx.rr_indexed_data[ortho_cost_index].inv_length;
rr_type = device_ctx.rr_nodes[inode].type();
rr_type = device_ctx.rr_nodes.node_type(inode);

if (rr_type == CHANX) {
ylow = device_ctx.rr_nodes[inode].ylow();
xhigh = device_ctx.rr_nodes[inode].xhigh();
xlow = device_ctx.rr_nodes[inode].xlow();
ylow = device_ctx.rr_nodes.node_ylow(inode);
xhigh = device_ctx.rr_nodes.node_xhigh(inode);
xlow = device_ctx.rr_nodes.node_xlow(inode);

/* Count vertical (orthogonal to inode) segs first. */

Expand All @@ -153,9 +152,9 @@ static int get_expected_segs_to_target(int inode, int target_node, int* num_segs
num_segs_same_dir = 0;
}
} else { /* inode is a CHANY */
ylow = device_ctx.rr_nodes[inode].ylow();
yhigh = device_ctx.rr_nodes[inode].yhigh();
xlow = device_ctx.rr_nodes[inode].xlow();
ylow = device_ctx.rr_nodes.node_ylow(inode);
yhigh = device_ctx.rr_nodes.node_yhigh(inode);
xlow = device_ctx.rr_nodes.node_xlow(inode);

/* Count horizontal (orthogonal to inode) segs first. */

Expand Down
14 changes: 7 additions & 7 deletions vpr/src/route/router_lookahead.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class RouterLookahead {
//
// Either compute or read methods must be invoked before invoking
// get_expected_cost.
virtual float get_expected_cost(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const = 0;
virtual std::pair<float, float> get_expected_delay_and_cong(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const = 0;
virtual float get_expected_cost(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const = 0;
virtual std::pair<float, float> get_expected_delay_and_cong(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const = 0;

// Compute router lookahead (if needed).
virtual void compute(const std::vector<t_segment_inf>& segment_inf) = 0;
Expand Down Expand Up @@ -54,8 +54,8 @@ const RouterLookahead* get_cached_router_lookahead(

class ClassicLookahead : public RouterLookahead {
public:
float get_expected_cost(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
std::pair<float, float> get_expected_delay_and_cong(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
float get_expected_cost(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;
std::pair<float, float> get_expected_delay_and_cong(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;

void compute(const std::vector<t_segment_inf>& /*segment_inf*/) override {
}
Expand All @@ -68,13 +68,13 @@ class ClassicLookahead : public RouterLookahead {
}

private:
float classic_wire_lookahead_cost(int node, int target_node, float criticality, float R_upstream) const;
float classic_wire_lookahead_cost(RRNodeId node, RRNodeId target_node, float criticality, float R_upstream) const;
};

class NoOpLookahead : public RouterLookahead {
protected:
float get_expected_cost(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
std::pair<float, float> get_expected_delay_and_cong(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
float get_expected_cost(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;
std::pair<float, float> get_expected_delay_and_cong(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;

void compute(const std::vector<t_segment_inf>& /*segment_inf*/) override {
}
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/route/router_lookahead_cost_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class CostMap {
///<delta locations that fall outside of a segment's bounding box.
///<The penalty map is addressed as follows penalty_[0][segment_index]

size_t seg_count_; ///<Total segment count in the architecture
size_t seg_count_ = 0; ///<Total segment count in the architecture

/**
* @brief Get penalty delay for a segment type
Expand Down
18 changes: 9 additions & 9 deletions vpr/src/route/router_lookahead_extended_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ float ExtendedMapLookahead::get_chan_ipin_delays(RRNodeId to_node) const {
auto& device_ctx = g_vpr_ctx.device();
auto& rr_graph = device_ctx.rr_nodes;

e_rr_type to_type = rr_graph.node_type(to_node);
VTR_ASSERT(to_type == SINK || to_type == IPIN);

auto to_tile_type = device_ctx.grid[rr_graph.node_xlow(to_node)][rr_graph.node_ylow(to_node)].type;
auto to_tile_index = to_tile_type->index;

Expand All @@ -166,14 +169,11 @@ float ExtendedMapLookahead::get_chan_ipin_delays(RRNodeId to_node) const {
//
// The from_node can be of one of the following types: CHANX, CHANY, SOURCE, OPIN
// The to_node is always a SINK
std::pair<float, float> ExtendedMapLookahead::get_expected_delay_and_cong(int inode, int target_node, const t_conn_cost_params& params, float /*R_upstream*/) const {
if (inode == target_node) {
std::pair<float, float> ExtendedMapLookahead::get_expected_delay_and_cong(RRNodeId from_node, RRNodeId to_node, const t_conn_cost_params& params, float /*R_upstream*/) const {
if (from_node == to_node) {
return std::make_pair(0., 0.);
}

RRNodeId from_node(inode);
RRNodeId to_node(target_node);

auto& device_ctx = g_vpr_ctx.device();
auto& rr_graph = device_ctx.rr_nodes;

Expand Down Expand Up @@ -230,7 +230,7 @@ std::pair<float, float> ExtendedMapLookahead::get_expected_delay_and_cong(int in

VTR_LOGV_DEBUG(f_router_debug, "Requested lookahead from node %d to %d\n", size_t(from_node), size_t(to_node));
const std::string& segment_name = device_ctx.rr_segments[from_seg_index].name;
VTR_LOGV_DEBUG(f_router_debug, "Lookahead returned %s (%d) with distance (%zd, %zd)\n",
VTR_LOGV_DEBUG(f_router_debug, "Lookahead returned %s (%d) with distance (%d, %d)\n",
segment_name.c_str(), from_seg_index,
dx, dy);
VTR_LOGV_DEBUG(f_router_debug, "Lookahead delay: %g\n", expected_delay_cost);
Expand Down Expand Up @@ -567,13 +567,13 @@ void ExtendedMapLookahead::compute(const std::vector<t_segment_inf>& segment_inf

// get an expected minimum cost for routing from the current node to the target node
float ExtendedMapLookahead::get_expected_cost(
int current_node,
int target_node,
RRNodeId current_node,
RRNodeId target_node,
const t_conn_cost_params& params,
float R_upstream) const {
auto& device_ctx = g_vpr_ctx.device();

t_rr_type rr_type = device_ctx.rr_nodes[current_node].type();
t_rr_type rr_type = device_ctx.rr_nodes.node_type(current_node);

if (rr_type == CHANX || rr_type == CHANY || rr_type == SOURCE || rr_type == OPIN) {
float delay_cost, cong_cost;
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/route/router_lookahead_extended_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class ExtendedMapLookahead : public RouterLookahead {
/**
* @brief Returns the expected cost to get to a destination node
*/
float get_expected_cost(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
float get_expected_cost(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;

/**
* @brief Returns a pair of expected delay and congestion
*/
std::pair<float, float> get_expected_delay_and_cong(int inode, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
std::pair<float, float> get_expected_delay_and_cong(RRNodeId inode, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;

/**
* @brief Computes the extended lookahead map
Expand Down
17 changes: 7 additions & 10 deletions vpr/src/route/router_lookahead_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ static void print_wire_cost_map(const std::vector<t_segment_inf>& segment_inf);
static void print_router_cost_map(const t_routing_cost_map& router_cost_map);

/******** Interface class member function definitions ********/
float MapLookahead::get_expected_cost(int current_node, int target_node, const t_conn_cost_params& params, float R_upstream) const {
float MapLookahead::get_expected_cost(RRNodeId current_node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const {
auto& device_ctx = g_vpr_ctx.device();
auto& rr_graph = device_ctx.rr_nodes;

t_rr_type rr_type = rr_graph.node_type(RRNodeId(current_node));
t_rr_type rr_type = rr_graph.node_type(current_node);

if (rr_type == CHANX || rr_type == CHANY || rr_type == SOURCE || rr_type == OPIN) {
float delay_cost, cong_cost;
Expand All @@ -252,13 +252,10 @@ float MapLookahead::get_expected_cost(int current_node, int target_node, const t
/******** Function Definitions ********/
/* queries the lookahead_map (should have been computed prior to routing) to get the expected cost
* from the specified source to the specified target */
std::pair<float, float> MapLookahead::get_expected_delay_and_cong(int inode, int target_node, const t_conn_cost_params& params, float /*R_upstream*/) const {
std::pair<float, float> MapLookahead::get_expected_delay_and_cong(RRNodeId from_node, RRNodeId to_node, const t_conn_cost_params& params, float /*R_upstream*/) const {
auto& device_ctx = g_vpr_ctx.device();
auto& rr_graph = device_ctx.rr_nodes;

RRNodeId from_node(inode);
RRNodeId to_node(target_node);

int delta_x, delta_y;
get_xy_deltas(from_node, to_node, &delta_x, &delta_y);
delta_x = abs(delta_x);
Expand Down Expand Up @@ -329,8 +326,8 @@ std::pair<float, float> MapLookahead::get_expected_delay_and_cong(int inode, int

VTR_ASSERT_SAFE_MSG(std::isfinite(expected_delay_cost),
vtr::string_fmt("Lookahead failed to estimate cost from %s: %s",
rr_node_arch_name(size_t(inode)).c_str(),
describe_rr_node(size_t(inode)).c_str())
rr_node_arch_name(size_t(from_node)).c_str(),
describe_rr_node(size_t(from_node)).c_str())
.c_str());

} else if (from_type == CHANX || from_type == CHANY) {
Expand All @@ -353,8 +350,8 @@ std::pair<float, float> MapLookahead::get_expected_delay_and_cong(int inode, int

VTR_ASSERT_SAFE_MSG(std::isfinite(expected_delay_cost),
vtr::string_fmt("Lookahead failed to estimate cost from %s: %s",
rr_node_arch_name(size_t(inode)).c_str(),
describe_rr_node(size_t(inode)).c_str())
rr_node_arch_name(size_t(from_node)).c_str(),
describe_rr_node(size_t(from_node)).c_str())
.c_str());
} else if (from_type == IPIN) { /* Change if you're allowing route-throughs */
return std::make_pair(0., device_ctx.rr_indexed_data[SINK_COST_INDEX].base_cost);
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/route/router_lookahead_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class MapLookahead : public RouterLookahead {
util::t_src_opin_delays src_opin_delays;

protected:
float get_expected_cost(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
std::pair<float, float> get_expected_delay_and_cong(int inode, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
float get_expected_cost(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;
std::pair<float, float> get_expected_delay_and_cong(RRNodeId from_node, RRNodeId to_node, const t_conn_cost_params& params, float R_upstream) const override;

void compute(const std::vector<t_segment_inf>& segment_inf) override;
void read(const std::string& file) override;
Expand Down
Loading