Skip to content

Commit 099d040

Browse files
replace ChanPlaceCostFacContainer with vtr::NdOffsetMatrix
1 parent 451b929 commit 099d040

File tree

2 files changed

+29
-56
lines changed

2 files changed

+29
-56
lines changed

vpr/src/place/net_cost_handler.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,22 @@ NetCostHandler::NetCostHandler(const t_placer_opts& placer_opts,
157157
void NetCostHandler::alloc_and_load_chan_w_factors_for_place_cost_(float place_cost_exp) {
158158
auto& device_ctx = g_vpr_ctx.device();
159159

160-
const size_t grid_height = device_ctx.grid.height();
161-
const size_t grid_width = device_ctx.grid.width();
160+
const int grid_height = device_ctx.grid.height();
161+
const int grid_width = device_ctx.grid.width();
162162

163163
/* Access arrays below as chan?_place_cost_fac_(subhigh, sublow). Since subhigh must be greater than or
164164
* equal to sublow, we will only access the lower half of a matrix, but we allocate the whole matrix anyway
165165
* for simplicity, so we can use the vtr utility matrix functions. */
166-
chanx_place_cost_fac_.resize({grid_height + 1, grid_height + 1});
167-
chany_place_cost_fac_.resize({grid_width + 1, grid_width + 1});
166+
chanx_place_cost_fac_ = vtr::NdOffsetMatrix<float, 2>({{{-1, grid_height - 1}, {-1, grid_height - 1}}});
167+
chanx_place_cost_fac_ = vtr::NdOffsetMatrix<float, 2>({{{-1, grid_width - 1}, {-1, grid_width - 1}}});
168168

169169
// First compute the number of tracks between channel high and channel low, inclusive.
170-
chanx_place_cost_fac_(-1, -1) = 0;
170+
chanx_place_cost_fac_[-1][-1] = 0;
171171

172-
for (int high = 0; high < (int)grid_height; high++) {
173-
chanx_place_cost_fac_(high, high) = (float)device_ctx.chan_width.x_list[high];
172+
for (int high = 0; high < grid_height; high++) {
173+
chanx_place_cost_fac_[high][high] = (float)device_ctx.chan_width.x_list[high];
174174
for (int low = -1; low < high; low++) {
175-
chanx_place_cost_fac_(high, low) = chanx_place_cost_fac_(high - 1, low) + (float)device_ctx.chan_width.x_list[high];
175+
chanx_place_cost_fac_[high][low] = chanx_place_cost_fac_[high - 1][low] + (float)device_ctx.chan_width.x_list[high];
176176
}
177177
}
178178

@@ -183,50 +183,50 @@ void NetCostHandler::alloc_and_load_chan_w_factors_for_place_cost_(float place_c
183183
* place_cost_exp power -- numbers other than one mean this is no *
184184
* longer a simple "average number of tracks"; it is some power of *
185185
* that, allowing greater penalization of narrow channels. */
186-
for (int high = -1; high < (int)grid_height; high++) {
186+
for (int high = -1; high < grid_height; high++) {
187187
for (int low = -1; low <= high; low++) {
188188
/* Since we will divide the wiring cost by the average channel *
189189
* capacity between high and low, having only 0 width channels *
190190
* will result in infinite wiring capacity normalization *
191191
* factor, and extremely bad placer behaviour. Hence we change *
192192
* this to a small (1 track) channel capacity instead. */
193-
if (chanx_place_cost_fac_(high, low) == 0.0f) {
193+
if (chanx_place_cost_fac_[high][low] == 0.0f) {
194194
VTR_LOG_WARN("CHANX place cost fac is 0 at %d %d\n", high, low);
195-
chanx_place_cost_fac_(high, low) = 1.0f;
195+
chanx_place_cost_fac_[high][low] = 1.0f;
196196
}
197197

198-
chanx_place_cost_fac_(high, low) = (high - low + 1.) / chanx_place_cost_fac_(high, low);
199-
chanx_place_cost_fac_(high, low) = pow((double)chanx_place_cost_fac_(high, low), (double)place_cost_exp);
198+
chanx_place_cost_fac_[high][low] = (high - low + 1.) / chanx_place_cost_fac_[high][low];
199+
chanx_place_cost_fac_[high][low] = pow((double)chanx_place_cost_fac_[high][low], (double)place_cost_exp);
200200
}
201201
}
202202

203203
/* Now do the same thing for the y-directed channels. First get the
204204
* number of tracks between channel high and channel low, inclusive. */
205-
chany_place_cost_fac_(-1, -1) = 0;
205+
chany_place_cost_fac_[-1][-1] = 0;
206206

207-
for (int high = 0; high < (int)grid_width; high++) {
208-
chany_place_cost_fac_(high, high) = device_ctx.chan_width.y_list[high];
207+
for (int high = 0; high < grid_width; high++) {
208+
chany_place_cost_fac_[high][high] = device_ctx.chan_width.y_list[high];
209209
for (int low = -1; low < high; low++) {
210-
chany_place_cost_fac_(high, low) = chany_place_cost_fac_(high - 1, low) + device_ctx.chan_width.y_list[high];
210+
chany_place_cost_fac_[high][low] = chany_place_cost_fac_[high - 1][low] + device_ctx.chan_width.y_list[high];
211211
}
212212
}
213213

214214
/* Now compute the inverse of the average number of tracks per channel
215215
* between high and low. Take to specified power. */
216-
for (int high = -1; high < (int)grid_width; high++) {
216+
for (int high = -1; high < grid_width; high++) {
217217
for (int low = -1; low <= high; low++) {
218218
/* Since we will divide the wiring cost by the average channel *
219219
* capacity between high and low, having only 0 width channels *
220220
* will result in infinite wiring capacity normalization *
221221
* factor, and extremely bad placer behaviour. Hence we change *
222222
* this to a small (1 track) channel capacity instead. */
223-
if (chany_place_cost_fac_(high, low) == 0.0f) {
223+
if (chany_place_cost_fac_[high][low] == 0.0f) {
224224
VTR_LOG_WARN("CHANY place cost fac is 0 at %d %d\n", high, low);
225-
chany_place_cost_fac_(high, low) = 1.0f;
225+
chany_place_cost_fac_[high][low] = 1.0f;
226226
}
227227

228-
chany_place_cost_fac_(high, low) = (high - low + 1.) / chany_place_cost_fac_(high, low);
229-
chany_place_cost_fac_(high, low) = pow((double)chany_place_cost_fac_(high, low), (double)place_cost_exp);
228+
chany_place_cost_fac_[high][low] = (high - low + 1.) / chany_place_cost_fac_[high][low];
229+
chany_place_cost_fac_[high][low] = pow((double)chany_place_cost_fac_[high][low], (double)place_cost_exp);
230230
}
231231
}
232232
}
@@ -1411,8 +1411,8 @@ double NetCostHandler::get_net_cube_bb_cost_(ClusterNetId net_id, bool use_ts) {
14111411
*/
14121412

14131413
double ncost;
1414-
ncost = (bb.xmax - bb.xmin + 1) * crossing * chanx_place_cost_fac_(bb.ymax, bb.ymin - 1);
1415-
ncost += (bb.ymax - bb.ymin + 1) * crossing * chany_place_cost_fac_(bb.xmax, bb.xmin - 1);
1414+
ncost = (bb.xmax - bb.xmin + 1) * crossing * chanx_place_cost_fac_[bb.ymax][bb.ymin - 1];
1415+
ncost += (bb.ymax - bb.ymin + 1) * crossing * chany_place_cost_fac_[bb.xmax][bb.xmin - 1];
14161416

14171417
return ncost;
14181418
}
@@ -1454,10 +1454,10 @@ double NetCostHandler::get_net_per_layer_bb_cost_(ClusterNetId net_id , bool use
14541454
*/
14551455

14561456
ncost += (bb[layer_num].xmax - bb[layer_num].xmin + 1) * crossing
1457-
* chanx_place_cost_fac_(bb[layer_num].ymax, bb[layer_num].ymin - 1);
1457+
* chanx_place_cost_fac_[bb[layer_num].ymax][bb[layer_num].ymin - 1];
14581458

14591459
ncost += (bb[layer_num].ymax - bb[layer_num].ymin + 1) * crossing
1460-
* chany_place_cost_fac_(bb[layer_num].xmax, bb[layer_num].xmin - 1);
1460+
* chany_place_cost_fac_[bb[layer_num].xmax][bb[layer_num].xmin - 1];
14611461
}
14621462

14631463
return ncost;

vpr/src/place/net_cost_handler.h

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "timing_place.h"
1111
#include "move_transactions.h"
1212
#include "place_util.h"
13+
#include "vtr_ndoffsetmatrix.h"
1314

1415
#include <functional>
1516

@@ -190,34 +191,6 @@ class NetCostHandler {
190191
vtr::vector<ClusterNetId, double> proposed_net_cost_;
191192
vtr::vector<ClusterNetId, NetUpdateState> bb_update_status_;
192193

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-
*/
203-
class ChanPlaceCostFacContainer : public vtr::NdMatrix<float, 2> {
204-
public:
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));
215-
}
216-
217-
private:
218-
using vtr::NdMatrix<float, 2>::operator[];
219-
};
220-
221194
/**
222195
* @brief Matrices below are used to precompute the inverse of the average
223196
* number of tracks per channel between [subhigh] and [sublow]. Access
@@ -227,8 +200,8 @@ class NetCostHandler {
227200
* number of tracks in that direction; for other cost functions they
228201
* will never be used.
229202
*/
230-
ChanPlaceCostFacContainer chanx_place_cost_fac_; // [-1...device_ctx.grid.width()-1]
231-
ChanPlaceCostFacContainer chany_place_cost_fac_; // [-1...device_ctx.grid.height()-1]
203+
vtr::NdOffsetMatrix<float, 2> chanx_place_cost_fac_; // [-1...device_ctx.grid.width()-1]
204+
vtr::NdOffsetMatrix<float, 2> chany_place_cost_fac_; // [-1...device_ctx.grid.height()-1]
232205

233206

234207
private:

0 commit comments

Comments
 (0)