Skip to content

Commit 08bad8f

Browse files
Merge branch 'specify_moves_explicitly' into noc_pack_part
2 parents 0026905 + 2778e2e commit 08bad8f

12 files changed

+66
-71
lines changed

libs/libarchfpga/src/device_grid.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#include "device_grid.h"
22

3+
#include <utility>
4+
35
DeviceGrid::DeviceGrid(std::string grid_name, vtr::NdMatrix<t_grid_tile, 3> grid)
4-
: name_(grid_name)
5-
, grid_(grid) {
6+
: name_(std::move(grid_name))
7+
, grid_(std::move(grid)) {
68
count_instances();
79
}
810

911
DeviceGrid::DeviceGrid(std::string grid_name, vtr::NdMatrix<t_grid_tile, 3> grid, std::vector<t_logical_block_type_ptr> limiting_res)
10-
: DeviceGrid(grid_name, grid) {
11-
limiting_resources_ = limiting_res;
12+
: DeviceGrid(std::move(grid_name), std::move(grid)) {
13+
limiting_resources_ = std::move(limiting_res);
1214
}
1315

1416
size_t DeviceGrid::num_instances(t_physical_tile_type_ptr type, int layer_num) const {

libs/libvtrutil/src/vtr_ndmatrix.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class NdMatrixBase {
288288
data_ = std::make_unique<T[]>(size());
289289
}
290290

291-
///@brief Returns the size of the matrix (number of elements) calucated from the current dimensions
291+
///@brief Returns the size of the matrix (number of elements) calculated from the current dimensions
292292
size_t calc_size() const {
293293
///@brief Size is the product of all dimension sizes
294294
size_t cnt = dim_size(0);
@@ -310,7 +310,7 @@ class NdMatrixBase {
310310
*
311311
* Examples:
312312
*
313-
* //A 2-dimensional matrix with indicies [0..4][0..9]
313+
* //A 2-dimensional matrix with indices [0..4][0..9]
314314
* NdMatrix<int,2> m1({5,10});
315315
*
316316
* //Accessing an element
@@ -319,17 +319,17 @@ class NdMatrixBase {
319319
* //Setting an element
320320
* m1[2][8] = 0;
321321
*
322-
* //A 3-dimensional matrix with indicies [0..4][0..9][0..19]
322+
* //A 3-dimensional matrix with indices [0..4][0..9][0..19]
323323
* NdMatrix<int,3> m2({5,10,20});
324324
*
325-
* //A 2-dimensional matrix with indicies [0..4][0..9], with all entries
325+
* //A 2-dimensional matrix with indices [0..4][0..9], with all entries
326326
* //initialized to 42
327327
* NdMatrix<int,2> m3({5,10}, 42);
328328
*
329329
* //Filling all entries with value 101
330330
* m3.fill(101);
331331
*
332-
* //Resizing an existing matrix (all values reset to default constucted value)
332+
* //Resizing an existing matrix (all values reset to default constructed value)
333333
* m3.resize({5,5})
334334
*
335335
* //Resizing an existing matrix (all elements set to value 88)

vpr/src/base/CheckSetup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void CheckSetup(const t_packer_opts& PackerOpts,
3838
"Timing analysis must be enabled for timing-driven placement.\n");
3939
}
4040

41-
if (!PlacerOpts.doPlacement && ("" != PlacerOpts.constraints_file)) {
41+
if (!PlacerOpts.doPlacement && (!PlacerOpts.constraints_file.empty())) {
4242
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
4343
"A block location file requires that placement is enabled.\n");
4444
}

vpr/src/base/SetupGrid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static std::vector<t_logical_block_type_ptr> grid_overused_resources(const Devic
318318
}
319319

320320
static bool grid_satisfies_instance_counts(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts, float maximum_utilization) {
321-
//Are the resources satisified?
321+
//Are the resources satisfied?
322322
auto overused_resources = grid_overused_resources(grid, instance_counts);
323323

324324
if (!overused_resources.empty()) {

vpr/src/base/read_options.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,8 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
20342034
.help(
20352035
"The percentage probabilities of different moves in Simulated Annealing placement."
20362036
"This option is only effective for timing-driven placement."
2037-
"The numbers listed are interpreted as the percentage probabilities of {uniformMove, MedianMove, CentroidMove, WeightedCentroid, WeightedMedian, Critical UniformMove, Timing feasible Region(TFR)}, in that order.")
2037+
"The numbers listed are interpreted as the percentage probabilities of {uniformMove, MedianMove, CentroidMove, "
2038+
"WeightedCentroid, WeightedMedian, Critical UniformMove, Timing feasible Region(TFR)}, in that order.")
20382039
.nargs('+')
20392040
.default_value({"100", "0", "0", "0", "0", "0", "0"})
20402041

vpr/src/base/vpr_types.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,9 @@ enum class ScreenUpdatePriority {
8989
/* Values large enough to be way out of range for any data, but small enough
9090
* to allow a small number to be added to them without going out of range. */
9191
#define HUGE_POSITIVE_FLOAT 1.e30
92-
#define HUGE_NEGATIVE_FLOAT -1.e30
9392

9493
/* Used to avoid floating-point errors when comparing values close to 0 */
9594
#define EPSILON 1.e-15
96-
#define NEGATIVE_EPSILON -1.e-15
9795

9896
#define FIRST_ITER_WIRELENTH_LIMIT 0.85 /* If used wirelength exceeds this value in first iteration of routing, do not route */
9997

@@ -110,8 +108,6 @@ constexpr auto INVALID_BLOCK_ID = ClusterBlockId(-2);
110108
* and maps it to the complex logic blocks found in the architecture
111109
******************************************************************************/
112110

113-
#define NO_CLUSTER -1
114-
#define NEVER_CLUSTER -2
115111
#define NOT_VALID (-10000) /* Marks gains that aren't valid */
116112
/* Ensure no gain can ever be this negative! */
117113
#ifndef UNDEFINED
@@ -553,7 +549,6 @@ enum class e_timing_update_type {
553549
/* Values of number of placement available move types */
554550
constexpr int NUM_PL_MOVE_TYPES = 7;
555551
constexpr int NUM_PL_NONTIMING_MOVE_TYPES = 3;
556-
constexpr int NUM_PL_1ST_STATE_MOVE_TYPES = 4;
557552

558553
/* Timing data structures end */
559554
enum sched_type {

vpr/src/place/RL_agent_util.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ void assign_current_move_generator(std::unique_ptr<MoveGenerator>& move_generato
119119
std::unique_ptr<MoveGenerator>& move_generator2,
120120
e_agent_state agent_state,
121121
const t_placer_opts& placer_opts,
122-
bool in_quench, std::unique_ptr<MoveGenerator>& current_move_generator) {
122+
bool in_quench,
123+
std::unique_ptr<MoveGenerator>& current_move_generator) {
123124
if (in_quench) {
124125
if (placer_opts.place_quench_algorithm.is_timing_driven() && placer_opts.place_agent_multistate)
125126
current_move_generator = std::move(move_generator2);

vpr/src/place/move_generator.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ struct MoveOutcomeStats {
2323
/**
2424
* @brief A Struct to hold statistics about the different move types
2525
*
26-
* blk_type_moves: the block type index of each proposed move (e.g. [0..NUM_PL_MOVE_TYPES * (agent_available_types.size()-1)])
27-
* accepted_moves: the number of accepted moves of each move and block type (e.g. [0..NUM_PL_MOVE_TYPES * (agent_available_types.size()-1)] )
28-
* rejected_moves: the number of rejected moves of each move and block type (e.g. [0..NUM_PL_MOVE_TYPES * (agent_available_types.size()-1)] )
26+
* blk_type_moves: the block type index of each proposed move (e.g. [0..NUM_PL_MOVE_TYPES][agent_available_types.size()-1)])
27+
* accepted_moves: the number of accepted moves of each move and block type (e.g. [0..NUM_PL_MOVE_TYPES][agent_available_types.size()-1)] )
28+
* rejected_moves: the number of rejected moves of each move and block type (e.g. [0..NUM_PL_MOVE_TYPES][agent_available_types.size()-1)] )
2929
*
3030
*/
3131
struct MoveTypeStat {
32-
std::vector<int> blk_type_moves;
33-
std::vector<int> accepted_moves;
34-
std::vector<int> rejected_moves;
32+
vtr::NdMatrix<int, 2> blk_type_moves;
33+
vtr::NdMatrix<int, 2> accepted_moves;
34+
vtr::NdMatrix<int, 2> rejected_moves;
3535
};
3636

3737
/**

vpr/src/place/move_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ void compressed_grid_to_loc(t_logical_block_type_ptr blk_type,
10291029
auto& grid = g_vpr_ctx.device().grid;
10301030
auto to_type = grid.get_physical_type({grid_loc.x, grid_loc.y, grid_loc.layer_num});
10311031

1032-
//Each x/y location contains only a single type, so we can pick a random z (capcity) location
1032+
//Each x/y location contains only a single type, so we can pick a random z (capacity) location
10331033
auto& compatible_sub_tiles = compressed_block_grid.compatible_sub_tile_num(to_type->index);
10341034
int sub_tile = compatible_sub_tiles[vtr::irand((int)compatible_sub_tiles.size() - 1)];
10351035

vpr/src/place/place.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,7 @@ static void print_resources_utilization();
543543

544544
static void print_placement_swaps_stats(const t_annealing_state& state);
545545

546-
static void print_placement_move_types_stats(
547-
const MoveTypeStat& move_type_stat);
546+
static void print_placement_move_types_stats(const MoveTypeStat& move_type_stat);
548547

549548
/*****************************************************************************/
550549
void try_place(const Netlist<>& net_list,
@@ -936,9 +935,9 @@ void try_place(const Netlist<>& net_list,
936935

937936
//allocate move type statistics vectors
938937
MoveTypeStat move_type_stat;
939-
move_type_stat.blk_type_moves.resize(device_ctx.logical_block_types.size() * (int)e_move_type::NUMBER_OF_AUTO_MOVES, 0);
940-
move_type_stat.accepted_moves.resize(device_ctx.logical_block_types.size() * (int)e_move_type::NUMBER_OF_AUTO_MOVES, 0);
941-
move_type_stat.rejected_moves.resize(device_ctx.logical_block_types.size() * (int)e_move_type::NUMBER_OF_AUTO_MOVES, 0);
938+
move_type_stat.blk_type_moves.resize({device_ctx.logical_block_types.size(), (int)e_move_type::NUMBER_OF_AUTO_MOVES}, 0);
939+
move_type_stat.accepted_moves.resize({device_ctx.logical_block_types.size(), (int)e_move_type::NUMBER_OF_AUTO_MOVES}, 0);
940+
move_type_stat.rejected_moves.resize({device_ctx.logical_block_types.size(), (int)e_move_type::NUMBER_OF_AUTO_MOVES}, 0);
942941

943942
/* Get the first range limiter */
944943
first_rlim = (float)max(device_ctx.grid.width() - 1,
@@ -1725,7 +1724,7 @@ static e_move_result try_swap(const t_annealing_state* state,
17251724
}
17261725

17271726
if (proposed_action.logical_blk_type_index != -1) { //if the agent proposed the block type, then collect the block type stat
1728-
++move_type_stat.blk_type_moves[(proposed_action.logical_blk_type_index * (int)e_move_type::NUMBER_OF_AUTO_MOVES) + (int)proposed_action.move_type];
1727+
++move_type_stat.blk_type_moves[proposed_action.logical_blk_type_index][(int)proposed_action.move_type];
17291728
}
17301729
LOG_MOVE_STATS_PROPOSED(t, blocks_affected);
17311730

@@ -1876,7 +1875,7 @@ static e_move_result try_swap(const t_annealing_state* state,
18761875
commit_move_blocks(blocks_affected);
18771876

18781877
if (proposed_action.logical_blk_type_index != -1) { //if the agent proposed the block type, then collect the block type stat
1879-
++move_type_stat.accepted_moves[(proposed_action.logical_blk_type_index * (int)e_move_type::NUMBER_OF_AUTO_MOVES) + (int)proposed_action.move_type];
1878+
++move_type_stat.accepted_moves[proposed_action.logical_blk_type_index][(int)proposed_action.move_type];
18801879
}
18811880
if (noc_opts.noc) {
18821881
commit_noc_costs();
@@ -1927,7 +1926,7 @@ static e_move_result try_swap(const t_annealing_state* state,
19271926
}
19281927

19291928
if (proposed_action.logical_blk_type_index != -1) { //if the agent proposed the block type, then collect the block type stat
1930-
++move_type_stat.rejected_moves[(proposed_action.logical_blk_type_index * (int)e_move_type::NUMBER_OF_AUTO_MOVES) + (int)proposed_action.move_type];
1929+
++move_type_stat.rejected_moves[proposed_action.logical_blk_type_index][(int)proposed_action.move_type];
19311930
}
19321931
/* Revert the traffic flow routes within the NoC*/
19331932
if (noc_opts.noc) {
@@ -4352,10 +4351,7 @@ static void print_placement_swaps_stats(const t_annealing_state& state) {
43524351
num_swap_aborted, 100 * abort_rate);
43534352
}
43544353

4355-
static void print_placement_move_types_stats(
4356-
const MoveTypeStat& move_type_stat) {
4357-
float moves, accepted, rejected, aborted;
4358-
4354+
static void print_placement_move_types_stats(const MoveTypeStat& move_type_stat) {
43594355
VTR_LOG("\n\nPlacement perturbation distribution by block and move type: \n");
43604356

43614357
VTR_LOG(
@@ -4365,11 +4361,12 @@ static void print_placement_move_types_stats(
43654361
VTR_LOG(
43664362
"------------------ ----------------- ---------------- ---------------- --------------- ------------ \n");
43674363

4368-
float total_moves = 0;
4369-
for (int blk_type_move : move_type_stat.blk_type_moves) {
4370-
total_moves += blk_type_move;
4364+
int total_moves = 0;
4365+
for (size_t i = 0; i < move_type_stat.blk_type_moves.size(); ++i) {
4366+
total_moves += move_type_stat.blk_type_moves.get(i);
43714367
}
43724368

4369+
43734370
auto& device_ctx = g_vpr_ctx.device();
43744371
auto& cluster_ctx = g_vpr_ctx.clustering();
43754372
int count = 0;
@@ -4383,24 +4380,23 @@ static void print_placement_move_types_stats(
43834380
}
43844381

43854382
count = 0;
4386-
43874383
for (int imove = 0; imove < num_of_avail_moves; imove++) {
43884384
const auto& move_name = move_type_to_string(e_move_type(imove));
4389-
moves = move_type_stat.blk_type_moves[itype.index * num_of_avail_moves + imove];
4385+
int moves = move_type_stat.blk_type_moves[itype.index][imove];
43904386
if (moves != 0) {
4391-
accepted = move_type_stat.accepted_moves[itype.index * num_of_avail_moves + imove];
4392-
rejected = move_type_stat.rejected_moves[itype.index * num_of_avail_moves + imove];
4393-
aborted = moves - (accepted + rejected);
4387+
int accepted = move_type_stat.accepted_moves[itype.index][imove];
4388+
int rejected = move_type_stat.rejected_moves[itype.index][imove];
4389+
int aborted = moves - (accepted + rejected);
43944390
if (count == 0) {
43954391
VTR_LOG("%-18.20s", itype.name);
43964392
} else {
43974393
VTR_LOG(" ");
43984394
}
43994395
VTR_LOG(
44004396
" %-22.20s %-16.2f %-15.2f %-14.2f %-13.2f\n",
4401-
move_name.c_str(), 100 * moves / total_moves,
4402-
100 * accepted / moves, 100 * rejected / moves,
4403-
100 * aborted / moves);
4397+
move_name.c_str(), 100.0f * (float)moves / (float)total_moves,
4398+
100.0f * (float)accepted / (float)moves, 100.0f * (float)rejected / (float)moves,
4399+
100.0f * (float)aborted / (float)moves);
44044400
}
44054401
count++;
44064402
}

vpr/src/place/simpleRL_move_generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ e_create_move SimpleRLMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block
2121
const t_placer_opts& placer_opts,
2222
const PlacerCriticalities* criticalities) {
2323
proposed_action = karmed_bandit_agent->propose_action();
24-
return avail_moves[proposed_action.move_type]->propose_move(blocks_affected, proposed_action, rlim, placer_opts, criticalities);
24+
return all_moves[proposed_action.move_type]->propose_move(blocks_affected, proposed_action, rlim, placer_opts, criticalities);
2525
}
2626

2727
void SimpleRLMoveGenerator::process_outcome(double reward, e_reward_function reward_fun) {

vpr/src/place/simpleRL_move_generator.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,18 @@ class KArmedBanditAgent {
8484
inline int agent_to_phy_blk_type(int idx);
8585

8686
protected:
87-
float exp_alpha_ = -1; //Step size for q_ updates (< 0 implies use incremental average)
88-
std::vector<e_move_type> available_moves_;
89-
size_t num_available_types_; //Number of block types that exist in the netlist. Agent may not choose the block type.
90-
size_t num_available_actions_; //Total number of available actions
91-
bool propose_blk_type_ = false; //Check if agent should propose both move and block type or only move type
92-
std::vector<size_t> num_action_chosen_; //Number of times each arm has been pulled (n)
93-
std::vector<float> q_; //Estimated value of each arm (Q)
94-
size_t last_action_; //type of the last action (move type) proposed
87+
float exp_alpha_ = -1; //Step size for q_ updates (< 0 implies use incremental average)
88+
std::vector<e_move_type> available_moves_; //All available moves from which the agent can choose
89+
size_t num_available_types_; //Number of block types that exist in the netlist. Agent may not choose the block type.
90+
size_t num_available_actions_; //Total number of available actions
91+
bool propose_blk_type_ = false; //Check if agent should propose both move and block type or only move type
92+
std::vector<size_t> num_action_chosen_; //Number of times each arm has been pulled (n)
93+
std::vector<float> q_; //Estimated value of each arm (Q)
94+
size_t last_action_; //type of the last action (move type) proposed
9595
/* Ratios of the average runtime to calculate each move type */
9696
/* These ratios are useful for different reward functions *
9797
* The vector is calculated by averaging many runs on different circuits */
98-
// std::vector<double> time_elapsed_
99-
const vtr::vector<e_move_type, double> time_elapsed_{1.0, 3.6, 5.4, 2.5, 2.1, 0.8, 2.2, 5.4};
98+
const vtr::vector<e_move_type, double> time_elapsed_{1.0, 3.6, 5.4, 2.5, 2.1, 0.8, 2.2};
10099

101100
FILE* agent_info_file_ = nullptr;
102101

@@ -164,6 +163,7 @@ class SoftmaxAgent : public KArmedBanditAgent {
164163
SoftmaxAgent(std::vector<e_move_type> available_moves, e_agent_space agent_space);
165164
~SoftmaxAgent() override;
166165

166+
167167
t_propose_action propose_action() override; //Returns the type of the next action as well as the block type the agent wishes to perform
168168

169169
private:
@@ -200,8 +200,8 @@ class SoftmaxAgent : public KArmedBanditAgent {
200200
*/
201201
class SimpleRLMoveGenerator : public MoveGenerator {
202202
private:
203-
vtr::vector<e_move_type, std::unique_ptr<MoveGenerator>> avail_moves; // list of pointers to the available move generators (the different move types)
204-
std::unique_ptr<KArmedBanditAgent> karmed_bandit_agent; // a pointer to the specific agent used (e.g. Softmax)
203+
vtr::vector<e_move_type, std::unique_ptr<MoveGenerator>> all_moves; // list of pointers to all move generators (the different move types)
204+
std::unique_ptr<KArmedBanditAgent> karmed_bandit_agent; // a pointer to the specific agent used (e.g. Softmax)
205205

206206
public:
207207
// constructor using a pointer to the agent used
@@ -232,20 +232,20 @@ class SimpleRLMoveGenerator : public MoveGenerator {
232232
template<class T, class>
233233
SimpleRLMoveGenerator::SimpleRLMoveGenerator(std::unique_ptr<T>& agent, float noc_attraction_weight, size_t high_fanout_thresh) {
234234
if (noc_attraction_weight > 0.0f) {
235-
avail_moves.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES);
235+
all_moves.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES);
236236
} else {
237-
avail_moves.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES - 1);
237+
all_moves.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES - 1);
238238
}
239239

240-
avail_moves[e_move_type::UNIFORM] = std::make_unique<UniformMoveGenerator>();
241-
avail_moves[e_move_type::MEDIAN] = std::make_unique<MedianMoveGenerator>();
242-
avail_moves[e_move_type::CENTROID] = std::make_unique<CentroidMoveGenerator>();
243-
avail_moves[e_move_type::W_CENTROID] = std::make_unique<WeightedCentroidMoveGenerator>();
244-
avail_moves[e_move_type::W_MEDIAN] = std::make_unique<WeightedMedianMoveGenerator>();
245-
avail_moves[e_move_type::CRIT_UNIFORM] = std::make_unique<CriticalUniformMoveGenerator>();
246-
avail_moves[e_move_type::FEASIBLE_REGION] = std::make_unique<FeasibleRegionMoveGenerator>();
240+
all_moves[e_move_type::UNIFORM] = std::make_unique<UniformMoveGenerator>();
241+
all_moves[e_move_type::MEDIAN] = std::make_unique<MedianMoveGenerator>();
242+
all_moves[e_move_type::CENTROID] = std::make_unique<CentroidMoveGenerator>();
243+
all_moves[e_move_type::W_CENTROID] = std::make_unique<WeightedCentroidMoveGenerator>();
244+
all_moves[e_move_type::W_MEDIAN] = std::make_unique<WeightedMedianMoveGenerator>();
245+
all_moves[e_move_type::CRIT_UNIFORM] = std::make_unique<CriticalUniformMoveGenerator>();
246+
all_moves[e_move_type::FEASIBLE_REGION] = std::make_unique<FeasibleRegionMoveGenerator>();
247247
if (noc_attraction_weight > 0.0f) {
248-
avail_moves[e_move_type::NOC_ATTRACTION_CENTROID] = std::make_unique<CentroidMoveGenerator>(noc_attraction_weight, high_fanout_thresh);
248+
all_moves[e_move_type::NOC_ATTRACTION_CENTROID] = std::make_unique<CentroidMoveGenerator>(noc_attraction_weight, high_fanout_thresh);
249249
}
250250

251251
karmed_bandit_agent = std::move(agent);

0 commit comments

Comments
 (0)