diff --git a/vpr/src/route/connection_router.cpp b/vpr/src/route/connection_router.cpp index 2113f5df0a7..ac8dc06a2f9 100644 --- a/vpr/src/route/connection_router.cpp +++ b/vpr/src/route/connection_router.cpp @@ -621,7 +621,7 @@ float ConnectionRouter::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; @@ -761,7 +761,7 @@ void ConnectionRouter::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(), @@ -848,7 +848,7 @@ void ConnectionRouter::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_, diff --git a/vpr/src/route/route_timing.cpp b/vpr/src/route/route_timing.cpp index a3910e06fe4..2ea640ff99a 100644 --- a/vpr/src/route/route_timing.cpp +++ b/vpr/src/route/route_timing.cpp @@ -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 @@ -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::max()); net_delay[net_id][ipin] = est_delay; diff --git a/vpr/src/route/router_lookahead.cpp b/vpr/src/route/router_lookahead.cpp index e38f48ee727..68e518898d1 100644 --- a/vpr/src/route/router_lookahead.cpp +++ b/vpr/src/route/router_lookahead.cpp @@ -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 make_router_lookahead_object(e_router_lookahead router_lookahead_type) { @@ -44,25 +44,23 @@ std::unique_ptr 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 ClassicLookahead::get_expected_delay_and_cong(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const { +std::pair 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]; @@ -91,11 +89,11 @@ std::pair 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 NoOpLookahead::get_expected_delay_and_cong(int /*node*/, int /*target_node*/, const t_conn_cost_params& /*params*/, float /*R_upstream*/) const { +std::pair 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.); } @@ -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).*/ @@ -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. */ @@ -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. */ diff --git a/vpr/src/route/router_lookahead.h b/vpr/src/route/router_lookahead.h index 23a01e32bc0..60555ec5c3b 100644 --- a/vpr/src/route/router_lookahead.h +++ b/vpr/src/route/router_lookahead.h @@ -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 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 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& segment_inf) = 0; @@ -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 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 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& /*segment_inf*/) override { } @@ -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 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 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& /*segment_inf*/) override { } diff --git a/vpr/src/route/router_lookahead_cost_map.h b/vpr/src/route/router_lookahead_cost_map.h index 1329a6007c8..39b0fd21751 100644 --- a/vpr/src/route/router_lookahead_cost_map.h +++ b/vpr/src/route/router_lookahead_cost_map.h @@ -100,7 +100,7 @@ class CostMap { ///index; @@ -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 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 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; @@ -230,7 +230,7 @@ std::pair 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); @@ -567,13 +567,13 @@ void ExtendedMapLookahead::compute(const std::vector& 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; diff --git a/vpr/src/route/router_lookahead_extended_map.h b/vpr/src/route/router_lookahead_extended_map.h index 5e57cd340ed..cec8a0faca8 100644 --- a/vpr/src/route/router_lookahead_extended_map.h +++ b/vpr/src/route/router_lookahead_extended_map.h @@ -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 get_expected_delay_and_cong(int inode, int target_node, const t_conn_cost_params& params, float R_upstream) const override; + std::pair 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 diff --git a/vpr/src/route/router_lookahead_map.cpp b/vpr/src/route/router_lookahead_map.cpp index aafae1d14d5..6c9916acc0f 100644 --- a/vpr/src/route/router_lookahead_map.cpp +++ b/vpr/src/route/router_lookahead_map.cpp @@ -230,11 +230,11 @@ static void print_wire_cost_map(const std::vector& 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; @@ -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 MapLookahead::get_expected_delay_and_cong(int inode, int target_node, const t_conn_cost_params& params, float /*R_upstream*/) const { +std::pair 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); @@ -329,8 +326,8 @@ std::pair 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) { @@ -353,8 +350,8 @@ std::pair 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); diff --git a/vpr/src/route/router_lookahead_map.h b/vpr/src/route/router_lookahead_map.h index dfb5d1c768d..067b94890c2 100644 --- a/vpr/src/route/router_lookahead_map.h +++ b/vpr/src/route/router_lookahead_map.h @@ -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 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 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& segment_inf) override; void read(const std::string& file) override; diff --git a/vpr/src/route/router_lookahead_map_utils.cpp b/vpr/src/route/router_lookahead_map_utils.cpp index 6346ba00006..98b56a92ee0 100644 --- a/vpr/src/route/router_lookahead_map_utils.cpp +++ b/vpr/src/route/router_lookahead_map_utils.cpp @@ -198,6 +198,10 @@ util::Cost_Entry util::Expansion_Cost_Entry::get_median_entry() const { /* find median by binning the delays of all entries and then chosing the bin * with the largest number of entries */ + // This is code that needs to be revisited. For the time being, if the median entry + // method calculation is used an assertion is thrown. + VTR_ASSERT_MSG(false, "Get median entry calculation method is not implemented!"); + int num_bins = 10; /* find entries with smallest and largest delays */