Skip to content

Commit

Permalink
rsz: Number of repairs based on path slack
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Bieganski <[email protected]>
  • Loading branch information
kbieganski committed Jan 8, 2025
1 parent efcf6a0 commit 8cc138c
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/rsz/include/rsz/Resizer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class Resizer : public dbStaState
bool repairSetup(double setup_margin,
double repair_tns_end_percent,
int max_passes,
int max_repairs_per_iter,
bool match_cell_footprint,
bool verbose,
bool skip_pin_swap,
Expand Down
62 changes: 45 additions & 17 deletions src/rsz/src/RepairSetup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void RepairSetup::init()
bool RepairSetup::repairSetup(const float setup_slack_margin,
const double repair_tns_end_percent,
const int max_passes,
const int max_repairs_per_iter,
const bool verbose,
const bool skip_pin_swap,
const bool skip_gate_cloning,
Expand All @@ -100,6 +101,7 @@ bool RepairSetup::repairSetup(const float setup_slack_margin,
bool repaired = false;
init();
constexpr int digits = 3;
max_repairs_per_iter_ = max_repairs_per_iter;
inserted_buffer_count_ = 0;
split_load_buffer_count_ = 0;
resize_count_ = 0;
Expand Down Expand Up @@ -174,7 +176,12 @@ bool RepairSetup::repairSetup(const float setup_slack_margin,
printProgress(opto_iteration, false, false, false, num_viols);
}
float fix_rate_threshold = inc_fix_rate_threshold_;
if (!violating_ends.empty()) {
min_viol_ = -violating_ends.back().second;
max_viol_ = -violating_ends.front().second;
}
for (const auto& end_original_slack : violating_ends) {
fallback_ = false;
Vertex* end = end_original_slack.first;
Slack end_slack = sta_->vertexSlack(end, max_);
Slack worst_slack;
Expand Down Expand Up @@ -325,6 +332,7 @@ bool RepairSetup::repairSetup(const float setup_slack_margin,
// Progress, Save checkpoint so we can back up to here.
resizer_->journalBegin();
} else {
fallback_ = true;
// Allow slack to increase to get out of local minima.
// Do not update prev_end_slack so it saves the high water mark.
decreasing_slack_passes++;
Expand Down Expand Up @@ -439,6 +447,7 @@ bool RepairSetup::repairSetup(const float setup_slack_margin,
void RepairSetup::repairSetup(const Pin* end_pin)
{
init();
max_repairs_per_iter_ = 1;
inserted_buffer_count_ = 0;
resize_count_ = 0;
swap_pin_count_ = 0;
Expand Down Expand Up @@ -495,7 +504,7 @@ bool RepairSetup::repairPath(PathRef& path,
const float setup_slack_margin)
{
PathExpanded expanded(&path, sta_);
bool changed = false;
int changed = 0;

if (expanded.size() > 1) {
const int path_length = expanded.size();
Expand Down Expand Up @@ -537,7 +546,26 @@ bool RepairSetup::repairPath(PathRef& path,
|| (pair1.second == pair2.second && pair1.first > pair2.first);
});
// Attack gates with largest load delays first.
int repairs_per_iter = 1;
if (max_viol_ - min_viol_ != 0.0) {
repairs_per_iter
+= std::round((max_repairs_per_iter_ - 1) * (-path_slack - min_viol_)
/ (max_viol_ - min_viol_));
}
if (fallback_) {
repairs_per_iter = 1;
}
debugPrint(logger_,
RSZ,
"repair_setup",
3,
"Path slack: {}, repairs: {}",
delayAsString(path_slack, sta_, 3),
repairs_per_iter);
for (const auto& [drvr_index, ignored] : load_delays) {
if (changed >= repairs_per_iter) {
break;
}
const PathRef* drvr_path = expanded.path(drvr_index);
Vertex* drvr_vertex = drvr_path->vertex(sta_);
const Pin* drvr_pin = drvr_vertex->pin();
Expand All @@ -561,24 +589,21 @@ bool RepairSetup::repairPath(PathRef& path,
drvr_index,
&expanded,
setup_slack_margin)) {
Pin* drvr_pin = drvr_path->pin(this);
Instance* drvr = network_->instance(drvr_pin);
buf_to_remove_.push_back(drvr);
changed = true;
break;
changed++;
continue;
}
}

if (upsizeDrvr(drvr_path, drvr_index, &expanded)) {
changed = true;
break;
changed++;
continue;
}

// Pin swapping
if (!skip_pin_swap) {
if (swapPins(drvr_path, drvr_index, &expanded)) {
changed = true;
break;
changed++;
continue;
}
}

Expand All @@ -600,8 +625,8 @@ bool RepairSetup::repairPath(PathRef& path,
network_->pathName(drvr_pin),
rebuffer_count);
inserted_buffer_count_ += rebuffer_count;
changed = true;
break;
changed++;
continue;
}
}

Expand All @@ -612,8 +637,8 @@ bool RepairSetup::repairPath(PathRef& path,
db_network_->instance(drvr_pin))
== resizer_->inserted_buffer_set_.end()
&& cloneDriver(drvr_path, drvr_index, path_slack, &expanded)) {
changed = true;
break;
changed++;
continue;
}

if (!skip_buffering) {
Expand All @@ -623,8 +648,8 @@ bool RepairSetup::repairPath(PathRef& path,
const int init_buffer_count = inserted_buffer_count_;
splitLoads(drvr_path, drvr_index, path_slack, &expanded);
split_load_buffer_count_ = inserted_buffer_count_ - init_buffer_count;
changed = true;
break;
changed++;
continue;
}
}
}
Expand All @@ -633,7 +658,7 @@ bool RepairSetup::repairPath(PathRef& path,
}
buf_to_remove_.clear();
}
return changed;
return changed > 0;
}

void RepairSetup::debugCheckMultipleBuffers(PathRef& path,
Expand Down Expand Up @@ -866,6 +891,7 @@ bool RepairSetup::removeDrvr(const PathRef* drvr_path,
}

if (resizer_->canRemoveBuffer(drvr, /* honorDontTouch */ true)) {
buf_to_remove_.push_back(drvr);
removed_buffer_count_++;
return true;
}
Expand Down Expand Up @@ -1923,6 +1949,7 @@ void RepairSetup::repairSetupLastGasp(const OptoParams& params, int& num_viols)
float fix_rate_threshold = inc_fix_rate_threshold_;

for (const auto& end_original_slack : violating_ends) {
fallback_ = false;
Vertex* end = end_original_slack.first;
Slack end_slack = sta_->vertexSlack(end, max_);
Slack worst_slack;
Expand Down Expand Up @@ -2007,6 +2034,7 @@ void RepairSetup::repairSetupLastGasp(const OptoParams& params, int& num_viols)
resizer_->journalEnd();
resizer_->journalBegin();
} else {
fallback_ = true;
resizer_->journalRestore(resize_count_,
inserted_buffer_count_,
cloned_gate_count_,
Expand Down
5 changes: 5 additions & 0 deletions src/rsz/src/RepairSetup.hh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class RepairSetup : public sta::dbStaState
// reduce tns (0.0-1.0).
double repair_tns_end_percent,
int max_passes,
int max_repairs_per_iter,
bool verbose,
bool skip_pin_swap,
bool skip_gate_cloning,
Expand Down Expand Up @@ -242,6 +243,10 @@ class RepairSetup : public sta::dbStaState
const Corner* corner_ = nullptr;
LibertyPort* drvr_port_ = nullptr;

bool fallback_ = false;
float min_viol_ = 0.0;
float max_viol_ = 0.0;
int max_repairs_per_iter_ = 1;
int resize_count_ = 0;
int inserted_buffer_count_ = 0;
int split_load_buffer_count_ = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/rsz/src/Resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3146,6 +3146,7 @@ void Resizer::cloneClkInverter(Instance* inv)
bool Resizer::repairSetup(double setup_margin,
double repair_tns_end_percent,
int max_passes,
int max_repairs_per_iter,
bool match_cell_footprint,
bool verbose,
bool skip_pin_swap,
Expand All @@ -3164,6 +3165,7 @@ bool Resizer::repairSetup(double setup_margin,
return repair_setup_->repairSetup(setup_margin,
repair_tns_end_percent,
max_passes,
max_repairs_per_iter,
verbose,
skip_pin_swap,
skip_gate_cloning,
Expand Down
4 changes: 3 additions & 1 deletion src/rsz/src/Resizer.i
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ bool
repair_setup(double setup_margin,
double repair_tns_end_percent,
int max_passes,
int max_repairs_per_iter,
bool match_cell_footprint, bool verbose,
bool skip_pin_swap, bool skip_gate_cloning,
bool skip_buffering, bool skip_buffer_removal,
Expand All @@ -622,7 +623,8 @@ repair_setup(double setup_margin,
ensureLinked();
Resizer *resizer = getResizer();
return resizer->repairSetup(setup_margin, repair_tns_end_percent,
max_passes, match_cell_footprint, verbose,
max_passes, max_repairs_per_iter,
match_cell_footprint, verbose,
skip_pin_swap, skip_gate_cloning,
skip_buffering, skip_buffer_removal,
skip_last_gasp);
Expand Down
10 changes: 8 additions & 2 deletions src/rsz/src/Resizer.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,14 @@ sta::define_cmd_args "repair_timing" {[-setup] [-hold]\
[-max_buffer_percent buffer_percent]\
[-max_utilization util] \
[-match_cell_footprint] \
[-max_repairs_per_iter max_repairs_per_iter]\
[-verbose]}

proc repair_timing { args } {
sta::parse_key_args "repair_timing" args \
keys {-setup_margin -hold_margin -slack_margin \
-libraries -max_utilization -max_buffer_percent \
-recover_power -repair_tns -max_passes} \
-recover_power -repair_tns -max_passes -max_repairs_per_iter} \
flags {-setup -hold -allow_setup_violations -skip_pin_swap -skip_gate_cloning \
-skip_buffering -skip_buffer_removal -skip_last_gasp -match_cell_footprint \
-verbose}
Expand Down Expand Up @@ -635,6 +636,11 @@ proc repair_timing { args } {
rsz::set_parasitics_src "detailed_routing"
}

set max_repairs_per_iter 1
if { [info exists keys(-max_repairs_per_iter)] } {
set max_repairs_per_iter $keys(-max_repairs_per_iter)
}

sta::check_argc_eq0 "repair_timing" $args
rsz::check_parasitics

Expand All @@ -646,7 +652,7 @@ proc repair_timing { args } {
} else {
if { $setup } {
set repaired_setup [rsz::repair_setup $setup_margin $repair_tns_end_percent $max_passes \
$match_cell_footprint $verbose \
$max_repairs_per_iter $match_cell_footprint $verbose \
$skip_pin_swap $skip_gate_cloning $skip_buffering \
$skip_buffer_removal $skip_last_gasp]
}
Expand Down

0 comments on commit 8cc138c

Please sign in to comment.