Skip to content

Commit 5f647af

Browse files
iterate over move type names
1 parent 2778e2e commit 5f647af

10 files changed

+118
-94
lines changed

vpr/src/base/CheckSetup.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void CheckSetup(const t_packer_opts& PackerOpts,
3131
"This is allowed, but strange, and circuit speed will suffer.\n");
3232
}
3333

34-
if ((false == Timing.timing_analysis_enabled)
34+
if (!Timing.timing_analysis_enabled
3535
&& (PlacerOpts.place_algorithm.is_timing_driven())) {
3636
/* May work, not tested */
3737
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
@@ -43,14 +43,20 @@ void CheckSetup(const t_packer_opts& PackerOpts,
4343
"A block location file requires that placement is enabled.\n");
4444
}
4545

46-
if (PlacerOpts.place_static_move_prob.size() != NUM_PL_MOVE_TYPES) {
46+
if (PlacerOpts.place_algorithm.is_timing_driven() &&
47+
PlacerOpts.place_static_move_prob.size() > NUM_PL_MOVE_TYPES) {
4748
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
48-
"The number of placer move probabilities should equal to the total number of supported moves. %d\n", PlacerOpts.place_static_move_prob.size());
49+
"The number of provided placer move probabilities (%d) should equal or less than the total number of supported moves (%d).\n",
50+
PlacerOpts.place_static_move_prob.size(),
51+
NUM_PL_MOVE_TYPES);
4952
}
5053

51-
if (PlacerOpts.place_static_notiming_move_prob.size() != NUM_PL_NONTIMING_MOVE_TYPES) {
54+
if (!PlacerOpts.place_algorithm.is_timing_driven() &&
55+
PlacerOpts.place_static_move_prob.size() > NUM_PL_NONTIMING_MOVE_TYPES) {
5256
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
53-
"The number of placer non timing move probabilities should equal to the total number of supported moves. %d\n", PlacerOpts.place_static_notiming_move_prob.size());
57+
"The number of placer non timing move probabilities (%d) should equal to or less than the total number of supported moves (%d).\n",
58+
PlacerOpts.place_static_move_prob.size(),
59+
NUM_PL_MOVE_TYPES);
5460
}
5561

5662
if (RouterOpts.doRouting) {

vpr/src/base/SetupVPR.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,8 @@ static void SetupPlacerOpts(const t_options& Options, t_placer_opts* PlacerOpts)
661661
PlacerOpts->effort_scaling = Options.place_effort_scaling;
662662
PlacerOpts->timing_update_type = Options.timing_update_type;
663663
PlacerOpts->enable_analytic_placer = Options.enable_analytic_placer;
664-
PlacerOpts->place_static_move_prob = Options.place_static_move_prob;
665-
PlacerOpts->place_static_notiming_move_prob = Options.place_static_notiming_move_prob;
664+
PlacerOpts->place_static_move_prob = vtr::vector<e_move_type, float>(Options.place_static_move_prob.value().begin(),
665+
Options.place_static_move_prob.value().end());
666666
PlacerOpts->place_high_fanout_net = Options.place_high_fanout_net;
667667
PlacerOpts->place_bounding_box_mode = Options.place_bounding_box_mode;
668668
PlacerOpts->RL_agent_placement = Options.RL_agent_placement;

vpr/src/base/read_options.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,24 +2032,17 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
20322032

20332033
place_grp.add_argument(args.place_static_move_prob, "--place_static_move_prob")
20342034
.help(
2035-
"The percentage probabilities of different moves in Simulated Annealing placement."
2036-
"This option is only effective for timing-driven placement."
2037-
"The numbers listed are interpreted as the percentage probabilities of {uniformMove, MedianMove, CentroidMove, "
2035+
"The percentage probabilities of different moves in Simulated Annealing placement. "
2036+
"For non-timing-driven placement, only the first 3 probabilities should be provided. "
2037+
"For timing-driven placement, all probabilities should be provided. "
2038+
"When the number of provided probabilities is less then the number of move types, zero probability "
2039+
"is assumed."
2040+
"The numbers listed are interpreted as the percentage probabilities of {UniformMove, MedianMove, CentroidMove, "
20382041
"WeightedCentroid, WeightedMedian, Critical UniformMove, Timing feasible Region(TFR)}, in that order.")
20392042
.nargs('+')
2040-
.default_value({"100", "0", "0", "0", "0", "0", "0"})
2041-
2043+
.default_value({"100"})
20422044
.show_in(argparse::ShowIn::HELP_ONLY);
20432045

2044-
place_grp.add_argument(args.place_static_notiming_move_prob, "--place_static_notiming_move_prob")
2045-
.help(
2046-
"The Probability of different non timing move in Simulated Annealing."
2047-
"This option is only effective for nontiming driven placement."
2048-
" The numbers listed are interpreted as the percentage probabilities of {uniformMove, MedianMove, CentroidMove}, in that order.")
2049-
.nargs('+')
2050-
.default_value({"100", "0", "0"})
2051-
2052-
.show_in(argparse::ShowIn::HELP_ONLY);
20532046

20542047
place_grp.add_argument(args.place_high_fanout_net, "--place_high_fanout_net")
20552048
.help(

vpr/src/base/read_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ struct t_options {
126126
argparse::ArgValue<e_place_delta_delay_algorithm> place_delta_delay_matrix_calculation_method;
127127
argparse::ArgValue<bool> enable_analytic_placer;
128128
argparse::ArgValue<std::vector<float>> place_static_move_prob;
129-
argparse::ArgValue<std::vector<float>> place_static_notiming_move_prob;
130129
argparse::ArgValue<int> place_high_fanout_net;
131130
argparse::ArgValue<e_place_bounding_box_mode> place_bounding_box_mode;
132131

vpr/src/base/vpr_types.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,8 @@ enum class e_place_delta_delay_algorithm {
11501150
DIJKSTRA_EXPANSION,
11511151
};
11521152

1153+
enum class e_move_type;
1154+
11531155
/**
11541156
* @brief Various options for the placer.
11551157
*
@@ -1248,8 +1250,7 @@ struct t_placer_opts {
12481250

12491251
std::string write_placement_delay_lookup;
12501252
std::string read_placement_delay_lookup;
1251-
std::vector<float> place_static_move_prob;
1252-
std::vector<float> place_static_notiming_move_prob;
1253+
vtr::vector<e_move_type, float> place_static_move_prob;
12531254
bool RL_agent_placement;
12541255
bool place_agent_multistate;
12551256
bool place_checkpointing;

vpr/src/place/RL_agent_util.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
#include "RL_agent_util.h"
2+
#include "static_move_generator.h"
23
#include "manual_move_generator.h"
34

45
void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator,
56
std::unique_ptr<MoveGenerator>& move_generator2,
67
const t_placer_opts& placer_opts,
78
int move_lim) {
89
if (!placer_opts.RL_agent_placement) { // RL agent is disabled
9-
if (placer_opts.place_algorithm.is_timing_driven()) {
10-
VTR_LOG("Using static probabilities for choosing each move type\n");
11-
VTR_LOG("Probability of Uniform_move : %f \n", placer_opts.place_static_move_prob[(int)e_move_type::UNIFORM]);
12-
VTR_LOG("Probability of Median_move : %f \n", placer_opts.place_static_move_prob[(int)e_move_type::MEDIAN]);
13-
VTR_LOG("Probability of Centroid_move : %f \n", placer_opts.place_static_move_prob[(int)e_move_type::CENTROID]);
14-
VTR_LOG("Probability of Weighted_centroid_move : %f \n", placer_opts.place_static_move_prob[(int)e_move_type::W_CENTROID]);
15-
VTR_LOG("Probability of Weighted_median_move : %f \n", placer_opts.place_static_move_prob[(int)e_move_type::W_MEDIAN]);
16-
VTR_LOG("Probability of Critical_uniform_move : %f \n", placer_opts.place_static_move_prob[(int)e_move_type::CRIT_UNIFORM]);
17-
VTR_LOG("Probability of Timing_feasible_region_move : %f \n", placer_opts.place_static_move_prob[(int)e_move_type::FEASIBLE_REGION]);
18-
move_generator = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_move_prob);
19-
move_generator2 = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_move_prob);
20-
} else { //Non-timing driven placement
21-
VTR_LOG("Using static probabilities for choosing each move type\n");
22-
VTR_LOG("Probability of Uniform_move : %f \n", placer_opts.place_static_notiming_move_prob[(int)e_move_type::UNIFORM]);
23-
VTR_LOG("Probability of Median_move : %f \n", placer_opts.place_static_notiming_move_prob[(int)e_move_type::MEDIAN]);
24-
VTR_LOG("Probability of Centroid_move : %f \n", placer_opts.place_static_notiming_move_prob[(int)e_move_type::CENTROID]);
25-
move_generator = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_notiming_move_prob);
26-
move_generator2 = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_notiming_move_prob);
10+
auto move_types = placer_opts.place_static_move_prob;
11+
move_types.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES, 0.0f);
12+
13+
VTR_LOG("Using static probabilities for choosing each move type\n");
14+
for (const auto move_type : placer_opts.place_static_move_prob.keys()) {
15+
const std::string& move_name = move_type_to_string(move_type);
16+
VTR_LOG("Probability of %s : %f \n",
17+
move_name.c_str(),
18+
placer_opts.place_static_move_prob[move_type]);
2719
}
20+
21+
move_generator = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_move_prob);
22+
move_generator2 = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_move_prob);
2823
} else { //RL based placement
2924
/* For the non timing driven placement: the agent has a single state *
3025
* - Available moves are (Uniform / Median / Centroid) *
@@ -113,7 +108,7 @@ void assign_current_move_generator(std::unique_ptr<MoveGenerator>& move_generato
113108
else
114109
current_move_generator = std::move(move_generator);
115110
} else {
116-
if (agent_state == EARLY_IN_THE_ANNEAL || !placer_opts.place_agent_multistate)
111+
if (agent_state == e_agent_state::EARLY_IN_THE_ANNEAL || !placer_opts.place_agent_multistate)
117112
current_move_generator = std::move(move_generator);
118113
else
119114
current_move_generator = std::move(move_generator2);
@@ -132,7 +127,7 @@ void update_move_generator(std::unique_ptr<MoveGenerator>& move_generator,
132127
else
133128
move_generator = std::move(current_move_generator);
134129
} else {
135-
if (agent_state == EARLY_IN_THE_ANNEAL || !placer_opts.place_agent_multistate)
130+
if (agent_state == e_agent_state::EARLY_IN_THE_ANNEAL || !placer_opts.place_agent_multistate)
136131
move_generator = std::move(current_move_generator);
137132
else
138133
move_generator2 = std::move(current_move_generator);

vpr/src/place/RL_agent_util.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#ifndef RL_AGENT_UTIL_H
22
#define RL_AGENT_UTIL_H
33

4-
#include "static_move_generator.h"
5-
#include "simpleRL_move_generator.h"
6-
#include "manual_move_generator.h"
4+
#include "move_generator.h"
5+
76

87
//enum represents the available agent states
9-
enum e_agent_state {
8+
enum class e_agent_state {
109
EARLY_IN_THE_ANNEAL,
1110
LATE_IN_THE_ANNEAL
1211
};
@@ -19,15 +18,28 @@ enum e_agent_state {
1918
* It returns a unique pointer for each move generator in move_generator and move_generator2
2019
* move_lim: represents the num of moves per temp.
2120
*/
22-
void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator, std::unique_ptr<MoveGenerator>& move_generator2, const t_placer_opts& placer_opts, int move_lim);
21+
void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator,
22+
std::unique_ptr<MoveGenerator>& move_generator2,
23+
const t_placer_opts& placer_opts,
24+
int move_lim);
2325

2426
/**
2527
* @brief copy one of the available move_generators to be the current move_generator that would be used in the placement based on the placer_options and the agent state
2628
*/
27-
void assign_current_move_generator(std::unique_ptr<MoveGenerator>& move_generator, std::unique_ptr<MoveGenerator>& move_generator2, e_agent_state agent_state, const t_placer_opts& placer_opts, bool in_quench, std::unique_ptr<MoveGenerator>& current_move_generator);
29+
void assign_current_move_generator(std::unique_ptr<MoveGenerator>& move_generator,
30+
std::unique_ptr<MoveGenerator>& move_generator2,
31+
e_agent_state agent_state,
32+
const t_placer_opts& placer_opts,
33+
bool in_quench,
34+
std::unique_ptr<MoveGenerator>& current_move_generator);
2835

2936
/**
3037
* @ brief move the updated current_move_generator to its original move_Generator structure based on he placer_options and the agent state
3138
*/
32-
void update_move_generator(std::unique_ptr<MoveGenerator>& move_generator, std::unique_ptr<MoveGenerator>& move_generator2, e_agent_state agent_state, const t_placer_opts& placer_opts, bool in_quench, std::unique_ptr<MoveGenerator>& current_move_generator);
39+
void update_move_generator(std::unique_ptr<MoveGenerator>& move_generator,
40+
std::unique_ptr<MoveGenerator>& move_generator2,
41+
e_agent_state agent_state,
42+
const t_placer_opts& placer_opts,
43+
bool in_quench,
44+
std::unique_ptr<MoveGenerator>& current_move_generator);
3345
#endif

vpr/src/place/place.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ void try_place(const Netlist<>& net_list,
981981
#endif /* ENABLE_ANALYTIC_PLACE */
982982

983983
//RL agent state definition
984-
e_agent_state agent_state = EARLY_IN_THE_ANNEAL;
984+
e_agent_state agent_state = e_agent_state::EARLY_IN_THE_ANNEAL;
985985

986986
std::unique_ptr<MoveGenerator> current_move_generator;
987987

@@ -1011,7 +1011,7 @@ void try_place(const Netlist<>& net_list,
10111011
//see if we should save the current placement solution as a checkpoint
10121012

10131013
if (placer_opts.place_checkpointing
1014-
&& agent_state == LATE_IN_THE_ANNEAL) {
1014+
&& agent_state == e_agent_state::LATE_IN_THE_ANNEAL) {
10151015
save_placement_checkpoint_if_needed(placement_checkpoint,
10161016
timing_info, costs, critical_path.delay());
10171017
}
@@ -1045,9 +1045,9 @@ void try_place(const Netlist<>& net_list,
10451045

10461046
if (placer_opts.place_algorithm.is_timing_driven()
10471047
&& placer_opts.place_agent_multistate
1048-
&& agent_state == EARLY_IN_THE_ANNEAL) {
1048+
&& agent_state == e_agent_state::EARLY_IN_THE_ANNEAL) {
10491049
if (state.alpha < 0.85 && state.alpha > 0.6) {
1050-
agent_state = LATE_IN_THE_ANNEAL;
1050+
agent_state = e_agent_state::LATE_IN_THE_ANNEAL;
10511051
VTR_LOG("Agent's 2nd state: \n");
10521052
}
10531053
}
Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,61 @@
1+
12
#include "static_move_generator.h"
2-
#include "globals.h"
3-
#include <algorithm>
3+
4+
#include "median_move_generator.h"
5+
#include "weighted_median_move_generator.h"
6+
#include "weighted_centroid_move_generator.h"
7+
#include "feasible_region_move_generator.h"
8+
#include "uniform_move_generator.h"
9+
#include "critical_uniform_move_generator.h"
10+
#include "centroid_move_generator.h"
411

512
#include "vtr_random.h"
613
#include "vtr_assert.h"
714

8-
StaticMoveGenerator::StaticMoveGenerator(const std::vector<float>& prob) {
9-
avail_moves.emplace_back(std::make_unique<UniformMoveGenerator>());
10-
avail_moves.emplace_back(std::make_unique<MedianMoveGenerator>());
11-
avail_moves.emplace_back(std::make_unique<CentroidMoveGenerator>());
12-
avail_moves.emplace_back(std::make_unique<WeightedCentroidMoveGenerator>());
13-
avail_moves.emplace_back(std::make_unique<WeightedMedianMoveGenerator>());
14-
avail_moves.emplace_back(std::make_unique<CriticalUniformMoveGenerator>());
15-
avail_moves.emplace_back(std::make_unique<FeasibleRegionMoveGenerator>());
15+
StaticMoveGenerator::StaticMoveGenerator(const vtr::vector<e_move_type, float>& move_probs) {
16+
all_moves.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES);
1617

17-
initialize_move_prob(prob);
18+
all_moves[e_move_type::UNIFORM] = std::make_unique<UniformMoveGenerator>();
19+
all_moves[e_move_type::MEDIAN] = std::make_unique<MedianMoveGenerator>();
20+
all_moves[e_move_type::CENTROID] = std::make_unique<CentroidMoveGenerator>();
21+
all_moves[e_move_type::W_CENTROID] = std::make_unique<WeightedCentroidMoveGenerator>();
22+
all_moves[e_move_type::W_MEDIAN] = std::make_unique<WeightedMedianMoveGenerator>();
23+
all_moves[e_move_type::CRIT_UNIFORM] = std::make_unique<CriticalUniformMoveGenerator>();
24+
all_moves[e_move_type::FEASIBLE_REGION] = std::make_unique<FeasibleRegionMoveGenerator>();
25+
26+
initialize_move_prob(move_probs);
1827
}
1928

20-
void StaticMoveGenerator::initialize_move_prob(const std::vector<float>& prob) {
21-
cumm_move_probs.push_back(prob[0]);
22-
for (size_t i = 1; i < prob.size(); i++) {
23-
cumm_move_probs.push_back(prob[i] + cumm_move_probs[i - 1]);
29+
void StaticMoveGenerator::initialize_move_prob(const vtr::vector<e_move_type, float>& move_probs) {
30+
cumm_move_probs.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES);
31+
std::fill(cumm_move_probs.begin(), cumm_move_probs.end(), 0.0f);
32+
33+
for(auto move_type : move_probs.keys()) {
34+
cumm_move_probs[move_type] = move_probs[move_type];
2435
}
2536

26-
total_prob = cumm_move_probs[cumm_move_probs.size() - 1];
37+
std::partial_sum(cumm_move_probs.begin(), cumm_move_probs.end(), cumm_move_probs.begin());
38+
39+
total_prob = cumm_move_probs.back();
2740
}
2841

29-
e_create_move StaticMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, t_propose_action& proposed_action, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* criticalities) {
42+
e_create_move StaticMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
43+
t_propose_action& proposed_action,
44+
float rlim,
45+
const t_placer_opts& placer_opts,
46+
const PlacerCriticalities* criticalities) {
3047
float rand_num = vtr::frand() * total_prob;
31-
for (size_t i = 0; i < cumm_move_probs.size(); i++) {
32-
if (rand_num <= cumm_move_probs[i]) {
33-
proposed_action.move_type = (e_move_type)i;
34-
return avail_moves[i]->propose_move(blocks_affected, proposed_action, rlim, placer_opts, criticalities);
48+
49+
for (auto move_type : cumm_move_probs.keys()) {
50+
if (rand_num <= cumm_move_probs[move_type]) {
51+
proposed_action.move_type = move_type;
52+
return all_moves[move_type]->propose_move(blocks_affected, proposed_action, rlim, placer_opts, criticalities);
3553
}
3654
}
37-
VTR_ASSERT_MSG(false, vtr::string_fmt("During static probability move selection, random number (%g) exceeded total expected probabaility (%g)", rand_num, total_prob).c_str());
55+
56+
VTR_ASSERT_MSG(false, vtr::string_fmt("During static probability move selection, random number (%g) exceeded total expected probability (%g)", rand_num, total_prob).c_str());
3857

3958
//Unreachable
40-
proposed_action.move_type = (e_move_type)(avail_moves.size() - 1);
41-
return avail_moves[avail_moves.size() - 1]->propose_move(blocks_affected, proposed_action, rlim, placer_opts, criticalities);
59+
proposed_action.move_type = e_move_type::INVALID_MOVE;
60+
return e_create_move::ABORT;
4261
}

0 commit comments

Comments
 (0)