Skip to content

Commit 7b5fbf8

Browse files
authored
Merge pull request #8437 from antmicro/rmp-simulated-annealing
rmp: Simulated annealing
2 parents d0658fb + 2389ab5 commit 7b5fbf8

22 files changed

+1627
-56
lines changed

src/rmp/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ cc_library(
1414
name = "rmp",
1515
srcs = [
1616
"src/Restructure.cpp",
17+
"src/annealing_strategy.cpp",
18+
"src/annealing_strategy.h",
1719
"src/delay_optimization_strategy.cpp",
1820
"src/delay_optimization_strategy.h",
1921
"src/logic_optimization_strategy.h",
2022
"src/resynthesis_strategy.h",
23+
"src/utils.cpp",
24+
"src/utils.h",
2125
"src/zero_slack_strategy.cpp",
2226
"src/zero_slack_strategy.h",
2327
],

src/rmp/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,36 @@ resynth
6666
| ----- | ----- |
6767
| `-corner` | Process corner to use. |
6868

69+
### Resynth with simulated annealing
70+
71+
Resynthesize parts of the design with an ABC script found via simulated annealing.
72+
The script is a series of operations on ABC's internal AIG data structure.
73+
A neighboring solution is a script with one operation added, removed, or two operations swapped.
74+
The optimization function is defined as the worst slack.
75+
76+
```tcl
77+
resynth_annealing
78+
[-corner corner]
79+
[-slack_threshold slack_threshold]
80+
[-seed seed]
81+
[-temp temp]
82+
[-iters iters]
83+
[-revert_after revert_after]
84+
[-initial_ops initial_ops]
85+
```
86+
87+
#### Options
88+
89+
| Switch Name | Description |
90+
| ----- | ----- |
91+
| `-corner` | Process corner to use. |
92+
| `-slack_threshold` | Specifies a (setup) timing slack value below which timing paths need to be analyzed for restructuring. The default value is `0`. |
93+
| `-seed` | Seed to use for randomness in simulated annealing. |
94+
| `-temp` | Initial temperature for simulated annealing. The default is the required arrival time on the worst slack endpoint. |
95+
| `-iters` | Number of iterations to run simulated annealing for. |
96+
| `-revert_after` | After the given number of iterations that worsen slack, revert to best found solution. |
97+
| `-initial_ops` | Size of the initial random solution (number of commands in the script for ABC). |
98+
6999
## Example scripts
70100

71101
Example scripts on running `rmp` for a sample design of `gcd` as follows:

src/rmp/include/rmp/Restructure.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,22 @@ class Restructure
6666

6767
void reset();
6868
void resynth(sta::Corner* corner);
69+
void resynthAnnealing(sta::Corner* corner);
6970
void run(char* liberty_file_name,
7071
float slack_threshold,
7172
unsigned max_depth,
7273
char* workdir_name,
7374
char* abc_logfile);
7475

76+
void setAnnealingSeed(uint64_t seed) { annealing_seed_ = seed; }
77+
void setAnnealingTemp(float temp) { annealing_temp_ = temp; }
78+
void setAnnealingIters(unsigned iters) { annealing_iters_ = iters; }
79+
void setAnnealingRevertAfter(unsigned revert_after)
80+
{
81+
annealing_revert_after_ = revert_after;
82+
}
83+
void setAnnealingInitialOps(unsigned ops) { annealing_init_ops_ = ops; }
84+
void setSlackThreshold(sta::Slack thresh) { slack_threshold_ = thresh; }
7585
void setMode(const char* mode_name);
7686
void setTieLoPort(sta::LibertyPort* loport);
7787
void setTieHiPort(sta::LibertyPort* hiport);
@@ -106,6 +116,14 @@ class Restructure
106116
est::EstimateParasitics* estimate_parasitics_;
107117
odb::dbBlock* block_ = nullptr;
108118

119+
// Annealing
120+
std::optional<uint64_t> annealing_seed_;
121+
std::optional<float> annealing_temp_;
122+
unsigned annealing_iters_ = 100;
123+
std::optional<unsigned> annealing_revert_after_;
124+
unsigned annealing_init_ops_ = 10;
125+
sta::Slack slack_threshold_ = 0;
126+
109127
std::string input_blif_file_name_;
110128
std::string output_blif_file_name_;
111129
std::vector<std::string> lib_file_names_;

src/rmp/src/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@ swig_lib(NAME rmp
1414

1515
add_library(rmp_lib
1616
Restructure.cpp
17+
annealing_strategy.cpp
1718
delay_optimization_strategy.cpp
19+
utils.cpp
1820
zero_slack_strategy.cpp
1921
)
2022

23+
# For ABC headers
24+
set_source_files_properties(annealing_strategy.cpp
25+
PROPERTIES COMPILE_FLAGS "-Wno-error=redundant-decls -Wno-error=unused-variable -Wno-error=unused-but-set-variable"
26+
)
27+
2128
target_sources(rmp
2229
PRIVATE
2330
MakeRestructure.cpp
@@ -42,7 +49,7 @@ target_include_directories(rmp_lib
4249
PUBLIC
4350
../include
4451
)
45-
52+
4653
target_link_libraries(rmp_lib
4754
PUBLIC
4855
odb
@@ -58,7 +65,7 @@ target_link_libraries(rmp
5865
PRIVATE
5966
rmp_lib
6067
)
61-
68+
6269
if (Python3_FOUND AND BUILD_PYTHON)
6370
swig_lib(NAME rmp_py
6471
NAMESPACE rmp

src/rmp/src/Restructure.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <utility>
2121
#include <vector>
2222

23+
#include "annealing_strategy.h"
2324
#include "base/abc/abc.h"
2425
#include "base/main/abcapis.h"
2526
#include "cut/abc_init.h"
@@ -87,6 +88,19 @@ void Restructure::resynth(sta::Corner* corner)
8788
open_sta_, name_generator_, resizer_, logger_);
8889
}
8990

91+
void Restructure::resynthAnnealing(sta::Corner* corner)
92+
{
93+
AnnealingStrategy annealing_strategy(corner,
94+
slack_threshold_,
95+
annealing_seed_,
96+
annealing_temp_,
97+
annealing_iters_,
98+
annealing_revert_after_,
99+
annealing_init_ops_);
100+
annealing_strategy.OptimizeDesign(
101+
open_sta_, name_generator_, resizer_, logger_);
102+
}
103+
90104
void Restructure::run(char* liberty_file_name,
91105
float slack_threshold,
92106
unsigned max_depth,

0 commit comments

Comments
 (0)