Skip to content

Commit 0693f1d

Browse files
add comments
1 parent 35a7e3e commit 0693f1d

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

vpr/src/place/net_cost_handler.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,12 @@ NetCostHandler::NetCostHandler(const t_placer_opts& placer_opts,
155155
}
156156

157157
void NetCostHandler::alloc_and_load_chan_w_factors_for_place_cost_(float place_cost_exp) {
158-
/* Allocates and loads the chanx_place_cost_fac and chany_place_cost_fac *
159-
* arrays with the inverse of the average number of tracks per channel *
160-
* between [subhigh] and [sublow]. This is only useful for the cost *
161-
* function that takes the length of the net bounding box in each *
162-
* dimension divided by the average number of tracks in that direction. *
163-
* For other cost functions, you don't have to bother calling this *
164-
* routine; when using the cost function described above, however, you *
165-
* must always call this routine after you call init_chan and before *
166-
* you do any placement cost determination. The place_cost_exp factor *
167-
* specifies to what power the width of the channel should be taken -- *
168-
* larger numbers make narrower channels more expensive. */
169-
170158
auto& device_ctx = g_vpr_ctx.device();
171159

172160
const size_t grid_height = device_ctx.grid.height();
173161
const size_t grid_width = device_ctx.grid.width();
174162

175-
/* Access arrays below as chan?_place_cost_fac[subhigh][sublow]. Since subhigh must be greater than or
163+
/* Access arrays below as chan?_place_cost_fac_(subhigh, sublow). Since subhigh must be greater than or
176164
* equal to sublow, we will only access the lower half of a matrix, but we allocate the whole matrix anyway
177165
* for simplicity, so we can use the vtr utility matrix functions. */
178166
chanx_place_cost_fac_.resize({grid_height + 1, grid_height + 1});
@@ -189,7 +177,7 @@ void NetCostHandler::alloc_and_load_chan_w_factors_for_place_cost_(float place_c
189177
}
190178

191179
/* Now compute the inverse of the average number of tracks per channel *
192-
* between high and low. The cost function divides by the average *
180+
* between high and low. The cost function divides by the average *
193181
* number of tracks per channel, so by storing the inverse I convert *
194182
* this to a faster multiplication. Take this final number to the *
195183
* place_cost_exp power -- numbers other than one mean this is no *
@@ -1400,6 +1388,7 @@ void NetCostHandler::get_layer_bb_from_scratch_(ClusterNetId net_id,
14001388
}
14011389
}
14021390

1391+
14031392
double NetCostHandler::get_net_cube_bb_cost_(ClusterNetId net_id, bool use_ts) {
14041393
// Finds the cost due to one net by looking at its coordinate bounding box.
14051394
auto& cluster_ctx = g_vpr_ctx.clustering();
@@ -1415,6 +1404,12 @@ double NetCostHandler::get_net_cube_bb_cost_(ClusterNetId net_id, bool use_ts) {
14151404
/* Cost = wire length along channel * cross_count / average *
14161405
* channel capacity. Do this for x, then y direction and add. */
14171406

1407+
/* For average channel width factor, I'll always include the channel immediately
1408+
* below and the channel immediately to the left of the bounding box, so both bb.ymin
1409+
* and bb.xmin are subtracted by 1 before being used as indices of chan?_place_cost_fac_.
1410+
* chan?_place_cost_fac_ objects can handle -1 indices internally.
1411+
*/
1412+
14181413
double ncost;
14191414
ncost = (bb.xmax - bb.xmin + 1) * crossing * chanx_place_cost_fac_(bb.ymax, bb.ymin - 1);
14201415
ncost += (bb.ymax - bb.ymin + 1) * crossing * chany_place_cost_fac_(bb.xmax, bb.xmin - 1);
@@ -1452,6 +1447,12 @@ double NetCostHandler::get_net_per_layer_bb_cost_(ClusterNetId net_id , bool use
14521447
/* Cost = wire length along channel * cross_count / average *
14531448
* channel capacity. Do this for x, then y direction and add. */
14541449

1450+
/* For average channel width factor, I'll always include the channel immediately
1451+
* below and the channel immediately to the left of the bounding box, so both bb.ymin
1452+
* and bb.xmin are subtracted by 1 before being used as indices of chan?_place_cost_fac_.
1453+
* chan?_place_cost_fac_ objects can handle -1 indices internally.
1454+
*/
1455+
14551456
ncost += (bb[layer_num].xmax - bb[layer_num].xmin + 1) * crossing
14561457
* chanx_place_cost_fac_(bb[layer_num].ymax, bb[layer_num].ymin - 1);
14571458

vpr/src/place/net_cost_handler.h

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,28 @@ class NetCostHandler {
190190
vtr::vector<ClusterNetId, double> proposed_net_cost_;
191191
vtr::vector<ClusterNetId, NetUpdateState> bb_update_status_;
192192

193+
/**
194+
* @brief This class is used to store the inverse of average channel
195+
* width between two channels inclusive. The difference of this class
196+
* with vtr::NdMatrix<float, 2> is that its index spaces starts from -1.
197+
* When the inverse average channel width is factored in, the channel
198+
* immediately below and the channel immediately to the left of the
199+
* bounding box are also considered. This class makes sure that when
200+
* the left and bottom edges of the bounding boxes are moved by one unit,
201+
* the indices used to access inverse average channel width are still valid.
202+
*/
193203
class ChanPlaceCostFacContainer : public vtr::NdMatrix<float, 2> {
194204
public:
195-
inline float& operator()(int i, int j) {
196-
return this->operator[]((size_t)(i+1)).operator[]((size_t)(j+1));
205+
/**
206+
* @brief Returns the inverse average channel width between channels low
207+
* and high inclusive.
208+
* @param high The high channel number.
209+
* @param low The low channel number.
210+
* @return The inverse average channel width between the given channel
211+
* numbers.
212+
*/
213+
inline float& operator()(int high, int low) {
214+
return this->operator[]((size_t)(high + 1)).operator[]((size_t)(low + 1));
197215
}
198216

199217
private:
@@ -203,14 +221,14 @@ class NetCostHandler {
203221
/**
204222
* @brief Matrices below are used to precompute the inverse of the average
205223
* number of tracks per channel between [subhigh] and [sublow]. Access
206-
* them as chan?_place_cost_fac[subhigh][sublow]. They are used to
224+
* them as chan?_place_cost_fac(subhigh, sublow). They are used to
207225
* speed up the computation of the cost function that takes the length
208226
* of the net bounding box in each dimension, divided by the average
209227
* number of tracks in that direction; for other cost functions they
210228
* will never be used.
211229
*/
212-
ChanPlaceCostFacContainer chanx_place_cost_fac_; // [0...device_ctx.grid.width()-2]
213-
ChanPlaceCostFacContainer chany_place_cost_fac_; // [0...device_ctx.grid.height()-2]
230+
ChanPlaceCostFacContainer chanx_place_cost_fac_; // [-1...device_ctx.grid.width()-1]
231+
ChanPlaceCostFacContainer chany_place_cost_fac_; // [-1...device_ctx.grid.height()-1]
214232

215233

216234
private:
@@ -253,6 +271,13 @@ class NetCostHandler {
253271
/**
254272
* @brief Allocates and loads the chanx_place_cost_fac and chany_place_cost_fac arrays with the inverse of
255273
* the average number of tracks per channel between [subhigh] and [sublow].
274+
*
275+
* @details This is only useful for the cost function that takes the length of the net bounding box in each
276+
* dimension divided by the average number of tracks in that direction. For other cost functions, you don't
277+
* have to bother calling this routine; when using the cost function described above, however, you must always
278+
* call this routine before you do any placement cost determination. The place_cost_exp factor specifies to
279+
* what power the width of the channel should be taken -- larger numbers make narrower channels more expensive.
280+
*
256281
* @param place_cost_exp It is an exponent to which you take the average inverse channel capacity;
257282
* a higher value would favour wider channels more over narrower channels during placement (usually we use 1).
258283
*/

0 commit comments

Comments
 (0)