Skip to content

Commit c413d22

Browse files
add comment for PlacementAnnealer class make a few methods private
1 parent c499cde commit c413d22

File tree

2 files changed

+50
-32
lines changed

2 files changed

+50
-32
lines changed

vpr/src/place/annealer.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ PlacementAnnealer::PlacementAnnealer(const t_placer_opts& placer_opts,
217217

218218
int first_move_lim = get_initial_move_lim(placer_opts, placer_opts_.anneal_sched);
219219

220-
221220
if (placer_opts.inner_loop_recompute_divider != 0) {
222221
inner_recompute_limit_ = static_cast<int>(0.5 + (float)first_move_lim / (float)placer_opts.inner_loop_recompute_divider);
223222
} else {
@@ -258,10 +257,10 @@ PlacementAnnealer::PlacementAnnealer(const t_placer_opts& placer_opts,
258257
move_type_stats_.rejected_moves.resize({device_ctx.logical_block_types.size(), (int)e_move_type::NUMBER_OF_AUTO_MOVES}, 0);
259258

260259
// Update the starting temperature for placement annealing to a more appropriate value
261-
annealing_state_.t = estimate_starting_temperature();
260+
annealing_state_.t = estimate_starting_temperature_();
262261
}
263262

264-
float PlacementAnnealer::estimate_starting_temperature() {
263+
float PlacementAnnealer::estimate_starting_temperature_() {
265264
if (placer_opts_.anneal_sched.type == e_sched_type::USER_SCHED) {
266265
return placer_opts_.anneal_sched.init_t;
267266
}
@@ -289,7 +288,7 @@ float PlacementAnnealer::estimate_starting_temperature() {
289288
#endif /*NO_GRAPHICS*/
290289

291290
// Will not deploy setup slack analysis, so omit crit_exponenet and setup_slack
292-
e_move_result swap_result = try_swap(*move_generator_1_, placer_opts_.place_algorithm, manual_move_enabled);
291+
e_move_result swap_result = try_swap_(*move_generator_1_, placer_opts_.place_algorithm, manual_move_enabled);
293292

294293
if (swap_result == e_move_result::ACCEPTED) {
295294
num_accepted++;
@@ -322,9 +321,9 @@ float PlacementAnnealer::estimate_starting_temperature() {
322321
return init_temp;
323322
}
324323

325-
e_move_result PlacementAnnealer::try_swap(MoveGenerator& move_generator,
326-
const t_place_algorithm& place_algorithm,
327-
bool manual_move_enabled) {
324+
e_move_result PlacementAnnealer::try_swap_(MoveGenerator& move_generator,
325+
const t_place_algorithm& place_algorithm,
326+
bool manual_move_enabled) {
328327
/* Picks some block and moves it to another spot. If this spot is
329328
* occupied, switch the blocks. Assess the change in cost function.
330329
* rlim is the range limiter.
@@ -638,7 +637,7 @@ void PlacementAnnealer::outer_loop_update_timing_info() {
638637
PlaceCritParams crit_params{annealing_state_.crit_exponent,
639638
placer_opts_.place_crit_limit};
640639

641-
//Update all timing related classes
640+
// Update all timing related classes
642641
perform_full_timing_update(crit_params, delay_model_, criticalities_, setup_slacks_,
643642
pin_timing_invalidator_, timing_info_, &costs_, placer_state_);
644643

@@ -667,7 +666,7 @@ void PlacementAnnealer::placement_inner_loop() {
667666

668667
// Inner loop begins
669668
for (int inner_iter = 0, inner_crit_iter_count = 1; inner_iter < annealing_state_.move_lim; inner_iter++) {
670-
e_move_result swap_result = try_swap(move_generator, placer_opts_.place_algorithm, manual_move_enabled);
669+
e_move_result swap_result = try_swap_(move_generator, placer_opts_.place_algorithm, manual_move_enabled);
671670

672671
if (swap_result == e_move_result::ACCEPTED) {
673672
// Move was accepted. Update statistics that are useful for the annealing schedule.
@@ -683,7 +682,6 @@ void PlacementAnnealer::placement_inner_loop() {
683682
/* Do we want to re-timing analyze the circuit to get updated slack and criticality values?
684683
* We do this only once in a while, since it is expensive.
685684
*/
686-
687685
const int recompute_limit = quench_started_ ? quench_recompute_limit_ : inner_recompute_limit_;
688686
// on last iteration don't recompute
689687
if (inner_crit_iter_count >= recompute_limit && inner_iter != annealing_state_.move_lim - 1) {

vpr/src/place/annealer.h

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,26 @@ class t_annealing_state {
133133
inline void update_crit_exponent(const t_placer_opts& placer_opts);
134134
};
135135

136-
136+
/**
137+
* @class PlacementAnnealer
138+
* @brief Implements a simulated annealing optimizer that minimizes the placement cost
139+
* by swapping clustered blocks. It always accepts swaps that reduce the placement cost,
140+
* but accepts the swaps that increase the cost with a diminishing probability.
141+
*
142+
* @details Swaps are performed in a two nested loops. The inner loop is implemented in
143+
* placement_inner_loop() method. Each iteration of the inner loop performs a single swap,
144+
* and all swaps performed in each iteration of the other loop are evaluated using the same
145+
* temperature.
146+
*
147+
* The user is expected to call outer_loop_update_timing_info() before calling
148+
* placement_inner_loop(). Then, outer_loop_update_state() should be called to
149+
* determine whether another iteration of the outer loop is required.
150+
* If outer_loop_update_state() returns false, start_quench() can be called to
151+
* set the temperate to zero so that the annealer behaves greedily. Then,
152+
* outer_loop_update_timing_info() and placement_inner_loop() can be called
153+
* to run the quench stage.
154+
*
155+
*/
137156
class PlacementAnnealer {
138157
public:
139158
PlacementAnnealer(const t_placer_opts& placer_opts,
@@ -171,26 +190,6 @@ class PlacementAnnealer {
171190
*/
172191
bool outer_loop_update_state();
173192

174-
/**
175-
* @brief Pick some block and moves it to another spot.
176-
*
177-
* If the new location is empty, directly move the block. If the new location
178-
* is occupied, switch the blocks. Due to the different sizes of the blocks,
179-
* this block switching may occur for multiple times. It might also cause the
180-
* current swap attempt to abort due to inability to find suitable locations
181-
* for moved blocks.
182-
*
183-
* The move generator will record all the switched blocks in the variable
184-
* `blocks_affected`. Afterwards, the move will be assessed by the chosen
185-
* cost formulation. Currently, there are three ways to assess move cost,
186-
* which are stored in the enum type `t_place_algorithm`.
187-
*
188-
* @return Whether the block swap is accepted, rejected or aborted.
189-
*/
190-
e_move_result try_swap(MoveGenerator& move_generator,
191-
const t_place_algorithm& place_algorithm,
192-
bool manual_move_enabled);
193-
194193
/**
195194
* @brief Starts the quench stage in simulated annealing by
196195
* setting the temperature to zero and reverting the move range limit
@@ -211,6 +210,27 @@ class PlacementAnnealer {
211210
std::tuple<const t_swap_stats&, const MoveTypeStat&, const t_placer_statistics&> get_stats() const;
212211

213212
private:
213+
214+
/**
215+
* @brief Pick some block and moves it to another spot.
216+
*
217+
* If the new location is empty, directly move the block. If the new location
218+
* is occupied, switch the blocks. Due to the different sizes of the blocks,
219+
* this block switching may occur for multiple times. It might also cause the
220+
* current swap attempt to abort due to inability to find suitable locations
221+
* for moved blocks.
222+
*
223+
* The move generator will record all the switched blocks in the variable
224+
* `blocks_affected`. Afterwards, the move will be assessed by the chosen
225+
* cost formulation. Currently, there are three ways to assess move cost,
226+
* which are stored in the enum type `t_place_algorithm`.
227+
*
228+
* @return Whether the block swap is accepted, rejected or aborted.
229+
*/
230+
e_move_result try_swap_(MoveGenerator& move_generator,
231+
const t_place_algorithm& place_algorithm,
232+
bool manual_move_enabled);
233+
214234
/**
215235
* @brief Determines whether a move should be accepted or not.
216236
* Moves with negative delta cost are always accepted, but
@@ -223,7 +243,7 @@ class PlacementAnnealer {
223243
e_move_result assess_swap_(double delta_c, double t);
224244

225245
/// @brief Find the starting temperature for the annealing loop.
226-
float estimate_starting_temperature();
246+
float estimate_starting_temperature_();
227247

228248
private:
229249
const t_placer_opts& placer_opts_;

0 commit comments

Comments
 (0)