Skip to content

Commit 08cfc0f

Browse files
committed
equivalent tiles: updated placer to use equivalent tile locations
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 507d661 commit 08cfc0f

File tree

1 file changed

+40
-47
lines changed

1 file changed

+40
-47
lines changed

vpr/src/place/place.cpp

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ static void comp_td_costs(const PlaceDelayModel& delay_model, float *timing_cost
287287

288288
static e_swap_result assess_swap(float delta_c, float t);
289289

290-
static bool find_to(t_type_ptr type, float rlim,
290+
static bool find_to(t_type_ptr from_type, t_type_ptr to_type, float rlim,
291291
int x_from, int y_from,
292292
int *px_to, int *py_to, int *pz_to);
293293
static void find_to_location(t_type_ptr type, float rlim,
294294
int x_from, int y_from,
295-
int *px_to, int *py_to, int *pz_to);
295+
int *px_to, int *py_to, int *pz_to, bool is_equivalent);
296296

297297
static void get_non_updateable_bb(ClusterNetId net_id, t_bb *bb_coord_new);
298298

@@ -353,8 +353,6 @@ static void generate_post_place_timing_reports(const t_placer_opts& placer_opts,
353353
const SetupTimingInfo& timing_info,
354354
const PlacementDelayCalculator& delay_calc);
355355

356-
static std::vector<int> get_available_placement_itypes(t_type_ptr type);
357-
static bool check_if_legal_placement(t_type_ptr cluster_type, t_type_ptr grid_type);
358356
/*****************************************************************************/
359357
void try_place(t_placer_opts placer_opts,
360358
t_annealing_sched annealing_sched,
@@ -1233,6 +1231,8 @@ static int setup_blocks_affected(ClusterBlockId b_from, int x_to, int y_to, int
12331231

12341232
b_to = place_ctx.grid_blocks[x_to][y_to].blocks[z_to];
12351233

1234+
t_type_ptr cluster_to_type = g_vpr_ctx.clustering().clb_nlist.block_type(b_to);
1235+
t_type_ptr grid_from_type = g_vpr_ctx.device().grid[x_from][y_from].type;
12361236
// Check whether the to_location is empty
12371237
if (b_to == EMPTY_BLOCK_ID) {
12381238

@@ -1254,7 +1254,7 @@ static int setup_blocks_affected(ClusterBlockId b_from, int x_to, int y_to, int
12541254
blocks_affected.moved_blocks[imoved_blk].swapped_from_is_empty = true;
12551255
blocks_affected.num_moved_blocks ++;
12561256

1257-
} else if (b_to != INVALID_BLOCK_ID) {
1257+
} else if (b_to != INVALID_BLOCK_ID && cluster_to_type->is_available_tile_index(grid_from_type->index)) {
12581258

12591259
// Does not allow a swap with a macro yet
12601260
get_imacro_from_iblk(&imacro, b_to, pl_macros, num_pl_macros);
@@ -1297,7 +1297,10 @@ static int setup_blocks_affected(ClusterBlockId b_from, int x_to, int y_to, int
12971297
blocks_affected.moved_blocks[imoved_blk].swapped_from_is_empty = false;
12981298
blocks_affected.num_moved_blocks ++;
12991299

1300-
} // Finish swapping the blocks and setting up blocks_affected
1300+
} else {
1301+
abort_swap = true;
1302+
return (abort_swap);
1303+
}// Finish swapping the blocks and setting up blocks_affected
13011304

13021305
return (abort_swap);
13031306

@@ -1355,7 +1358,7 @@ static int find_affected_blocks(ClusterBlockId b_from, int x_to, int y_to, int z
13551358
if ( curr_x_to < 1 || curr_x_to >= int(device_ctx.grid.width())
13561359
|| curr_y_to < 1 || curr_y_to >= int(device_ctx.grid.height())
13571360
|| curr_z_to < 0
1358-
|| device_ctx.grid[curr_x_to][curr_y_to].type != cluster_ctx.clb_nlist.block_type(curr_b_from)) {
1361+
|| !cluster_ctx.clb_nlist.block_type(curr_b_from)->is_available_tile_index(device_ctx.grid[curr_x_to][curr_y_to].type->index)) {
13591362
abort_swap = true;
13601363
} else {
13611364
abort_swap = setup_blocks_affected(curr_b_from, curr_x_to, curr_y_to, curr_z_to);
@@ -1415,11 +1418,18 @@ static e_swap_result try_swap(float t,
14151418

14161419
auto cluster_from_type = cluster_ctx.clb_nlist.block_type(b_from);
14171420
auto grid_from_type = g_vpr_ctx.device().grid[x_from][y_from].type;
1421+
VTR_ASSERT(cluster_from_type->is_available_tile_index(grid_from_type->index));
14181422

1419-
VTR_ASSERT(check_if_legal_placement(cluster_from_type, grid_from_type));
1423+
t_type_ptr to_block_type = cluster_ctx.clb_nlist.block_type(b_from);
1424+
int rand_block_type = vtr::irand(to_block_type->num_equivalent_tiles);
1425+
if (rand_block_type != 0) {
1426+
to_block_type = to_block_type->equivalent_tiles[rand_block_type-1];
1427+
}
14201428

1421-
if (!find_to(cluster_ctx.clb_nlist.block_type(b_from), rlim, x_from, y_from, &x_to, &y_to, &z_to))
1422-
return REJECTED;
1429+
VTR_ASSERT(cluster_from_type->is_available_tile_index(to_block_type->index));
1430+
1431+
if (!find_to(cluster_from_type, to_block_type, rlim, x_from, y_from, &x_to, &y_to, &z_to))
1432+
return REJECTED;
14231433

14241434
#if 0
14251435
auto& grid = g_vpr_ctx.device().grid;
@@ -1449,7 +1459,7 @@ static e_swap_result try_swap(float t,
14491459

14501460
// Find all the nets affected by this swap and update thier bounding box
14511461
int num_nets_affected = find_affected_nets_and_update_costs(place_algorithm, delay_model, bb_delta_c, timing_delta_c, delay_delta_c);
1452-
1462+
14531463
if (place_algorithm == PATH_TIMING_DRIVEN_PLACE) {
14541464
/*in this case we redefine delta_c as a combination of timing and bb. *
14551465
*additionally, we normalize all values, therefore delta_c is in *
@@ -1730,7 +1740,7 @@ static void update_td_delta_costs(const PlaceDelayModel& delay_model, const Clus
17301740
}
17311741
}
17321742

1733-
static bool find_to(t_type_ptr type, float rlim,
1743+
static bool find_to(t_type_ptr from_type, t_type_ptr to_type, float rlim,
17341744
int x_from, int y_from,
17351745
int *px_to, int *py_to, int *pz_to) {
17361746

@@ -1747,9 +1757,7 @@ static bool find_to(t_type_ptr type, float rlim,
17471757

17481758
auto& grid = g_vpr_ctx.device().grid;
17491759
auto& place_ctx = g_vpr_ctx.placement();
1750-
1751-
auto grid_type = grid[x_from][y_from].type;
1752-
VTR_ASSERT(check_if_legal_placement(type, grid_type));
1760+
auto& cluster_ctx = g_vpr_ctx.clustering();
17531761

17541762
int rlx = min<float>(grid.width() - 1, rlim);
17551763
int rly = min<float>(grid.height() - 1, rlim); /* Added rly for aspect_ratio != 1 case. */
@@ -1768,27 +1776,27 @@ static bool find_to(t_type_ptr type, float rlim,
17681776
}
17691777

17701778
num_tries = 0;
1771-
itype = type->index;
1779+
itype = to_type->index;
17721780

17731781
do { /* Until legal */
17741782
is_legal = true;
17751783

17761784
/* Limit the number of tries when searching for an alternative position */
1777-
if(num_tries >= 2 * min(active_area / (type->width * type->height), num_legal_pos[itype]) + 10) {
1785+
if(num_tries >= 2 * min(active_area / (to_type->width * to_type->height), num_legal_pos[itype]) + 10) {
17781786
/* Tried randomly searching for a suitable position */
17791787
return false;
17801788
} else {
17811789
num_tries++;
17821790
}
17831791

1784-
find_to_location(type, rlim, x_from, y_from,
1785-
px_to, py_to, pz_to);
1792+
find_to_location(to_type, rlim, x_from, y_from,
1793+
px_to, py_to, pz_to, from_type != to_type);
17861794

17871795
if((x_from == *px_to) && (y_from == *py_to)) {
17881796
is_legal = false;
17891797
} else if(*px_to > max_x || *px_to < min_x || *py_to > max_y || *py_to < min_y) {
17901798
is_legal = false;
1791-
} else if(grid[*px_to][*py_to].type != grid[x_from][y_from].type) {
1799+
} else if(to_type != grid[*px_to][*py_to].type) {
17921800
is_legal = false;
17931801
} else {
17941802
/* Find z_to and test to validate that the "to" block is *not* fixed */
@@ -1797,7 +1805,11 @@ static bool find_to(t_type_ptr type, float rlim,
17971805
*pz_to = vtr::irand(grid[*px_to][*py_to].type->capacity - 1);
17981806
}
17991807
ClusterBlockId b_to = place_ctx.grid_blocks[*px_to][*py_to].blocks[*pz_to];
1800-
if ((b_to != EMPTY_BLOCK_ID) && (place_ctx.block_locs[b_to].is_fixed == true)) {
1808+
auto b_to_type = cluster_ctx.clb_nlist.block_type(b_to);
1809+
auto grid_from_type = grid[x_from][y_from].type;
1810+
1811+
if (b_to != EMPTY_BLOCK_ID &&
1812+
((place_ctx.block_locs[b_to].is_fixed == true) || (!b_to_type->is_available_tile_index(grid_from_type->index)))) {
18011813
is_legal = false;
18021814
}
18031815
}
@@ -1810,13 +1822,13 @@ static bool find_to(t_type_ptr type, float rlim,
18101822
vpr_throw(VPR_ERROR_PLACE, __FILE__, __LINE__,"in routine find_to: (x_to,y_to) = (%d,%d)\n", *px_to, *py_to);
18111823
}
18121824

1813-
VTR_ASSERT(check_if_legal_placement(type, grid[*px_to][*py_to].type));
1825+
VTR_ASSERT(from_type->is_available_tile_index(grid[*px_to][*py_to].type->index));
18141826
return true;
18151827
}
18161828

18171829
static void find_to_location(t_type_ptr type, float rlim,
18181830
int x_from, int y_from,
1819-
int *px_to, int *py_to, int *pz_to) {
1831+
int *px_to, int *py_to, int *pz_to, bool is_equivalent) {
18201832

18211833
auto& device_ctx = g_vpr_ctx.device();
18221834
auto& grid = device_ctx.grid;
@@ -1834,7 +1846,7 @@ static void find_to_location(t_type_ptr type, float rlim,
18341846
int max_y = min<float>(grid.height() - 1, y_from + rly);
18351847

18361848
*pz_to = 0;
1837-
if (int(grid.width() / 4) < rlx || int(grid.height() / 4) < rly || num_legal_pos[itype] < active_area) {
1849+
if (int(grid.width() / 4) < rlx || int(grid.height() / 4) < rly || num_legal_pos[itype] < active_area || is_equivalent) {
18381850
int ipos = vtr::irand(num_legal_pos[itype] - 1);
18391851
*px_to = legal_pos[itype][ipos].x;
18401852
*py_to = legal_pos[itype][ipos].y;
@@ -2848,7 +2860,7 @@ static void initial_placement_pl_macros(int macros_max_num_tries, int * free_loc
28482860

28492861
bool no_free_locations = true;
28502862
// Loop over all the possible equivalent tiles
2851-
for (int itype : get_available_placement_itypes(cluster_ctx.clb_nlist.block_type(blk_id))) {
2863+
for (int itype : cluster_ctx.clb_nlist.block_type(blk_id)->available_tiles_indices) {
28522864
if (free_locations[itype] >= pl_macros[imacro].num_blocks) {
28532865
no_free_locations = false;
28542866
} else {
@@ -2935,7 +2947,7 @@ static void initial_placement_blocks(int * free_locations, enum e_pad_loc_type p
29352947
*/
29362948
bool no_free_locations = true;
29372949
// Loop over all the possible equivalent tiles
2938-
for (int itype : get_available_placement_itypes(cluster_ctx.clb_nlist.block_type(blk_id))) {
2950+
for (int itype : cluster_ctx.clb_nlist.block_type(blk_id)->available_tiles_indices) {
29392951
if (free_locations[itype] > 0) {
29402952
no_free_locations = false;
29412953
} else {
@@ -2983,6 +2995,7 @@ static void initial_placement_blocks(int * free_locations, enum e_pad_loc_type p
29832995

29842996
static void initial_placement_location(int * free_locations, int itype,
29852997
int *pipos, int *px_to, int *py_to, int *pz_to) {
2998+
29862999
*pipos = vtr::irand(free_locations[itype] - 1);
29873000
*px_to = legal_pos[itype][*pipos].x;
29883001
*py_to = legal_pos[itype][*pipos].y;
@@ -3236,8 +3249,7 @@ static void check_place(const t_placer_costs& costs,
32363249
if (EMPTY_BLOCK_ID == bnum || INVALID_BLOCK_ID == bnum)
32373250
continue;
32383251

3239-
// Check if block has been placed in a valid location
3240-
if (!check_if_legal_placement(cluster_ctx.clb_nlist.block_type(bnum), device_ctx.grid[i][j].type)) {
3252+
if (!cluster_ctx.clb_nlist.block_type(bnum)->is_available_tile_index(device_ctx.grid[i][j].type->index)) {
32413253
VTR_LOG_ERROR(
32423254
"Block %zu type (%s) does not match grid location (%zu,%zu) type (%s).\n",
32433255
size_t(bnum), cluster_ctx.clb_nlist.block_type(bnum)->name, i, j, device_ctx.grid[i][j].type->name);
@@ -3376,22 +3388,3 @@ static void generate_post_place_timing_reports(const t_placer_opts& placer_opts,
33763388

33773389
timing_reporter.report_timing_setup(placer_opts.post_place_timing_report_file, *timing_info.setup_analyzer(), analysis_opts.timing_report_npaths);
33783390
}
3379-
3380-
static std::vector<int> get_available_placement_itypes(t_type_ptr type) {
3381-
std::vector<int> itypes(1, type->index);
3382-
3383-
for(int itype = 0; itype < type->num_equivalent_tiles; itype++) {
3384-
itypes.push_back(type->equivalent_tiles[itype]->index);
3385-
}
3386-
3387-
return itypes;
3388-
}
3389-
3390-
static bool check_if_legal_placement(t_type_ptr cluster_type, t_type_ptr grid_type) {
3391-
std::vector<int> itypes = get_available_placement_itypes(cluster_type);
3392-
if (std::find(itypes.begin(), itypes.end(), grid_type->index) != itypes.end()) {
3393-
return true;
3394-
}
3395-
3396-
return false;
3397-
}

0 commit comments

Comments
 (0)