Skip to content

Commit 49d4396

Browse files
add comments
1 parent a6c8688 commit 49d4396

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

vpr/src/place/net_cost_handler.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,41 @@ void NetCostHandler::alloc_and_load_chan_w_factors_for_place_cost_() {
156156
const int grid_height = (int)device_ctx.grid.height();
157157
const int grid_width = (int)device_ctx.grid.width();
158158

159-
/* Access arrays below as chan?_place_cost_fac_(subhigh, sublow). Since subhigh must be greater than or
160-
* equal to sublow, we will only access the lower half of a matrix, but we allocate the whole matrix anyway
161-
* for simplicity, so we can use the vtr utility matrix functions. */
159+
/* These arrays contain accumulative channel width between channel zero and
160+
* the channel specified by the given index. The accumulated channel width
161+
* is inclusive, meaning that it includes both channel zero and channel `idx`.
162+
* To compute the total channel width between channels 'low' and 'high', use the
163+
* following formula:
164+
* acc_chan?_width_[high] - acc_chan?_width_[low - 1]
165+
* This returns the total number of tracks between channels 'low' and 'high',
166+
* including tracks in these channels.
167+
*
168+
* Channel -1 doesn't exist, so we can say it has zero tracks. We need to be able
169+
* to access these arrays with index -1 to handle cases where the lower channel is 0.
170+
*/
162171
acc_chanx_width_ = vtr::NdOffsetMatrix<int, 1>({{{-1, grid_height}}});
163172
acc_chany_width_ = vtr::NdOffsetMatrix<int, 1>({{{-1, grid_width}}});
164173

165-
// First compute the number of tracks between channel high and channel low, inclusive.
174+
// initialize the first element (index -1) with zero
166175
acc_chanx_width_[-1] = 0;
167176
for (int y = 0; y < grid_height; y++) {
168177
acc_chanx_width_[y] = acc_chanx_width_[y - 1] + device_ctx.chan_width.x_list[y];
178+
179+
/* If the number of tracks in a channel is zero, two consecutive elements take the same
180+
* value. This can lead to a division by zero in get_chanxy_cost_fac_(). To avoid this
181+
* potential issue, we assume that the channel width is at least 1.
182+
*/
169183
if (acc_chanx_width_[y] == acc_chanx_width_[y - 1]) {
170184
acc_chanx_width_[y]++;
171185
}
172186
}
173187

188+
// initialize the first element (index -1) with zero
174189
acc_chany_width_[-1] = 0;
175190
for (int x = 0; x < grid_width; x++) {
176191
acc_chany_width_[x] = acc_chany_width_[x - 1] + device_ctx.chan_width.y_list[x];
192+
193+
// to avoid a division by zero
177194
if (acc_chany_width_[x] == acc_chany_width_[x - 1]) {
178195
acc_chany_width_[x]++;
179196
}

vpr/src/place/net_cost_handler.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,13 @@ class NetCostHandler {
446446
* @param bb_coord_new The new bb calculated by this function
447447
*/
448448
inline void update_bb_same_layer_(ClusterNetId net_id,
449-
const t_physical_tile_loc& pin_old_loc,
450-
const t_physical_tile_loc& pin_new_loc,
451-
const std::vector<t_2D_bb>& curr_bb_edge,
452-
const std::vector<t_2D_bb>& curr_bb_coord,
453-
vtr::NdMatrixProxy<int, 1> bb_pin_sink_count_new,
454-
std::vector<t_2D_bb>& bb_edge_new,
455-
std::vector<t_2D_bb>& bb_coord_new);
449+
const t_physical_tile_loc& pin_old_loc,
450+
const t_physical_tile_loc& pin_new_loc,
451+
const std::vector<t_2D_bb>& curr_bb_edge,
452+
const std::vector<t_2D_bb>& curr_bb_coord,
453+
vtr::NdMatrixProxy<int, 1> bb_pin_sink_count_new,
454+
std::vector<t_2D_bb>& bb_edge_new,
455+
std::vector<t_2D_bb>& bb_coord_new);
456456

457457
/**
458458
* @brief Computes the bounding box from scratch using 2D bounding boxes (per-layer mode)
@@ -510,6 +510,16 @@ class NetCostHandler {
510510
*/
511511
double get_net_wirelength_from_layer_bb_(ClusterNetId net_id);
512512

513+
/**
514+
* @brief Computes the inverse of average channel width for horizontal and
515+
* vertical channels within a bounding box.
516+
* @tparam BBT This can be either t_bb or t_2D_bb.
517+
* @param bb The bounding box for which the inverse of average channel width
518+
* within the bounding box is computed.
519+
* @return std::pair<double, double>
520+
* first -> The inverse of average channel width for horizontal channels.
521+
* second -> The inverse of average channel width for vertical channels.
522+
*/
513523
template<typename BBT>
514524
std::pair<double, double> get_chanxy_cost_fac_(const BBT& bb) {
515525
const int total_chanx_width = acc_chanx_width_[bb.ymax] - acc_chanx_width_[bb.ymin - 1];
@@ -530,9 +540,9 @@ class NetCostHandler {
530540
* distributed across tiles, the cost factor will be the same for all bounding boxes, but it will still
531541
* weight z-directed vs. x- and y-directed connections appropriately.
532542
*
533-
* @param bounding_box Bounding box of the net which chanz cost factor is to be calculated
543+
* @param bb Bounding box of the net which chanz cost factor is to be calculated
534544
* @return ChanZ cost factor
535545
*/
536-
float get_chanz_cost_factor_(const t_bb& bounding_box);
546+
float get_chanz_cost_factor_(const t_bb& bb);
537547

538548
};

0 commit comments

Comments
 (0)