@@ -125,7 +125,7 @@ void GCell::updateLocations()
125125 bbox.mergeInit ();
126126 int64_t inst_area = 0 ;
127127 for (Instance* inst : insts_) {
128- inst_area += inst->area ();
128+ inst_area += inst->getArea ();
129129 bbox.merge ({inst->lx (), inst->ly (), inst->ux (), inst->uy ()});
130130 }
131131 odb::Rect core_area = insts_[0 ]->dbInst ()->getBlock ()->getCoreArea ();
@@ -1070,6 +1070,11 @@ NesterovBaseCommon::NesterovBaseCommon(NesterovBaseVars nbVars,
10701070 }
10711071 }
10721072
1073+ // Instance extension from pin density done in placerBase construction
1074+ if (log_->debugCheck (GPL, " extendPinDensity" , 1 )) {
1075+ reportInstanceExtensionByPinDensity ();
1076+ }
1077+
10731078 // TODO:
10741079 // at this moment, GNet and GPin is equal to
10751080 // Net and Pin
@@ -1516,7 +1521,7 @@ void NesterovBaseCommon::revertGCellSizeToMinRc()
15161521 int dx = rect.dx ();
15171522 int dy = rect.dy ();
15181523
1519- if (rect.area () > gCell ->insts ()[0 ]->area ()) {
1524+ if (rect.area () > gCell ->insts ()[0 ]->getArea ()) {
15201525 gCell ->setSize (dx, dy, GCell::GCellChange::kRoutability );
15211526 } else {
15221527 gCell ->setSize (dx, dy, GCell::GCellChange::kNone );
@@ -1683,6 +1688,179 @@ void NesterovBaseCommon::fixPointers()
16831688 }
16841689}
16851690
1691+ void NesterovBaseCommon::reportInstanceExtensionByPinDensity () const
1692+ {
1693+ int64_t total_original_area = 0 ;
1694+ int64_t total_extended_area = 0 ;
1695+ int64_t total_area_diff = 0 ;
1696+ int increased_instance_count = 0 ;
1697+ int64_t increased_area = 0 ;
1698+ int decreased_instance_count = 0 ;
1699+ int64_t decreased_area = 0 ;
1700+ int unchanged_instance_count = 0 ;
1701+ int total_instance_count = 0 ;
1702+ struct MasterStats
1703+ {
1704+ int instance_count = 0 ;
1705+ int pin_count = 0 ;
1706+ double total_original_area = 0 ;
1707+ double total_extended_area = 0 ;
1708+ float original_area_per_pin = 0.0 ;
1709+ float extended_area_per_pin = 0.0 ;
1710+ float area_diff = 0.0 ;
1711+ };
1712+ static std::unordered_map<std::string, struct MasterStats > master_stats_map;
1713+
1714+ odb::dbBlock* block = pbc_->db ()->getChip ()->getBlock ();
1715+
1716+ for (const GCell& gcell : gCellStor_ ) {
1717+ if (!gcell.isInstance ()) {
1718+ continue ;
1719+ }
1720+ odb::dbInst* db_inst = gcell.insts ()[0 ]->dbInst ();
1721+ odb::dbBox* bbox = db_inst->getBBox ();
1722+ if (!bbox) {
1723+ continue ;
1724+ }
1725+ ++total_instance_count;
1726+ int orig_dx = bbox->getDX ();
1727+ int orig_dy = bbox->getDY ();
1728+ int64_t orig_area
1729+ = static_cast <int64_t >(orig_dx) * static_cast <int64_t >(orig_dy);
1730+
1731+ int ext_dx = gcell.ux () - gcell.lx ();
1732+ int ext_dy = gcell.uy () - gcell.ly ();
1733+ int64_t ext_area
1734+ = static_cast <int64_t >(ext_dx) * static_cast <int64_t >(ext_dy);
1735+
1736+ total_original_area += orig_area;
1737+ total_extended_area += ext_area;
1738+ int64_t area_diff = ext_area - orig_area;
1739+ total_area_diff += area_diff;
1740+
1741+ if (area_diff > 0 ) {
1742+ ++increased_instance_count;
1743+ increased_area += area_diff;
1744+ } else if (area_diff < 0 ) {
1745+ ++decreased_instance_count;
1746+ decreased_area += -area_diff;
1747+ } else {
1748+ ++unchanged_instance_count;
1749+ }
1750+
1751+ // Collect per-master statistics
1752+ odb::dbMaster* master = db_inst->getMaster ();
1753+ std::string master_name = master->getName ();
1754+ auto & stats = master_stats_map[master_name];
1755+ stats.instance_count += 1 ;
1756+ if (stats.pin_count == 0 ) {
1757+ stats.pin_count = db_inst->getITerms ().size ();
1758+ }
1759+ stats.total_original_area = block->dbuAreaToMicrons (orig_area);
1760+ stats.total_extended_area = block->dbuAreaToMicrons (ext_area);
1761+
1762+ // Save area per pin
1763+ int pin_count = db_inst->getITerms ().size ();
1764+ if (pin_count > 0 ) {
1765+ stats.original_area_per_pin
1766+ = block->dbuAreaToMicrons (orig_area) / pin_count;
1767+ stats.extended_area_per_pin
1768+ = block->dbuAreaToMicrons (ext_area) / pin_count;
1769+ }
1770+ // Populate area_diff as the percentage difference between extended and
1771+ // original area
1772+ if (orig_area != 0 ) {
1773+ stats.area_diff = 100 .0f
1774+ * (static_cast <float >(ext_area - orig_area)
1775+ / static_cast <float >(orig_area));
1776+ } else {
1777+ stats.area_diff = 0 .0f ;
1778+ }
1779+ }
1780+
1781+ // Log per-master statistics
1782+ log_->report (" NB Per-master statistics:" );
1783+ for (const auto & entry : master_stats_map) {
1784+ const std::string& master_name = entry.first ;
1785+ const MasterStats& stats = entry.second ;
1786+ log_->report (
1787+ " Master: {} | Instances: {} | Pins: {} | Total original area: {} "
1788+ " um^2 | Total extended area: {} um^2 | Area diff: {:.2f}% | Original "
1789+ " area/pin: {:.4f} um^2 | Extended area/pin: {:.4f} um^2" ,
1790+ master_name,
1791+ stats.instance_count ,
1792+ stats.pin_count ,
1793+ stats.total_original_area ,
1794+ stats.total_extended_area ,
1795+ stats.area_diff ,
1796+ stats.original_area_per_pin ,
1797+ stats.extended_area_per_pin );
1798+ }
1799+
1800+ // Write per-master statistics to CSV
1801+ const std::string csv_filename = " inflation_stats.csv" ;
1802+ std::ofstream csv_file (csv_filename, std::ios::out);
1803+ if (csv_file.is_open ()) {
1804+ csv_file << " master_name,instance_count,pin_count,total_original_area_um2,"
1805+ " total_extended_area_um2,area_diff_percent,original_area_per_"
1806+ " pin_um2,extended_area_per_pin_um2\n " ;
1807+ for (const auto & entry : master_stats_map) {
1808+ const std::string& master_name = entry.first ;
1809+ const MasterStats& stats = entry.second ;
1810+ csv_file << master_name << " ," << stats.instance_count << " ,"
1811+ << stats.pin_count << " ," << stats.total_original_area << " ,"
1812+ << stats.total_extended_area << " ," << stats.area_diff << " ,"
1813+ << stats.original_area_per_pin << " ,"
1814+ << stats.extended_area_per_pin << " \n " ;
1815+ }
1816+ csv_file.close ();
1817+ }
1818+
1819+ log_->report (" NB Total original area: {} um^2" ,
1820+ block->dbuAreaToMicrons (total_original_area));
1821+ log_->report (" NB Total extended area: {} um^2" ,
1822+ block->dbuAreaToMicrons (total_extended_area));
1823+ log_->report (" NB Total area difference (extended - original): {} um^2" ,
1824+ block->dbuAreaToMicrons (total_area_diff));
1825+ log_->report (" NB Total area increased: {} um^2 ({} instances)" ,
1826+ block->dbuAreaToMicrons (increased_area),
1827+ increased_instance_count);
1828+ log_->report (" NB Total area decreased: {} um^2 ({} instances)" ,
1829+ block->dbuAreaToMicrons (decreased_area),
1830+ decreased_instance_count);
1831+ log_->report (
1832+ " NB Total area modified (sum of increases and decreases): {} um^2" ,
1833+ block->dbuAreaToMicrons (increased_area + decreased_area));
1834+ if (total_original_area != 0 ) {
1835+ double rel_diff = static_cast <double >(total_area_diff)
1836+ / static_cast <double >(total_original_area);
1837+ log_->report (" NB Relative area difference: {:.2f}%%" , rel_diff * 100.0 );
1838+ }
1839+ log_->report (" NB Number of instances with increased area: {}" ,
1840+ increased_instance_count);
1841+ log_->report (" NB Number of instances with decreased area: {}" ,
1842+ decreased_instance_count);
1843+ log_->report (" NB Number of instances with unchanged area: {}" ,
1844+ unchanged_instance_count);
1845+ if (total_instance_count != 0 ) {
1846+ double percent_increased = static_cast <double >(increased_instance_count)
1847+ / static_cast <double >(total_instance_count)
1848+ * 100.0 ;
1849+ double percent_decreased = static_cast <double >(decreased_instance_count)
1850+ / static_cast <double >(total_instance_count)
1851+ * 100.0 ;
1852+ double percent_unchanged = static_cast <double >(unchanged_instance_count)
1853+ / static_cast <double >(total_instance_count)
1854+ * 100.0 ;
1855+ log_->report (" NB Percentage of instances with increased area: {:.2f}%%" ,
1856+ percent_increased);
1857+ log_->report (" NB Percentage of instances with decreased area: {:.2f}%%" ,
1858+ percent_decreased);
1859+ log_->report (" NB Percentage of instances with unchanged area: {:.2f}%%" ,
1860+ percent_unchanged);
1861+ }
1862+ }
1863+
16861864// //////////////////////////////////////////////
16871865// NesterovBase
16881866
@@ -3275,9 +3453,9 @@ void NesterovBase::createCbkGCell(odb::dbInst* db_inst, size_t stor_index)
32753453size_t NesterovBaseCommon::createCbkGCell (odb::dbInst* db_inst)
32763454{
32773455 debugPrint (log_, GPL, " callbacks" , 2 , " NBC createCbkGCell" );
3278- Instance gpl_inst (db_inst, pbc_.get (), log_);
3456+ Instance pb_inst (db_inst, pbc_.get (), log_);
32793457
3280- pb_insts_stor_.push_back (gpl_inst );
3458+ pb_insts_stor_.push_back (pb_inst );
32813459 GCell gcell (&pb_insts_stor_.back ());
32823460 gCellStor_ .push_back (gcell);
32833461 minRcCellSize_.emplace_back (gcell.lx (), gcell.ly (), gcell.ux (), gcell.uy ());
0 commit comments