Skip to content

Commit ce61781

Browse files
authored
Merge pull request The-OpenROAD-Project#7395 from gudeh/gpl-update-routability-vector
gpl: update routability vector after instance removal
2 parents ab45717 + 86dc1f4 commit ce61781

File tree

6 files changed

+109
-107
lines changed

6 files changed

+109
-107
lines changed

src/gpl/src/nesterovBase.cpp

Lines changed: 76 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,9 @@ void GCell::print(utl::Logger* logger, bool print_only_name = true) const
282282
}
283283
}
284284

285-
void GCell::printToFile(const std::string& filename,
286-
bool print_only_name = true) const
285+
void GCell::printToFile(std::ostream& out, bool print_only_name) const
287286
{
288-
std::ofstream out(filename, std::ios::app);
289-
if (!out.is_open()) {
287+
if (!out) {
290288
return;
291289
}
292290

@@ -307,8 +305,6 @@ void GCell::printToFile(const std::string& filename,
307305
gradientX_,
308306
gradientY_);
309307
}
310-
311-
out.close();
312308
}
313309

314310
////////////////////////////////////////////////
@@ -1461,6 +1457,43 @@ int64_t NesterovBaseCommon::getHpwl()
14611457
return hpwl;
14621458
}
14631459

1460+
void NesterovBaseCommon::resetMinRcCellSize()
1461+
{
1462+
minRcCellSize_.clear();
1463+
minRcCellSize_.shrink_to_fit();
1464+
}
1465+
1466+
void NesterovBaseCommon::resizeMinRcCellSize()
1467+
{
1468+
minRcCellSize_.resize(nbc_gcells_.size(), std::make_pair(0, 0));
1469+
}
1470+
1471+
void NesterovBaseCommon::updateMinRcCellSize()
1472+
{
1473+
for (auto& gCell : nbc_gcells_) {
1474+
if (!gCell->isStdInstance()) {
1475+
continue;
1476+
}
1477+
1478+
minRcCellSize_[&gCell - nbc_gcells_.data()]
1479+
= std::make_pair(gCell->dx(), gCell->dy());
1480+
}
1481+
}
1482+
1483+
void NesterovBaseCommon::revertGCellSizeToMinRc()
1484+
{
1485+
// revert back the gcell sizes
1486+
for (auto& gCell : nbc_gcells_) {
1487+
if (!gCell->isStdInstance()) {
1488+
continue;
1489+
}
1490+
1491+
int idx = &gCell - nbc_gcells_.data();
1492+
1493+
gCell->setSize(minRcCellSize_[idx].first, minRcCellSize_[idx].second);
1494+
}
1495+
}
1496+
14641497
GCell* NesterovBaseCommon::getGCellByIndex(size_t i)
14651498
{
14661499
if (i >= gCellStor_.size()) {
@@ -1932,9 +1965,9 @@ int NesterovBase::fillerDy() const
19321965
return fillerDy_;
19331966
}
19341967

1935-
int NesterovBase::fillerCnt() const
1968+
int NesterovBase::getFillerCnt() const
19361969
{
1937-
return static_cast<int>(gCellFillers_.size());
1970+
return static_cast<int>(fillerStor_.size());
19381971
}
19391972

19401973
int64_t NesterovBase::fillerCellArea() const
@@ -2713,27 +2746,6 @@ void NesterovBase::nesterovAdjustPhi()
27132746
}
27142747
}
27152748

2716-
void NesterovBase::cutFillerCoordinates()
2717-
{
2718-
curSLPCoordi_.resize(fillerCnt());
2719-
curSLPWireLengthGrads_.resize(fillerCnt());
2720-
curSLPDensityGrads_.resize(fillerCnt());
2721-
curSLPSumGrads_.resize(fillerCnt());
2722-
2723-
nextSLPCoordi_.resize(fillerCnt());
2724-
nextSLPWireLengthGrads_.resize(fillerCnt());
2725-
nextSLPDensityGrads_.resize(fillerCnt());
2726-
nextSLPSumGrads_.resize(fillerCnt());
2727-
2728-
prevSLPCoordi_.resize(fillerCnt());
2729-
prevSLPWireLengthGrads_.resize(fillerCnt());
2730-
prevSLPDensityGrads_.resize(fillerCnt());
2731-
prevSLPSumGrads_.resize(fillerCnt());
2732-
2733-
curCoordi_.resize(fillerCnt());
2734-
nextCoordi_.resize(fillerCnt());
2735-
}
2736-
27372749
void NesterovBase::snapshot()
27382750
{
27392751
if (isConverged_) {
@@ -3000,9 +3012,7 @@ void NesterovBase::updateGCellState(float wlCoeffX, float wlCoeffY)
30003012
new_instances.clear();
30013013
}
30023014

3003-
void NesterovBase::createCbkGCell(odb::dbInst* db_inst,
3004-
size_t stor_index,
3005-
RouteBase* rb)
3015+
void NesterovBase::createCbkGCell(odb::dbInst* db_inst, size_t stor_index)
30063016
{
30073017
debugPrint(log_,
30083018
GPL,
@@ -3039,7 +3049,6 @@ void NesterovBase::createCbkGCell(odb::dbInst* db_inst,
30393049
snapshotSLPSumGrads_.emplace_back();
30403050
}
30413051

3042-
rb->pushBackMinRcCellSize(gcell->dx(), gcell->dy());
30433052
} else {
30443053
debugPrint(log_,
30453054
GPL,
@@ -3051,7 +3060,7 @@ void NesterovBase::createCbkGCell(odb::dbInst* db_inst,
30513060

30523061
size_t NesterovBaseCommon::createCbkGCell(odb::dbInst* db_inst)
30533062
{
3054-
debugPrint(log_, GPL, "callbacks", 2, "NBC createGCell");
3063+
debugPrint(log_, GPL, "callbacks", 2, "NBC createCbkGCell");
30553064
Instance gpl_inst(db_inst,
30563065
pbc_->padLeft() * pbc_->siteSizeX(),
30573066
pbc_->padRight() * pbc_->siteSizeX(),
@@ -3061,6 +3070,7 @@ size_t NesterovBaseCommon::createCbkGCell(odb::dbInst* db_inst)
30613070
pb_insts_stor_.push_back(gpl_inst);
30623071
GCell gcell(&pb_insts_stor_.back());
30633072
gCellStor_.push_back(gcell);
3073+
minRcCellSize_.emplace_back(gcell.dx(), gcell.dy());
30643074
GCell* gcell_ptr = &gCellStor_.back();
30653075
gCellMap_[gcell_ptr->insts()[0]] = gcell_ptr;
30663076
db_inst_to_nbc_index_map_[db_inst] = gCellStor_.size() - 1;
@@ -3175,18 +3185,17 @@ std::pair<odb::dbInst*, size_t> NesterovBaseCommon::destroyCbkGCell(
31753185
}
31763186

31773187
size_t index_remove = it->second;
3178-
size_t last_index = gCellStor_.size() - 1;
3179-
31803188
db_inst_to_nbc_index_map_.erase(it);
31813189

31823190
std::pair<odb::dbInst*, size_t> replacement;
3191+
size_t last_index = gCellStor_.size() - 1;
31833192

31843193
if (index_remove != last_index) {
31853194
std::swap(gCellStor_[index_remove], gCellStor_[last_index]);
3195+
std::swap(minRcCellSize_[index_remove], minRcCellSize_[last_index]);
31863196

31873197
odb::dbInst* swapped_inst = gCellStor_[index_remove].insts()[0]->dbInst();
31883198
db_inst_to_nbc_index_map_[swapped_inst] = index_remove;
3189-
31903199
replacement = {swapped_inst, index_remove};
31913200
}
31923201

@@ -3195,6 +3204,7 @@ std::pair<odb::dbInst*, size_t> NesterovBaseCommon::destroyCbkGCell(
31953204
delta_area_ -= area_change;
31963205

31973206
gCellStor_.pop_back();
3207+
minRcCellSize_.pop_back();
31983208
return replacement;
31993209
}
32003210

@@ -3353,21 +3363,44 @@ void NesterovBaseCommon::printGCells()
33533363
}
33543364
}
33553365

3356-
void NesterovBaseCommon::printGCellsToFile(const std::string& filename)
3366+
void NesterovBaseCommon::printGCellsToFile(const std::string& filename,
3367+
bool print_only_name,
3368+
bool also_print_minRc)
33573369
{
33583370
std::ofstream out(filename);
33593371
if (!out.is_open()) {
33603372
return;
33613373
}
33623374

33633375
out << "gCellStor_.size(): " << gCellStor_.size() << "\n";
3364-
out.close(); // reuse printToFile which appends
3376+
out.close();
3377+
3378+
std::ofstream out_append(filename, std::ios::app);
3379+
if (!out_append.is_open()) {
3380+
return;
3381+
}
33653382

33663383
for (size_t i = 0; i < gCellStor_.size(); ++i) {
3367-
std::ofstream out_idx(filename, std::ios::app);
3368-
out_idx << fmt::format("idx:{}\n", i);
3369-
out_idx.close();
3370-
gCellStor_[i].printToFile(filename);
3384+
out_append << fmt::format("idx:{}\n", i);
3385+
gCellStor_[i].printToFile(out_append, print_only_name);
3386+
}
3387+
3388+
out_append.close();
3389+
3390+
if (also_print_minRc) {
3391+
std::string minrc_filename = filename + ".minrc";
3392+
std::ofstream minrc_out(minrc_filename);
3393+
if (!minrc_out.is_open()) {
3394+
return;
3395+
}
3396+
3397+
for (size_t i = 0; i < minRcCellSize_.size(); ++i) {
3398+
const auto& min_rc = minRcCellSize_[i];
3399+
minrc_out << fmt::format(
3400+
"idx:{} minRc: {} {}\n", i, min_rc.first, min_rc.second);
3401+
}
3402+
3403+
minrc_out.close();
33713404
}
33723405
}
33733406

src/gpl/src/nesterovBase.h

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class GCell
111111
bool contains(odb::dbInst* db_inst) const;
112112

113113
void print(utl::Logger* logger, bool print_only_name) const;
114-
void printToFile(const std::string& filename, bool print_only_name) const;
114+
void printToFile(std::ostream& out, bool print_only_name = true) const;
115115

116116
private:
117117
std::vector<Instance*> insts_;
@@ -838,6 +838,11 @@ class NesterovBaseCommon
838838
void moveGCell(odb::dbInst* db_inst);
839839
void fixPointers();
840840

841+
void resetMinRcCellSize();
842+
void resizeMinRcCellSize();
843+
void updateMinRcCellSize();
844+
void revertGCellSizeToMinRc();
845+
841846
GCell& getGCell(size_t index) { return gCellStor_[index]; }
842847

843848
size_t getGCellIndex(const GCell* gCell) const
@@ -846,7 +851,9 @@ class NesterovBaseCommon
846851
}
847852

848853
void printGCells();
849-
void printGCellsToFile(const std::string& filename);
854+
void printGCellsToFile(const std::string& filename,
855+
bool print_only_name = true,
856+
bool also_print_minRc = false);
850857
void printGPins();
851858

852859
// TODO do this for each region? Also, manage this properly if other callbacks
@@ -866,6 +873,8 @@ class NesterovBaseCommon
866873
std::vector<GPin> gPinStor_;
867874

868875
std::vector<GCell*> nbc_gcells_;
876+
// For usage in routability mode, parallel to nbc_gcells_
877+
std::vector<std::pair<int, int>> minRcCellSize_;
869878
std::vector<GNet*> gNets_;
870879
std::vector<GPin*> gPins_;
871880

@@ -905,8 +914,6 @@ class NesterovBase
905914
GCell& getFillerGCell(size_t index) { return fillerStor_[index]; }
906915

907916
const std::vector<GCellHandle>& getGCells() const { return nb_gcells_; }
908-
const std::vector<GCell*>& gCellInsts() const { return gCellInsts_; }
909-
const std::vector<GCell*>& gCellFillers() const { return gCellFillers_; }
910917

911918
float getSumOverflow() const { return sumOverflow_; }
912919
float getSumOverflowUnscaled() const { return sumOverflowUnscaled_; }
@@ -935,7 +942,7 @@ class NesterovBase
935942
// will be used in Routability-driven loop
936943
int fillerDx() const;
937944
int fillerDy() const;
938-
int fillerCnt() const;
945+
int getFillerCnt() const;
939946
int64_t fillerCellArea() const;
940947
int64_t whiteSpaceArea() const;
941948
int64_t movableArea() const;
@@ -1040,7 +1047,6 @@ class NesterovBase
10401047
void updateNextIter(int iter);
10411048
void setTrueReprintIterHeader() { reprint_iter_header = true; }
10421049
float getPhiCoef(float scaledDiffHpwl) const;
1043-
void cutFillerCoordinates();
10441050

10451051
void snapshot();
10461052

@@ -1063,7 +1069,7 @@ class NesterovBase
10631069

10641070
bool isDiverged() const { return isDiverged_; }
10651071

1066-
void createCbkGCell(odb::dbInst* db_inst, size_t stor_index, RouteBase* rb);
1072+
void createCbkGCell(odb::dbInst* db_inst, size_t stor_index);
10671073
void destroyCbkGCell(odb::dbInst* db_inst);
10681074
void destroyFillerGCell(size_t index_remove);
10691075

@@ -1092,10 +1098,7 @@ class NesterovBase
10921098
int64_t macroInstsArea_ = 0;
10931099

10941100
std::vector<GCell> fillerStor_;
1095-
10961101
std::vector<GCellHandle> nb_gcells_;
1097-
std::vector<GCell*> gCellInsts_;
1098-
std::vector<GCell*> gCellFillers_;
10991102

11001103
std::unordered_map<odb::dbInst*, size_t> db_inst_to_nb_index_map_;
11011104

@@ -1134,8 +1137,18 @@ class NesterovBase
11341137
// save initial coordinates -- needed for RD
11351138
std::vector<FloatPoint> initCoordi_;
11361139

1137-
// densityPenalty stor
1138-
std::vector<float> densityPenaltyStor_;
1140+
// Snapshot data for routability, parallel vectors
1141+
std::vector<FloatPoint> snapshotCoordi_;
1142+
std::vector<FloatPoint> snapshotSLPCoordi_;
1143+
std::vector<FloatPoint> snapshotSLPSumGrads_;
1144+
float snapshotDensityPenalty_ = 0;
1145+
float snapshotStepLength_ = 0;
1146+
1147+
// For destroying elements in parallel vectors
1148+
void swapAndPop(std::vector<FloatPoint>& vec,
1149+
size_t remove_index,
1150+
size_t last_index);
1151+
void swapAndPopParallelVectors(size_t remove_index, size_t last_index);
11391152

11401153
float wireLengthGradSum_ = 0;
11411154
float densityGradSum_ = 0;
@@ -1169,19 +1182,7 @@ class NesterovBase
11691182
bool isConverged_ = false;
11701183
bool reprint_iter_header;
11711184

1172-
// Snapshot data for routability, parallel vectors
1173-
std::vector<FloatPoint> snapshotCoordi_;
1174-
std::vector<FloatPoint> snapshotSLPCoordi_;
1175-
std::vector<FloatPoint> snapshotSLPSumGrads_;
1176-
float snapshotDensityPenalty_ = 0;
1177-
float snapshotStepLength_ = 0;
1178-
11791185
void initFillerGCells();
1180-
1181-
void swapAndPop(std::vector<FloatPoint>& vec,
1182-
size_t remove_index,
1183-
size_t last_index);
1184-
void swapAndPopParallelVectors(size_t remove_index, size_t last_index);
11851186
};
11861187

11871188
inline std::vector<Bin>& NesterovBase::bins()

src/gpl/src/nesterovPlace.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,6 @@ int NesterovPlace::doNesterovPlace(int start_iter)
654654

655655
// if routability is needed
656656
if (is_routability_need_ || isRevertInitNeeded) {
657-
// cutFillerCoordinates();
658-
659657
// revert back the current density penality
660658
curA = route_snapshotA;
661659
wireLengthCoefX_ = route_snapshot_WlCoefX;
@@ -775,13 +773,13 @@ nesterovDbCbk::nesterovDbCbk(NesterovPlace* nesterov_place)
775773
{
776774
}
777775

778-
void NesterovPlace::createGCell(odb::dbInst* db_inst)
776+
void NesterovPlace::createCbkGCell(odb::dbInst* db_inst)
779777
{
780778
auto gcell_index = nbc_->createCbkGCell(db_inst);
781779
for (auto& nesterov : nbVec_) {
782780
// TODO: manage regions, not every NB should create a
783781
// gcell.
784-
nesterov->createCbkGCell(db_inst, gcell_index, rb_.get());
782+
nesterov->createCbkGCell(db_inst, gcell_index);
785783
}
786784
}
787785

@@ -844,7 +842,7 @@ void nesterovDbCbk::inDbPostMoveInst(odb::dbInst* db_inst)
844842

845843
void nesterovDbCbk::inDbInstCreate(odb::dbInst* db_inst)
846844
{
847-
nesterov_place_->createGCell(db_inst);
845+
nesterov_place_->createCbkGCell(db_inst);
848846
}
849847

850848
// TODO: use the region to create new gcell.

0 commit comments

Comments
 (0)