1
1
#include " RL_agent_util.h"
2
2
#include " manual_move_generator.h"
3
3
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
6
9
if (placer_opts.place_algorithm .is_timing_driven ()) {
7
10
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 ]);
15
18
move_generator = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_move_prob );
16
19
move_generator2 = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_move_prob );
17
20
} else { // Non-timing driven placement
18
21
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 ]);
22
25
move_generator = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_notiming_move_prob );
23
26
move_generator2 = std::make_unique<StaticMoveGenerator>(placer_opts.place_static_notiming_move_prob );
24
27
}
@@ -42,27 +45,35 @@ void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator, std:
42
45
* only move type. *
43
46
* This state is activated late in the anneal and in the Quench */
44
47
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
+ }
47
58
48
59
if (placer_opts.place_agent_algorithm == E_GREEDY) {
49
60
std::unique_ptr<EpsilonGreedyAgent> karmed_bandit_agent1, karmed_bandit_agent2;
50
61
// agent's 1st state
51
62
if (placer_opts.place_agent_space == e_agent_space::MOVE_BLOCK_TYPE) {
52
63
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 ,
54
65
e_agent_space::MOVE_BLOCK_TYPE,
55
66
placer_opts.place_agent_epsilon );
56
67
} else {
57
68
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 ,
59
70
e_agent_space::MOVE_TYPE,
60
71
placer_opts.place_agent_epsilon );
61
72
}
62
73
karmed_bandit_agent1->set_step (placer_opts.place_agent_gamma , move_lim);
63
74
move_generator = std::make_unique<SimpleRLMoveGenerator>(karmed_bandit_agent1);
64
75
// 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 ,
66
77
e_agent_space::MOVE_TYPE,
67
78
placer_opts.place_agent_epsilon );
68
79
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:
72
83
// agent's 1st state
73
84
if (placer_opts.place_agent_space == e_agent_space::MOVE_BLOCK_TYPE) {
74
85
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 ,
76
87
e_agent_space::MOVE_BLOCK_TYPE);
77
88
} else {
78
89
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 ,
80
91
e_agent_space::MOVE_TYPE);
81
92
}
82
93
karmed_bandit_agent1->set_step (placer_opts.place_agent_gamma , move_lim);
83
94
move_generator = std::make_unique<SimpleRLMoveGenerator>(karmed_bandit_agent1);
84
95
// 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 ,
86
97
e_agent_space::MOVE_TYPE);
87
98
karmed_bandit_agent2->set_step (placer_opts.place_agent_gamma , move_lim);
88
99
move_generator2 = std::make_unique<SimpleRLMoveGenerator>(karmed_bandit_agent2);
89
100
}
90
101
}
91
102
}
92
103
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) {
94
110
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 )
96
112
current_move_generator = std::move (move_generator2);
97
113
else
98
114
current_move_generator = std::move (move_generator);
99
115
} 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 )
101
117
current_move_generator = std::move (move_generator);
102
118
else
103
119
current_move_generator = std::move (move_generator2);
104
120
}
105
121
}
106
122
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) {
108
129
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 )
110
131
move_generator2 = std::move (current_move_generator);
111
132
else
112
133
move_generator = std::move (current_move_generator);
113
134
} 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 )
115
136
move_generator = std::move (current_move_generator);
116
137
else
117
138
move_generator2 = std::move (current_move_generator);
0 commit comments