Skip to content

Remove PlacerMoveContext #2989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions vpr/src/place/RL_agent_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create_move_generators(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
const t_placer_opts& placer_opts,
int move_lim,
double noc_attraction_weight,
Expand All @@ -25,8 +26,8 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
move_name.c_str(),
placer_opts.place_static_move_prob[move_type]);
}
move_generators.first = std::make_unique<StaticMoveGenerator>(placer_state, place_macros, reward_fun, rng, placer_opts.place_static_move_prob);
move_generators.second = std::make_unique<StaticMoveGenerator>(placer_state, place_macros, reward_fun, rng, placer_opts.place_static_move_prob);
move_generators.first = std::make_unique<StaticMoveGenerator>(placer_state, place_macros, net_cost_handler, reward_fun, rng, placer_opts.place_static_move_prob);
move_generators.second = std::make_unique<StaticMoveGenerator>(placer_state, place_macros, net_cost_handler, reward_fun, rng, placer_opts.place_static_move_prob);
} else { //RL based placement
/* For the non timing driven placement: the agent has a single state *
* - Available moves are (Uniform / Median / Centroid) *
Expand Down Expand Up @@ -91,6 +92,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
move_generators.first = std::make_unique<SimpleRLMoveGenerator>(placer_state,
place_macros,
net_cost_handler,
reward_fun,
rng,
karmed_bandit_agent1,
Expand All @@ -105,6 +107,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
move_generators.second = std::make_unique<SimpleRLMoveGenerator>(placer_state,
place_macros,
net_cost_handler,
reward_fun,
rng,
karmed_bandit_agent2,
Expand All @@ -129,6 +132,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
move_generators.first = std::make_unique<SimpleRLMoveGenerator>(placer_state,
place_macros,
net_cost_handler,
reward_fun,
rng,
karmed_bandit_agent1,
Expand All @@ -142,6 +146,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
move_generators.second = std::make_unique<SimpleRLMoveGenerator>(placer_state,
place_macros,
net_cost_handler,
reward_fun,
rng,
karmed_bandit_agent2,
Expand Down
1 change: 1 addition & 0 deletions vpr/src/place/RL_agent_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum class e_agent_state {
*/
std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create_move_generators(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
const t_placer_opts& placer_opts,
int move_lim,
double noc_attraction_weight,
Expand Down
6 changes: 3 additions & 3 deletions vpr/src/place/annealer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ PlacementAnnealer::PlacementAnnealer(const t_placer_opts& placer_opts,
, rng_(rng)
, move_generator_1_(std::move(move_generator_1))
, move_generator_2_(std::move(move_generator_2))
, manual_move_generator_(placer_state, place_macros, rng)
, manual_move_generator_(placer_state, place_macros, net_cost_handler, rng)
, agent_state_(e_agent_state::EARLY_IN_THE_ANNEAL)
, delay_model_(delay_model)
, criticalities_(criticalities)
Expand Down Expand Up @@ -257,14 +257,14 @@ PlacementAnnealer::PlacementAnnealer(const t_placer_opts& placer_opts,
tot_iter_ = 0;

// Get the first range limiter
placer_state_.mutable_move().first_rlim = (float)std::max(device_ctx.grid.width() - 1, device_ctx.grid.height() - 1);
MoveGenerator::first_rlim = (float)std::max(device_ctx.grid.width() - 1, device_ctx.grid.height() - 1);

// In automatic schedule we do a number of random moves before starting the main annealer
// to get an estimate for the initial temperature. We set this temperature low
// to ensure that initial placement quality will be preserved
constexpr float pre_annealing_temp = 1.e-15f;
annealing_state_ = t_annealing_state(pre_annealing_temp,
placer_state_.move().first_rlim,
MoveGenerator::first_rlim,
first_move_lim,
first_crit_exponent);

Expand Down
9 changes: 5 additions & 4 deletions vpr/src/place/move_generators/centroid_move_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@

CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
e_reward_function reward_function,
vtr::RngContainer& rng)
: MoveGenerator(placer_state, place_macros, reward_function, rng)
: MoveGenerator(placer_state, place_macros, net_cost_handler, reward_function, rng)
, weighted_(false)
, noc_attraction_weight_(0.0f)
, noc_attraction_enabled_(false) {}

CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
e_reward_function reward_function,
vtr::RngContainer& rng,
float noc_attraction_weight,
size_t high_fanout_net)
: MoveGenerator(placer_state, place_macros, reward_function, rng)
: MoveGenerator(placer_state, place_macros, net_cost_handler, reward_function, rng)
, noc_attraction_weight_(noc_attraction_weight)
, noc_attraction_enabled_(true) {
VTR_ASSERT(noc_attraction_weight > 0.0 && noc_attraction_weight <= 1.0);
Expand All @@ -41,7 +43,6 @@ e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block
const auto& block_locs = placer_state.block_locs();
const auto& device_ctx = g_vpr_ctx.device();
const auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& place_move_ctx = placer_state.move();
const auto& blk_loc_registry = placer_state.blk_loc_registry();

// Find a movable block based on blk_type
Expand Down Expand Up @@ -71,7 +72,7 @@ e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block
VTR_ASSERT(is_tile_compatible(grid_from_type, cluster_from_type));

t_range_limiters range_limiters{rlim,
place_move_ctx.first_rlim,
first_rlim,
placer_opts.place_dm_rlim};

t_pl_loc to;
Expand Down
7 changes: 3 additions & 4 deletions vpr/src/place/move_generators/centroid_move_generator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef VPR_CENTROID_MOVE_GEN_H
#define VPR_CENTROID_MOVE_GEN_H
#pragma once

#include "move_generator.h"

Expand Down Expand Up @@ -33,6 +32,7 @@ class CentroidMoveGenerator : public MoveGenerator {
*/
CentroidMoveGenerator(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
e_reward_function reward_function,
vtr::RngContainer& rng);

Expand All @@ -53,6 +53,7 @@ class CentroidMoveGenerator : public MoveGenerator {
*/
CentroidMoveGenerator(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
e_reward_function reward_function,
vtr::RngContainer& rng,
float noc_attraction_weight,
Expand Down Expand Up @@ -131,5 +132,3 @@ class CentroidMoveGenerator : public MoveGenerator {
*/
void initialize_noc_groups(size_t high_fanout_net);
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

CriticalUniformMoveGenerator::CriticalUniformMoveGenerator(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
e_reward_function reward_function,
vtr::RngContainer& rng)
: MoveGenerator(placer_state, place_macros, reward_function, rng) {}
: MoveGenerator(placer_state, place_macros, net_cost_handler, reward_function, rng) {}

e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
t_propose_action& proposed_action,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef VPR_CRITICAL_UNIFORM_MOVE_GEN_H
#define VPR_CRITICAL_UNIFORM_MOVE_GEN_H
#pragma once

#include "move_generator.h"

Expand All @@ -21,6 +20,7 @@ class CriticalUniformMoveGenerator : public MoveGenerator {
CriticalUniformMoveGenerator() = delete;
CriticalUniformMoveGenerator(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
e_reward_function reward_function,
vtr::RngContainer& rng);

Expand All @@ -31,5 +31,3 @@ class CriticalUniformMoveGenerator : public MoveGenerator {
const t_placer_opts& /*placer_opts*/,
const PlacerCriticalities* /*criticalities*/) override;
};

#endif
52 changes: 26 additions & 26 deletions vpr/src/place/move_generators/feasible_region_move_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

FeasibleRegionMoveGenerator::FeasibleRegionMoveGenerator(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
e_reward_function reward_function,
vtr::RngContainer& rng)
: MoveGenerator(placer_state, place_macros, reward_function, rng) {}
: MoveGenerator(placer_state, place_macros, net_cost_handler, reward_function, rng) {}

e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
t_propose_action& proposed_action,
Expand All @@ -23,7 +24,6 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved&
const PlacerCriticalities* criticalities) {
const auto& cluster_ctx = g_vpr_ctx.clustering();
auto& placer_state = placer_state_.get();
auto& place_move_ctx = placer_state.mutable_move();
const auto& block_locs = placer_state.block_locs();
const auto& blk_loc_registry = placer_state.blk_loc_registry();

Expand All @@ -48,18 +48,22 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved&

//from block data
t_pl_loc from = block_locs[b_from].loc;
auto cluster_from_type = cluster_ctx.clb_nlist.block_type(b_from);
auto grid_from_type = g_vpr_ctx.device().grid.get_physical_type({from.x, from.y, from.layer});
t_logical_block_type_ptr cluster_from_type = cluster_ctx.clb_nlist.block_type(b_from);
t_physical_tile_type_ptr grid_from_type = g_vpr_ctx.device().grid.get_physical_type({from.x, from.y, from.layer});
VTR_ASSERT(is_tile_compatible(grid_from_type, cluster_from_type));

/* Calculate the feasible region */
t_pl_loc to;
// Currently, we don't change the layer for this move
to.layer = from.layer;
int max_x, min_x, max_y, min_y;

place_move_ctx.X_coord.clear();
place_move_ctx.Y_coord.clear();
int max_x = std::numeric_limits<int>::min();
int min_x = std::numeric_limits<int>::max();
int max_y = std::numeric_limits<int>::min();
int min_y = std::numeric_limits<int>::max();

bool found = false;

//For critical input nodes, calculate the x & y min-max values
for (ClusterPinId pin_id : cluster_ctx.clb_nlist.block_input_pins(b_from)) {
ClusterNetId net_id = cluster_ctx.clb_nlist.pin_net(pin_id);
Expand All @@ -69,28 +73,25 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved&
int ipin = cluster_ctx.clb_nlist.pin_net_index(pin_id);
if (criticalities->criticality(net_id, ipin) > placer_opts.place_crit_limit) {
ClusterBlockId bnum = cluster_ctx.clb_nlist.net_driver_block(net_id);
place_move_ctx.X_coord.push_back(block_locs[bnum].loc.x);
place_move_ctx.Y_coord.push_back(block_locs[bnum].loc.y);
const t_pl_loc& loc = block_locs[bnum].loc;
min_x = std::min(min_x, loc.x);
max_x = std::max(max_x, loc.x);
min_y = std::min(min_y, loc.y);
max_y = std::max(max_y, loc.y);
found = true;
}
}
if (!place_move_ctx.X_coord.empty()) {
max_x = *(std::max_element(place_move_ctx.X_coord.begin(), place_move_ctx.X_coord.end()));
min_x = *(std::min_element(place_move_ctx.X_coord.begin(), place_move_ctx.X_coord.end()));
max_y = *(std::max_element(place_move_ctx.Y_coord.begin(), place_move_ctx.Y_coord.end()));
min_y = *(std::min_element(place_move_ctx.Y_coord.begin(), place_move_ctx.Y_coord.end()));
} else {
max_x = from.x;
min_x = from.x;
max_y = from.y;
min_y = from.y;

if (!found) {
min_x = max_x = from.x;
min_y = max_y = from.y;
}

//Get the most critical output of the node
int xt, yt;
ClusterBlockId b_output = cluster_ctx.clb_nlist.net_pin_block(net_from, pin_from);
t_pl_loc output_loc = block_locs[b_output].loc;
xt = output_loc.x;
yt = output_loc.y;
int xt = output_loc.x;
int yt = output_loc.y;

/**
* @brief determine the feasible region
Expand Down Expand Up @@ -128,14 +129,13 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved&
VTR_ASSERT(FR_coords.ymin <= FR_coords.ymax);

t_range_limiters range_limiters{rlim,
place_move_ctx.first_rlim,
first_rlim,
placer_opts.place_dm_rlim};

// Try to find a legal location inside the feasible region
if (!find_to_loc_median(cluster_from_type, from, &FR_coords, to, b_from, blk_loc_registry, rng_)) {
/** If there is no legal location in the feasible region, calculate the center of the FR and try to find a legal location
* in a range around this center.
*/
/* If there is no legal location in the feasible region, calculate the center of the FR and try to find a legal location
* in a range around this center. */
t_pl_loc center;
center.x = (FR_coords.xmin + FR_coords.xmax) / 2;
center.y = (FR_coords.ymin + FR_coords.ymax) / 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef VPR_FEASIBLE_REGION_MOVE_GEN_H
#define VPR_FEASIBLE_REGION_MOVE_GEN_H
#pragma once

#include "move_generator.h"

Expand All @@ -25,6 +24,7 @@ class FeasibleRegionMoveGenerator : public MoveGenerator {
FeasibleRegionMoveGenerator() = delete;
FeasibleRegionMoveGenerator(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
e_reward_function reward_function,
vtr::RngContainer& rng);

Expand All @@ -35,5 +35,3 @@ class FeasibleRegionMoveGenerator : public MoveGenerator {
const t_placer_opts& placer_opts,
const PlacerCriticalities* criticalities) override;
};

#endif
3 changes: 2 additions & 1 deletion vpr/src/place/move_generators/manual_move_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

ManualMoveGenerator::ManualMoveGenerator(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
vtr::RngContainer& rng)
: MoveGenerator(placer_state, place_macros, e_reward_function::UNDEFINED_REWARD, rng) {}
: MoveGenerator(placer_state, place_macros, net_cost_handler, e_reward_function::UNDEFINED_REWARD, rng) {}

//Manual Move Generator function
e_create_move ManualMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
Expand Down
6 changes: 2 additions & 4 deletions vpr/src/place/move_generators/manual_move_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* @brief Contains the ManualMoveGenerator class.
*/

#ifndef VPR_MANUAL_MOVE_GEN_H
#define VPR_MANUAL_MOVE_GEN_H
#pragma once

#include "move_generator.h"

Expand All @@ -22,6 +21,7 @@ class ManualMoveGenerator : public MoveGenerator {
ManualMoveGenerator() = delete;
ManualMoveGenerator(PlacerState& placer_state,
const PlaceMacros& place_macros,
const NetCostHandler& net_cost_handler,
vtr::RngContainer& rng);

//Evaluates if move is successful and legal or unable to do.
Expand All @@ -31,5 +31,3 @@ class ManualMoveGenerator : public MoveGenerator {
const t_placer_opts& /*placer_opts*/,
const PlacerCriticalities* /*criticalities*/) override;
};

#endif /*VPR_MANUAL_MOVE_GEN_H */
Loading