Skip to content

Commit 33c4c01

Browse files
Merge pull request #3021 from AlexandreSinger/feature-appack-max-dist-cli
[APPack] Updated Max Candidate Distance Interface
2 parents 576c5c3 + 4079c04 commit 33c4c01

13 files changed

+496
-48
lines changed

doc/src/vpr/command_line_usage.rst

+43
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,49 @@ Analytical Placement is generally split into three stages:
12701270

12711271
**Default:** ``0.5``
12721272

1273+
.. option:: --appack_max_dist_th { auto | <regex>:<float>,<float> }
1274+
1275+
Sets the maximum candidate distance thresholds for the logical block types
1276+
used by APPack. APPack uses the primitive-level placement produced by the
1277+
global placer to cluster primitives together. APPack uses the thresholds
1278+
here to ignore primitives which are too far away from the cluster being formed.
1279+
1280+
When this option is set to "auto", VPR will select good values for these
1281+
thresholds based on the primitives contained within each logical block type.
1282+
1283+
Using this option, the user can set the maximum candidate distance threshold
1284+
of logical block types to something else. The strings passed in by the user
1285+
should be of the form ``<regex>:<float>,<float>`` where the regex string is
1286+
used to match the name of the logical block type to set, the first float
1287+
is a scaling term, and the second float is an offset. The threshold will
1288+
be set to max(scale * (W + H), offset), where W and H are the width and height
1289+
of the device. This allows the user to specify a threshold based on the
1290+
size of the device, while also preventing the number from going below "offset".
1291+
When multiple strings are provided, the thresholds are set from left to right,
1292+
and any logical block types which have been unset will be set to their "auto"
1293+
values.
1294+
1295+
For example:
1296+
1297+
.. code-block:: none
1298+
1299+
--appack_max_dist_th .*:0.1,0 "clb|memory:0,5"
1300+
1301+
Would set all logical block types to be 0.1 * (W + H), except for the clb and
1302+
memory block, which will be set to a fixed value of 5.
1303+
1304+
Another example:
1305+
1306+
.. code-block:: none
1307+
1308+
--appack_max_dist_th "clb|LAB:0.2,5"
1309+
1310+
This will set all of the logical block types to their "auto" thresholds, except
1311+
for logical blocks with the name clb/LAB which will be set to 0.2 * (W + H) or
1312+
5 (whichever is larger).
1313+
1314+
**Default:** ``auto``
1315+
12731316
.. option:: --ap_verbosity <int>
12741317

12751318
Controls the verbosity of the AP flow output.

vpr/src/analytical_place/full_legalizer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ void APPack::legalize(const PartialPlacement& p_placement) {
520520
// Run the Packer stage with the flat placement as a hint.
521521
try_pack(vpr_setup_.PackerOpts,
522522
vpr_setup_.AnalysisOpts,
523+
vpr_setup_.APOpts,
523524
arch_,
524525
vpr_setup_.PackerRRGraph,
525526
prepacker_,

vpr/src/base/SetupVPR.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ void SetupAPOpts(const t_options& options,
550550
apOpts.full_legalizer_type = options.ap_full_legalizer.value();
551551
apOpts.detailed_placer_type = options.ap_detailed_placer.value();
552552
apOpts.ap_timing_tradeoff = options.ap_timing_tradeoff.value();
553+
apOpts.appack_max_dist_th = options.appack_max_dist_th.value();
553554
apOpts.log_verbosity = options.ap_verbosity.value();
554555
}
555556

vpr/src/base/read_options.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,31 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
19451945
.default_value("0.5")
19461946
.show_in(argparse::ShowIn::HELP_ONLY);
19471947

1948+
ap_grp.add_argument(args.appack_max_dist_th, "--appack_max_dist_th")
1949+
.help(
1950+
"Sets the maximum candidate distance thresholds for the logical block types"
1951+
"used by APPack. APPack uses the primitive-level placement produced by the"
1952+
"global placer to cluster primitives together. APPack uses the thresholds"
1953+
"here to ignore primitives which are too far away from the cluster being formed."
1954+
"\n"
1955+
"When this option is set to auto, VPR will select good values for these"
1956+
"thresholds based on the primitives contained within each logical block type."
1957+
"\n"
1958+
"Using this option, the user can set the maximum candidate distance threshold"
1959+
"of logical block types to something else. The strings passed in by the user"
1960+
"should be of the form <regex>:<float>,<float> where the regex string is"
1961+
"used to match the name of the logical block type to set, the first float"
1962+
"is a scaling term, and the second float is an offset. The threshold will"
1963+
"be set to max(scale * (W + H), offset), where W and H are the width and height"
1964+
"of the device. This allows the user to specify a threshold based on the"
1965+
"size of the device, while also preventing the number from going below offset"
1966+
"When multiple strings are provided, the thresholds are set from left to right,"
1967+
"and any logical block types which have been unset will be set to their auto"
1968+
"values.")
1969+
.nargs('+')
1970+
.default_value({"auto"})
1971+
.show_in(argparse::ShowIn::HELP_ONLY);
1972+
19481973
ap_grp.add_argument<int>(args.ap_verbosity, "--ap_verbosity")
19491974
.help(
19501975
"Controls how verbose the AP flow's log messages will be. Higher "

vpr/src/base/read_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct t_options {
102102
argparse::ArgValue<e_ap_partial_legalizer> ap_partial_legalizer;
103103
argparse::ArgValue<e_ap_full_legalizer> ap_full_legalizer;
104104
argparse::ArgValue<e_ap_detailed_placer> ap_detailed_placer;
105+
argparse::ArgValue<std::vector<std::string>> appack_max_dist_th;
105106
argparse::ArgValue<int> ap_verbosity;
106107
argparse::ArgValue<float> ap_timing_tradeoff;
107108

vpr/src/base/vpr_api.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ bool vpr_pack(t_vpr_setup& vpr_setup, const t_arch& arch) {
658658
vpr_setup.PackerOpts.device_layout,
659659
vpr_setup.AnalysisOpts);
660660

661-
return try_pack(vpr_setup.PackerOpts, vpr_setup.AnalysisOpts,
661+
return try_pack(vpr_setup.PackerOpts, vpr_setup.AnalysisOpts, vpr_setup.APOpts,
662662
arch,
663663
vpr_setup.PackerRRGraph,
664664
prepacker,

vpr/src/base/vpr_types.h

+5
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,9 @@ struct t_placer_opts {
11131113
* @param ap_timing_tradeoff
11141114
* A trade-off parameter used to decide how focused the AP flow
11151115
* should be on optimizing timing over wirelength.
1116+
* @param appack_max_dist_th
1117+
* Array of string passed by the user to configure the max candidate
1118+
* distance thresholds.
11161119
* @param log_verbosity
11171120
* The verbosity level of log messages in the AP flow, with higher
11181121
* values leading to more verbose messages.
@@ -1130,6 +1133,8 @@ struct t_ap_opts {
11301133

11311134
float ap_timing_tradeoff;
11321135

1136+
std::vector<std::string> appack_max_dist_th;
1137+
11331138
int log_verbosity;
11341139
};
11351140

vpr/src/pack/appack_context.h

+22-41
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
#pragma once
1010

11-
#include <algorithm>
12-
#include <limits>
11+
#include "appack_max_dist_th_manager.h"
1312
#include "device_grid.h"
1413
#include "flat_placement_types.h"
1514
#include "physical_types.h"
1615
#include "vpr_context.h"
16+
#include "vpr_types.h"
1717
#include "vpr_utils.h"
1818

1919
/**
@@ -25,29 +25,10 @@
2525
*/
2626
struct t_appack_options {
2727
// Constructor for the appack options.
28-
t_appack_options(const FlatPlacementInfo& flat_placement_info,
29-
const DeviceGrid& device_grid) {
28+
t_appack_options(const FlatPlacementInfo& flat_placement_info) {
3029
// If the flat placement info is valid, we want to use APPack.
3130
// TODO: Should probably check that all the information is valid here.
3231
use_appack = flat_placement_info.valid;
33-
34-
// Set the max candidate distance as being some fraction of the longest
35-
// distance on the device (from the bottom corner to the top corner).
36-
// We also use an offset for the minimum this distance can be to prevent
37-
// small devices from finding candidates.
38-
float max_candidate_distance_scale = 0.1f;
39-
float max_candidate_distance_offset = 15.0f;
40-
// Longest L1 distance on the device.
41-
float longest_distance = device_grid.width() + device_grid.height();
42-
max_candidate_distance = std::max(max_candidate_distance_scale * longest_distance,
43-
max_candidate_distance_offset);
44-
45-
// Infer the logical block type in the architecture. This will be used
46-
// for the max candidate distance optimization to use a more aggressive
47-
// distance.
48-
t_logical_block_type_ptr logic_block_type = infer_logic_block_type(device_grid);
49-
if (logic_block_type != nullptr)
50-
logic_block_type_index = logic_block_type->index;
5132
}
5233

5334
// Whether to use APPack or not.
@@ -88,22 +69,6 @@ struct t_appack_options {
8869
// Squared scaling factor for the quadratic decay term.
8970
static constexpr float quad_fac_sqr = (1.0f - attenuation_th) / (dist_th * dist_th);
9071

91-
// =========== Candidate selection distance ============================ //
92-
// When selecting candidates, what distance from the cluster will we
93-
// consider? Any candidate beyond this distance will not be proposed.
94-
// This is set in the constructor.
95-
// TODO: It may be a good idea to have max different distances for different
96-
// types of molecules / clusters. For example, CLBs vs DSPs
97-
float max_candidate_distance = std::numeric_limits<float>::max();
98-
99-
// A scaling applied to the max candidate distance of all clusters that are
100-
// not logic blocks.
101-
static constexpr float max_candidate_distance_non_lb_scale = 3.5f;
102-
103-
// TODO: This should be an option similar to the target pin utilization
104-
// so we can specify the max distance per block type!
105-
int logic_block_type_index = -1;
106-
10772
// =========== Unrelated clustering ==================================== //
10873
// After searching for candidates by connectivity and timing, the user may
10974
// turn on unrelated clustering, which will allow molecules which are
@@ -144,9 +109,21 @@ struct APPackContext : public Context {
144109
/**
145110
* @brief Constructor for the APPack context.
146111
*/
147-
APPackContext(const FlatPlacementInfo& fplace_info, const DeviceGrid& device_grid)
148-
: appack_options(fplace_info, device_grid)
149-
, flat_placement_info(fplace_info) {}
112+
APPackContext(const FlatPlacementInfo& fplace_info,
113+
const t_ap_opts& ap_opts,
114+
const std::vector<t_logical_block_type> logical_block_types,
115+
const DeviceGrid& device_grid)
116+
: appack_options(fplace_info)
117+
, flat_placement_info(fplace_info) {
118+
119+
// If the flat placement info has been provided, calculate max distance
120+
// thresholds for all logical block types.
121+
if (fplace_info.valid) {
122+
max_distance_threshold_manager.init(ap_opts.appack_max_dist_th,
123+
logical_block_types,
124+
device_grid);
125+
}
126+
}
150127

151128
/**
152129
* @brief Options used to configure APPack.
@@ -157,4 +134,8 @@ struct APPackContext : public Context {
157134
* @brief The flat placement information passed into APPack.
158135
*/
159136
const FlatPlacementInfo& flat_placement_info;
137+
138+
// When selecting candidates, what distance from the cluster will we
139+
// consider? Any candidate beyond this distance will not be proposed.
140+
APPackMaxDistThManager max_distance_threshold_manager;
160141
};

0 commit comments

Comments
 (0)