Skip to content

Commit 88fb2e1

Browse files
specify available move types explicitly
1 parent 633193b commit 88fb2e1

File tree

8 files changed

+124
-90
lines changed

8 files changed

+124
-90
lines changed

libs/libvtrutil/src/vtr_ndmatrix.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class NdMatrixProxy<T, 1> {
139139
* This should improve memory usage (no extra pointers to store for each dimension),
140140
* and cache locality (less indirection via pointers, predictable strides).
141141
*
142-
* The indicies are calculated based on the dimensions to access the appropriate elements.
142+
* The indices are calculated based on the dimensions to access the appropriate elements.
143143
* Since the indexing calculations are visible to the compiler at compile time they can be
144144
* optimized to be efficient.
145145
*/
@@ -288,7 +288,7 @@ class NdMatrixBase {
288288
data_ = std::make_unique<T[]>(size());
289289
}
290290

291-
///@brief Returns the size of the matrix (number of elements) calucated from the current dimensions
291+
///@brief Returns the size of the matrix (number of elements) calculated from the current dimensions
292292
size_t calc_size() const {
293293
///@brief Size is the product of all dimension sizes
294294
size_t cnt = dim_size(0);
@@ -310,7 +310,7 @@ class NdMatrixBase {
310310
*
311311
* Examples:
312312
*
313-
* //A 2-dimensional matrix with indicies [0..4][0..9]
313+
* //A 2-dimensional matrix with indices [0..4][0..9]
314314
* NdMatrix<int,2> m1({5,10});
315315
*
316316
* //Accessing an element
@@ -319,17 +319,17 @@ class NdMatrixBase {
319319
* //Setting an element
320320
* m1[2][8] = 0;
321321
*
322-
* //A 3-dimensional matrix with indicies [0..4][0..9][0..19]
322+
* //A 3-dimensional matrix with indices [0..4][0..9][0..19]
323323
* NdMatrix<int,3> m2({5,10,20});
324324
*
325-
* //A 2-dimensional matrix with indicies [0..4][0..9], with all entries
325+
* //A 2-dimensional matrix with indices [0..4][0..9], with all entries
326326
* //initialized to 42
327327
* NdMatrix<int,2> m3({5,10}, 42);
328328
*
329329
* //Filling all entries with value 101
330330
* m3.fill(101);
331331
*
332-
* //Resizing an existing matrix (all values reset to default constucted value)
332+
* //Resizing an existing matrix (all values reset to default constructed value)
333333
* m3.resize({5,5})
334334
*
335335
* //Resizing an existing matrix (all elements set to value 88)

vpr/src/base/CheckSetup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void CheckSetup(const t_packer_opts& PackerOpts,
3838
"Timing analysis must be enabled for timing-driven placement.\n");
3939
}
4040

41-
if (!PlacerOpts.doPlacement && ("" != PlacerOpts.constraints_file)) {
41+
if (!PlacerOpts.doPlacement && (!PlacerOpts.constraints_file.empty())) {
4242
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
4343
"A block location file requires that placement is enabled.\n");
4444
}
@@ -57,7 +57,7 @@ void CheckSetup(const t_packer_opts& PackerOpts,
5757
if (!Timing.timing_analysis_enabled
5858
&& (DEMAND_ONLY != RouterOpts.base_cost_type && DEMAND_ONLY_NORMALIZED_LENGTH != RouterOpts.base_cost_type)) {
5959
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
60-
"base_cost_type must be demand_only or demand_only_normailzed_length when timing analysis is disabled.\n");
60+
"base_cost_type must be demand_only or demand_only_normalized_length when timing analysis is disabled.\n");
6161
}
6262
}
6363

vpr/src/base/read_options.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,8 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
20342034
.help(
20352035
"The percentage probabilities of different moves in Simulated Annealing placement."
20362036
"This option is only effective for timing-driven placement."
2037-
"The numbers listed are interpreted as the percentage probabilities of {uniformMove, MedianMove, CentroidMove, WeightedCentroid, WeightedMedian, Timing feasible Region(TFR), Critical UniformMove}, in that order.")
2037+
"The numbers listed are interpreted as the percentage probabilities of {uniformMove, MedianMove, CentroidMove, "
2038+
"WeightedCentroid, WeightedMedian, Critical UniformMove, Timing feasible Region(TFR)}, in that order.")
20382039
.nargs('+')
20392040
.default_value({"100", "0", "0", "0", "0", "0", "0"})
20402041

vpr/src/base/vpr_types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,9 @@ enum class e_timing_update_type {
550550
****************************************************************************/
551551

552552
/* Values of number of placement available move types */
553-
#define NUM_PL_MOVE_TYPES 7
554-
#define NUM_PL_NONTIMING_MOVE_TYPES 3
555-
#define NUM_PL_1ST_STATE_MOVE_TYPES 4
553+
constexpr int NUM_PL_MOVE_TYPES = 7;
554+
constexpr int NUM_PL_NONTIMING_MOVE_TYPES = 3;
555+
constexpr int NUM_PL_1ST_STATE_MOVE_TYPES = 4;
556556

557557
/* Timing data structures end */
558558
enum sched_type {

vpr/src/place/RL_agent_util.cpp

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
#include "RL_agent_util.h"
22
#include "manual_move_generator.h"
33

4-
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) {
5-
if (placer_opts.RL_agent_placement == false) {
4+
void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator,
5+
std::unique_ptr<MoveGenerator>& move_generator2,
6+
const t_placer_opts& placer_opts,
7+
int move_lim) {
8+
if (!placer_opts.RL_agent_placement) { // RL agent is disabled
69
if (placer_opts.place_algorithm.is_timing_driven()) {
710
VTR_LOG("Using static probabilities for choosing each move type\n");
8-
VTR_LOG("Probability of Uniform_move : %f \n", placer_opts.place_static_move_prob[0]);
9-
VTR_LOG("Probability of Median_move : %f \n", placer_opts.place_static_move_prob[1]);
10-
VTR_LOG("Probability of Centroid_move : %f \n", placer_opts.place_static_move_prob[2]);
11-
VTR_LOG("Probability of Weighted_centroid_move : %f \n", placer_opts.place_static_move_prob[3]);
12-
VTR_LOG("Probability of Weighted_median_move : %f \n", placer_opts.place_static_move_prob[4]);
13-
VTR_LOG("Probability of Timing_feasible_region_move : %f \n", placer_opts.place_static_move_prob[5]);
14-
VTR_LOG("Probability of Critical_uniform_move : %f \n", placer_opts.place_static_move_prob[6]);
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]);
1518
move_generator = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_move_prob);
1619
move_generator2 = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_move_prob);
1720
} else { //Non-timing driven placement
1821
VTR_LOG("Using static probabilities for choosing each move type\n");
19-
VTR_LOG("Probability of Uniform_move : %f \n", placer_opts.place_static_notiming_move_prob[0]);
20-
VTR_LOG("Probability of Median_move : %f \n", placer_opts.place_static_notiming_move_prob[1]);
21-
VTR_LOG("Probability of Centroid_move : %f \n", placer_opts.place_static_notiming_move_prob[2]);
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]);
2225
move_generator = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_notiming_move_prob);
2326
move_generator2 = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_notiming_move_prob);
2427
}
@@ -42,27 +45,35 @@ void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator, std:
4245
* only move type. *
4346
* This state is activated late in the anneal and in the Quench */
4447

45-
int num_1st_state_avail_moves = placer_opts.place_algorithm.is_timing_driven() ? NUM_PL_1ST_STATE_MOVE_TYPES : NUM_PL_NONTIMING_MOVE_TYPES;
46-
int num_2nd_state_avail_moves = placer_opts.place_algorithm.is_timing_driven() ? NUM_PL_MOVE_TYPES : NUM_PL_NONTIMING_MOVE_TYPES;
48+
std::vector<e_move_type> first_state_avail_moves {e_move_type::UNIFORM, e_move_type::MEDIAN, e_move_type::CENTROID};
49+
if (placer_opts.place_algorithm.is_timing_driven()) {
50+
first_state_avail_moves.push_back(e_move_type::W_CENTROID);
51+
}
52+
53+
std::vector<e_move_type> second_state_avail_moves {e_move_type::UNIFORM, e_move_type::MEDIAN, e_move_type::CENTROID};
54+
if (placer_opts.place_algorithm.is_timing_driven()) {
55+
second_state_avail_moves.insert(second_state_avail_moves.end(),
56+
{e_move_type::W_CENTROID, e_move_type::W_MEDIAN, e_move_type::CRIT_UNIFORM, e_move_type::FEASIBLE_REGION});
57+
}
4758

4859
if (placer_opts.place_agent_algorithm == E_GREEDY) {
4960
std::unique_ptr<EpsilonGreedyAgent> karmed_bandit_agent1, karmed_bandit_agent2;
5061
//agent's 1st state
5162
if (placer_opts.place_agent_space == e_agent_space::MOVE_BLOCK_TYPE) {
5263
VTR_LOG("Using simple RL 'Epsilon Greedy agent' for choosing move and block types\n");
53-
karmed_bandit_agent1 = std::make_unique<EpsilonGreedyAgent>(num_1st_state_avail_moves,
64+
karmed_bandit_agent1 = std::make_unique<EpsilonGreedyAgent>(first_state_avail_moves,
5465
e_agent_space::MOVE_BLOCK_TYPE,
5566
placer_opts.place_agent_epsilon);
5667
} else {
5768
VTR_LOG("Using simple RL 'Epsilon Greedy agent' for choosing move types\n");
58-
karmed_bandit_agent1 = std::make_unique<EpsilonGreedyAgent>(num_1st_state_avail_moves,
69+
karmed_bandit_agent1 = std::make_unique<EpsilonGreedyAgent>(first_state_avail_moves,
5970
e_agent_space::MOVE_TYPE,
6071
placer_opts.place_agent_epsilon);
6172
}
6273
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
6374
move_generator = std::make_unique<SimpleRLMoveGenerator>(karmed_bandit_agent1);
6475
//agent's 2nd state
65-
karmed_bandit_agent2 = std::make_unique<EpsilonGreedyAgent>(num_2nd_state_avail_moves,
76+
karmed_bandit_agent2 = std::make_unique<EpsilonGreedyAgent>(second_state_avail_moves,
6677
e_agent_space::MOVE_TYPE,
6778
placer_opts.place_agent_epsilon);
6879
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
@@ -72,46 +83,56 @@ void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator, std:
7283
//agent's 1st state
7384
if (placer_opts.place_agent_space == e_agent_space::MOVE_BLOCK_TYPE) {
7485
VTR_LOG("Using simple RL 'Softmax agent' for choosing move and block types\n");
75-
karmed_bandit_agent1 = std::make_unique<SoftmaxAgent>(num_1st_state_avail_moves,
86+
karmed_bandit_agent1 = std::make_unique<SoftmaxAgent>(first_state_avail_moves,
7687
e_agent_space::MOVE_BLOCK_TYPE);
7788
} else {
7889
VTR_LOG("Using simple RL 'Softmax agent' for choosing move types\n");
79-
karmed_bandit_agent1 = std::make_unique<SoftmaxAgent>(num_1st_state_avail_moves,
90+
karmed_bandit_agent1 = std::make_unique<SoftmaxAgent>(first_state_avail_moves,
8091
e_agent_space::MOVE_TYPE);
8192
}
8293
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
8394
move_generator = std::make_unique<SimpleRLMoveGenerator>(karmed_bandit_agent1);
8495
//agent's 2nd state
85-
karmed_bandit_agent2 = std::make_unique<SoftmaxAgent>(num_2nd_state_avail_moves,
96+
karmed_bandit_agent2 = std::make_unique<SoftmaxAgent>(second_state_avail_moves,
8697
e_agent_space::MOVE_TYPE);
8798
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
8899
move_generator2 = std::make_unique<SimpleRLMoveGenerator>(karmed_bandit_agent2);
89100
}
90101
}
91102
}
92103

93-
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) {
104+
void assign_current_move_generator(std::unique_ptr<MoveGenerator>& move_generator,
105+
std::unique_ptr<MoveGenerator>& move_generator2,
106+
e_agent_state agent_state,
107+
const t_placer_opts& placer_opts,
108+
bool in_quench,
109+
std::unique_ptr<MoveGenerator>& current_move_generator) {
94110
if (in_quench) {
95-
if (placer_opts.place_quench_algorithm.is_timing_driven() && placer_opts.place_agent_multistate == true)
111+
if (placer_opts.place_quench_algorithm.is_timing_driven() && placer_opts.place_agent_multistate)
96112
current_move_generator = std::move(move_generator2);
97113
else
98114
current_move_generator = std::move(move_generator);
99115
} else {
100-
if (agent_state == EARLY_IN_THE_ANNEAL || placer_opts.place_agent_multistate == false)
116+
if (agent_state == EARLY_IN_THE_ANNEAL || !placer_opts.place_agent_multistate)
101117
current_move_generator = std::move(move_generator);
102118
else
103119
current_move_generator = std::move(move_generator2);
104120
}
105121
}
106122

107-
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) {
123+
void update_move_generator(std::unique_ptr<MoveGenerator>& move_generator,
124+
std::unique_ptr<MoveGenerator>& move_generator2,
125+
e_agent_state agent_state,
126+
const t_placer_opts& placer_opts,
127+
bool in_quench,
128+
std::unique_ptr<MoveGenerator>& current_move_generator) {
108129
if (in_quench) {
109-
if (placer_opts.place_quench_algorithm.is_timing_driven() && placer_opts.place_agent_multistate == true)
130+
if (placer_opts.place_quench_algorithm.is_timing_driven() && placer_opts.place_agent_multistate)
110131
move_generator2 = std::move(current_move_generator);
111132
else
112133
move_generator = std::move(current_move_generator);
113134
} else {
114-
if (agent_state == EARLY_IN_THE_ANNEAL || placer_opts.place_agent_multistate == false)
135+
if (agent_state == EARLY_IN_THE_ANNEAL || !placer_opts.place_agent_multistate)
115136
move_generator = std::move(current_move_generator);
116137
else
117138
move_generator2 = std::move(current_move_generator);

vpr/src/place/place.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,9 @@ void try_place(const Netlist<>& net_list,
936936

937937
//allocate move type statistics vectors
938938
MoveTypeStat move_type_stat;
939-
move_type_stat.blk_type_moves.resize(device_ctx.logical_block_types.size() * placer_opts.place_static_move_prob.size(), 0);
940-
move_type_stat.accepted_moves.resize(device_ctx.logical_block_types.size() * placer_opts.place_static_move_prob.size(), 0);
941-
move_type_stat.rejected_moves.resize(device_ctx.logical_block_types.size() * placer_opts.place_static_move_prob.size(), 0);
939+
move_type_stat.blk_type_moves.resize(device_ctx.logical_block_types.size() * (int)e_move_type::NUMBER_OF_AUTO_MOVES, 0);
940+
move_type_stat.accepted_moves.resize(device_ctx.logical_block_types.size() * (int)e_move_type::NUMBER_OF_AUTO_MOVES, 0);
941+
move_type_stat.rejected_moves.resize(device_ctx.logical_block_types.size() * (int)e_move_type::NUMBER_OF_AUTO_MOVES, 0);
942942

943943
/* Get the first range limiter */
944944
first_rlim = (float)max(device_ctx.grid.width() - 1,
@@ -1725,7 +1725,7 @@ static e_move_result try_swap(const t_annealing_state* state,
17251725
}
17261726

17271727
if (proposed_action.logical_blk_type_index != -1) { //if the agent proposed the block type, then collect the block type stat
1728-
++move_type_stat.blk_type_moves[(proposed_action.logical_blk_type_index * (placer_opts.place_static_move_prob.size())) + (int)proposed_action.move_type];
1728+
++move_type_stat.blk_type_moves[(proposed_action.logical_blk_type_index * (int)e_move_type::NUMBER_OF_AUTO_MOVES) + (int)proposed_action.move_type];
17291729
}
17301730
LOG_MOVE_STATS_PROPOSED(t, blocks_affected);
17311731

@@ -1876,7 +1876,7 @@ static e_move_result try_swap(const t_annealing_state* state,
18761876
commit_move_blocks(blocks_affected);
18771877

18781878
if (proposed_action.logical_blk_type_index != -1) { //if the agent proposed the block type, then collect the block type stat
1879-
++move_type_stat.accepted_moves[(proposed_action.logical_blk_type_index * (placer_opts.place_static_move_prob.size())) + (int)proposed_action.move_type];
1879+
++move_type_stat.accepted_moves[(proposed_action.logical_blk_type_index * (int)e_move_type::NUMBER_OF_AUTO_MOVES) + (int)proposed_action.move_type];
18801880
}
18811881
if (noc_opts.noc) {
18821882
commit_noc_costs();
@@ -1927,7 +1927,7 @@ static e_move_result try_swap(const t_annealing_state* state,
19271927
}
19281928

19291929
if (proposed_action.logical_blk_type_index != -1) { //if the agent proposed the block type, then collect the block type stat
1930-
++move_type_stat.rejected_moves[(proposed_action.logical_blk_type_index * (placer_opts.place_static_move_prob.size())) + (int)proposed_action.move_type];
1930+
++move_type_stat.rejected_moves[(proposed_action.logical_blk_type_index * (int)e_move_type::NUMBER_OF_AUTO_MOVES) + (int)proposed_action.move_type];
19311931
}
19321932
/* Revert the traffic flow routes within the NoC*/
19331933
if (noc_opts.noc) {

0 commit comments

Comments
 (0)