Skip to content

Commit 97d0813

Browse files
add reward_function_ to MoveGenerator
1 parent 0cb04be commit 97d0813

22 files changed

+79
-50
lines changed

vpr/src/place/RL_agent_util.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
66
const t_placer_opts& placer_opts,
77
int move_lim,
88
double noc_attraction_weight) {
9-
9+
e_reward_function reward_fun = string_to_reward(placer_opts.place_reward_fun);
1010
std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> move_generators;
1111

12+
1213
if (!placer_opts.RL_agent_placement) { // RL agent is disabled
1314
auto move_types = placer_opts.place_static_move_prob;
1415
move_types.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES, 0.0f);
@@ -20,8 +21,8 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
2021
move_name.c_str(),
2122
placer_opts.place_static_move_prob[move_type]);
2223
}
23-
move_generators.first = std::make_unique<StaticMoveGenerator>(placer_state, placer_opts.place_static_move_prob);
24-
move_generators.second = std::make_unique<StaticMoveGenerator>(placer_state, placer_opts.place_static_move_prob);
24+
move_generators.first = std::make_unique<StaticMoveGenerator>(placer_state, reward_fun, placer_opts.place_static_move_prob);
25+
move_generators.second = std::make_unique<StaticMoveGenerator>(placer_state, reward_fun, placer_opts.place_static_move_prob);
2526
} else { //RL based placement
2627
/* For the non timing driven placement: the agent has a single state *
2728
* - Available moves are (Uniform / Median / Centroid) *
@@ -74,6 +75,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
7475
}
7576
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
7677
move_generators.first = std::make_unique<SimpleRLMoveGenerator>(placer_state,
78+
reward_fun,
7779
karmed_bandit_agent1,
7880
noc_attraction_weight,
7981
placer_opts.place_high_fanout_net);
@@ -83,6 +85,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
8385
placer_opts.place_agent_epsilon);
8486
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
8587
move_generators.second = std::make_unique<SimpleRLMoveGenerator>(placer_state,
88+
reward_fun,
8689
karmed_bandit_agent2,
8790
noc_attraction_weight,
8891
placer_opts.place_high_fanout_net);
@@ -100,6 +103,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
100103
}
101104
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
102105
move_generators.first = std::make_unique<SimpleRLMoveGenerator>(placer_state,
106+
reward_fun,
103107
karmed_bandit_agent1,
104108
noc_attraction_weight,
105109
placer_opts.place_high_fanout_net);
@@ -108,6 +112,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
108112
e_agent_space::MOVE_TYPE);
109113
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
110114
move_generators.second = std::make_unique<SimpleRLMoveGenerator>(placer_state,
115+
reward_fun,
111116
karmed_bandit_agent2,
112117
noc_attraction_weight,
113118
placer_opts.place_high_fanout_net);

vpr/src/place/centroid_move_generator.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ vtr::vector<ClusterBlockId, NocGroupId> CentroidMoveGenerator::cluster_to_noc_gr
1616
std::map<ClusterBlockId, NocGroupId> CentroidMoveGenerator::noc_router_to_noc_group_;
1717

1818

19-
CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state)
20-
: MoveGenerator(placer_state)
19+
CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state,
20+
e_reward_function reward_function)
21+
: MoveGenerator(placer_state, reward_function)
2122
, noc_attraction_w_(0.0f)
2223
, noc_attraction_enabled_(false) {}
2324

2425
CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state,
26+
e_reward_function reward_function,
2527
float noc_attraction_weight,
2628
size_t high_fanout_net)
27-
: MoveGenerator(placer_state)
29+
: MoveGenerator(placer_state, reward_function)
2830
, noc_attraction_w_(noc_attraction_weight)
2931
, noc_attraction_enabled_(true) {
3032
VTR_ASSERT(noc_attraction_weight > 0.0 && noc_attraction_weight <= 1.0);

vpr/src/place/centroid_move_generator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class CentroidMoveGenerator : public MoveGenerator {
2727
* @param placer_state A mutable reference to the placement state which will
2828
* be stored in this object.
2929
*/
30-
explicit CentroidMoveGenerator(PlacerState& placer_state);
30+
CentroidMoveGenerator(PlacerState& placer_state,
31+
e_reward_function reward_function);
3132

3233
/**
3334
* The move generator created by calling this constructor considers both
@@ -45,6 +46,7 @@ class CentroidMoveGenerator : public MoveGenerator {
4546
* ignored when forming NoC groups.
4647
*/
4748
CentroidMoveGenerator(PlacerState& placer_state,
49+
e_reward_function reward_function,
4850
float noc_attraction_weight,
4951
size_t high_fanout_net);
5052

vpr/src/place/critical_uniform_move_generator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
#include "placer_state.h"
55
#include "move_utils.h"
66

7-
CriticalUniformMoveGenerator::CriticalUniformMoveGenerator(PlacerState& placer_state)
8-
: MoveGenerator(placer_state) {}
7+
CriticalUniformMoveGenerator::CriticalUniformMoveGenerator(PlacerState& placer_state,
8+
e_reward_function reward_function)
9+
: MoveGenerator(placer_state, reward_function) {}
910

1011
e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
1112
t_propose_action& proposed_action,

vpr/src/place/critical_uniform_move_generator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
class CriticalUniformMoveGenerator : public MoveGenerator {
1818
public:
1919
CriticalUniformMoveGenerator() = delete;
20-
explicit CriticalUniformMoveGenerator(PlacerState& placer_state);
20+
CriticalUniformMoveGenerator(PlacerState& placer_state,
21+
e_reward_function reward_function);
2122

2223
private:
2324
e_create_move propose_move(t_pl_blocks_to_be_moved& blocks_affected,

vpr/src/place/directed_moves_util.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
* @brief enum represents the different reward functions
99
*/
1010
enum class e_reward_function {
11-
BASIC, ///@ directly uses the change of the annealing cost function
12-
NON_PENALIZING_BASIC, ///@ same as basic reward function but with 0 reward if it's a hill-climbing one
13-
RUNTIME_AWARE, ///@ same as NON_PENALIZING_BASIC but with normalizing with the runtime factor of each move type
14-
WL_BIASED_RUNTIME_AWARE ///@ same as RUNTIME_AWARE but more biased to WL cost (the factor of the bias is REWARD_BB_TIMING_RELATIVE_WEIGHT)
11+
BASIC, ///@ directly uses the change of the annealing cost function
12+
NON_PENALIZING_BASIC, ///@ same as basic reward function but with 0 reward if it's a hill-climbing one
13+
RUNTIME_AWARE, ///@ same as NON_PENALIZING_BASIC but with normalizing with the runtime factor of each move type
14+
WL_BIASED_RUNTIME_AWARE, ///@ same as RUNTIME_AWARE but more biased to WL cost (the factor of the bias is REWARD_BB_TIMING_RELATIVE_WEIGHT)
15+
UNDEFINED_REWARD ///@ Used for manual moves
1516
};
1617

1718
e_reward_function string_to_reward(const std::string& st);

vpr/src/place/feasible_region_move_generator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#include <algorithm>
99
#include <cmath>
1010

11-
FeasibleRegionMoveGenerator::FeasibleRegionMoveGenerator(PlacerState& placer_state)
12-
: MoveGenerator(placer_state) {}
11+
FeasibleRegionMoveGenerator::FeasibleRegionMoveGenerator(PlacerState& placer_state,
12+
e_reward_function reward_function)
13+
: MoveGenerator(placer_state, reward_function) {}
1314

1415
e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
1516
t_propose_action& proposed_action,

vpr/src/place/feasible_region_move_generator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
class FeasibleRegionMoveGenerator : public MoveGenerator {
2222
public:
2323
FeasibleRegionMoveGenerator() = delete;
24-
explicit FeasibleRegionMoveGenerator(PlacerState& placer_state);
24+
FeasibleRegionMoveGenerator(PlacerState& placer_state,
25+
e_reward_function reward_function);
2526

2627
private:
2728
e_create_move propose_move(t_pl_blocks_to_be_moved& blocks_affected,

vpr/src/place/manual_move_generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#endif //NO_GRAPHICS
2020

2121
ManualMoveGenerator::ManualMoveGenerator(PlacerState& placer_state)
22-
: MoveGenerator(placer_state) {}
22+
: MoveGenerator(placer_state, e_reward_function::UNDEFINED_REWARD) {}
2323

2424
//Manual Move Generator function
2525
e_create_move ManualMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,

vpr/src/place/manual_move_generator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class ManualMoveGenerator : public MoveGenerator {
2828
public:
2929
ManualMoveGenerator() = delete;
30-
explicit ManualMoveGenerator(PlacerState& placer_state);
30+
ManualMoveGenerator(PlacerState& placer_state);
3131

3232
//Evaluates if move is successful and legal or unable to do.
3333
e_create_move propose_move(t_pl_blocks_to_be_moved& blocks_affected,

vpr/src/place/median_move_generator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
#include <algorithm>
99

10-
MedianMoveGenerator::MedianMoveGenerator(PlacerState& placer_state)
11-
: MoveGenerator(placer_state) {}
10+
MedianMoveGenerator::MedianMoveGenerator(PlacerState& placer_state,
11+
e_reward_function reward_function)
12+
: MoveGenerator(placer_state, reward_function) {}
1213

1314
e_create_move MedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
1415
t_propose_action& proposed_action,

vpr/src/place/median_move_generator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
class MedianMoveGenerator : public MoveGenerator {
1919
public:
2020
MedianMoveGenerator() = delete;
21-
explicit MedianMoveGenerator(PlacerState& placer_state);
21+
MedianMoveGenerator(PlacerState& placer_state,
22+
e_reward_function reward_function);
2223

2324
private:
2425
e_create_move propose_move(t_pl_blocks_to_be_moved& blocks_affected,

vpr/src/place/move_generator.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ struct MoveTypeStat {
4444
*/
4545
class MoveGenerator {
4646
public:
47-
MoveGenerator(PlacerState& placer_state)
48-
: placer_state_(placer_state) {}
47+
MoveGenerator(PlacerState& placer_state, e_reward_function reward_function)
48+
: placer_state_(placer_state)
49+
, reward_func_(reward_function) {}
4950

5051
MoveGenerator() = delete;
5152
virtual ~MoveGenerator() = default;
@@ -83,6 +84,7 @@ class MoveGenerator {
8384

8485
protected:
8586
std::reference_wrapper<PlacerState> placer_state_;
87+
e_reward_function reward_func_;
8688
};
8789

8890
#endif

vpr/src/place/simpleRL_move_generator.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class SimpleRLMoveGenerator : public MoveGenerator {
217217
template<class T,
218218
class = typename std::enable_if<std::is_same<T, EpsilonGreedyAgent>::value || std::is_same<T, SoftmaxAgent>::value>::type>
219219
explicit SimpleRLMoveGenerator(PlacerState& placer_state,
220+
e_reward_function reward_function,
220221
std::unique_ptr<T>& agent,
221222
float noc_attraction_weight,
222223
size_t high_fanout_thresh);
@@ -234,25 +235,27 @@ class SimpleRLMoveGenerator : public MoveGenerator {
234235

235236
template<class T, class>
236237
SimpleRLMoveGenerator::SimpleRLMoveGenerator(PlacerState& placer_state,
238+
e_reward_function reward_function,
237239
std::unique_ptr<T>& agent,
238240
float noc_attraction_weight,
239241
size_t high_fanout_thresh)
240-
: MoveGenerator(placer_state) {
242+
: MoveGenerator(placer_state, reward_function) {
241243
if (noc_attraction_weight > 0.0f) {
242244
all_moves.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES);
243245
} else {
244246
all_moves.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES - 1);
245247
}
246248

247-
all_moves[e_move_type::UNIFORM] = std::make_unique<UniformMoveGenerator>(placer_state);
248-
all_moves[e_move_type::MEDIAN] = std::make_unique<MedianMoveGenerator>(placer_state);
249-
all_moves[e_move_type::CENTROID] = std::make_unique<CentroidMoveGenerator>(placer_state);
250-
all_moves[e_move_type::W_CENTROID] = std::make_unique<WeightedCentroidMoveGenerator>(placer_state);
251-
all_moves[e_move_type::W_MEDIAN] = std::make_unique<WeightedMedianMoveGenerator>(placer_state);
252-
all_moves[e_move_type::CRIT_UNIFORM] = std::make_unique<CriticalUniformMoveGenerator>(placer_state);
253-
all_moves[e_move_type::FEASIBLE_REGION] = std::make_unique<FeasibleRegionMoveGenerator>(placer_state);
249+
all_moves[e_move_type::UNIFORM] = std::make_unique<UniformMoveGenerator>(placer_state, reward_function);
250+
all_moves[e_move_type::MEDIAN] = std::make_unique<MedianMoveGenerator>(placer_state, reward_function);
251+
all_moves[e_move_type::CENTROID] = std::make_unique<CentroidMoveGenerator>(placer_state, reward_function);
252+
all_moves[e_move_type::W_CENTROID] = std::make_unique<WeightedCentroidMoveGenerator>(placer_state, reward_function);
253+
all_moves[e_move_type::W_MEDIAN] = std::make_unique<WeightedMedianMoveGenerator>(placer_state, reward_function);
254+
all_moves[e_move_type::CRIT_UNIFORM] = std::make_unique<CriticalUniformMoveGenerator>(placer_state, reward_function);
255+
all_moves[e_move_type::FEASIBLE_REGION] = std::make_unique<FeasibleRegionMoveGenerator>(placer_state, reward_function);
254256
if (noc_attraction_weight > 0.0f) {
255-
all_moves[e_move_type::NOC_ATTRACTION_CENTROID] = std::make_unique<CentroidMoveGenerator>(placer_state, noc_attraction_weight, high_fanout_thresh);
257+
all_moves[e_move_type::NOC_ATTRACTION_CENTROID] = std::make_unique<CentroidMoveGenerator>(placer_state, reward_function,
258+
noc_attraction_weight, high_fanout_thresh);
256259
}
257260

258261
karmed_bandit_agent = std::move(agent);

vpr/src/place/static_move_generator.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313
#include "vtr_assert.h"
1414

1515
StaticMoveGenerator::StaticMoveGenerator(PlacerState& placer_state,
16+
e_reward_function reward_function,
1617
const vtr::vector<e_move_type, float>& move_probs)
17-
: MoveGenerator(placer_state) {
18+
: MoveGenerator(placer_state, reward_function) {
1819
all_moves.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES);
1920

20-
all_moves[e_move_type::UNIFORM] = std::make_unique<UniformMoveGenerator>(placer_state);
21-
all_moves[e_move_type::MEDIAN] = std::make_unique<MedianMoveGenerator>(placer_state);
22-
all_moves[e_move_type::CENTROID] = std::make_unique<CentroidMoveGenerator>(placer_state);
23-
all_moves[e_move_type::W_CENTROID] = std::make_unique<WeightedCentroidMoveGenerator>(placer_state);
24-
all_moves[e_move_type::W_MEDIAN] = std::make_unique<WeightedMedianMoveGenerator>(placer_state);
25-
all_moves[e_move_type::CRIT_UNIFORM] = std::make_unique<CriticalUniformMoveGenerator>(placer_state);
26-
all_moves[e_move_type::FEASIBLE_REGION] = std::make_unique<FeasibleRegionMoveGenerator>(placer_state);
21+
all_moves[e_move_type::UNIFORM] = std::make_unique<UniformMoveGenerator>(placer_state, reward_function);
22+
all_moves[e_move_type::MEDIAN] = std::make_unique<MedianMoveGenerator>(placer_state, reward_function);
23+
all_moves[e_move_type::CENTROID] = std::make_unique<CentroidMoveGenerator>(placer_state, reward_function);
24+
all_moves[e_move_type::W_CENTROID] = std::make_unique<WeightedCentroidMoveGenerator>(placer_state, reward_function);
25+
all_moves[e_move_type::W_MEDIAN] = std::make_unique<WeightedMedianMoveGenerator>(placer_state, reward_function);
26+
all_moves[e_move_type::CRIT_UNIFORM] = std::make_unique<CriticalUniformMoveGenerator>(placer_state, reward_function);
27+
all_moves[e_move_type::FEASIBLE_REGION] = std::make_unique<FeasibleRegionMoveGenerator>(placer_state, reward_function);
2728

2829
initialize_move_prob(move_probs);
2930
}

vpr/src/place/static_move_generator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class StaticMoveGenerator : public MoveGenerator {
1919
public:
2020
StaticMoveGenerator() = delete;
2121
StaticMoveGenerator(PlacerState& placer_state,
22+
e_reward_function reward_function,
2223
const vtr::vector<e_move_type, float>& move_probs);
2324

2425
e_create_move propose_move(t_pl_blocks_to_be_moved& blocks_affected,

vpr/src/place/uniform_move_generator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#include "placer_state.h"
66
#include "move_utils.h"
77

8-
UniformMoveGenerator::UniformMoveGenerator(PlacerState& placer_state)
9-
: MoveGenerator(placer_state) {}
8+
UniformMoveGenerator::UniformMoveGenerator(PlacerState& placer_state,
9+
e_reward_function reward_function)
10+
: MoveGenerator(placer_state, reward_function) {}
1011

1112
e_create_move UniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
1213
t_propose_action& proposed_action,

vpr/src/place/uniform_move_generator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
class UniformMoveGenerator : public MoveGenerator {
1212
public:
1313
UniformMoveGenerator() = delete;
14-
explicit UniformMoveGenerator(PlacerState& placer_state);
14+
UniformMoveGenerator(PlacerState& placer_state,
15+
e_reward_function reward_function);
1516

1617
private:
1718
e_create_move propose_move(t_pl_blocks_to_be_moved& blocks_affected,

vpr/src/place/weighted_centroid_move_generator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "placer_state.h"
77
#include "move_utils.h"
88

9-
WeightedCentroidMoveGenerator::WeightedCentroidMoveGenerator(PlacerState& placer_state)
10-
: MoveGenerator(placer_state) {}
9+
WeightedCentroidMoveGenerator::WeightedCentroidMoveGenerator(PlacerState& placer_state,
10+
e_reward_function reward_function)
11+
: MoveGenerator(placer_state, reward_function) {}
1112

1213
e_create_move WeightedCentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
1314
t_propose_action& proposed_action,

vpr/src/place/weighted_centroid_move_generator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
class WeightedCentroidMoveGenerator : public MoveGenerator {
1616
public:
1717
WeightedCentroidMoveGenerator() = delete;
18-
explicit WeightedCentroidMoveGenerator(PlacerState& placer_state);
18+
WeightedCentroidMoveGenerator(PlacerState& placer_state,
19+
e_reward_function reward_function);
1920

2021
private:
2122
e_create_move propose_move(t_pl_blocks_to_be_moved& blocks_affected,

0 commit comments

Comments
 (0)