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);
0 commit comments