@@ -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+
14641497GCell* 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
19401973int64_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-
27372749void 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
30523061size_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
0 commit comments