Skip to content

Commit f71176c

Browse files
authored
Merge pull request #2989 from verilog-to-routing/temp_remove_place_move_ctx
Remove PlacerMoveContext
2 parents c881146 + 1706dd4 commit f71176c

31 files changed

+394
-415
lines changed

vpr/src/place/RL_agent_util.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create_move_generators(PlacerState& placer_state,
99
const PlaceMacros& place_macros,
10+
const NetCostHandler& net_cost_handler,
1011
const t_placer_opts& placer_opts,
1112
int move_lim,
1213
double noc_attraction_weight,
@@ -25,8 +26,8 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
2526
move_name.c_str(),
2627
placer_opts.place_static_move_prob[move_type]);
2728
}
28-
move_generators.first = std::make_unique<StaticMoveGenerator>(placer_state, place_macros, reward_fun, rng, placer_opts.place_static_move_prob);
29-
move_generators.second = std::make_unique<StaticMoveGenerator>(placer_state, place_macros, reward_fun, rng, placer_opts.place_static_move_prob);
29+
move_generators.first = std::make_unique<StaticMoveGenerator>(placer_state, place_macros, net_cost_handler, reward_fun, rng, placer_opts.place_static_move_prob);
30+
move_generators.second = std::make_unique<StaticMoveGenerator>(placer_state, place_macros, net_cost_handler, reward_fun, rng, placer_opts.place_static_move_prob);
3031
} else { //RL based placement
3132
/* For the non timing driven placement: the agent has a single state *
3233
* - Available moves are (Uniform / Median / Centroid) *
@@ -91,6 +92,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
9192
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
9293
move_generators.first = std::make_unique<SimpleRLMoveGenerator>(placer_state,
9394
place_macros,
95+
net_cost_handler,
9496
reward_fun,
9597
rng,
9698
karmed_bandit_agent1,
@@ -105,6 +107,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
105107
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
106108
move_generators.second = std::make_unique<SimpleRLMoveGenerator>(placer_state,
107109
place_macros,
110+
net_cost_handler,
108111
reward_fun,
109112
rng,
110113
karmed_bandit_agent2,
@@ -129,6 +132,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
129132
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
130133
move_generators.first = std::make_unique<SimpleRLMoveGenerator>(placer_state,
131134
place_macros,
135+
net_cost_handler,
132136
reward_fun,
133137
rng,
134138
karmed_bandit_agent1,
@@ -142,6 +146,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
142146
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
143147
move_generators.second = std::make_unique<SimpleRLMoveGenerator>(placer_state,
144148
place_macros,
149+
net_cost_handler,
145150
reward_fun,
146151
rng,
147152
karmed_bandit_agent2,

vpr/src/place/RL_agent_util.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum class e_agent_state {
3030
*/
3131
std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create_move_generators(PlacerState& placer_state,
3232
const PlaceMacros& place_macros,
33+
const NetCostHandler& net_cost_handler,
3334
const t_placer_opts& placer_opts,
3435
int move_lim,
3536
double noc_attraction_weight,

vpr/src/place/annealer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ PlacementAnnealer::PlacementAnnealer(const t_placer_opts& placer_opts,
213213
, rng_(rng)
214214
, move_generator_1_(std::move(move_generator_1))
215215
, move_generator_2_(std::move(move_generator_2))
216-
, manual_move_generator_(placer_state, place_macros, rng)
216+
, manual_move_generator_(placer_state, place_macros, net_cost_handler, rng)
217217
, agent_state_(e_agent_state::EARLY_IN_THE_ANNEAL)
218218
, delay_model_(delay_model)
219219
, criticalities_(criticalities)
@@ -257,14 +257,14 @@ PlacementAnnealer::PlacementAnnealer(const t_placer_opts& placer_opts,
257257
tot_iter_ = 0;
258258

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

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

vpr/src/place/move_generators/centroid_move_generator.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@
1111

1212
CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state,
1313
const PlaceMacros& place_macros,
14+
const NetCostHandler& net_cost_handler,
1415
e_reward_function reward_function,
1516
vtr::RngContainer& rng)
16-
: MoveGenerator(placer_state, place_macros, reward_function, rng)
17+
: MoveGenerator(placer_state, place_macros, net_cost_handler, reward_function, rng)
1718
, weighted_(false)
1819
, noc_attraction_weight_(0.0f)
1920
, noc_attraction_enabled_(false) {}
2021

2122
CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state,
2223
const PlaceMacros& place_macros,
24+
const NetCostHandler& net_cost_handler,
2325
e_reward_function reward_function,
2426
vtr::RngContainer& rng,
2527
float noc_attraction_weight,
2628
size_t high_fanout_net)
27-
: MoveGenerator(placer_state, place_macros, reward_function, rng)
29+
: MoveGenerator(placer_state, place_macros, net_cost_handler, reward_function, rng)
2830
, noc_attraction_weight_(noc_attraction_weight)
2931
, noc_attraction_enabled_(true) {
3032
VTR_ASSERT(noc_attraction_weight > 0.0 && noc_attraction_weight <= 1.0);
@@ -41,7 +43,6 @@ e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block
4143
const auto& block_locs = placer_state.block_locs();
4244
const auto& device_ctx = g_vpr_ctx.device();
4345
const auto& cluster_ctx = g_vpr_ctx.clustering();
44-
const auto& place_move_ctx = placer_state.move();
4546
const auto& blk_loc_registry = placer_state.blk_loc_registry();
4647

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

7374
t_range_limiters range_limiters{rlim,
74-
place_move_ctx.first_rlim,
75+
first_rlim,
7576
placer_opts.place_dm_rlim};
7677

7778
t_pl_loc to;

vpr/src/place/move_generators/centroid_move_generator.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef VPR_CENTROID_MOVE_GEN_H
2-
#define VPR_CENTROID_MOVE_GEN_H
1+
#pragma once
32

43
#include "move_generator.h"
54

@@ -33,6 +32,7 @@ class CentroidMoveGenerator : public MoveGenerator {
3332
*/
3433
CentroidMoveGenerator(PlacerState& placer_state,
3534
const PlaceMacros& place_macros,
35+
const NetCostHandler& net_cost_handler,
3636
e_reward_function reward_function,
3737
vtr::RngContainer& rng);
3838

@@ -53,6 +53,7 @@ class CentroidMoveGenerator : public MoveGenerator {
5353
*/
5454
CentroidMoveGenerator(PlacerState& placer_state,
5555
const PlaceMacros& place_macros,
56+
const NetCostHandler& net_cost_handler,
5657
e_reward_function reward_function,
5758
vtr::RngContainer& rng,
5859
float noc_attraction_weight,
@@ -131,5 +132,3 @@ class CentroidMoveGenerator : public MoveGenerator {
131132
*/
132133
void initialize_noc_groups(size_t high_fanout_net);
133134
};
134-
135-
#endif

vpr/src/place/move_generators/critical_uniform_move_generator.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
CriticalUniformMoveGenerator::CriticalUniformMoveGenerator(PlacerState& placer_state,
1212
const PlaceMacros& place_macros,
13+
const NetCostHandler& net_cost_handler,
1314
e_reward_function reward_function,
1415
vtr::RngContainer& rng)
15-
: MoveGenerator(placer_state, place_macros, reward_function, rng) {}
16+
: MoveGenerator(placer_state, place_macros, net_cost_handler, reward_function, rng) {}
1617

1718
e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
1819
t_propose_action& proposed_action,

vpr/src/place/move_generators/critical_uniform_move_generator.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef VPR_CRITICAL_UNIFORM_MOVE_GEN_H
2-
#define VPR_CRITICAL_UNIFORM_MOVE_GEN_H
1+
#pragma once
32

43
#include "move_generator.h"
54

@@ -21,6 +20,7 @@ class CriticalUniformMoveGenerator : public MoveGenerator {
2120
CriticalUniformMoveGenerator() = delete;
2221
CriticalUniformMoveGenerator(PlacerState& placer_state,
2322
const PlaceMacros& place_macros,
23+
const NetCostHandler& net_cost_handler,
2424
e_reward_function reward_function,
2525
vtr::RngContainer& rng);
2626

@@ -31,5 +31,3 @@ class CriticalUniformMoveGenerator : public MoveGenerator {
3131
const t_placer_opts& /*placer_opts*/,
3232
const PlacerCriticalities* /*criticalities*/) override;
3333
};
34-
35-
#endif

vpr/src/place/move_generators/feasible_region_move_generator.cpp

+26-26
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212

1313
FeasibleRegionMoveGenerator::FeasibleRegionMoveGenerator(PlacerState& placer_state,
1414
const PlaceMacros& place_macros,
15+
const NetCostHandler& net_cost_handler,
1516
e_reward_function reward_function,
1617
vtr::RngContainer& rng)
17-
: MoveGenerator(placer_state, place_macros, reward_function, rng) {}
18+
: MoveGenerator(placer_state, place_macros, net_cost_handler, reward_function, rng) {}
1819

1920
e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
2021
t_propose_action& proposed_action,
@@ -23,7 +24,6 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved&
2324
const PlacerCriticalities* criticalities) {
2425
const auto& cluster_ctx = g_vpr_ctx.clustering();
2526
auto& placer_state = placer_state_.get();
26-
auto& place_move_ctx = placer_state.mutable_move();
2727
const auto& block_locs = placer_state.block_locs();
2828
const auto& blk_loc_registry = placer_state.blk_loc_registry();
2929

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

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

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

61-
place_move_ctx.X_coord.clear();
62-
place_move_ctx.Y_coord.clear();
60+
int max_x = std::numeric_limits<int>::min();
61+
int min_x = std::numeric_limits<int>::max();
62+
int max_y = std::numeric_limits<int>::min();
63+
int min_y = std::numeric_limits<int>::max();
64+
65+
bool found = false;
66+
6367
//For critical input nodes, calculate the x & y min-max values
6468
for (ClusterPinId pin_id : cluster_ctx.clb_nlist.block_input_pins(b_from)) {
6569
ClusterNetId net_id = cluster_ctx.clb_nlist.pin_net(pin_id);
@@ -69,28 +73,25 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved&
6973
int ipin = cluster_ctx.clb_nlist.pin_net_index(pin_id);
7074
if (criticalities->criticality(net_id, ipin) > placer_opts.place_crit_limit) {
7175
ClusterBlockId bnum = cluster_ctx.clb_nlist.net_driver_block(net_id);
72-
place_move_ctx.X_coord.push_back(block_locs[bnum].loc.x);
73-
place_move_ctx.Y_coord.push_back(block_locs[bnum].loc.y);
76+
const t_pl_loc& loc = block_locs[bnum].loc;
77+
min_x = std::min(min_x, loc.x);
78+
max_x = std::max(max_x, loc.x);
79+
min_y = std::min(min_y, loc.y);
80+
max_y = std::max(max_y, loc.y);
81+
found = true;
7482
}
7583
}
76-
if (!place_move_ctx.X_coord.empty()) {
77-
max_x = *(std::max_element(place_move_ctx.X_coord.begin(), place_move_ctx.X_coord.end()));
78-
min_x = *(std::min_element(place_move_ctx.X_coord.begin(), place_move_ctx.X_coord.end()));
79-
max_y = *(std::max_element(place_move_ctx.Y_coord.begin(), place_move_ctx.Y_coord.end()));
80-
min_y = *(std::min_element(place_move_ctx.Y_coord.begin(), place_move_ctx.Y_coord.end()));
81-
} else {
82-
max_x = from.x;
83-
min_x = from.x;
84-
max_y = from.y;
85-
min_y = from.y;
84+
85+
if (!found) {
86+
min_x = max_x = from.x;
87+
min_y = max_y = from.y;
8688
}
8789

8890
//Get the most critical output of the node
89-
int xt, yt;
9091
ClusterBlockId b_output = cluster_ctx.clb_nlist.net_pin_block(net_from, pin_from);
9192
t_pl_loc output_loc = block_locs[b_output].loc;
92-
xt = output_loc.x;
93-
yt = output_loc.y;
93+
int xt = output_loc.x;
94+
int yt = output_loc.y;
9495

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

130131
t_range_limiters range_limiters{rlim,
131-
place_move_ctx.first_rlim,
132+
first_rlim,
132133
placer_opts.place_dm_rlim};
133134

134135
// Try to find a legal location inside the feasible region
135136
if (!find_to_loc_median(cluster_from_type, from, &FR_coords, to, b_from, blk_loc_registry, rng_)) {
136-
/** If there is no legal location in the feasible region, calculate the center of the FR and try to find a legal location
137-
* in a range around this center.
138-
*/
137+
/* If there is no legal location in the feasible region, calculate the center of the FR and try to find a legal location
138+
* in a range around this center. */
139139
t_pl_loc center;
140140
center.x = (FR_coords.xmin + FR_coords.xmax) / 2;
141141
center.y = (FR_coords.ymin + FR_coords.ymax) / 2;

vpr/src/place/move_generators/feasible_region_move_generator.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef VPR_FEASIBLE_REGION_MOVE_GEN_H
2-
#define VPR_FEASIBLE_REGION_MOVE_GEN_H
1+
#pragma once
32

43
#include "move_generator.h"
54

@@ -25,6 +24,7 @@ class FeasibleRegionMoveGenerator : public MoveGenerator {
2524
FeasibleRegionMoveGenerator() = delete;
2625
FeasibleRegionMoveGenerator(PlacerState& placer_state,
2726
const PlaceMacros& place_macros,
27+
const NetCostHandler& net_cost_handler,
2828
e_reward_function reward_function,
2929
vtr::RngContainer& rng);
3030

@@ -35,5 +35,3 @@ class FeasibleRegionMoveGenerator : public MoveGenerator {
3535
const t_placer_opts& placer_opts,
3636
const PlacerCriticalities* criticalities) override;
3737
};
38-
39-
#endif

vpr/src/place/move_generators/manual_move_generator.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222

2323
ManualMoveGenerator::ManualMoveGenerator(PlacerState& placer_state,
2424
const PlaceMacros& place_macros,
25+
const NetCostHandler& net_cost_handler,
2526
vtr::RngContainer& rng)
26-
: MoveGenerator(placer_state, place_macros, e_reward_function::UNDEFINED_REWARD, rng) {}
27+
: MoveGenerator(placer_state, place_macros, net_cost_handler, e_reward_function::UNDEFINED_REWARD, rng) {}
2728

2829
//Manual Move Generator function
2930
e_create_move ManualMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,

vpr/src/place/move_generators/manual_move_generator.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* @brief Contains the ManualMoveGenerator class.
66
*/
77

8-
#ifndef VPR_MANUAL_MOVE_GEN_H
9-
#define VPR_MANUAL_MOVE_GEN_H
8+
#pragma once
109

1110
#include "move_generator.h"
1211

@@ -22,6 +21,7 @@ class ManualMoveGenerator : public MoveGenerator {
2221
ManualMoveGenerator() = delete;
2322
ManualMoveGenerator(PlacerState& placer_state,
2423
const PlaceMacros& place_macros,
24+
const NetCostHandler& net_cost_handler,
2525
vtr::RngContainer& rng);
2626

2727
//Evaluates if move is successful and legal or unable to do.
@@ -31,5 +31,3 @@ class ManualMoveGenerator : public MoveGenerator {
3131
const t_placer_opts& /*placer_opts*/,
3232
const PlacerCriticalities* /*criticalities*/) override;
3333
};
34-
35-
#endif /*VPR_MANUAL_MOVE_GEN_H */

0 commit comments

Comments
 (0)