Skip to content

Commit 328604c

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

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

vpr/src/place/place.cpp

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ 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(ClusterBlockId blk, t_type_ptr 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,
@@ -1225,14 +1225,19 @@ static int setup_blocks_affected(ClusterBlockId b_from, int x_to, int y_to, int
12251225
ClusterBlockId b_to;
12261226
int abort_swap = false;
12271227

1228-
auto& place_ctx = g_vpr_ctx.mutable_placement();
1228+
auto& place_ctx = g_vpr_ctx.mutable_placement();
1229+
auto clb_nlist = g_vpr_ctx.clustering().clb_nlist;
1230+
auto grid = g_vpr_ctx.device().grid;
12291231

12301232
x_from = place_ctx.block_locs[b_from].x;
12311233
y_from = place_ctx.block_locs[b_from].y;
12321234
z_from = place_ctx.block_locs[b_from].z;
12331235

12341236
b_to = place_ctx.grid_blocks[x_to][y_to].blocks[z_to];
12351237

1238+
auto cluster_to_type = clb_nlist.block_type(b_to);
1239+
auto grid_from_type = grid[x_from][y_from].type;
1240+
12361241
// Check whether the to_location is empty
12371242
if (b_to == EMPTY_BLOCK_ID) {
12381243

@@ -1254,7 +1259,8 @@ static int setup_blocks_affected(ClusterBlockId b_from, int x_to, int y_to, int
12541259
blocks_affected.moved_blocks[imoved_blk].swapped_from_is_empty = true;
12551260
blocks_affected.num_moved_blocks ++;
12561261

1257-
} else if (b_to != INVALID_BLOCK_ID) {
1262+
// If location is not empty checks that the block in the `to` location is compatible with the `from` location
1263+
} else if (b_to != INVALID_BLOCK_ID && check_if_legal_placement(cluster_to_type, grid_from_type)) {
12581264

12591265
// Does not allow a swap with a macro yet
12601266
get_imacro_from_iblk(&imacro, b_to, pl_macros, num_pl_macros);
@@ -1285,6 +1291,7 @@ static int setup_blocks_affected(ClusterBlockId b_from, int x_to, int y_to, int
12851291
blocks_affected.moved_blocks[imoved_blk].swapped_from_is_empty = false;
12861292
blocks_affected.num_moved_blocks ++;
12871293

1294+
// Finish swapping the blocks and setting up blocks_affected
12881295
imoved_blk = blocks_affected.num_moved_blocks;
12891296
blocks_affected.moved_blocks[imoved_blk].block_num = b_to;
12901297
blocks_affected.moved_blocks[imoved_blk].xold = x_to;
@@ -1296,8 +1303,10 @@ static int setup_blocks_affected(ClusterBlockId b_from, int x_to, int y_to, int
12961303
blocks_affected.moved_blocks[imoved_blk].swapped_to_was_empty = false;
12971304
blocks_affected.moved_blocks[imoved_blk].swapped_from_is_empty = false;
12981305
blocks_affected.num_moved_blocks ++;
1299-
1300-
} // Finish swapping the blocks and setting up blocks_affected
1306+
} else {
1307+
abort_swap = true;
1308+
return (abort_swap);
1309+
}
13011310

13021311
return (abort_swap);
13031312

@@ -1355,7 +1364,7 @@ static int find_affected_blocks(ClusterBlockId b_from, int x_to, int y_to, int z
13551364
if ( curr_x_to < 1 || curr_x_to >= int(device_ctx.grid.width())
13561365
|| curr_y_to < 1 || curr_y_to >= int(device_ctx.grid.height())
13571366
|| curr_z_to < 0
1358-
|| device_ctx.grid[curr_x_to][curr_y_to].type != cluster_ctx.clb_nlist.block_type(curr_b_from)) {
1367+
|| !check_if_legal_placement(cluster_ctx.clb_nlist.block_type(curr_b_from), device_ctx.grid[curr_x_to][curr_y_to].type)) {
13591368
abort_swap = true;
13601369
} else {
13611370
abort_swap = setup_blocks_affected(curr_b_from, curr_x_to, curr_y_to, curr_z_to);
@@ -1418,8 +1427,16 @@ static e_swap_result try_swap(float t,
14181427

14191428
VTR_ASSERT(check_if_legal_placement(cluster_from_type, grid_from_type));
14201429

1421-
if (!find_to(cluster_ctx.clb_nlist.block_type(b_from), rlim, x_from, y_from, &x_to, &y_to, &z_to))
1430+
t_type_ptr to_block_type = cluster_ctx.clb_nlist.block_type(b_from);
1431+
int rand_block_type = vtr::irand(to_block_type->num_equivalent_tiles);
1432+
if (rand_block_type != 0) {
1433+
to_block_type = to_block_type->equivalent_tiles[rand_block_type-1];
1434+
}
1435+
1436+
1437+
if (!find_to(b_from, to_block_type, rlim, x_from, y_from, &x_to, &y_to, &z_to)) {
14221438
return REJECTED;
1439+
}
14231440

14241441
#if 0
14251442
auto& grid = g_vpr_ctx.device().grid;
@@ -1535,6 +1552,7 @@ static e_swap_result try_swap(float t,
15351552
place_ctx.block_locs[b_from].y = blocks_affected.moved_blocks[iblk].yold;
15361553
place_ctx.block_locs[b_from].z = blocks_affected.moved_blocks[iblk].zold;
15371554
}
1555+
15381556
}
15391557

15401558
/* Resets the num_moved_blocks, but do not free blocks_moved array. Defensive Coding */
@@ -1730,7 +1748,7 @@ static void update_td_delta_costs(const PlaceDelayModel& delay_model, const Clus
17301748
}
17311749
}
17321750

1733-
static bool find_to(t_type_ptr type, float rlim,
1751+
static bool find_to(ClusterBlockId blk, t_type_ptr type, float rlim,
17341752
int x_from, int y_from,
17351753
int *px_to, int *py_to, int *pz_to) {
17361754

@@ -1745,11 +1763,11 @@ static bool find_to(t_type_ptr type, float rlim,
17451763
bool is_legal;
17461764
int itype;
17471765

1748-
auto& grid = g_vpr_ctx.device().grid;
1749-
auto& place_ctx = g_vpr_ctx.placement();
1766+
auto& grid = g_vpr_ctx.device().grid;
1767+
auto& place_ctx = g_vpr_ctx.placement();
17501768

1751-
auto grid_type = grid[x_from][y_from].type;
1752-
VTR_ASSERT(check_if_legal_placement(type, grid_type));
1769+
auto cluster_type = g_vpr_ctx.clustering().clb_nlist.block_type(blk);
1770+
VTR_ASSERT(check_if_legal_placement(cluster_type, type));
17531771

17541772
int rlx = min<float>(grid.width() - 1, rlim);
17551773
int rly = min<float>(grid.height() - 1, rlim); /* Added rly for aspect_ratio != 1 case. */
@@ -1788,7 +1806,7 @@ static bool find_to(t_type_ptr type, float rlim,
17881806
is_legal = false;
17891807
} else if(*px_to > max_x || *px_to < min_x || *py_to > max_y || *py_to < min_y) {
17901808
is_legal = false;
1791-
} else if(grid[*px_to][*py_to].type != grid[x_from][y_from].type) {
1809+
} else if(!check_if_legal_placement(cluster_type, grid[*px_to][*py_to].type)) {
17921810
is_legal = false;
17931811
} else {
17941812
/* Find z_to and test to validate that the "to" block is *not* fixed */
@@ -1810,7 +1828,7 @@ static bool find_to(t_type_ptr type, float rlim,
18101828
vpr_throw(VPR_ERROR_PLACE, __FILE__, __LINE__,"in routine find_to: (x_to,y_to) = (%d,%d)\n", *px_to, *py_to);
18111829
}
18121830

1813-
VTR_ASSERT(check_if_legal_placement(type, grid[*px_to][*py_to].type));
1831+
VTR_ASSERT(check_if_legal_placement(cluster_type, grid[*px_to][*py_to].type));
18141832
return true;
18151833
}
18161834

@@ -1834,19 +1852,23 @@ static void find_to_location(t_type_ptr type, float rlim,
18341852
int max_y = min<float>(grid.height() - 1, y_from + rly);
18351853

18361854
*pz_to = 0;
1837-
if (int(grid.width() / 4) < rlx || int(grid.height() / 4) < rly || num_legal_pos[itype] < active_area) {
1855+
1856+
// TODO: Must check how to find a new location now that we have equivalent tiles.
1857+
// XXX: Lines which are commented out prevented to find equivalent tiles to swap with. They are temporarily disabled
1858+
1859+
// if (int(grid.width() / 4) < rlx || int(grid.height() / 4) < rly || num_legal_pos[itype] < active_area) {
18381860
int ipos = vtr::irand(num_legal_pos[itype] - 1);
18391861
*px_to = legal_pos[itype][ipos].x;
18401862
*py_to = legal_pos[itype][ipos].y;
18411863
*pz_to = legal_pos[itype][ipos].z;
1842-
} else {
1843-
int x_rel = vtr::irand(max(0, max_x - min_x));
1844-
int y_rel = vtr::irand(max(0, max_y - min_y));
1845-
*px_to = min_x + x_rel;
1846-
*py_to = min_y + y_rel;
1847-
*px_to = (*px_to) - grid[*px_to][*py_to].width_offset; /* align it */
1848-
*py_to = (*py_to) - grid[*px_to][*py_to].height_offset; /* align it */
1849-
}
1864+
// } else {
1865+
// int x_rel = vtr::irand(max(0, max_x - min_x));
1866+
// int y_rel = vtr::irand(max(0, max_y - min_y));
1867+
// *px_to = min_x + x_rel;
1868+
// *py_to = min_y + y_rel;
1869+
// *px_to = (*px_to) - grid[*px_to][*py_to].width_offset; /* align it */
1870+
// *py_to = (*py_to) - grid[*px_to][*py_to].height_offset; /* align it */
1871+
// }
18501872
}
18511873

18521874
static e_swap_result assess_swap(float delta_c, float t) {
@@ -3388,6 +3410,10 @@ static std::vector<int> get_available_placement_itypes(t_type_ptr type) {
33883410
}
33893411

33903412
static bool check_if_legal_placement(t_type_ptr cluster_type, t_type_ptr grid_type) {
3413+
if (cluster_type->index == grid_type->index) {
3414+
return true;
3415+
}
3416+
33913417
std::vector<int> itypes = get_available_placement_itypes(cluster_type);
33923418
if (std::find(itypes.begin(), itypes.end(), grid_type->index) != itypes.end()) {
33933419
return true;

0 commit comments

Comments
 (0)