Skip to content

Commit 3d80a84

Browse files
committed
vpr: router_lookahead: comment on how missing entries are filled - fix gaurd name
1 parent 98d9a30 commit 3d80a84

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

vpr/src/route/router_lookahead_compressed_map.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Created by amin on 11/27/23.
33
//
44

5-
#ifndef VTR_ROUTER_LOOKAHEAD_SPARSE_MAP_H
6-
#define VTR_ROUTER_LOOKAHEAD_SPARSE_MAP_H
5+
#ifndef VTR_ROUTER_LOOKAHEAD_COMPRESSED_MAP_H
6+
#define VTR_ROUTER_LOOKAHEAD_COMPRESSED_MAP_H
77

88
#include <string>
99
#include <limits>
@@ -72,4 +72,4 @@ typedef vtr::NdMatrix<util::Cost_Entry, 5> t_compressed_wire_cost_map; //[0..num
7272
// The first index is the layer number that the node under consideration is on, and the forth index
7373
// is the layer number that the target node is on.
7474

75-
#endif //VTR_ROUTER_LOOKAHEAD_SPARSE_MAP_H
75+
#endif //VTR_ROUTER_LOOKAHEAD_COMPRESSED_MAP_H

vpr/src/route/router_lookahead_cost_map.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ static constexpr float PENALTY_FACTOR = 1.f;
2626
///@brief Minimum penalty cost that is added when penalizing a delta outside the segment bounding box.
2727
static constexpr float PENALTY_MIN = 1e-12f;
2828

29+
/**
30+
* @brief Store the minimum delay and congestion between `min_cost` and `new_cost` in `min_cost`.
31+
* @attention The cost in either min_cost or new_cost can be invalid.
32+
* @param min_cost
33+
* @param new_cost
34+
*/
35+
static void assign_min_entry(util::Cost_Entry& min_cost, const util::Cost_Entry& new_cost);
36+
2937
// also known as the L1 norm
3038
static int manhattan_distance(const vtr::Point<int>& a, const vtr::Point<int>& b) {
3139
return abs(b.x() - a.x()) + abs(b.y() - a.y());
@@ -341,21 +349,21 @@ std::vector<std::pair<int, int>> CostMap::list_empty() const {
341349
return results;
342350
}
343351

344-
static void assign_min_entry(util::Cost_Entry* dst, const util::Cost_Entry& src) {
352+
static void assign_min_entry(util::Cost_Entry& min_cost, const util::Cost_Entry& new_cost) {
345353
// The values in src is only being assigned to dst if they are valid
346-
if (!std::isnan(src.delay)) {
347-
if (std::isnan(dst->delay)) {
348-
dst->delay = src.delay;
354+
if (!std::isnan(new_cost.delay)) {
355+
if (std::isnan(min_cost.delay)) {
356+
min_cost.delay = new_cost.delay;
349357
} else {
350-
dst->delay = std::min(dst->delay, src.delay);
358+
min_cost.delay = std::min(min_cost.delay, new_cost.delay);
351359
}
352360
}
353361

354-
if (!std::isnan(src.congestion)) {
355-
if (std::isnan(dst->congestion)) {
356-
dst->congestion = src.congestion;
362+
if (!std::isnan(new_cost.congestion)) {
363+
if (std::isnan(min_cost.congestion)) {
364+
min_cost.congestion = new_cost.congestion;
357365
} else {
358-
dst->congestion = std::min(dst->congestion, src.congestion);
366+
min_cost.congestion = std::min(min_cost.congestion, new_cost.congestion);
359367
}
360368
}
361369
}
@@ -384,11 +392,11 @@ std::pair<util::Cost_Entry, int> CostMap::get_nearby_cost_entry(const vtr::NdMat
384392
int yp = cy + oy;
385393
int yn = cy - oy;
386394
if (bounds.contains(vtr::Point<int>(x, yp))) {
387-
assign_min_entry(&min_entry, matrix[x][yp]);
395+
assign_min_entry(min_entry, matrix[x][yp]);
388396
in_bounds = true;
389397
}
390398
if (bounds.contains(vtr::Point<int>(x, yn))) {
391-
assign_min_entry(&min_entry, matrix[x][yn]);
399+
assign_min_entry(min_entry, matrix[x][yn]);
392400
in_bounds = true;
393401
}
394402
}

vpr/src/route/router_lookahead_map.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
# include "serdes_utils.h"
5151
#endif /* VTR_ENABLE_CAPNPROTO */
5252

53+
const int VALID_NEIGHBOR_NUMBER = 3;
54+
5355
/* when a list of delay/congestion entries at a coordinate in Cost_Entry is boiled down to a single
5456
* representative entry, this enum is passed-in to specify how that representative entry should be
5557
* calculated */
@@ -142,6 +144,18 @@ static void fill_in_missing_lookahead_entries(int segment_index, e_rr_type chan_
142144
/* returns a cost entry in the f_wire_cost_map that is near the specified coordinates (and preferably towards (0,0)) */
143145
static util::Cost_Entry get_nearby_cost_entry(int from_layer_num, int x, int y, int to_layer_num, int segment_index, int chan_index);
144146

147+
/**
148+
* @brief Fill in the missing entry in router lookahead map
149+
* If there is a missing entry in the router lookahead, search among its neighbors in a 3x3 window. If there are `VALID_NEIGHBOR_NUMBER` valid entries,
150+
* take the average of them and fill in the missing entry.
151+
* @param from_layer_num The layer num of the source node
152+
* @param missing_dx Dx of the missing input
153+
* @param missing_dy Dy of the missing input
154+
* @param to_layer_num The layer num of the destination point
155+
* @param segment_index The segment index of the source node
156+
* @param chan_index The channel index of the source node
157+
* @return The cost for the missing entry
158+
*/
145159
static util::Cost_Entry get_nearby_cost_entry_average_neighbour(int from_layer_num,
146160
int missing_dx,
147161
int missing_dy,
@@ -641,13 +655,14 @@ static util::Cost_Entry get_nearby_cost_entry_average_neighbour(int from_layer_n
641655
int to_layer_num,
642656
int segment_index,
643657
int chan_index) {
658+
// Make sure that the given loaction doesn't have a valid entry
644659
VTR_ASSERT(std::isnan(f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][missing_dx][missing_dy].delay));
645660
VTR_ASSERT(std::isnan(f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][missing_dx][missing_dy].congestion));
646661

647-
int neighbour_num = 0;
648-
float neighbour_delay_sum = 0;
649-
float neighbour_cong_sum = 0;
650-
std::array<int, 3> window = {-1, 0, 1};
662+
int neighbour_num = 0; // Number of neighbours with valid entry
663+
float neighbour_delay_sum = 0; // Acc of valid delay costs
664+
float neighbour_cong_sum = 0; // Acc of valid congestion costs
665+
std::array<int, 3> window = {-1, 0, 1}; // Average window size
651666
for (int dx : window) {
652667
int neighbour_x = missing_dx + dx;
653668
if (neighbour_x < 0 || neighbour_x >= (int)f_wire_cost_map.dim_size(4)) {
@@ -668,10 +683,12 @@ static util::Cost_Entry get_nearby_cost_entry_average_neighbour(int from_layer_n
668683
}
669684
}
670685

671-
if (neighbour_num >= 3) {
686+
// Store the average only if there are enough number of neighbours with valid entry
687+
if (neighbour_num >= VALID_NEIGHBOR_NUMBER) {
672688
return {neighbour_delay_sum / static_cast<float>(neighbour_num),
673689
neighbour_cong_sum / static_cast<float>(neighbour_num)};
674690
} else {
691+
// If there are not enough neighbours with valid entry, retrieve to the previous way of getting the missing cost
675692
return get_nearby_cost_entry(from_layer_num, missing_dx, missing_dy, to_layer_num, segment_index, chan_index);
676693
}
677694
}

0 commit comments

Comments
 (0)