Skip to content

Commit aec608f

Browse files
authored
Merge pull request #1570 from verilog-to-routing/directedMoves_and_RL
Directed moves and Reinforcement Learning agent
2 parents 64d15e2 + 91d70d5 commit aec608f

File tree

148 files changed

+3375
-681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+3375
-681
lines changed

vpr/src/base/CheckSetup.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ void CheckSetup(const t_packer_opts& PackerOpts,
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) {
47+
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+
}
50+
51+
if (PlacerOpts.place_static_notiming_move_prob.size() != NUM_PL_NONTIMING_MOVE_TYPES) {
52+
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());
54+
}
55+
4656
if (RouterOpts.doRouting) {
4757
if (!Timing.timing_analysis_enabled
4858
&& (DEMAND_ONLY != RouterOpts.base_cost_type && DEMAND_ONLY_NORMALIZED_LENGTH != RouterOpts.base_cost_type)) {

vpr/src/base/SetupVPR.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,18 @@ static void SetupPlacerOpts(const t_options& Options, t_placer_opts* PlacerOpts)
573573
PlacerOpts->effort_scaling = Options.place_effort_scaling;
574574
PlacerOpts->timing_update_type = Options.timing_update_type;
575575
PlacerOpts->enable_analytic_placer = Options.enable_analytic_placer;
576+
PlacerOpts->place_static_move_prob = Options.place_static_move_prob;
577+
PlacerOpts->place_static_notiming_move_prob = Options.place_static_notiming_move_prob;
578+
PlacerOpts->place_high_fanout_net = Options.place_high_fanout_net;
579+
PlacerOpts->RL_agent_placement = Options.RL_agent_placement;
580+
PlacerOpts->place_agent_multistate = Options.place_agent_multistate;
581+
PlacerOpts->place_checkpointing = Options.place_checkpointing;
582+
PlacerOpts->place_agent_epsilon = Options.place_agent_epsilon;
583+
PlacerOpts->place_agent_gamma = Options.place_agent_gamma;
584+
PlacerOpts->place_dm_rlim = Options.place_dm_rlim;
585+
PlacerOpts->place_reward_fun = Options.place_reward_fun;
586+
PlacerOpts->place_crit_limit = Options.place_crit_limit;
587+
PlacerOpts->place_agent_algorithm = Options.place_agent_algorithm;
576588
}
577589

578590
static void SetupAnalysisOpts(const t_options& Options, t_analysis_opts& analysis_opts) {

vpr/src/base/read_options.cpp

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,37 @@ struct ParsePlaceAlgorithm {
393393
}
394394
};
395395

396+
struct ParsePlaceAgentAlgorithm {
397+
ConvertedValue<e_agent_algorithm> from_str(std::string str) {
398+
ConvertedValue<e_agent_algorithm> conv_value;
399+
if (str == "e_greedy")
400+
conv_value.set_value(E_GREEDY);
401+
else if (str == "softmax")
402+
conv_value.set_value(SOFTMAX);
403+
else {
404+
std::stringstream msg;
405+
msg << "Invalid conversion from '" << str << "' to e_agent_algorithm (expected one of: " << argparse::join(default_choices(), ", ") << ")";
406+
conv_value.set_error(msg.str());
407+
}
408+
return conv_value;
409+
}
410+
411+
ConvertedValue<std::string> to_str(e_agent_algorithm val) {
412+
ConvertedValue<std::string> conv_value;
413+
if (val == E_GREEDY)
414+
conv_value.set_value("e_greedy");
415+
else {
416+
VTR_ASSERT(val == SOFTMAX);
417+
conv_value.set_value("softmax");
418+
}
419+
return conv_value;
420+
}
421+
422+
std::vector<std::string> default_choices() {
423+
return {"e_greedy", "softmax"};
424+
}
425+
};
426+
396427
struct ParseFixPins {
397428
ConvertedValue<e_pad_loc_type> from_str(std::string str) {
398429
ConvertedValue<e_pad_loc_type> conv_value;
@@ -1625,7 +1656,7 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
16251656

16261657
place_grp.add_argument(args.PlaceInnerNum, "--inner_num")
16271658
.help("Controls number of moves per temperature: inner_num * num_blocks ^ (4/3)")
1628-
.default_value("1.0")
1659+
.default_value("0.5")
16291660
.show_in(argparse::ShowIn::HELP_ONLY);
16301661

16311662
place_grp.add_argument<e_place_effort_scaling, ParsePlaceEfforScaling>(args.place_effort_scaling, "--place_effort_scaling")
@@ -1758,6 +1789,103 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
17581789
.default_value("false")
17591790
.show_in(argparse::ShowIn::HELP_ONLY);
17601791

1792+
place_grp.add_argument(args.place_static_move_prob, "--place_static_move_prob")
1793+
.help(
1794+
"The percentage probabilities of different moves in Simulated Annealing placement."
1795+
"This option is only effective for timing-driven placement."
1796+
"The numbers listed are interpreted as the percentage probabilities of {uniformMove, MedianMove, CentroidMove, WeightedCentroid, WeightedMedian, Timing feasible Region(TFR), Critical UniformMove}, in that order.")
1797+
.nargs('+')
1798+
.default_value({"100", "0", "0", "0", "0", "0", "0"})
1799+
1800+
.show_in(argparse::ShowIn::HELP_ONLY);
1801+
1802+
place_grp.add_argument(args.place_static_notiming_move_prob, "--place_static_notiming_move_prob")
1803+
.help(
1804+
"The Probability of different non timing move in Simulated Annealing."
1805+
"This option is only effective for nontiming driven placement."
1806+
" The numbers listed are interpreted as the percentage probabilities of {uniformMove, MedianMove, CentroidMove}, in that order.")
1807+
.nargs('+')
1808+
.default_value({"100", "0", "0"})
1809+
1810+
.show_in(argparse::ShowIn::HELP_ONLY);
1811+
1812+
place_grp.add_argument(args.place_high_fanout_net, "--place_high_fanout_net")
1813+
.help(
1814+
"Sets the assumed high fanout net during placement. "
1815+
"Any net with higher fanout would be ignored while calculating some of the directed moves: Median and WeightedMedian")
1816+
.default_value("10")
1817+
.show_in(argparse::ShowIn::HELP_ONLY);
1818+
1819+
place_grp.add_argument<bool, ParseOnOff>(args.RL_agent_placement, "--RL_agent_placement")
1820+
.help(
1821+
"Uses a Reinforcement Learning (RL) agent in choosing the appropiate move type in placement."
1822+
"It activates the RL agent placement instead of using fixed probability for each move type.")
1823+
.default_value("on")
1824+
.show_in(argparse::ShowIn::HELP_ONLY);
1825+
1826+
place_grp.add_argument<bool, ParseOnOff>(args.place_agent_multistate, "--place_agent_multistate")
1827+
.help(
1828+
"Enable multistate agent. "
1829+
"A second state will be activated late in the annealing and in the Quench that includes all the timing driven directed moves.")
1830+
.default_value("on")
1831+
.show_in(argparse::ShowIn::HELP_ONLY);
1832+
1833+
place_grp.add_argument<bool, ParseOnOff>(args.place_checkpointing, "--place_checkpointing")
1834+
.help(
1835+
"Enable Placement checkpoints. This means saving the placement and restore it if it's better than later placements."
1836+
"Only effective if agnet's 2nd state is activated.")
1837+
.default_value("on")
1838+
.show_in(argparse::ShowIn::HELP_ONLY);
1839+
1840+
place_grp.add_argument(args.place_agent_epsilon, "--place_agent_epsilon")
1841+
.help(
1842+
"Placement RL agent's epsilon for epsilon-greedy agent."
1843+
"Epsilon represents the percentage of exploration actions taken vs the exploitation ones.")
1844+
.default_value("0.3")
1845+
.show_in(argparse::ShowIn::HELP_ONLY);
1846+
1847+
place_grp.add_argument(args.place_agent_gamma, "--place_agent_gamma")
1848+
.help(
1849+
"Controls how quickly the agent's memory decays. "
1850+
"Values between [0., 1.] specify the fraction of weight in the exponentially weighted reward average applied to moves which occured greater than moves_per_temp moves ago."
1851+
"Values < 0 cause the unweighted reward sample average to be used (all samples are weighted equally)")
1852+
.default_value("0.05")
1853+
.show_in(argparse::ShowIn::HELP_ONLY);
1854+
1855+
place_grp.add_argument(args.place_dm_rlim, "--place_dm_rlim")
1856+
.help(
1857+
"The maximum range limit of any directed move other than the uniform move. "
1858+
"It also shrinks with the default rlim")
1859+
.default_value("3.0")
1860+
.show_in(argparse::ShowIn::HELP_ONLY);
1861+
1862+
place_grp.add_argument(args.place_reward_fun, "--place_reward_fun")
1863+
.help(
1864+
"The reward function used by placement RL agent."
1865+
"The available values are: basic, nonPenalizing_basic, runtime_aware, WLbiased_runtime_aware")
1866+
.default_value("WLbiased_runtime_aware")
1867+
.show_in(argparse::ShowIn::HELP_ONLY);
1868+
1869+
place_grp.add_argument(args.place_crit_limit, "--place_crit_limit")
1870+
.help(
1871+
"The criticality limit to count a block as a critical one (or have a critical connection). "
1872+
"It used in some directed moves that only move critical blocks like critical uniform and feasible region. "
1873+
"Its range equals to [0., 1.].")
1874+
.default_value("0.7")
1875+
.show_in(argparse::ShowIn::HELP_ONLY);
1876+
/*
1877+
* place_grp.add_argument(args.place_timing_cost_func, "--place_timing_cost_func")
1878+
* .help(
1879+
* "which timing cost function to use")
1880+
* .default_value("0")
1881+
* .show_in(argparse::ShowIn::HELP_ONLY);
1882+
*/
1883+
place_grp.add_argument<e_agent_algorithm, ParsePlaceAgentAlgorithm>(args.place_agent_algorithm, "--place_agent_algorithm")
1884+
.help("Controls which placement RL agent is used")
1885+
.default_value("softmax")
1886+
.choices({"e_greedy", "softmax"})
1887+
.show_in(argparse::ShowIn::HELP_ONLY);
1888+
17611889
auto& place_timing_grp = parser.add_argument_group("timing-driven placement options");
17621890

17631891
place_timing_grp.add_argument(args.PlaceTimingTradeoff, "--timing_tradeoff")

vpr/src/base/read_options.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ struct t_options {
114114
argparse::ArgValue<e_place_effort_scaling> place_effort_scaling;
115115
argparse::ArgValue<e_place_delta_delay_algorithm> place_delta_delay_matrix_calculation_method;
116116
argparse::ArgValue<bool> enable_analytic_placer;
117+
argparse::ArgValue<std::vector<float>> place_static_move_prob;
118+
argparse::ArgValue<std::vector<float>> place_static_notiming_move_prob;
119+
argparse::ArgValue<int> place_high_fanout_net;
120+
121+
argparse::ArgValue<bool> RL_agent_placement;
122+
argparse::ArgValue<bool> place_agent_multistate;
123+
argparse::ArgValue<bool> place_checkpointing;
124+
argparse::ArgValue<float> place_agent_epsilon;
125+
argparse::ArgValue<float> place_agent_gamma;
126+
argparse::ArgValue<float> place_dm_rlim;
127+
argparse::ArgValue<e_agent_algorithm> place_agent_algorithm;
128+
argparse::ArgValue<std::string> place_reward_fun;
129+
//argparse::ArgValue<int> place_timing_cost_func;
130+
argparse::ArgValue<float> place_crit_limit;
117131

118132
/* Timing-driven placement options only */
119133
argparse::ArgValue<float> PlaceTimingTradeoff;

vpr/src/base/vpr_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ bool vpr_pack(t_vpr_setup& vpr_setup, const t_arch& arch) {
590590
}
591591

592592
void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch) {
593-
vtr::ScopedStartFinishTimer timer("Load Packing");
593+
vtr::ScopedStartFinishTimer timer("Load packing");
594594

595595
VTR_ASSERT_MSG(!vpr_setup.FileNameOpts.NetFile.empty(),
596596
"Must have valid .net filename to load packing");

vpr/src/base/vpr_types.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ enum class e_timing_update_type {
490490
* Placement and routing data types
491491
****************************************************************************/
492492

493+
/* Values of number of placement available move types */
494+
#define NUM_PL_MOVE_TYPES 7
495+
#define NUM_PL_NONTIMING_MOVE_TYPES 3
496+
#define NUM_PL_1ST_STATE_MOVE_TYPES 4
497+
493498
/* Timing data structures end */
494499
enum sched_type {
495500
AUTO_SCHED,
@@ -920,6 +925,18 @@ enum e_pad_loc_type {
920925
RANDOM
921926
};
922927

928+
/**
929+
* @brief Used to determine the RL agent's algorithm
930+
*
931+
* This algorithm controls the exploration-exploitation and how we select the new action
932+
* Currently, the supported algorithms are: epsilon greedy and softmax
933+
* For more details, check simpleRL_move_generator.cpp
934+
*/
935+
enum e_agent_algorithm {
936+
E_GREEDY,
937+
SOFTMAX
938+
};
939+
923940
///@brief Used to calculate the inner placer loop's block swapping limit move_lim.
924941
enum e_place_effort_scaling {
925942
CIRCUIT, ///<Effort scales based on circuit size only
@@ -1033,6 +1050,19 @@ struct t_placer_opts {
10331050

10341051
std::string write_placement_delay_lookup;
10351052
std::string read_placement_delay_lookup;
1053+
std::vector<float> place_static_move_prob;
1054+
std::vector<float> place_static_notiming_move_prob;
1055+
bool RL_agent_placement;
1056+
bool place_agent_multistate;
1057+
bool place_checkpointing;
1058+
int place_high_fanout_net;
1059+
e_agent_algorithm place_agent_algorithm;
1060+
float place_agent_epsilon;
1061+
float place_agent_gamma;
1062+
float place_dm_rlim;
1063+
//int place_timing_cost_func;
1064+
std::string place_reward_fun;
1065+
float place_crit_limit;
10361066

10371067
/**
10381068
* @brief Tile types that should be used during delay sampling.

vpr/src/draw/draw.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050

5151
#include "move_utils.h"
5252

53+
#ifdef VTR_ENABLE_DEBUG_LOGGING
54+
# include "move_utils.h"
55+
#endif
56+
5357
#ifdef WIN32 /* For runtime tracking in WIN32. The clock() function defined in time.h will *
5458
* track CPU runtime. */
5559
# include <time.h>

0 commit comments

Comments
 (0)