Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider state-dependent leakage during sizing #6791

Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion src/rsz/include/rsz/Resizer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class Resizer : public dbStaState, public dbNetworkObserver
void invalidateParasitics(const Pin* pin, const Net* net);
void eraseParasitics(const Net* net);
void eliminateDeadLogic(bool clean_nets);
std::optional<float> cellLeakage(const LibertyCell* cell);
std::optional<float> cellLeakage(LibertyCell* cell);
// For debugging - calls getSwappableCells
void reportEquivalentCells(LibertyCell* base_cell, bool match_cell_footprint);

Expand Down Expand Up @@ -793,6 +793,7 @@ class Resizer : public dbStaState, public dbNetworkObserver
std::stack<InstanceTuple> cloned_gates_;
std::unordered_set<Instance*> cloned_inst_set_;
std::unordered_map<std::string, BufferData> removed_buffer_map_;
std::unordered_map<LibertyCell*, std::optional<float>> cell_leakage_cache_;

// Need to track all changes for buffer removal
InstanceSet all_sized_inst_set_;
Expand Down
70 changes: 49 additions & 21 deletions src/rsz/src/Resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "sta/Graph.hh"
#include "sta/GraphDelayCalc.hh"
#include "sta/InputDrive.hh"
#include "sta/LeakagePower.hh"
#include "sta/Liberty.hh"
#include "sta/Network.hh"
#include "sta/Parasitics.hh"
Expand Down Expand Up @@ -132,6 +133,8 @@ using sta::VertexOutEdgeIterator;

using sta::BufferUse;
using sta::CLOCK;
using sta::LeakagePower;
using sta::LeakagePowerSeq;

Resizer::Resizer()
: recover_power_(new RecoverPower(this)),
Expand Down Expand Up @@ -1281,17 +1284,39 @@ void Resizer::resizePreamble()
findTargetLoads();
}

// Convert sta results to std::optional
std::optional<float> Resizer::cellLeakage(const LibertyCell* cell)
// Convert static cell leakage to std::optional.
// For state-dependent leakage, compute the average
// across all the power states. Cache the leakage for
// runtime.
std::optional<float> Resizer::cellLeakage(LibertyCell* cell)
{
float leakage;
auto it = cell_leakage_cache_.find(cell);
if (it != cell_leakage_cache_.end()) {
return it->second;
}

float leakage = 0.0;
bool exists;
cell->leakagePower(leakage, exists);
std::optional<float> value;
if (exists) {
value = leakage;
cell_leakage_cache_[cell] = leakage;
return leakage;
}

// Compute average leakage across power conds for state-dependent leakage
LeakagePowerSeq* leakages = cell->leakagePowers();
if (!leakages || leakages->empty()) {
cell_leakage_cache_[cell] = std::nullopt;
return std::nullopt;
}
return value;

float total_leakage = 0.0;
for (LeakagePower* leak : *leakages) {
total_leakage += leak->power();
}
leakage = total_leakage / leakages->size();
cell_leakage_cache_[cell] = leakage;
return leakage;
}

// For debugging
Expand All @@ -1305,19 +1330,23 @@ void Resizer::reportEquivalentCells(LibertyCell* base_cell,

// Sort equiv cells by ascending area and leakage
// STA sorts them by drive resistance
std::sort(equiv_cells.begin(),
equiv_cells.end(),
[this](const LibertyCell* a, const LibertyCell* b) {
if (!sta::fuzzyEqual(a->area(), b->area())) {
return a->area() < b->area();
}
std::optional<float> leakage_a = this->cellLeakage(a);
std::optional<float> leakage_b = this->cellLeakage(b);
if (leakage_a && leakage_b) {
return *leakage_a < *leakage_b;
}
return leakage_a.has_value();
});
std::stable_sort(equiv_cells.begin(),
equiv_cells.end(),
[this](LibertyCell* a, LibertyCell* b) {
dbMaster* master_a = this->getDbNetwork()->staToDb(a);
dbMaster* master_b = this->getDbNetwork()->staToDb(b);
if (master_a && master_b) {
if (master_a->getArea() != master_b->getArea()) {
return master_a->getArea() < master_b->getArea();
}
}
std::optional<float> leakage_a = this->cellLeakage(a);
std::optional<float> leakage_b = this->cellLeakage(b);
if (leakage_a && leakage_b) {
return *leakage_a < *leakage_b;
}
return leakage_a.has_value() && !leakage_b.has_value();
});

logger_->report(
"The following {} cells are equivalent to {}{}",
Expand Down Expand Up @@ -1403,7 +1432,7 @@ LibertyCellSeq Resizer::getSwappableCells(LibertyCell* source_cell)
}

dbMaster* master = db_network_->staToDb(source_cell);
if (master && !master->isCore()) {
if (master == nullptr || !master->isCore()) {
swappable_cells_cache_[source_cell] = {};
return {};
}
Expand Down Expand Up @@ -1673,7 +1702,6 @@ int Resizer::resizeToTargetSlew(const Pin* drvr_pin)
if (target_cell != cell) {
debugPrint(logger_,
RSZ,

"resize",
2,
"{} {} -> {}",
Expand Down