Skip to content

Commit 98cc4d8

Browse files
committed
lookahead: addressed review comments
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 070bb74 commit 98cc4d8

File tree

5 files changed

+77
-11
lines changed

5 files changed

+77
-11
lines changed

libs/libvtrutil/src/vtr_geometry.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ Rect<T> bounding_box(const Rect<T>& lhs, const Rect<T>& rhs);
149149
template<typename T, typename std::enable_if<std::is_integral<T>::value>::type...>
150150
Point<T> sample(const vtr::Rect<T>& r, T x, T y, T d);
151151

152+
// clamps v to be between low (lo) and high (hi), inclusive.
153+
template<class T>
154+
static constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
155+
return std::min(std::max(v, lo), hi);
156+
}
157+
152158
//A 2D line
153159
template<class T>
154160
class Line {

vpr/src/route/router_lookahead_cost_map.cpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "router_lookahead_map_utils.h"
44
#include "globals.h"
55
#include "echo_files.h"
6+
#include "vtr_geometry.h"
67

78
#ifdef VTR_ENABLE_CAPNPROTO
89
# include "capnp/serialize.h"
@@ -30,19 +31,13 @@ static int manhattan_distance(const vtr::Point<int>& a, const vtr::Point<int>& b
3031
return abs(b.x() - a.x()) + abs(b.y() - a.y());
3132
}
3233

33-
// clamps v to be between low (lo) and high (hi), inclusive.
34-
template<class T>
35-
static constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
36-
return std::min(std::max(v, lo), hi);
37-
}
38-
3934
template<typename T>
4035
static vtr::Point<T> closest_point_in_rect(const vtr::Rect<T>& r, const vtr::Point<T>& p) {
4136
if (r.empty()) {
4237
return vtr::Point<T>(0, 0);
4338
} else {
44-
return vtr::Point<T>(clamp<T>(p.x(), r.xmin(), r.xmax() - 1),
45-
clamp<T>(p.y(), r.ymin(), r.ymax() - 1));
39+
return vtr::Point<T>(vtr::clamp<T>(p.x(), r.xmin(), r.xmax() - 1),
40+
vtr::clamp<T>(p.y(), r.ymin(), r.ymax() - 1));
4641
}
4742
}
4843

@@ -57,7 +52,11 @@ void CostMap::set_counts(size_t seg_count) {
5752
seg_count_ = seg_count;
5853
}
5954

60-
// cached node -> segment map
55+
/**
56+
* @brief Gets the segment index corresponding to a node index
57+
* @param from_node_ind node index
58+
* @return segment index corresponding to the input node
59+
*/
6160
int CostMap::node_to_segment(int from_node_ind) const {
6261
const auto& device_ctx = g_vpr_ctx.device();
6362

@@ -67,6 +66,26 @@ int CostMap::node_to_segment(int from_node_ind) const {
6766
return device_ctx.rr_indexed_data[from_cost_index].seg_index;
6867
}
6968

69+
/**
70+
* @brief Penalizes a specific cost entry based on its distance to the cost map bounds.
71+
* @param entry cost entry to penalize
72+
* @param distance distance to the cost map bounds (can be zero in case the entry is within the bounds)
73+
* @param penalty penalty factor relative to the current segment type
74+
*
75+
* If a specific (delta_x, delta_y) coordinates pair falls out of a segment bounding box, the returned cost is a result of the following equation:
76+
*
77+
* delay + distance * penalty * PENALTY_FACTOR
78+
*
79+
* delay : delay of the closest point in the bounding box for the specific wire segment
80+
* distance : this can assume two values:
81+
* - 0 : in case the deltas fall within the bounding box (in this case no penalty is added)
82+
* - non-0 : in case the point is out of the bounding box, the value is the manhattan distance between the point and the closest point within the bounding box.
83+
* penalty : value determined when building the lookahead and relative to a specific segment type (meaning there is one penalty value for each segment type).
84+
* The base delay_penalty value is a calculated as follows:
85+
* (max_delay - min_delay) / max(1, manhattan_distance(max_location, min_location))
86+
*
87+
* PENALTY_FACTOR: impact of the penalty on the total delay cost.
88+
*/
7089
static util::Cost_Entry penalize(const util::Cost_Entry& entry, int distance, float penalty) {
7190
penalty = std::max(penalty, PENALTY_MIN);
7291
return util::Cost_Entry(entry.delay + distance * penalty * PENALTY_FACTOR,
@@ -202,6 +221,15 @@ void CostMap::set_cost_map(const util::RoutingCosts& delay_costs, const util::Ro
202221
//
203222
// In case the lookahead is queried to return a cost that is outside of the bounding box, the closest
204223
// cost within the bounding box is returned, with the addition of a calculated penalty cost.
224+
//
225+
// The bounding boxes do have two dimensions and are specified as matrices.
226+
// The first dimension though is unused and set to be constant as it is required to keep consistency
227+
// with the lookahead map. The extended lookahead map and the normal one index the various costs as follows:
228+
// - Lookahead map : [0..chan_index][seg_index][dx][dy]
229+
// - Extended lookahead map: [0][seg_index][dx][dy]
230+
//
231+
// The extended lookahead map does not require the first channel index distinction, therefore the first dimension
232+
// remains unused.
205233
vtr::Matrix<vtr::Rect<int>> bounds({1, seg_count_});
206234
for (const auto& entry : delay_costs) {
207235
bounds[0][entry.first.seg_index].expand_bounding_box(vtr::Rect<int>(entry.first.delta));

vpr/src/route/router_lookahead_cost_map.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class CostMap {
6363
* @param cy y location of the cost map entry that needs to be filled
6464
* @param bounds bounds of the cost map corresponding to the current segment
6565
* @return A pair containing the nearby cost entry and the distance from the current location to the narby cost entry found.
66+
*
67+
* The coordinates identifying the cost map location to fill (cx, cy) need to fall within the bounding box provided as input (bounds). If the (cx, cy) point falls out of the bounds, a default cost entry is returned instead.
6668
*/
6769
std::pair<util::Cost_Entry, int> get_nearby_cost_entry(const vtr::NdMatrix<util::Cost_Entry, 2>& matrix, int cx, int cy, const vtr::Rect<int>& bounds);
6870

vpr/src/route/router_lookahead_extended_map.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@
4545
// Don't continue storing a path after hitting a lower-or-same cost entry.
4646
static constexpr bool BREAK_ON_MISS = false;
4747

48-
///@brief Threshold indicating the minimum number of paths to sample for each point in a sample region
48+
/**
49+
* @brief Threshold indicating the minimum number of paths to sample for each point in a sample region
50+
*
51+
* Each sample region contains a set of points containing the starting nodes from which the Dijkstra expansions
52+
* are performed.
53+
* Each node produces a number N of paths that are being explored exhaustively until no more expansions are possible,
54+
* and the number of paths for each Dijkstra run is added to the total number of paths found when computing a sample region
55+
* In case there are still points in a region that were not picked to perform the Dijkstra expansion, and the
56+
* MIN_PATH_COUNT threshold has been reached, the sample region is intended to be complete and the computation of a next
57+
* sample region begins.
58+
*/
4959
static constexpr int MIN_PATH_COUNT = 1000;
5060

5161
template<typename Entry>
@@ -193,6 +203,16 @@ float ExtendedMapLookahead::get_map_cost(RRNodeId from_node,
193203
float expected_delay = cost_entry.delay;
194204
float expected_congestion = cost_entry.congestion;
195205

206+
// The CHAN -> IPIN delay was removed from the cost map calculation, as it might tamper the addition
207+
// of a smaller cost to this node location. This might happen as not all the CHAN -> IPIN connection
208+
// have a delay, therefore, a different cost than the correct one might have been added to the cost
209+
// map location of the input node.
210+
//
211+
// The CHAN -> IPIN delay gets re-added to the final calculation as it effectively is a valid delay
212+
// to reach the destination.
213+
//
214+
// TODO: Capture this delay as a funtion of both the current wire type and the ipin to have a more
215+
// realistic excpected cost returned.
196216
float site_pin_delay = this->get_chan_ipin_delays(to_node);
197217
expected_delay += site_pin_delay;
198218

@@ -549,6 +569,8 @@ float ExtendedMapLookahead::get_expected_cost(
549569
return get_map_cost(
550570
RRNodeId(current_node), RRNodeId(target_node), params.criticality);
551571
} else if (rr_type == IPIN) { /* Change if you're allowing route-throughs */
572+
// This is to return only the cost between the IPIN and SINK. No need to
573+
// query the cost map, as the routing of this connection is almost done.
552574
return (device_ctx.rr_indexed_data[SINK_COST_INDEX].base_cost);
553575
} else { /* Change this if you want to investigate route-throughs */
554576
return (0.);

vpr/src/route/router_lookahead_extended_map.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ExtendedMapLookahead : public RouterLookahead {
2222
* @param from_node starting node
2323
* @param delta_x x delta value that is the distance between the current node to the target node
2424
* @param delta_y y delta value that is the distance between the current node to the target node
25-
* @param criticality_fac criticality of the current connection
25+
* @param criticality_fac criticality of the current connection between 0 (all congestion) and 1 (all timing)
2626
* @return expected cost to get to the destination
2727
*/
2828
float get_src_opin_cost(RRNodeId from_node, int delta_x, int delta_y, float criticality_fac) const;
@@ -31,6 +31,14 @@ class ExtendedMapLookahead : public RouterLookahead {
3131
* @brief Returns the CHAN -> IPIN delay that gets added to the final expected delay
3232
* @param to_node target node for which we query the IPIN delay
3333
* @return IPIN delay relative to the input destination node
34+
*
35+
* The CHAN -> IPIN delay was removed from the cost map calculation, as it might tamper the addition
36+
* of a smaller cost to this node location. This might happen as not all the CHAN -> IPIN connection
37+
* have a delay, therefore, a different cost than the correct one might have been added to the cost
38+
* map location of the input node.
39+
*
40+
* The CHAN -> IPIN delay gets re-added to the final calculation as it effectively is a valid delay
41+
* to reach the destination.
3442
*/
3543
float get_chan_ipin_delays(RRNodeId to_node) const;
3644

0 commit comments

Comments
 (0)