Skip to content

Commit 0fa2cfd

Browse files
enum class e_reward_function
1 parent b39cfe8 commit 0fa2cfd

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

vpr/src/place/directed_moves_util.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ void calculate_centroid_loc(ClusterBlockId b_from,
136136
}
137137

138138
static std::map<std::string, e_reward_function> available_reward_function = {
139-
{"basic", BASIC},
140-
{"nonPenalizing_basic", NON_PENALIZING_BASIC},
141-
{"runtime_aware", RUNTIME_AWARE},
142-
{"WLbiased_runtime_aware", WL_BIASED_RUNTIME_AWARE}};
139+
{"basic", e_reward_function::BASIC},
140+
{"nonPenalizing_basic", e_reward_function::NON_PENALIZING_BASIC},
141+
{"runtime_aware", e_reward_function::RUNTIME_AWARE},
142+
{"WLbiased_runtime_aware", e_reward_function::WL_BIASED_RUNTIME_AWARE}};
143143

144144
e_reward_function string_to_reward(const std::string& st) {
145145
return available_reward_function[st];

vpr/src/place/directed_moves_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* @brief enum represents the different reward functions
99
*/
10-
enum e_reward_function {
10+
enum class e_reward_function {
1111
BASIC, ///@ directly uses the change of the annealing cost function
1212
NON_PENALIZING_BASIC, ///@ same as basic reward function but with 0 reward if it's a hill-climbing one
1313
RUNTIME_AWARE, ///@ same as NON_PENALIZING_BASIC but with normalizing with the runtime factor of each move type

vpr/src/place/place.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,11 @@ static void generate_post_place_timing_reports(const t_placer_opts& placer_opts,
319319
bool is_flat);
320320

321321
//calculate the agent's reward and the total process outcome
322-
static void calculate_reward_and_process_outcome(
323-
const t_placer_opts& placer_opts,
324-
const MoveOutcomeStats& move_outcome_stats,
325-
const double& delta_c,
326-
float timing_bb_factor,
327-
MoveGenerator& move_generator);
322+
static void calculate_reward_and_process_outcome(const t_placer_opts& placer_opts,
323+
const MoveOutcomeStats& move_outcome_stats,
324+
double delta_c,
325+
float timing_bb_factor,
326+
MoveGenerator& move_generator);
328327

329328
static void print_place_status_header(bool noc_enabled);
330329

@@ -2023,7 +2022,7 @@ static int check_placement_costs(const t_placer_costs& costs,
20232022
double bb_cost_check;
20242023
double timing_cost_check;
20252024

2026-
const auto& cube_bb = g_vpr_ctx.placement().cube_bb;
2025+
const bool cube_bb = g_vpr_ctx.placement().cube_bb;
20272026

20282027
if (cube_bb) {
20292028
bb_cost_check = comp_bb_cost(CHECK);
@@ -2398,28 +2397,25 @@ static void print_placement_move_types_stats(const MoveTypeStat& move_type_stat)
23982397
VTR_LOG("\n");
23992398
}
24002399

2401-
static void calculate_reward_and_process_outcome(
2402-
const t_placer_opts& placer_opts,
2403-
const MoveOutcomeStats& move_outcome_stats,
2404-
const double& delta_c,
2405-
float timing_bb_factor,
2406-
MoveGenerator& move_generator) {
2407-
std::string reward_fun_string = placer_opts.place_reward_fun;
2400+
static void calculate_reward_and_process_outcome(const t_placer_opts& placer_opts,
2401+
const MoveOutcomeStats& move_outcome_stats,
2402+
double delta_c,
2403+
float timing_bb_factor,
2404+
MoveGenerator& move_generator) {
24082405
static std::optional<e_reward_function> reward_fun;
24092406
if (!reward_fun.has_value()) {
2410-
reward_fun = string_to_reward(reward_fun_string);
2407+
reward_fun = string_to_reward(placer_opts.place_reward_fun);
24112408
}
24122409

2413-
if (reward_fun == BASIC) {
2410+
if (reward_fun == e_reward_function::BASIC) {
24142411
move_generator.process_outcome(-1 * delta_c, reward_fun.value());
2415-
} else if (reward_fun == NON_PENALIZING_BASIC
2416-
|| reward_fun == RUNTIME_AWARE) {
2412+
} else if (reward_fun == e_reward_function::NON_PENALIZING_BASIC || reward_fun == e_reward_function::RUNTIME_AWARE) {
24172413
if (delta_c < 0) {
24182414
move_generator.process_outcome(-1 * delta_c, reward_fun.value());
24192415
} else {
24202416
move_generator.process_outcome(0, reward_fun.value());
24212417
}
2422-
} else if (reward_fun == WL_BIASED_RUNTIME_AWARE) {
2418+
} else if (reward_fun == e_reward_function::WL_BIASED_RUNTIME_AWARE) {
24232419
if (delta_c < 0) {
24242420
float reward = -1
24252421
* (move_outcome_stats.delta_cost_norm

vpr/src/place/simpleRL_move_generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ std::vector<int> KArmedBanditAgent::get_available_logical_blk_types_() {
112112

113113
void KArmedBanditAgent::process_outcome(double reward, e_reward_function reward_fun) {
114114
++num_action_chosen_[last_action_];
115-
if (reward_fun == RUNTIME_AWARE || reward_fun == WL_BIASED_RUNTIME_AWARE) {
115+
if (reward_fun == e_reward_function::RUNTIME_AWARE || reward_fun == e_reward_function::WL_BIASED_RUNTIME_AWARE) {
116116
e_move_type move_type = action_to_move_type_(last_action_);
117117
reward /= time_elapsed_[move_type];
118118
}

0 commit comments

Comments
 (0)