@@ -271,22 +271,37 @@ void NetCostHandler::alloc_and_load_for_fast_vertical_cost_update_(float place_c
271271 }
272272 }
273273
274- for (int x_high = 0 ; x_high < (int )device_ctx.grid .width (); x_high++) {
275- for (int y_high = 0 ; y_high < (int )device_ctx.grid .height (); y_high++) {
276- for (int x_low = 0 ; x_low <= x_high; x_low++) {
277- for (int y_low = 0 ; y_low <= y_high; y_low++) {
278- int num_inter_die_conn = 0 ;
279- for (int x = x_low; x <= x_high; x++) {
280- for (int y = y_low; y <= y_high; y++) {
281- num_inter_die_conn += tile_num_inter_die_conn[x][y];
282- }
283- }
284- int seen_num_tiles = (x_high - x_low + 1 ) * (y_high - y_low + 1 );
285- chanz_place_cost_fac_[x_high][y_high][x_low][y_low] = seen_num_tiles / static_cast <float >(num_inter_die_conn);
274+ vtr::NdMatrix<float , 2 > acc_tile_num_inter_die_conn ({grid_width, grid_height}, 0 .);
275+ acc_tile_num_inter_die_conn[0 ][0 ] = tile_num_inter_die_conn[0 ][0 ];
276+ // Initialize the first row and column
277+ for (size_t x = 1 ; x < device_ctx.grid .width (); x++) {
278+ acc_tile_num_inter_die_conn[x][0 ] = acc_tile_num_inter_die_conn[x-1 ][0 ] + \
279+ tile_num_inter_die_conn[x][0 ];
280+ }
286281
287- chanz_place_cost_fac_[x_high][y_high][x_low][y_low] = pow (
288- (double )chanz_place_cost_fac_[x_high][y_high][x_low][y_low],
289- (double )place_cost_exp);
282+ for (size_t y = 1 ; y < device_ctx.grid .height (); y++) {
283+ acc_tile_num_inter_die_conn[0 ][y] = acc_tile_num_inter_die_conn[0 ][y-1 ] + \
284+ tile_num_inter_die_conn[0 ][y];
285+ }
286+
287+ for (size_t x_high = 1 ; x_high < device_ctx.grid .width (); x_high++) {
288+ for (size_t y_high = 1 ; y_high < device_ctx.grid .height (); y_high++) {
289+ for (size_t x_low = 1 ; x_low <= x_high; x_low++) {
290+ for (size_t y_low = 1 ; y_low <= y_high; y_low++) {
291+ int num_inter_die_conn = acc_tile_num_inter_die_conn[x_high][y_high] - \
292+ acc_tile_num_inter_die_conn[x_low-1 ][y_high] - \
293+ acc_tile_num_inter_die_conn[x_high][y_low-1 ] + \
294+ acc_tile_num_inter_die_conn[x_low-1 ][y_low-1 ];
295+ int seen_num_tiles = (x_high - x_low + 1 ) * (y_high - y_low + 1 );
296+ if (num_inter_die_conn == 0 ) {
297+ VTR_LOG_WARN (" CHANZ place cost fac is 0 at (%lu,%lu), (%lu,%lu)\n " , x_low, y_low, x_high, y_high);
298+ chanz_place_cost_fac_[x_high][y_high][x_low][y_low] = 1 .0f ;
299+ } else {
300+ chanz_place_cost_fac_[x_high][y_high][x_low][y_low] = seen_num_tiles / static_cast <float >(num_inter_die_conn);
301+ chanz_place_cost_fac_[x_high][y_high][x_low][y_low] = pow (
302+ (double )chanz_place_cost_fac_[x_high][y_high][x_low][y_low],
303+ (double )place_cost_exp);
304+ }
290305 }
291306 }
292307 }
0 commit comments