Skip to content

Commit 3e50497

Browse files
update move generators with argument of vtr::RngContainer
1 parent bb575f6 commit 3e50497

23 files changed

+111
-81
lines changed

vpr/src/base/SetupVPR.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
#include <cstring>
21
#include <vector>
3-
#include <sstream>
42
#include <list>
53

64
#include "vtr_assert.h"
75
#include "vtr_util.h"
8-
#include "vtr_random.h"
96
#include "vtr_log.h"
10-
#include "vtr_memory.h"
117
#include "vtr_time.h"
128

139
#include "vpr_types.h"
@@ -21,7 +17,6 @@
2117
#include "pb_type_graph.h"
2218
#include "pack_types.h"
2319
#include "lb_type_rr_graph.h"
24-
#include "rr_graph_area.h"
2520
#include "echo_arch.h"
2621
#include "read_options.h"
2722
#include "echo_files.h"
@@ -117,7 +112,7 @@ void SetupVPR(const t_options* options,
117112

118113
auto& device_ctx = g_vpr_ctx.mutable_device();
119114

120-
if (options->CircuitName.value() == "") {
115+
if (options->CircuitName.value().empty()) {
121116
VPR_FATAL_ERROR(VPR_ERROR_BLIF_F,
122117
"No blif file found in arguments (did you specify an architecture file?)\n");
123118
}
@@ -156,7 +151,7 @@ void SetupVPR(const t_options* options,
156151
//save the device layout, which is required to parse the architecture file
157152
arch->device_layout = options->device_layout;
158153

159-
if (readArchFile == true) {
154+
if (readArchFile) {
160155
vtr::ScopedStartFinishTimer t("Loading Architecture Description");
161156
switch (options->arch_format) {
162157
case e_arch_format::VTR:
@@ -305,9 +300,6 @@ void SetupVPR(const t_options* options,
305300
/* init global variables */
306301
vtr::out_file_prefix = options->out_file_prefix;
307302

308-
/* Set seed for pseudo-random placement, default seed to 1 */
309-
vtr::srandom(placerOpts->seed);
310-
311303
{
312304
vtr::ScopedStartFinishTimer t("Building complex block graph");
313305
alloc_and_load_all_pb_graphs(powerOpts->do_power, routerOpts->flat_routing);
@@ -348,7 +340,7 @@ void SetupVPR(const t_options* options,
348340

349341
static void SetupTiming(const t_options& Options, const bool TimingEnabled, t_timing_inf* Timing) {
350342
/* Don't do anything if they don't want timing */
351-
if (false == TimingEnabled) {
343+
if (!TimingEnabled) {
352344
Timing->timing_analysis_enabled = false;
353345
return;
354346
}
@@ -570,7 +562,7 @@ static void SetupAnnealSched(const t_options& Options,
570562
}
571563

572564
/**
573-
* @brief Sets up the s_packer_opts structure baesd on users inputs and
565+
* @brief Sets up the s_packer_opts structure based on users inputs and
574566
* on the architecture specified.
575567
*
576568
* Error checking, such as checking for conflicting params is assumed

vpr/src/place/RL_agent_util.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
2222
move_name.c_str(),
2323
placer_opts.place_static_move_prob[move_type]);
2424
}
25-
move_generators.first = std::make_unique<StaticMoveGenerator>(placer_state, reward_fun, placer_opts.place_static_move_prob);
26-
move_generators.second = std::make_unique<StaticMoveGenerator>(placer_state, reward_fun, placer_opts.place_static_move_prob);
25+
move_generators.first = std::make_unique<StaticMoveGenerator>(placer_state, reward_fun, rng, placer_opts.place_static_move_prob);
26+
move_generators.second = std::make_unique<StaticMoveGenerator>(placer_state, reward_fun, rng, placer_opts.place_static_move_prob);
2727
} else { //RL based placement
2828
/* For the non timing driven placement: the agent has a single state *
2929
* - Available moves are (Uniform / Median / Centroid) *
@@ -79,6 +79,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
7979
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
8080
move_generators.first = std::make_unique<SimpleRLMoveGenerator>(placer_state,
8181
reward_fun,
82+
rng,
8283
karmed_bandit_agent1,
8384
noc_attraction_weight,
8485
placer_opts.place_high_fanout_net);
@@ -90,6 +91,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
9091
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
9192
move_generators.second = std::make_unique<SimpleRLMoveGenerator>(placer_state,
9293
reward_fun,
94+
rng,
9395
karmed_bandit_agent2,
9496
noc_attraction_weight,
9597
placer_opts.place_high_fanout_net);
@@ -110,6 +112,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
110112
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
111113
move_generators.first = std::make_unique<SimpleRLMoveGenerator>(placer_state,
112114
reward_fun,
115+
rng,
113116
karmed_bandit_agent1,
114117
noc_attraction_weight,
115118
placer_opts.place_high_fanout_net);
@@ -120,6 +123,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
120123
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
121124
move_generators.second = std::make_unique<SimpleRLMoveGenerator>(placer_state,
122125
reward_fun,
126+
rng,
123127
karmed_bandit_agent2,
124128
noc_attraction_weight,
125129
placer_opts.place_high_fanout_net);

vpr/src/place/centroid_move_generator.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ std::map<ClusterBlockId, NocGroupId> CentroidMoveGenerator::noc_router_to_noc_gr
1717

1818

1919
CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state,
20-
e_reward_function reward_function)
21-
: MoveGenerator(placer_state, reward_function)
20+
e_reward_function reward_function,
21+
vtr::RngContainer& rng)
22+
: MoveGenerator(placer_state, reward_function, rng)
2223
, noc_attraction_w_(0.0f)
2324
, noc_attraction_enabled_(false) {}
2425

2526
CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state,
2627
e_reward_function reward_function,
28+
vtr::RngContainer& rng,
2729
float noc_attraction_weight,
2830
size_t high_fanout_net)
29-
: MoveGenerator(placer_state, reward_function)
31+
: MoveGenerator(placer_state, reward_function, rng)
3032
, noc_attraction_w_(noc_attraction_weight)
3133
, noc_attraction_enabled_(true) {
3234
VTR_ASSERT(noc_attraction_weight > 0.0 && noc_attraction_weight <= 1.0);
@@ -59,7 +61,8 @@ e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block
5961
/*highly_crit_block=*/false,
6062
/*net_from=*/nullptr,
6163
/*pin_from=*/nullptr,
62-
placer_state);
64+
placer_state,
65+
rng_);
6366

6467
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug,
6568
"Centroid Move Choose Block %d - rlim %f\n",
@@ -92,7 +95,7 @@ e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block
9295
// layer for the centroid location. So if the layer is not valid, we set it to the same layer as from loc.
9396
centroid.layer = (centroid.layer < 0) ? from.layer : centroid.layer;
9497
/* Find a location near the weighted centroid_loc */
95-
if (!find_to_loc_centroid(cluster_from_type, from, centroid, range_limiters, to, b_from, blk_loc_registry)) {
98+
if (!find_to_loc_centroid(cluster_from_type, from, centroid, range_limiters, to, b_from, blk_loc_registry, rng_)) {
9699
return e_create_move::ABORT;
97100
}
98101

vpr/src/place/centroid_move_generator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class CentroidMoveGenerator : public MoveGenerator {
3030
* of the RL agent.
3131
*/
3232
CentroidMoveGenerator(PlacerState& placer_state,
33-
e_reward_function reward_function);
33+
e_reward_function reward_function,
34+
vtr::RngContainer& rng);
3435

3536
/**
3637
* The move generator created by calling this constructor considers both
@@ -49,6 +50,7 @@ class CentroidMoveGenerator : public MoveGenerator {
4950
*/
5051
CentroidMoveGenerator(PlacerState& placer_state,
5152
e_reward_function reward_function,
53+
vtr::RngContainer& rng,
5254
float noc_attraction_weight,
5355
size_t high_fanout_net);
5456

vpr/src/place/critical_uniform_move_generator.cpp

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

77
CriticalUniformMoveGenerator::CriticalUniformMoveGenerator(PlacerState& placer_state,
8-
e_reward_function reward_function)
9-
: MoveGenerator(placer_state, reward_function) {}
8+
e_reward_function reward_function,
9+
vtr::RngContainer& rng)
10+
: MoveGenerator(placer_state, reward_function, rng) {}
1011

1112
e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
1213
t_propose_action& proposed_action,
@@ -26,7 +27,8 @@ e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved
2627
/*highly_crit_block=*/true,
2728
&net_from,
2829
&pin_from,
29-
placer_state);
30+
placer_state,
31+
rng_);
3032

3133
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "Critical Uniform Move Choose Block %d - rlim %f\n", size_t(b_from), rlim);
3234

@@ -42,7 +44,7 @@ e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved
4244

4345
t_pl_loc to;
4446
to.layer = from.layer;
45-
if (!find_to_loc_uniform(cluster_from_type, rlim, from, to, b_from, blk_loc_registry)) {
47+
if (!find_to_loc_uniform(cluster_from_type, rlim, from, to, b_from, blk_loc_registry, rng_)) {
4648
return e_create_move::ABORT;
4749
}
4850

vpr/src/place/critical_uniform_move_generator.h

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

2324
private:
2425
e_create_move propose_move(t_pl_blocks_to_be_moved& blocks_affected,

vpr/src/place/feasible_region_move_generator.cpp

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

1111
FeasibleRegionMoveGenerator::FeasibleRegionMoveGenerator(PlacerState& placer_state,
12-
e_reward_function reward_function)
13-
: MoveGenerator(placer_state, reward_function) {}
12+
e_reward_function reward_function,
13+
vtr::RngContainer& rng)
14+
: MoveGenerator(placer_state, reward_function, rng) {}
1415

1516
e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
1617
t_propose_action& proposed_action,
@@ -31,7 +32,8 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved&
3132
/*highly_crit_block=*/true,
3233
&net_from,
3334
&pin_from,
34-
placer_state);
35+
placer_state,
36+
rng_);
3537

3638
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "Feasible Region Move Choose Block %di - rlim %f\n", size_t(b_from), rlim);
3739

@@ -126,7 +128,7 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved&
126128
placer_opts.place_dm_rlim};
127129

128130
// Try to find a legal location inside the feasible region
129-
if (!find_to_loc_median(cluster_from_type, from, &FR_coords, to, b_from, blk_loc_registry)) {
131+
if (!find_to_loc_median(cluster_from_type, from, &FR_coords, to, b_from, blk_loc_registry, rng_)) {
130132
/** If there is no legal location in the feasible region, calculate the center of the FR and try to find a legal location
131133
* in a range around this center.
132134
*/
@@ -135,7 +137,7 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved&
135137
center.y = (FR_coords.ymin + FR_coords.ymax) / 2;
136138
// TODO: Currently, we don't move blocks between different types of layers
137139
center.layer = from.layer;
138-
if (!find_to_loc_centroid(cluster_from_type, from, center, range_limiters, to, b_from, blk_loc_registry))
140+
if (!find_to_loc_centroid(cluster_from_type, from, center, range_limiters, to, b_from, blk_loc_registry, rng_))
139141
return e_create_move::ABORT;
140142
}
141143

vpr/src/place/feasible_region_move_generator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class FeasibleRegionMoveGenerator : public MoveGenerator {
2222
public:
2323
FeasibleRegionMoveGenerator() = delete;
2424
FeasibleRegionMoveGenerator(PlacerState& placer_state,
25-
e_reward_function reward_function);
25+
e_reward_function reward_function,
26+
vtr::RngContainer& rng);
2627

2728
private:
2829
e_create_move propose_move(t_pl_blocks_to_be_moved& blocks_affected,

vpr/src/place/initial_placement.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ static std::vector<ClusterBlockId> find_centroid_loc(const t_pl_macro& pl_macro,
171171
static bool find_centroid_neighbor(t_pl_loc& centroid_loc,
172172
t_logical_block_type_ptr block_type,
173173
bool search_for_empty,
174-
const BlkLocRegistry& blk_loc_registry);
174+
const BlkLocRegistry& blk_loc_registry,
175+
vtr::RngContainer& rng);
175176

176177
/**
177178
* @brief tries to place a macro at a centroid location of its placed connections.
@@ -335,7 +336,8 @@ static bool is_loc_legal(const t_pl_loc& loc,
335336
static bool find_centroid_neighbor(t_pl_loc& centroid_loc,
336337
t_logical_block_type_ptr block_type,
337338
bool search_for_empty,
338-
const BlkLocRegistry& blk_loc_registry) {
339+
const BlkLocRegistry& blk_loc_registry,
340+
vtr::RngContainer& rng) {
339341
const auto& compressed_block_grid = g_vpr_ctx.placement().compressed_block_grids[block_type->index];
340342
const int num_layers = g_vpr_ctx.device().grid.get_num_layers();
341343
const int centroid_loc_layer_num = centroid_loc.layer;
@@ -370,13 +372,14 @@ static bool find_centroid_neighbor(t_pl_loc& centroid_loc,
370372
/*is_median=*/false,
371373
centroid_loc_layer_num,
372374
search_for_empty,
373-
blk_loc_registry);
375+
blk_loc_registry,
376+
rng);
374377

375378
if (!legal) {
376379
return false;
377380
}
378381

379-
compressed_grid_to_loc(block_type, to_compressed_loc, centroid_loc);
382+
compressed_grid_to_loc(block_type, to_compressed_loc, centroid_loc, rng);
380383

381384
return legal;
382385
}
@@ -504,7 +507,7 @@ static bool try_centroid_placement(const t_pl_macro& pl_macro,
504507
//try to find a near location that meet these requirements
505508
bool neighbor_legal_loc = false;
506509
if (!is_loc_legal(centroid_loc, pr, block_type)) {
507-
neighbor_legal_loc = find_centroid_neighbor(centroid_loc, block_type, false, blk_loc_registry);
510+
neighbor_legal_loc = find_centroid_neighbor(centroid_loc, block_type, false, blk_loc_registry, rng);
508511
if (!neighbor_legal_loc) { //no neighbor candidate found
509512
return false;
510513
}
@@ -698,7 +701,8 @@ bool try_place_macro_randomly(const t_pl_macro& pl_macro,
698701
/*is_median=*/false,
699702
selected_layer,
700703
/*search_for_empty=*/false,
701-
blk_loc_registry);
704+
blk_loc_registry,
705+
rng);
702706

703707

704708
if (!legal) {
@@ -707,7 +711,7 @@ bool try_place_macro_randomly(const t_pl_macro& pl_macro,
707711
}
708712

709713
t_pl_loc loc;
710-
compressed_grid_to_loc(block_type, to_compressed_loc, loc);
714+
compressed_grid_to_loc(block_type, to_compressed_loc, loc, rng);
711715

712716
auto& device_ctx = g_vpr_ctx.device();
713717

vpr/src/place/manual_move_generator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
# include "draw.h"
1919
#endif //NO_GRAPHICS
2020

21-
ManualMoveGenerator::ManualMoveGenerator(PlacerState& placer_state)
22-
: MoveGenerator(placer_state, e_reward_function::UNDEFINED_REWARD) {}
21+
ManualMoveGenerator::ManualMoveGenerator(PlacerState& placer_state, vtr::RngContainer& rng)
22+
: MoveGenerator(placer_state, e_reward_function::UNDEFINED_REWARD, rng) {}
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-
ManualMoveGenerator(PlacerState& placer_state);
30+
ManualMoveGenerator(PlacerState& placer_state, vtr::RngContainer& rng);
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,

0 commit comments

Comments
 (0)