Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/odb/test/replace_hier_mod1.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ report_checks -through r2/D -digits 3
# - it looks like "-through" creates a cache internally.
#report_checks -through u1z -through r2/D -digits 3
puts "Equivalence check - pre"
run_equivalence_test replace_hier_mod1 ./Nangate45/work_around_yosys/ "None"
run_equivalence_test replace_hier_mod1 \
-lib_dir ./Nangate45/work_around_yosys/ \
-remove_cells "None"

puts "### swap bc1 to inv_chain ###"
#set_debug_level ODB replace_design 1
Expand All @@ -50,7 +52,9 @@ estimate_parasitics -placement
report_checks -through r2/D -digits 3
#report_checks -through u1z -through r2/D -digits 3
puts "Equivalence check - swap (buffer_chain -> inv_chain)"
run_equivalence_test replace_hier_mod1 ./Nangate45/work_around_yosys/ "None"
run_equivalence_test replace_hier_mod1 \
-lib_dir ./Nangate45/work_around_yosys/ \
-remove_cells "None"

puts "### swap bc1 back to buffer_chain ###"
replace_hier_module bc1 buffer_chain
Expand All @@ -63,7 +67,9 @@ estimate_parasitics -placement
report_checks -through r2/D -digits 3
#report_checks -through u1z -through r2/D -digits 3
puts "Equivalence check - swap for rollback (inv_chain -> buffer_chain)"
run_equivalence_test replace_hier_mod1 ./Nangate45/work_around_yosys/ "None"
run_equivalence_test replace_hier_mod1 \
-lib_dir ./Nangate45/work_around_yosys/ \
-remove_cells "None"

puts "### swap bc1 back to inv_chain ###"
replace_hier_module bc1 inv_chain
Expand All @@ -76,4 +82,6 @@ estimate_parasitics -placement
report_checks -through r2/D -digits 3
#report_checks -through u1z -through r2/D -digits 3
puts "Equivalence check - redo swap (buffer_chain -> inv_chain)"
run_equivalence_test replace_hier_mod1 ./Nangate45/work_around_yosys/ "None"
run_equivalence_test replace_hier_mod1 \
-lib_dir ./Nangate45/work_around_yosys/ \
-remove_cells "None"
8 changes: 6 additions & 2 deletions src/odb/test/replace_hier_mod2.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ estimate_parasitics -placement
report_checks -through _carry_out_and_/C -field input
report_cell_usage _551_
puts "Checking equivalence after swap #2 (Rollback)..."
run_equivalence_test replace_hier_mod2 sky130hd/work_around_yosys "None"
run_equivalence_test replace_hier_mod2 \
-lib_dir ./sky130hd/work_around_yosys/ \
-remove_cells "None"

# Swap #3. BRENT_KUNG -> KOGGE_STONE (Redo)
replace_hier_module _551_ LCU_16_KOGGE_STONE
Expand All @@ -59,4 +61,6 @@ estimate_parasitics -placement
report_checks -through _carry_out_and_/C -field input
report_cell_usage _551_
puts "Checking equivalence after swap #4 (Rollback again)..."
run_equivalence_test replace_hier_mod2 sky130hd/work_around_yosys "None"
run_equivalence_test replace_hier_mod2 \
-lib_dir ./sky130hd/work_around_yosys/ \
-remove_cells "None"
4 changes: 3 additions & 1 deletion src/odb/test/replace_hier_mod6.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ proc do_swap { from_alu to_alu } {
estimate_parasitics -placement
report_checks -fields input_pins -through _001_
report_cell_usage _120_
run_equivalence_test $test_name ./sky130hd/work_around_yosys/ "None"
run_equivalence_test $test_name \
-lib_dir ./sky130hd/work_around_yosys/ \
-remove_cells "None"
} else {
puts "Failed to replace hier module"
}
Expand Down
4 changes: 3 additions & 1 deletion src/odb/test/replace_hier_mod_undo2.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ odb::dbDatabase_undoEco $block
report_cell_usage gcd_1/_552_
report_checks -through gcd_1/_carry_out_and_/B -fields input_pins

run_equivalence_test replace_hier_mod5 ./Nangate45/work_around_yosys/ "None"
run_equivalence_test replace_hier_mod5 \
-lib_dir ./Nangate45/work_around_yosys/ \
-remove_cells "None"
9 changes: 9 additions & 0 deletions src/rmp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ cc_library(
"src/annealing_strategy.h",
"src/delay_optimization_strategy.cpp",
"src/delay_optimization_strategy.h",
"src/genetic_strategy.cpp",
"src/genetic_strategy.h",
"src/gia.cpp",
"src/gia.h",
"src/logic_optimization_strategy.h",
"src/resynthesis_strategy.h",
"src/slack_tuning_strategy.cpp",
"src/slack_tuning_strategy.h",
"src/utils.cpp",
"src/utils.h",
"src/zero_slack_strategy.cpp",
Expand Down Expand Up @@ -52,6 +58,9 @@ cc_library(
"@boost.optional",
"@boost.phoenix",
"@boost.spirit",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/random",
],
)

Expand Down
39 changes: 39 additions & 0 deletions src/rmp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,45 @@ resynth_annealing
| `-revert_after` | After the given number of iterations that worsen slack, revert to best found solution. |
| `-initial_ops` | Size of the initial random solution (number of commands in the script for ABC). |

### Resynth with genetic slack tuning

Resynthesize parts of the design with an ABC script found via genetic algorithm.
An individual in a population is a series of operations on ABC's internal AIG data structure.
Each such operation is considered a gene. Genotype can be changed by a mutation with operations such
as adding, removing or swapping genes with a `mut_prob` probability. Individual can also be changed
by crossing two genes together with a `cross_prob` probability.
The optimization function is defined as the worst slack.

```tcl
resynth_genetic
[-corner corner]
[-slack_threshold slack_threshold]
[-seed seed]
[-pop_size pop_size]
[-mut_prob mut_prob]
[-cross_prob cross_prob]
[-tourn_prob tourn_prob]
[-tourn_size tourn_size]
[-iters iters]
[-initial_ops initial_ops]
```

#### Options

| Switch Name | Description |
| ----- | ----- |
| `-corner` | Process corner to use. |
| `-slack_threshold` | Specifies a (setup) timing slack value below which timing paths need to be analyzed for restructuring. The default value is `0`. |
| `-seed` | Seed to use for randomness. |
| `-pop_size` | Population size. |
| `-mut_prob` | Probability of applying mutation operator. |
| `-cross_prob` | Probability of applying crossover operator. |
| `-tourn_prob` | Tournament probability. |
| `-tourn_size` | Tournament size. |
| `-iters` | Number of iterations to run genetic algorithm. |
| `-initial_ops` | Size of the initial random solution (number of commands in the script for ABC). |


## Example scripts

Example scripts on running `rmp` for a sample design of `gcd` as follows:
Expand Down
29 changes: 29 additions & 0 deletions src/rmp/include/rmp/Restructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Restructure
void reset();
void resynth(sta::Corner* corner);
void resynthAnnealing(sta::Corner* corner);
void resynthGenetic(sta::Corner* corner);
void run(char* liberty_file_name,
float slack_threshold,
unsigned max_depth,
Expand All @@ -88,6 +89,23 @@ class Restructure
annealing_revert_after_ = revert_after;
}
void setAnnealingInitialOps(unsigned ops) { annealing_init_ops_ = ops; }
void setGeneticSeed(std::mt19937::result_type seed) { genetic_seed_ = seed; }
void setGeneticPopSize(unsigned pop_size) { genetic_pop_size_ = pop_size; }
void setGeneticMutProb(float mut_prob) { genetic_mut_prob_ = mut_prob; }
void setGeneticCrossProb(float cross_prob)
{
genetic_cross_prob_ = cross_prob;
}
void setGeneticTournSize(unsigned tourn_size)
{
genetic_tourn_size_ = tourn_size;
}
void setGeneticTournProb(float tourn_prob)
{
genetic_tourn_prob_ = tourn_prob;
}
void setGeneticIters(unsigned iters) { genetic_iters_ = iters; }
void setGeneticInitialOps(unsigned ops) { genetic_init_ops_ = ops; }
void setSlackThreshold(sta::Slack thresh) { slack_threshold_ = thresh; }
void setMode(const char* mode_name);
void setTieLoPort(sta::LibertyPort* loport);
Expand Down Expand Up @@ -129,6 +147,17 @@ class Restructure
unsigned annealing_iters_ = 100;
std::optional<unsigned> annealing_revert_after_;
unsigned annealing_init_ops_ = 10;

// Genetic
std::optional<std::mt19937::result_type> genetic_seed_;
unsigned genetic_pop_size_ = 4;
float genetic_mut_prob_ = 0.5;
float genetic_cross_prob_ = 0.5;
unsigned genetic_tourn_size_ = 4;
float genetic_tourn_prob_ = 0.8;
unsigned genetic_iters_ = 10;
unsigned genetic_init_ops_ = 10;

sta::Slack slack_threshold_ = 0;

std::string input_blif_file_name_;
Expand Down
6 changes: 6 additions & 0 deletions src/rmp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ add_library(rmp_lib
Restructure.cpp
annealing_strategy.cpp
delay_optimization_strategy.cpp
genetic_strategy.cpp
gia.cpp
slack_tuning_strategy.cpp
utils.cpp
zero_slack_strategy.cpp
)
Expand Down Expand Up @@ -48,6 +51,8 @@ target_include_directories(rmp
target_include_directories(rmp_lib
PUBLIC
../include
PRIVATE
.
)

target_link_libraries(rmp_lib
Expand All @@ -59,6 +64,7 @@ target_link_libraries(rmp_lib
utl_lib
cut
${ABC_LIBRARY}
absl_hash
)

target_link_libraries(rmp
Expand Down
17 changes: 17 additions & 0 deletions src/rmp/src/Restructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "cut/blif.h"
#include "db_sta/dbNetwork.hh"
#include "db_sta/dbSta.hh"
#include "genetic_strategy.h"
#include "odb/db.h"
#include "rsz/Resizer.hh"
#include "sta/Delay.hh"
Expand Down Expand Up @@ -102,6 +103,22 @@ void Restructure::resynthAnnealing(sta::Corner* corner)
open_sta_, name_generator_, resizer_, logger_);
}

void Restructure::resynthGenetic(sta::Corner* corner)
{
GeneticStrategy genetic_strategy(corner,
slack_threshold_,
genetic_seed_,
genetic_pop_size_,
genetic_mut_prob_,
genetic_cross_prob_,
genetic_tourn_size_,
genetic_tourn_prob_,
genetic_iters_,
genetic_init_ops_);
genetic_strategy.OptimizeDesign(
open_sta_, name_generator_, resizer_, logger_);
}

void Restructure::run(char* liberty_file_name,
float slack_threshold,
unsigned max_depth,
Expand Down
Loading