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)) */
143145static 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+ */
145159static 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