Skip to content

Commit

Permalink
remove one of the signatures of pick_from_block and pick_from_highly_…
Browse files Browse the repository at this point in the history
…critical_block
  • Loading branch information
soheilshahrouz committed Dec 5, 2024
1 parent d579250 commit 864bd28
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 94 deletions.
2 changes: 1 addition & 1 deletion libs/libarchfpga/src/physical_types_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ int get_logical_block_physical_sub_tile_index(t_physical_tile_type_ptr physical_
t_logical_block_type_ptr logical_block);
/**
* @brief Returns the physical pin index (within 'physical_tile') corresponding to the
* logical index ('pin' of the first instance of 'logical_block' within the physcial tile.
* logical index ('pin' of the first instance of 'logical_block' within the physical tile.
*
* This function is called before/during placement, when a sub tile index was not yet assigned.
*
Expand Down
93 changes: 17 additions & 76 deletions vpr/src/place/move_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,26 +552,19 @@ ClusterBlockId propose_block_to_move(const t_placer_opts& placer_opts,
int* pin_from,
const PlacerState& placer_state,
vtr::RngContainer& rng) {
ClusterBlockId b_from = ClusterBlockId::INVALID();
const auto& cluster_ctx = g_vpr_ctx.clustering();

if (logical_blk_type_index == -1) { //If the block type is unspecified, choose any random block to be swapped with another random block
if (highly_crit_block) {
b_from = pick_from_highly_critical_block(*net_from, *pin_from, placer_state, *placer_criticalities, rng);
} else {
b_from = pick_from_block(rng);
}
ClusterBlockId b_from = ClusterBlockId::INVALID();

//if a movable block found, set the block type
if (b_from) {
logical_blk_type_index = cluster_ctx.clb_nlist.block_type(b_from)->index;
}
} else { //If the block type is specified, choose a random block with blk_type to be swapped with another random block
if (highly_crit_block) {
b_from = pick_from_highly_critical_block(*net_from, *pin_from, logical_blk_type_index, placer_state, *placer_criticalities, rng);
} else {
b_from = pick_from_block(logical_blk_type_index, rng);
}
if (highly_crit_block) {
b_from = pick_from_highly_critical_block(*net_from, *pin_from, logical_blk_type_index, placer_state, *placer_criticalities, rng);
} else {
b_from = pick_from_block(logical_blk_type_index, rng);
}

//if a movable block found, set the block type
if (b_from) {
logical_blk_type_index = cluster_ctx.clb_nlist.block_type(b_from)->index;
}

if constexpr (VTR_ENABLE_DEBUG_LOGGING_CONST_EXPR) {
Expand All @@ -590,71 +583,20 @@ const std::vector<ClusterBlockId>& movable_blocks_per_type(const t_logical_block
return place_ctx.movable_blocks_per_type[blk_type.index];
}

ClusterBlockId pick_from_block(vtr::RngContainer& rng) {
auto& place_ctx = g_vpr_ctx.placement();

// get the number of movable clustered blocks
const size_t n_movable_blocks = place_ctx.movable_blocks.size();

if (n_movable_blocks > 0) {
//Pick a movable block at random and return it
auto b_from = ClusterBlockId(rng.irand((int)n_movable_blocks - 1));
return b_from;
} else {
//No movable blocks found
return ClusterBlockId::INVALID();
}
}

ClusterBlockId pick_from_block(const int logical_blk_type_index, vtr::RngContainer& rng) {
auto& place_ctx = g_vpr_ctx.placement();

const auto& movable_blocks_of_type = place_ctx.movable_blocks_per_type[logical_blk_type_index];

if (movable_blocks_of_type.empty()) {
return ClusterBlockId::INVALID();
}

auto b_from = ClusterBlockId(movable_blocks_of_type[rng.irand((int)movable_blocks_of_type.size() - 1)]);

return b_from;
}

//Pick a random highly critical block to be swapped with another random block.
//If none is found return ClusterBlockId::INVALID()
ClusterBlockId pick_from_highly_critical_block(ClusterNetId& net_from,
int& pin_from,
const PlacerState& placer_state,
const PlacerCriticalities& placer_criticalities,
vtr::RngContainer& rng) {
const auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& block_locs = placer_state.block_locs();

//Initialize critical net and pin to be invalid
net_from = ClusterNetId::INVALID();
pin_from = -1;
const auto& place_ctx = g_vpr_ctx.placement();

const auto& highly_crit_pins = placer_criticalities.get_highly_critical_pins();
// if logical block type is specified, pick the 'from' block from block of that type; otherwise,
// pick it from all blocks
const auto& movable_blocks = (logical_blk_type_index < 0 )? place_ctx.movable_blocks : place_ctx.movable_blocks_per_type[logical_blk_type_index];

//check if any critical block is available
if (highly_crit_pins.empty()) {
if (movable_blocks.empty()) {
return ClusterBlockId::INVALID();
}

//pick a random highly critical pin and find the nets driver block
std::pair<ClusterNetId, int> crit_pin = highly_crit_pins[rng.irand(highly_crit_pins.size() - 1)];
ClusterBlockId b_from = cluster_ctx.clb_nlist.net_driver_block(crit_pin.first);

if (block_locs[b_from].is_fixed) {
return ClusterBlockId::INVALID(); //Block is fixed, cannot move
}
ClusterBlockId b_from = movable_blocks[rng.irand((int)movable_blocks.size() - 1)];

net_from = crit_pin.first;
pin_from = crit_pin.second;
return b_from;

//Unreachable statement
return ClusterBlockId::INVALID();
}

//Pick a random highly critical block with a specified block type to be swapped with another random block.
Expand Down Expand Up @@ -686,7 +628,7 @@ ClusterBlockId pick_from_highly_critical_block(ClusterNetId& net_from,
//Check if picked block type matches with the blk_type specified, and it is not fixed
//blk_type from propose move doesn't account for the EMPTY type
auto b_from_type = cluster_ctx.clb_nlist.block_type(b_from);
if (b_from_type->index == logical_blk_type_index) {
if (b_from_type->index == logical_blk_type_index || logical_blk_type_index < 0) {
if (block_locs[b_from].is_fixed) {
return ClusterBlockId::INVALID(); //Block is fixed, cannot move
}
Expand All @@ -697,7 +639,6 @@ ClusterBlockId pick_from_highly_critical_block(ClusterNetId& net_from,
}

//No critical block with 'blk_type' found
//Unreachable statement
return ClusterBlockId::INVALID();
}

Expand Down
17 changes: 0 additions & 17 deletions vpr/src/place/move_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,6 @@ ClusterBlockId propose_block_to_move(const t_placer_opts& placer_opts,
*/
const std::vector<ClusterBlockId>& movable_blocks_per_type(const t_logical_block_type& blk_type);

/**
* @brief Select a random block to be swapped with another block
*
* @return BlockId of the selected block, ClusterBlockId::INVALID() if no block with specified block type found
*/
ClusterBlockId pick_from_block(vtr::RngContainer& rng);

/**
* @brief Find a block with a specific block type to be swapped with another block
Expand All @@ -201,17 +195,6 @@ ClusterBlockId pick_from_block(vtr::RngContainer& rng);
*/
ClusterBlockId pick_from_block(int logical_blk_type_index, vtr::RngContainer& rng);

/**
* @brief Select a random highly critical block to be swapped with another block
*
* @return BlockId of the selected block, ClusterBlockId::INVALID() if no block with specified block type found
*/
ClusterBlockId pick_from_highly_critical_block(ClusterNetId& net_from,
int& pin_from,
const PlacerState& placer_state,
const PlacerCriticalities& placer_criticalities,
vtr::RngContainer& rng);

/**
* @brief Find a block with a specific block type to be swapped with another block
*
Expand Down

0 comments on commit 864bd28

Please sign in to comment.