Skip to content

Commit 9cc02c3

Browse files
authored
Merge pull request #2542 from verilog-to-routing/specify_moves_explicitly
Specify available moves explicitly
2 parents 8fe7da8 + 5f647af commit 9cc02c3

18 files changed

+264
-213
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: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,39 @@ void CheckSetup(const t_packer_opts& PackerOpts,
3131
"This is allowed, but strange, and circuit speed will suffer.\n");
3232
}
3333

34-
if ((false == Timing.timing_analysis_enabled)
34+
if (!Timing.timing_analysis_enabled
3535
&& (PlacerOpts.place_algorithm.is_timing_driven())) {
3636
/* May work, not tested */
3737
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
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
}
4545

46-
if (PlacerOpts.place_static_move_prob.size() != NUM_PL_MOVE_TYPES) {
46+
if (PlacerOpts.place_algorithm.is_timing_driven() &&
47+
PlacerOpts.place_static_move_prob.size() > NUM_PL_MOVE_TYPES) {
4748
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
48-
"The number of placer move probabilities should equal to the total number of supported moves. %d\n", PlacerOpts.place_static_move_prob.size());
49+
"The number of provided placer move probabilities (%d) should equal or less than the total number of supported moves (%d).\n",
50+
PlacerOpts.place_static_move_prob.size(),
51+
NUM_PL_MOVE_TYPES);
4952
}
5053

51-
if (PlacerOpts.place_static_notiming_move_prob.size() != NUM_PL_NONTIMING_MOVE_TYPES) {
54+
if (!PlacerOpts.place_algorithm.is_timing_driven() &&
55+
PlacerOpts.place_static_move_prob.size() > NUM_PL_NONTIMING_MOVE_TYPES) {
5256
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
53-
"The number of placer non timing move probabilities should equal to the total number of supported moves. %d\n", PlacerOpts.place_static_notiming_move_prob.size());
57+
"The number of placer non timing move probabilities (%d) should equal to or less than the total number of supported moves (%d).\n",
58+
PlacerOpts.place_static_move_prob.size(),
59+
NUM_PL_MOVE_TYPES);
5460
}
5561

5662
if (RouterOpts.doRouting) {
5763
if (!Timing.timing_analysis_enabled
5864
&& (DEMAND_ONLY != RouterOpts.base_cost_type && DEMAND_ONLY_NORMALIZED_LENGTH != RouterOpts.base_cost_type)) {
5965
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
60-
"base_cost_type must be demand_only or demand_only_normailzed_length when timing analysis is disabled.\n");
66+
"base_cost_type must be demand_only or demand_only_normalized_length when timing analysis is disabled.\n");
6167
}
6268
}
6369

vpr/src/base/SetupGrid.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ using vtr::t_formula_data;
3131

3232
static DeviceGrid auto_size_device_grid(const std::vector<t_grid_def>& grid_layouts, const std::map<t_logical_block_type_ptr, size_t>& minimum_instance_counts, float maximum_device_utilization);
3333
static std::vector<t_logical_block_type_ptr> grid_overused_resources(const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t> instance_counts);
34-
static bool grid_satisfies_instance_counts(const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t> instance_counts, float maximum_utilization);
35-
static DeviceGrid build_device_grid(const t_grid_def& grid_def, size_t width, size_t height, bool warn_out_of_range = true, std::vector<t_logical_block_type_ptr> limiting_resources = std::vector<t_logical_block_type_ptr>());
34+
static bool grid_satisfies_instance_counts(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts, float maximum_utilization);
35+
static DeviceGrid build_device_grid(const t_grid_def& grid_def, size_t width, size_t height, bool warn_out_of_range = true, const std::vector<t_logical_block_type_ptr>& limiting_resources = std::vector<t_logical_block_type_ptr>());
3636

3737
static void CheckGrid(const DeviceGrid& grid);
3838

@@ -316,8 +316,8 @@ static std::vector<t_logical_block_type_ptr> grid_overused_resources(const Devic
316316
return overused_resources;
317317
}
318318

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

323323
if (!overused_resources.empty()) {
@@ -335,7 +335,7 @@ static bool grid_satisfies_instance_counts(const DeviceGrid& grid, std::map<t_lo
335335
}
336336

337337
///@brief Build the specified device grid
338-
static DeviceGrid build_device_grid(const t_grid_def& grid_def, size_t grid_width, size_t grid_height, bool warn_out_of_range, const std::vector<t_logical_block_type_ptr> limiting_resources) {
338+
static DeviceGrid build_device_grid(const t_grid_def& grid_def, size_t grid_width, size_t grid_height, bool warn_out_of_range, const std::vector<t_logical_block_type_ptr>& limiting_resources) {
339339
if (grid_def.grid_type == GridDefType::FIXED) {
340340
if (grid_def.width != int(grid_width) || grid_def.height != int(grid_height)) {
341341
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
@@ -754,7 +754,7 @@ static void CheckGrid(const DeviceGrid& grid) {
754754
}
755755
}
756756

757-
float calculate_device_utilization(const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t> instance_counts) {
757+
float calculate_device_utilization(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts) {
758758
//Record the resources of the grid
759759
std::map<t_physical_tile_type_ptr, size_t> grid_resources;
760760
for (int layer_num = 0; layer_num < grid.get_num_layers(); ++layer_num) {

vpr/src/base/SetupGrid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ DeviceGrid create_device_grid(std::string layout_name, const std::vector<t_grid_
2727
* Calculate the device utilization (i.e. fraction of used grid tiles)
2828
* foor the specified grid and resource requirements
2929
*/
30-
float calculate_device_utilization(const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t> instance_counts);
30+
float calculate_device_utilization(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts);
3131

3232
/**
3333
* @brief Returns the effective size of the device

vpr/src/base/SetupVPR.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,8 @@ static void SetupPlacerOpts(const t_options& Options, t_placer_opts* PlacerOpts)
661661
PlacerOpts->effort_scaling = Options.place_effort_scaling;
662662
PlacerOpts->timing_update_type = Options.timing_update_type;
663663
PlacerOpts->enable_analytic_placer = Options.enable_analytic_placer;
664-
PlacerOpts->place_static_move_prob = Options.place_static_move_prob;
665-
PlacerOpts->place_static_notiming_move_prob = Options.place_static_notiming_move_prob;
664+
PlacerOpts->place_static_move_prob = vtr::vector<e_move_type, float>(Options.place_static_move_prob.value().begin(),
665+
Options.place_static_move_prob.value().end());
666666
PlacerOpts->place_high_fanout_net = Options.place_high_fanout_net;
667667
PlacerOpts->place_bounding_box_mode = Options.place_bounding_box_mode;
668668
PlacerOpts->RL_agent_placement = Options.RL_agent_placement;

vpr/src/base/read_options.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,23 +2032,17 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
20322032

20332033
place_grp.add_argument(args.place_static_move_prob, "--place_static_move_prob")
20342034
.help(
2035-
"The percentage probabilities of different moves in Simulated Annealing placement."
2036-
"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, Timing feasible Region(TFR), Critical UniformMove}, in that order.")
2035+
"The percentage probabilities of different moves in Simulated Annealing placement. "
2036+
"For non-timing-driven placement, only the first 3 probabilities should be provided. "
2037+
"For timing-driven placement, all probabilities should be provided. "
2038+
"When the number of provided probabilities is less then the number of move types, zero probability "
2039+
"is assumed."
2040+
"The numbers listed are interpreted as the percentage probabilities of {UniformMove, MedianMove, CentroidMove, "
2041+
"WeightedCentroid, WeightedMedian, Critical UniformMove, Timing feasible Region(TFR)}, in that order.")
20382042
.nargs('+')
2039-
.default_value({"100", "0", "0", "0", "0", "0", "0"})
2040-
2043+
.default_value({"100"})
20412044
.show_in(argparse::ShowIn::HELP_ONLY);
20422045

2043-
place_grp.add_argument(args.place_static_notiming_move_prob, "--place_static_notiming_move_prob")
2044-
.help(
2045-
"The Probability of different non timing move in Simulated Annealing."
2046-
"This option is only effective for nontiming driven placement."
2047-
" The numbers listed are interpreted as the percentage probabilities of {uniformMove, MedianMove, CentroidMove}, in that order.")
2048-
.nargs('+')
2049-
.default_value({"100", "0", "0"})
2050-
2051-
.show_in(argparse::ShowIn::HELP_ONLY);
20522046

20532047
place_grp.add_argument(args.place_high_fanout_net, "--place_high_fanout_net")
20542048
.help(

vpr/src/base/read_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ struct t_options {
126126
argparse::ArgValue<e_place_delta_delay_algorithm> place_delta_delay_matrix_calculation_method;
127127
argparse::ArgValue<bool> enable_analytic_placer;
128128
argparse::ArgValue<std::vector<float>> place_static_move_prob;
129-
argparse::ArgValue<std::vector<float>> place_static_notiming_move_prob;
130129
argparse::ArgValue<int> place_high_fanout_net;
131130
argparse::ArgValue<e_place_bounding_box_mode> place_bounding_box_mode;
132131

vpr/src/base/vpr_types.h

Lines changed: 7 additions & 11 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,12 +108,10 @@ 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
115-
#define NOT_VALID -10000 /* Marks gains that aren't valid */
111+
#define NOT_VALID (-10000) /* Marks gains that aren't valid */
116112
/* Ensure no gain can ever be this negative! */
117113
#ifndef UNDEFINED
118-
# define UNDEFINED -1
114+
# define UNDEFINED (-1)
119115
#endif
120116

121117
enum class e_router_lookahead {
@@ -550,9 +546,8 @@ enum class e_timing_update_type {
550546
****************************************************************************/
551547

552548
/* Values of number of placement available move types */
553-
#define NUM_PL_MOVE_TYPES 7
554-
#define NUM_PL_NONTIMING_MOVE_TYPES 3
555-
#define NUM_PL_1ST_STATE_MOVE_TYPES 4
549+
constexpr int NUM_PL_MOVE_TYPES = 7;
550+
constexpr int NUM_PL_NONTIMING_MOVE_TYPES = 3;
556551

557552
/* Timing data structures end */
558553
enum sched_type {
@@ -1155,6 +1150,8 @@ enum class e_place_delta_delay_algorithm {
11551150
DIJKSTRA_EXPANSION,
11561151
};
11571152

1153+
enum class e_move_type;
1154+
11581155
/**
11591156
* @brief Various options for the placer.
11601157
*
@@ -1253,8 +1250,7 @@ struct t_placer_opts {
12531250

12541251
std::string write_placement_delay_lookup;
12551252
std::string read_placement_delay_lookup;
1256-
std::vector<float> place_static_move_prob;
1257-
std::vector<float> place_static_notiming_move_prob;
1253+
vtr::vector<e_move_type, float> place_static_move_prob;
12581254
bool RL_agent_placement;
12591255
bool place_agent_multistate;
12601256
bool place_checkpointing;

0 commit comments

Comments
 (0)