Skip to content

Commit 51227f3

Browse files
committed
lookahead: have get_expected_cost using RRNodeIds instead of plain int
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent f6aa8d2 commit 51227f3

8 files changed

+46
-53
lines changed

vpr/src/route/connection_router.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ float ConnectionRouter<Heap>::compute_node_cost_using_rcv(const t_conn_cost_para
621621

622622
const t_conn_delay_budget* delay_budget = cost_params.delay_budget;
623623

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

626626
float expected_total_delay_cost;
627627
float expected_total_cong_cost;
@@ -761,7 +761,7 @@ void ConnectionRouter<Heap>::evaluate_timing_driven_node_costs(t_heap* to,
761761
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);
762762
} else {
763763
//Update total cost
764-
float expected_cost = router_lookahead_.get_expected_cost(to_node, target_node, cost_params, to->R_upstream);
764+
float expected_cost = router_lookahead_.get_expected_cost(RRNodeId(to_node), RRNodeId(target_node), cost_params, to->R_upstream);
765765
VTR_LOGV_DEBUG(router_debug_ && !std::isfinite(expected_cost),
766766
" Lookahead from %s (%s) to %s (%s) is non-finite, expected_cost = %f, to->R_upstream = %f\n",
767767
rr_node_arch_name(to_node).c_str(), describe_rr_node(to_node).c_str(),
@@ -848,7 +848,7 @@ void ConnectionRouter<Heap>::add_route_tree_node_to_heap(
848848
// tot_cost = backward_path_cost + cost_params.astar_fac * expected_cost;
849849
float tot_cost = backward_path_cost
850850
+ cost_params.astar_fac
851-
* router_lookahead_.get_expected_cost(inode, target_node, cost_params, R_upstream);
851+
* router_lookahead_.get_expected_cost(RRNodeId(inode), RRNodeId(target_node), cost_params, R_upstream);
852852
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());
853853

854854
push_back_node(&heap_, rr_node_route_inf_,

vpr/src/route/route_timing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,7 @@ static void init_net_delay_from_lookahead(const RouterLookahead& router_lookahea
21442144
for (size_t ipin = 1; ipin < cluster_ctx.clb_nlist.net_pins(net_id).size(); ++ipin) {
21452145
int sink_rr = route_ctx.net_rr_terminals[net_id][ipin];
21462146

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

21502150
net_delay[net_id][ipin] = est_delay;

vpr/src/route/router_lookahead.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "globals.h"
77
#include "route_timing.h"
88

9-
static int get_expected_segs_to_target(int inode, int target_node, int* num_segs_ortho_dir_ptr);
9+
static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int* num_segs_ortho_dir_ptr);
1010
static int round_up(float x);
1111

1212
static std::unique_ptr<RouterLookahead> make_router_lookahead_object(e_router_lookahead router_lookahead_type) {
@@ -44,25 +44,23 @@ std::unique_ptr<RouterLookahead> make_router_lookahead(
4444
return router_lookahead;
4545
}
4646

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

5151
return delay_cost + cong_cost;
5252
}
5353

54-
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 {
54+
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 {
5555
auto& device_ctx = g_vpr_ctx.device();
5656

57-
t_rr_type rr_type = device_ctx.rr_nodes[node].type();
57+
t_rr_type rr_type = device_ctx.rr_nodes.node_type(node);
5858

5959
if (rr_type == CHANX || rr_type == CHANY) {
60-
VTR_ASSERT_SAFE(device_ctx.rr_nodes[node].type() == CHANX || device_ctx.rr_nodes[node].type() == CHANY);
61-
6260
int num_segs_ortho_dir = 0;
6361
int num_segs_same_dir = get_expected_segs_to_target(node, target_node, &num_segs_ortho_dir);
6462

65-
int cost_index = device_ctx.rr_nodes[node].cost_index();
63+
int cost_index = device_ctx.rr_nodes.node_cost_index(node);
6664
int ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;
6765

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

94-
float NoOpLookahead::get_expected_cost(int /*current_node*/, int /*target_node*/, const t_conn_cost_params& /*params*/, float /*R_upstream*/) const {
92+
float NoOpLookahead::get_expected_cost(RRNodeId /*current_node*/, RRNodeId /*target_node*/, const t_conn_cost_params& /*params*/, float /*R_upstream*/) const {
9593
return 0.;
9694
}
9795

98-
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 {
96+
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 {
9997
return std::make_pair(0., 0.);
10098
}
10199

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

108-
static int get_expected_segs_to_target(int inode, int target_node, int* num_segs_ortho_dir_ptr) {
106+
static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int* num_segs_ortho_dir_ptr) {
109107
/* Returns the number of segments the same type as inode that will be needed *
110108
* to reach target_node (not including inode) in each direction (the same *
111109
* 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
117115
int no_need_to_pass_by_clb;
118116
float inv_length, ortho_inv_length, ylow, yhigh, xlow, xhigh;
119117

120-
target_x = device_ctx.rr_nodes[target_node].xlow();
121-
target_y = device_ctx.rr_nodes[target_node].ylow();
122-
cost_index = device_ctx.rr_nodes[inode].cost_index();
118+
target_x = device_ctx.rr_nodes.node_xlow(target_node);
119+
target_y = device_ctx.rr_nodes.node_ylow(target_node);
120+
121+
cost_index = device_ctx.rr_nodes.node_cost_index(inode);
123122
inv_length = device_ctx.rr_indexed_data[cost_index].inv_length;
124123
ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;
125124
ortho_inv_length = device_ctx.rr_indexed_data[ortho_cost_index].inv_length;
126-
rr_type = device_ctx.rr_nodes[inode].type();
125+
rr_type = device_ctx.rr_nodes.node_type(inode);
127126

128127
if (rr_type == CHANX) {
129-
ylow = device_ctx.rr_nodes[inode].ylow();
130-
xhigh = device_ctx.rr_nodes[inode].xhigh();
131-
xlow = device_ctx.rr_nodes[inode].xlow();
128+
ylow = device_ctx.rr_nodes.node_ylow(inode);
129+
xhigh = device_ctx.rr_nodes.node_xhigh(inode);
130+
xlow = device_ctx.rr_nodes.node_xlow(inode);
132131

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

@@ -153,9 +152,9 @@ static int get_expected_segs_to_target(int inode, int target_node, int* num_segs
153152
num_segs_same_dir = 0;
154153
}
155154
} else { /* inode is a CHANY */
156-
ylow = device_ctx.rr_nodes[inode].ylow();
157-
yhigh = device_ctx.rr_nodes[inode].yhigh();
158-
xlow = device_ctx.rr_nodes[inode].xlow();
155+
ylow = device_ctx.rr_nodes.node_ylow(inode);
156+
yhigh = device_ctx.rr_nodes.node_yhigh(inode);
157+
xlow = device_ctx.rr_nodes.node_xlow(inode);
159158

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

vpr/src/route/router_lookahead.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class RouterLookahead {
1212
//
1313
// Either compute or read methods must be invoked before invoking
1414
// get_expected_cost.
15-
virtual float get_expected_cost(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const = 0;
16-
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;
15+
virtual float get_expected_cost(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const = 0;
16+
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;
1717

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

5555
class ClassicLookahead : public RouterLookahead {
5656
public:
57-
float get_expected_cost(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
58-
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;
57+
float get_expected_cost(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;
58+
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;
5959

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

7070
private:
71-
float classic_wire_lookahead_cost(int node, int target_node, float criticality, float R_upstream) const;
71+
float classic_wire_lookahead_cost(RRNodeId node, RRNodeId target_node, float criticality, float R_upstream) const;
7272
};
7373

7474
class NoOpLookahead : public RouterLookahead {
7575
protected:
76-
float get_expected_cost(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
77-
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;
76+
float get_expected_cost(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;
77+
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;
7878

7979
void compute(const std::vector<t_segment_inf>& /*segment_inf*/) override {
8080
}

vpr/src/route/router_lookahead_extended_map.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,11 @@ float ExtendedMapLookahead::get_chan_ipin_delays(RRNodeId to_node) const {
169169
//
170170
// The from_node can be of one of the following types: CHANX, CHANY, SOURCE, OPIN
171171
// The to_node is always a SINK
172-
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 {
173-
if (inode == target_node) {
172+
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 {
173+
if (from_node == to_node) {
174174
return std::make_pair(0., 0.);
175175
}
176176

177-
RRNodeId from_node(inode);
178-
RRNodeId to_node(target_node);
179-
180177
auto& device_ctx = g_vpr_ctx.device();
181178
auto& rr_graph = device_ctx.rr_nodes;
182179

@@ -570,13 +567,13 @@ void ExtendedMapLookahead::compute(const std::vector<t_segment_inf>& segment_inf
570567

571568
// get an expected minimum cost for routing from the current node to the target node
572569
float ExtendedMapLookahead::get_expected_cost(
573-
int current_node,
574-
int target_node,
570+
RRNodeId current_node,
571+
RRNodeId target_node,
575572
const t_conn_cost_params& params,
576573
float R_upstream) const {
577574
auto& device_ctx = g_vpr_ctx.device();
578575

579-
t_rr_type rr_type = device_ctx.rr_nodes[current_node].type();
576+
t_rr_type rr_type = device_ctx.rr_nodes.node_type(current_node);
580577

581578
if (rr_type == CHANX || rr_type == CHANY || rr_type == SOURCE || rr_type == OPIN) {
582579
float delay_cost, cong_cost;

vpr/src/route/router_lookahead_extended_map.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ class ExtendedMapLookahead : public RouterLookahead {
5959
/**
6060
* @brief Returns the expected cost to get to a destination node
6161
*/
62-
float get_expected_cost(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
62+
float get_expected_cost(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;
6363

6464
/**
6565
* @brief Returns a pair of expected delay and congestion
6666
*/
67-
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;
67+
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;
6868

6969
/**
7070
* @brief Computes the extended lookahead map

vpr/src/route/router_lookahead_map.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ static void print_wire_cost_map(const std::vector<t_segment_inf>& segment_inf);
230230
static void print_router_cost_map(const t_routing_cost_map& router_cost_map);
231231

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

237-
t_rr_type rr_type = rr_graph.node_type(RRNodeId(current_node));
237+
t_rr_type rr_type = rr_graph.node_type(current_node);
238238

239239
if (rr_type == CHANX || rr_type == CHANY || rr_type == SOURCE || rr_type == OPIN) {
240240
float delay_cost, cong_cost;
@@ -252,13 +252,10 @@ float MapLookahead::get_expected_cost(int current_node, int target_node, const t
252252
/******** Function Definitions ********/
253253
/* queries the lookahead_map (should have been computed prior to routing) to get the expected cost
254254
* from the specified source to the specified target */
255-
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 {
255+
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 {
256256
auto& device_ctx = g_vpr_ctx.device();
257257
auto& rr_graph = device_ctx.rr_nodes;
258258

259-
RRNodeId from_node(inode);
260-
RRNodeId to_node(target_node);
261-
262259
int delta_x, delta_y;
263260
get_xy_deltas(from_node, to_node, &delta_x, &delta_y);
264261
delta_x = abs(delta_x);
@@ -329,8 +326,8 @@ std::pair<float, float> MapLookahead::get_expected_delay_and_cong(int inode, int
329326

330327
VTR_ASSERT_SAFE_MSG(std::isfinite(expected_delay_cost),
331328
vtr::string_fmt("Lookahead failed to estimate cost from %s: %s",
332-
rr_node_arch_name(size_t(inode)).c_str(),
333-
describe_rr_node(size_t(inode)).c_str())
329+
rr_node_arch_name(size_t(from_node)).c_str(),
330+
describe_rr_node(size_t(from_node)).c_str())
334331
.c_str());
335332

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

354351
VTR_ASSERT_SAFE_MSG(std::isfinite(expected_delay_cost),
355352
vtr::string_fmt("Lookahead failed to estimate cost from %s: %s",
356-
rr_node_arch_name(size_t(inode)).c_str(),
357-
describe_rr_node(size_t(inode)).c_str())
353+
rr_node_arch_name(size_t(from_node)).c_str(),
354+
describe_rr_node(size_t(from_node)).c_str())
358355
.c_str());
359356
} else if (from_type == IPIN) { /* Change if you're allowing route-throughs */
360357
return std::make_pair(0., device_ctx.rr_indexed_data[SINK_COST_INDEX].base_cost);

vpr/src/route/router_lookahead_map.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class MapLookahead : public RouterLookahead {
1212
util::t_src_opin_delays src_opin_delays;
1313

1414
protected:
15-
float get_expected_cost(int node, int target_node, const t_conn_cost_params& params, float R_upstream) const override;
16-
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;
15+
float get_expected_cost(RRNodeId node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const override;
16+
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;
1717

1818
void compute(const std::vector<t_segment_inf>& segment_inf) override;
1919
void read(const std::string& file) override;

0 commit comments

Comments
 (0)