Skip to content

Commit 2d34797

Browse files
replace unordered_map with vector for storing movable blocks for each type
1 parent 419324e commit 2d34797

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

vpr/src/base/vpr_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ struct PlacementContext : public Context {
390390
std::vector<ClusterBlockId> movable_blocks;
391391

392392
///@brief Stores ClusterBlockId of all movable clustered of each block type
393-
std::unordered_map<int, std::vector<ClusterBlockId>> movable_blocks_per_type;
393+
std::vector<std::vector<ClusterBlockId>> movable_blocks_per_type;
394394

395395
/**
396396
* @brief Compressed grid space for each block type

vpr/src/place/initial_placement.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ static void alloc_and_load_movable_blocks();
230230
static void check_initial_placement_legality() {
231231
auto& cluster_ctx = g_vpr_ctx.clustering();
232232
auto& place_ctx = g_vpr_ctx.placement();
233+
auto& device_ctx = g_vpr_ctx.device();
233234

234235
int unplaced_blocks = 0;
235236

@@ -256,19 +257,19 @@ static void check_initial_placement_legality() {
256257
VPR_FATAL_ERROR(VPR_ERROR_PLACE, "Fixed block was mistakenly marked as movable during initial placement.\n");
257258
}
258259
}
259-
260-
for (const auto& blk_type : place_ctx.movable_blocks_per_type) {
261-
int logical_block_type = blk_type.first;
262-
const auto& movable_blocks = blk_type.second;
263-
for (auto movable_blk_id : movable_blocks) {
260+
261+
for (const auto& logical_block_type : device_ctx.logical_block_types) {
262+
const auto& movable_blocks_of_type = place_ctx.movable_blocks_per_type[logical_block_type.index];
263+
for (const auto& movable_blk_id : movable_blocks_of_type) {
264264
if (place_ctx.block_locs[movable_blk_id].is_fixed) {
265-
VPR_FATAL_ERROR(VPR_ERROR_PLACE, "Fixed block of logical type %d was mistakenly marked as movable during initial placement.\n",
266-
logical_block_type);
265+
VPR_FATAL_ERROR(VPR_ERROR_PLACE, "Fixed block %d of logical type %s was mistakenly marked as movable during initial placement.\n",
266+
(size_t)movable_blk_id, logical_block_type.name);
267267
}
268-
if (cluster_ctx.clb_nlist.block_type(movable_blk_id)->index != logical_block_type) {
269-
VPR_FATAL_ERROR(VPR_ERROR_PLACE, "Clustered block of logical type %d was mistakenly marked as logical type %d.\n",
270-
cluster_ctx.clb_nlist.block_type(movable_blk_id)->index,
271-
logical_block_type);
268+
if (cluster_ctx.clb_nlist.block_type(movable_blk_id)->index != logical_block_type.index) {
269+
VPR_FATAL_ERROR(VPR_ERROR_PLACE, "Clustered block %d of logical type %s was mistakenly marked as logical type %s.\n",
270+
(size_t)movable_blk_id,
271+
cluster_ctx.clb_nlist.block_type(movable_blk_id)->name,
272+
logical_block_type.name);
272273
}
273274
}
274275
}
@@ -1156,11 +1157,15 @@ bool place_one_block(const ClusterBlockId& blk_id,
11561157

11571158
static void alloc_and_load_movable_blocks() {
11581159
auto& place_ctx = g_vpr_ctx.mutable_placement();
1159-
auto& cluster_ctx = g_vpr_ctx.clustering();
1160+
const auto& cluster_ctx = g_vpr_ctx.clustering();
1161+
const auto& device_ctx = g_vpr_ctx.device();
11601162

11611163
place_ctx.movable_blocks.clear();
11621164
place_ctx.movable_blocks_per_type.clear();
11631165

1166+
size_t n_logical_blocks = device_ctx.logical_block_types.size();
1167+
place_ctx.movable_blocks_per_type.resize(n_logical_blocks);
1168+
11641169

11651170
// iterate over all clustered blocks and store block ids of movable ones
11661171
for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {

vpr/src/place/move_utils.cpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ e_block_move_result record_macro_swaps(t_pl_blocks_to_be_moved& blocks_affected,
221221
//to a new position offset from its current position by swap_offset. The new location must be where
222222
//blk_to is located and blk_to must be part of imacro_to.
223223
e_block_move_result record_macro_macro_swaps(t_pl_blocks_to_be_moved& blocks_affected, const int imacro_from, int& imember_from, const int imacro_to, ClusterBlockId blk_to, t_pl_offset swap_offset) {
224-
//Adds the macro imacro_to to the set of affected block caused by swapping 'blk_to' to it's
224+
//Adds the macro imacro_to to the set of affected block caused by swapping 'blk_to' to its
225225
//new position.
226226
//
227227
//This function is only called when both the main swap's from/to blocks are placement macros.
@@ -484,7 +484,7 @@ std::set<t_pl_loc> determine_locations_emptied_by_move(t_pl_blocks_to_be_moved&
484484
std::set<t_pl_loc> moved_to;
485485

486486
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) {
487-
//When a block is moved it's old location becomes free
487+
//When a block is moved its old location becomes free
488488
moved_from.emplace(blocks_affected.moved_blocks[iblk].old_loc);
489489

490490
//But any block later moved to a position fills it
@@ -591,19 +591,12 @@ ClusterBlockId propose_block_to_move(const t_placer_opts& /* placer_opts */,
591591
}
592592

593593
const std::vector<ClusterBlockId>& movable_blocks_per_type(const t_logical_block_type& blk_type) {
594-
// empty vector is declared static to avoid re-allocation every time the function is called
595-
static std::vector<ClusterBlockId> empty_vector;
596-
597594
const auto& place_ctx = g_vpr_ctx.placement();
598595

599-
if (place_ctx.movable_blocks_per_type.count(blk_type.index) == 0) {
600-
return empty_vector;
601-
}
602-
603596
// the vector is returned as const reference to avoid unnecessary copies,
604597
// especially that returned vectors may be very large as they contain
605598
// all clustered blocks with a specific block type
606-
return place_ctx.movable_blocks_per_type.at(blk_type.index);
599+
return place_ctx.movable_blocks_per_type[blk_type.index];
607600
}
608601

609602
//Pick a random movable block to be swapped with another random block.
@@ -629,22 +622,15 @@ ClusterBlockId pick_from_block() {
629622
ClusterBlockId pick_from_block(const int logical_blk_type_index) {
630623
auto& place_ctx = g_vpr_ctx.mutable_placement();
631624

632-
auto found_blocks = place_ctx.movable_blocks_per_type.find(logical_blk_type_index);
633-
if (found_blocks != place_ctx.movable_blocks_per_type.end()) {
634-
const auto& blocks_per_type = found_blocks->second;
635-
//no blocks with this type is movable
636-
if (blocks_per_type.empty()) {
637-
return ClusterBlockId::INVALID();
638-
}
639-
640-
//Pick a block at random
641-
auto b_from = ClusterBlockId(blocks_per_type[vtr::irand((int)blocks_per_type.size() - 1)]);
625+
const auto& movable_blocks_of_type = place_ctx.movable_blocks_per_type[logical_blk_type_index];
642626

643-
// return the movable block of the given type
644-
return b_from;
627+
if (movable_blocks_of_type.empty()) {
628+
return ClusterBlockId::INVALID();
645629
}
646630

647-
return ClusterBlockId::INVALID();
631+
auto b_from = ClusterBlockId(movable_blocks_of_type[vtr::irand((int)movable_blocks_of_type.size() - 1)]);
632+
633+
return b_from;
648634
}
649635

650636
//Pick a random highly critical block to be swapped with another random block.

vpr/src/place/move_utils.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* Cut off for incremental bounding box updates. *
88
* 4 is fastest -- I checked. */
99
/* To turn off incremental bounding box updates, set this to a huge value */
10-
#define SMALL_NET 4
10+
constexpr size_t SMALL_NET = 4;
1111

1212
/* This is for the placement swap routines. A swap attempt could be *
1313
* rejected, accepted or aborted (due to the limitations placed on the *
@@ -126,6 +126,11 @@ ClusterBlockId propose_block_to_move(const t_placer_opts& placer_opts,
126126
ClusterNetId* net_from,
127127
int* pin_from);
128128

129+
/**
130+
* Returns all movable clustered blocks with a specified logical block type.
131+
* @param blk_type Specifies the logical block block type.
132+
* @return A const reference to a vector containing all movable blocks with the specified logical block type.
133+
*/
129134
const std::vector<ClusterBlockId>& movable_blocks_per_type(const t_logical_block_type& blk_type);
130135

131136
/**

0 commit comments

Comments
 (0)