Skip to content

Commit 8bd04e4

Browse files
add movable_blocks_per_type()
1 parent 15cf98e commit 8bd04e4

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

vpr/src/place/initial_placement.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,20 +1162,6 @@ static void alloc_and_load_movable_blocks() {
11621162
place_ctx.movable_blocks.clear();
11631163
place_ctx.movable_blocks_per_type.clear();
11641164

1165-
std::vector<int> available_logical_blk_types;
1166-
1167-
for (const auto& logical_blk_type : device_ctx.logical_block_types) {
1168-
//ignore empty type
1169-
if (logical_blk_type.index == 0) {
1170-
continue;
1171-
}
1172-
1173-
const auto& blk_per_type = cluster_ctx.clb_nlist.blocks_per_type(logical_blk_type);
1174-
1175-
if (!blk_per_type.empty()) {
1176-
available_logical_blk_types.push_back(logical_blk_type.index);
1177-
}
1178-
}
11791165

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

vpr/src/place/move_utils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,22 @@ ClusterBlockId propose_block_to_move(const t_placer_opts& /* placer_opts */,
590590
return b_from;
591591
}
592592

593+
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+
597+
const auto& place_ctx = g_vpr_ctx.placement();
598+
599+
if (place_ctx.movable_blocks_per_type.count(blk_type.index) == 0) {
600+
return empty_vector;
601+
}
602+
603+
// the vector is returned as const reference to avoid unnecessary copies,
604+
// especially that returned vectors may be very large as they contain
605+
// all clustered blocks with a specific block type
606+
return place_ctx.movable_blocks_per_type.at(blk_type.index);
607+
}
608+
593609
//Pick a random movable block to be swapped with another random block.
594610
//If none is found return ClusterBlockId::INVALID()
595611
ClusterBlockId pick_from_block() {

vpr/src/place/move_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ ClusterBlockId propose_block_to_move(const t_placer_opts& placer_opts,
126126
ClusterNetId* net_from,
127127
int* pin_from);
128128

129+
const std::vector<ClusterBlockId>& movable_blocks_per_type(const t_logical_block_type& blk_type);
130+
129131
/**
130132
* @brief Select a random block to be swapped with another block
131133
*

vpr/src/place/simpleRL_move_generator.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ int KArmedBanditAgent::action_to_blk_type_(const size_t action_idx) {
7979
}
8080

8181
std::vector<int> KArmedBanditAgent::get_available_logical_blk_types_() {
82-
auto& device_ctx = g_vpr_ctx.device();
83-
auto& cluster_ctx = g_vpr_ctx.clustering();
82+
const auto& device_ctx = g_vpr_ctx.device();
8483

8584
std::vector<int> available_blk_types;
8685

@@ -89,7 +88,7 @@ std::vector<int> KArmedBanditAgent::get_available_logical_blk_types_() {
8988
continue;
9089
}
9190

92-
const auto& blk_per_type = cluster_ctx.clb_nlist.blocks_per_type(logical_blk_type);
91+
const auto& blk_per_type = movable_blocks_per_type(logical_blk_type);
9392

9493
if (!blk_per_type.empty()) {
9594
available_blk_types.push_back(logical_blk_type.index);
@@ -304,7 +303,10 @@ t_propose_action SoftmaxAgent::propose_action() {
304303

305304
void SoftmaxAgent::set_block_ratio_() {
306305
auto& cluster_ctx = g_vpr_ctx.clustering();
307-
size_t num_total_blocks = cluster_ctx.clb_nlist.blocks().size();
306+
const auto& place_ctx = g_vpr_ctx.placement();
307+
size_t num_movable_total_blocks = place_ctx.movable_blocks.size();
308+
309+
num_movable_total_blocks = std::max<size_t>(num_movable_total_blocks, 1);
308310

309311
// allocate enough space for available block types in the netlist
310312
block_type_ratio_.resize(num_available_types_);
@@ -316,8 +318,8 @@ void SoftmaxAgent::set_block_ratio_() {
316318
for (size_t itype = 0; itype < num_available_types_; itype++) {
317319
t_logical_block_type blk_type;
318320
blk_type.index = agent_to_phy_blk_type(itype);
319-
auto num_blocks = cluster_ctx.clb_nlist.blocks_per_type(blk_type).size();
320-
block_type_ratio_[itype] = (float)num_blocks / num_total_blocks;
321+
auto num_blocks = movable_blocks_per_type(blk_type).size();
322+
block_type_ratio_[itype] = (float)num_blocks / num_movable_total_blocks;
321323
block_type_ratio_[itype] /= num_available_moves_;
322324
}
323325
}

0 commit comments

Comments
 (0)