From 7e6a0b0ba7e051996c5e553ad19243067273a729 Mon Sep 17 00:00:00 2001 From: liulixinkerry Date: Wed, 5 Jun 2024 16:11:25 +0800 Subject: [PATCH] Refine cpp code to avoid always including torch and pybind --- cpp_to_py/common/common.h | 11 --- cpp_to_py/common/db/Cell.h | 2 +- cpp_to_py/common/db/Database.cpp | 12 +-- cpp_to_py/common/db/Database.h | 22 ++--- cpp_to_py/common/db/Geometry.cpp | 16 ++-- cpp_to_py/common/db/Geometry.h | 10 +-- cpp_to_py/common/db/Net.cpp | 6 +- cpp_to_py/common/db/Net.h | 2 +- cpp_to_py/common/db/Pin.cpp | 8 +- cpp_to_py/common/db/Region.cpp | 8 +- cpp_to_py/common/db/Via.h | 2 +- cpp_to_py/common/io/file_bkshf_db.cpp | 44 +++++----- cpp_to_py/common/io/file_constraints.cpp | 4 +- cpp_to_py/common/io/file_lefdef_db.cpp | 90 ++++++++++----------- cpp_to_py/common/io/file_verilog.cpp | 4 +- cpp_to_py/draw_placement/Drawer.cpp | 4 + cpp_to_py/draw_placement/Drawer.h | 19 ++++- cpp_to_py/draw_placement/draw_placement.cpp | 1 + cpp_to_py/gpudp/PyBindCppMain.cpp | 3 + cpp_to_py/gpudp/db/dp_torch.h | 1 + cpp_to_py/gpudp/lg/filler_legalize.cpp | 4 +- cpp_to_py/gpugr/PyBindCppMain.cpp | 3 + cpp_to_py/gpugr/db/GRDatabase.cpp | 44 +++++----- cpp_to_py/gpugr/db/GRDatabase.h | 2 +- cpp_to_py/gpugr/gr/GPURouter.cu | 38 ++++----- cpp_to_py/gpugr/gr/GPURouter.h | 17 ++-- cpp_to_py/gpugr/gr/GPURouterTorch.cu | 5 +- cpp_to_py/gpugr/gr/PatternRoute.cpp | 4 +- cpp_to_py/gpugr/gr/RouteForce.cpp | 2 +- cpp_to_py/io_parser/BindHelper.h | 4 +- cpp_to_py/io_parser/PyBindCppMain.cpp | 6 +- cpp_to_py/io_parser/gp/GPDatabase.h | 1 + cpp_to_py/routedp/PyBindCppMain.cpp | 1 + src/detail_placement.py | 16 ++-- src/run_placement_nesterov.py | 6 +- 35 files changed, 225 insertions(+), 197 deletions(-) diff --git a/cpp_to_py/common/common.h b/cpp_to_py/common/common.h index 92e3a0b..2beff9d 100644 --- a/cpp_to_py/common/common.h +++ b/cpp_to_py/common/common.h @@ -30,19 +30,8 @@ #include -// Torch library -#include - // utils #include "common/utils/utils.h" -// Pybind11 -#include -#include -#include -#include - -using namespace std; - using utils::assert_msg; using utils::logger; \ No newline at end of file diff --git a/cpp_to_py/common/db/Cell.h b/cpp_to_py/common/db/Cell.h index 9045b8c..4f93e21 100644 --- a/cpp_to_py/common/db/Cell.h +++ b/cpp_to_py/common/db/Cell.h @@ -119,7 +119,7 @@ public: void unplace(); unsigned numPins() const { return _pins.size(); } - friend ostream& operator<<(ostream& os, const Cell& c) { + friend std::ostream& operator<<(std::ostream& os, const Cell& c) { return os << c._name << "\t(" << c.lx() << ", " << c.ly() << ')'; } }; diff --git a/cpp_to_py/common/db/Database.cpp b/cpp_to_py/common/db/Database.cpp index e764480..1310c42 100644 --- a/cpp_to_py/common/db/Database.cpp +++ b/cpp_to_py/common/db/Database.cpp @@ -526,7 +526,7 @@ void Database::SetupRows() { // NOTE: currently we only support horizontal row for (unsigned y = 0; y != nSitesY; ++y) { - rows[y] = new Row("core_SITE_ROW_" + to_string(y), "core", coreLX, coreLY + y * siteH); + rows[y] = new Row("core_SITE_ROW_" + std::to_string(y), "core", coreLX, coreLY + y * siteH); rows[y]->xStep(stepX); rows[y]->yStep(0); rows[y]->xNum(nSitesX); @@ -814,10 +814,10 @@ long long Database::getHPWL() { Pin* pin = nets[i]->pins[j]; int x, y; pin->getPinCenter(x, y); - lx = min(lx, x); - ly = min(ly, y); - hx = max(hx, x); - hy = max(hy, y); + lx = std::min(lx, x); + ly = std::min(ly, y); + hx = std::max(hx, x); + hy = std::max(hy, y); } hpwl += (hx - lx) + (hy - ly); } @@ -896,7 +896,7 @@ Region* Database::getRegion(const unsigned char id) { } NDR* Database::getNDR(const string& name) const { - map::const_iterator mi = ndrs.find(name); + std::map::const_iterator mi = ndrs.find(name); if (mi == ndrs.end()) { return nullptr; } diff --git a/cpp_to_py/common/db/Database.h b/cpp_to_py/common/db/Database.h index 6392058..fa88672 100644 --- a/cpp_to_py/common/db/Database.h +++ b/cpp_to_py/common/db/Database.h @@ -1,9 +1,13 @@ #pragma once -#include "common/common.h" #include "Setting.h" +#include "common/common.h" namespace db { + +using std::string; +using std::vector; + class Rectangle; class Geometry; class GeoMap; @@ -31,20 +35,20 @@ class GCellGrid; class BsRouteInfo; } // namespace db +#include "BsRouteInfo.h" #include "Cell.h" #include "DesignRule.h" +#include "GCellGrid.h" #include "Geometry.h" #include "Layer.h" -#include "SiteMap.h" #include "Net.h" #include "Pin.h" #include "Region.h" -#include "GCellGrid.h" #include "Row.h" -#include "Site.h" #include "SNet.h" +#include "Site.h" +#include "SiteMap.h" #include "Via.h" -#include "BsRouteInfo.h" namespace db { @@ -91,7 +95,7 @@ public: vector nets; vector rows; vector regions; - map ndrs; + std::map ndrs; vector snets; vector tracks; @@ -220,9 +224,9 @@ public: bool writeDEF(const std::string& file); bool writeICCAD2017(const string& inputDef, const string& outputDef); bool writeICCAD2017(const string& outputDef); - bool writeComponents(ofstream& ofs); - bool writeBuffer(ofstream& ofs, const string& line); - void writeBufferFlush(ofstream& ofs); + bool writeComponents(std::ofstream& ofs); + bool writeBuffer(std::ofstream& ofs, const string& line); + void writeBufferFlush(std::ofstream& ofs); bool readBSAux(const std::string& auxFile, const std::string& plFile); bool readBSNodes(const std::string& file); diff --git a/cpp_to_py/common/db/Geometry.cpp b/cpp_to_py/common/db/Geometry.cpp index 7c94913..3e5386b 100644 --- a/cpp_to_py/common/db/Geometry.cpp +++ b/cpp_to_py/common/db/Geometry.cpp @@ -4,10 +4,10 @@ using namespace db; /***** Rectangle *****/ Rectangle& Rectangle::operator+=(const Rectangle& geo) { - lx = min(lx, geo.lx); - ly = min(ly, geo.ly); - hx = max(hx, geo.hx); - hy = max(hy, geo.hy); + lx = std::min(lx, geo.lx); + ly = std::min(ly, geo.ly); + hx = std::max(hx, geo.hx); + hy = std::max(hy, geo.hy); return *this; } @@ -45,8 +45,8 @@ void Rectangle::sliceH(vector& rects) { continue; } if (L.hx >= R.lx) { - R.lx = min(L.lx, R.lx); - R.hx = max(L.hx, R.hx); + R.lx = std::min(L.lx, R.lx); + R.hx = std::max(L.hx, R.hx); L.hx = L.lx; } } @@ -92,8 +92,8 @@ void Rectangle::sliceV(vector& rects) { continue; } if (L.hy >= R.ly) { - R.ly = min(L.ly, R.ly); - R.hy = max(L.hy, R.hy); + R.ly = std::min(L.ly, R.ly); + R.hy = std::max(L.hy, R.hy); L.hy = L.ly; } } diff --git a/cpp_to_py/common/db/Geometry.h b/cpp_to_py/common/db/Geometry.h index f79e04e..c7660b1 100644 --- a/cpp_to_py/common/db/Geometry.h +++ b/cpp_to_py/common/db/Geometry.h @@ -34,7 +34,7 @@ public: static void sliceH(vector& rects); static void sliceV(vector& rects); - friend ostream& operator<<(ostream& os, const Rectangle& r) { + friend std::ostream& operator<<(std::ostream& os, const Rectangle& r) { return os << '(' << r.lx << ", " << r.ly << ")\t(" << r.hx << ", " << r.hy << ')'; } }; @@ -52,7 +52,7 @@ public: class GeoMap : public Rectangle { private: - map _map; + std::map _map; public: bool empty() const noexcept { return _map.empty(); } @@ -60,9 +60,9 @@ public: const Geometry& front() const { return _map.begin()->second; } const Geometry& front2() const { return (++_map.begin())->second; } const Geometry& back() const { return _map.rbegin()->second; } - map::const_iterator begin() const noexcept { return _map.begin(); } - map::const_iterator end() const noexcept { return _map.end(); } - map::const_iterator find(const int k) const { return _map.find(k); } + std::map::const_iterator begin() const noexcept { return _map.begin(); } + std::map::const_iterator end() const noexcept { return _map.end(); } + std::map::const_iterator find(const int k) const { return _map.find(k); } const Geometry& at(const int k) const { return _map.at(k); } diff --git a/cpp_to_py/common/db/Net.cpp b/cpp_to_py/common/db/Net.cpp index 478352b..b5994f3 100644 --- a/cpp_to_py/common/db/Net.cpp +++ b/cpp_to_py/common/db/Net.cpp @@ -109,7 +109,7 @@ void Net::addPin(Pin* pin) { /***** PowerNet *****/ void PowerNet::addRail(SNet* snet, int lx, int hx, int y) { - map::iterator rail = rails.find(y); + std::map::iterator rail = rails.find(y); if (rail != rails.end() && rail->second != snet) { logger.error("rail %s already exists at y=%d , new rail %s is from %d to %d", rail->second->name.c_str(), y, snet->name.c_str(), @@ -125,13 +125,13 @@ bool PowerNet::getRowPower(int ly, int hy, char& topPower, char& botPower) { bool valid = true; topPower = 'x'; botPower = 'x'; - map::iterator topRail = rails.find(hy); + std::map::iterator topRail = rails.find(hy); if (topRail != rails.end()) { topPower = topRail->second->type; } else { valid = false; } - map::iterator botRail = rails.find(ly); + std::map::iterator botRail = rails.find(ly); if (botRail != rails.end()) { botPower = botRail->second->type; } else { diff --git a/cpp_to_py/common/db/Net.h b/cpp_to_py/common/db/Net.h index 72eb50b..d88499a 100644 --- a/cpp_to_py/common/db/Net.h +++ b/cpp_to_py/common/db/Net.h @@ -26,7 +26,7 @@ public: unsigned toNode; // path = [] // direction : N,S,E,W,U,D - vector> path; + vector> path; NetRouteSegment(const unsigned fromi = 0, const unsigned toi = 0, const char dir = '\0', const unsigned len = 0); diff --git a/cpp_to_py/common/db/Pin.cpp b/cpp_to_py/common/db/Pin.cpp index 4364512..c90bbf0 100644 --- a/cpp_to_py/common/db/Pin.cpp +++ b/cpp_to_py/common/db/Pin.cpp @@ -104,10 +104,10 @@ utils::PointT Pin::getPinParentCenter() const { /***** Pin Type *****/ void PinType::addShape(const Layer& layer, const int lx, const int ly, const int hx, const int hy) { - boundLX = min(boundLX, lx); - boundLY = min(boundLY, ly); - boundHX = max(boundHX, hx); - boundHY = max(boundHY, hy); + boundLX = std::min(boundLX, lx); + boundLY = std::min(boundLY, ly); + boundHX = std::max(boundHX, hx); + boundHY = std::max(boundHY, hy); shapes.emplace_back(layer, lx, ly, hx, hy); } diff --git a/cpp_to_py/common/db/Region.cpp b/cpp_to_py/common/db/Region.cpp index 10af240..70f7083 100644 --- a/cpp_to_py/common/db/Region.cpp +++ b/cpp_to_py/common/db/Region.cpp @@ -5,8 +5,8 @@ using namespace db; void Region::addRect(const int xl, const int yl, const int xh, const int yh) { rects.emplace_back(xl, yl, xh, yh); - lx = min(lx, xl); - ly = min(ly, yl); - hx = max(hx, xh); - hy = max(hy, yh); + lx = std::min(lx, xl); + ly = std::min(ly, yl); + hx = std::max(hx, xh); + hy = std::max(hy, yh); } diff --git a/cpp_to_py/common/db/Via.h b/cpp_to_py/common/db/Via.h index 1483142..52a7458 100644 --- a/cpp_to_py/common/db/Via.h +++ b/cpp_to_py/common/db/Via.h @@ -44,7 +44,7 @@ private: public: string name = ""; - set rects; + std::set rects; ViaRule rule; ViaType(const string& name = "", const bool isDef = false) : isDef_(isDef), name(name) {} diff --git a/cpp_to_py/common/io/file_bkshf_db.cpp b/cpp_to_py/common/io/file_bkshf_db.cpp index a23f00b..4754f62 100644 --- a/cpp_to_py/common/io/file_bkshf_db.cpp +++ b/cpp_to_py/common/io/file_bkshf_db.cpp @@ -54,7 +54,7 @@ public: int tileH; double blockagePorosity; vector IOPinRouteLayer; - vector>> routeBlkgs; // cellID, BlockedLayers + vector>> routeBlkgs; // cellID, BlockedLayers BookshelfData() { nCells = 0; @@ -163,8 +163,8 @@ public: } void estimateSiteSize() { - set sizeSet; - set heightSet; + std::set sizeSet; + std::set heightSet; for (int i = 0; i < nCells; i++) { if (!typeStdCell[i]) { @@ -186,8 +186,8 @@ public: vector sizes; vector heights; - set::iterator ii = sizeSet.begin(); - set::iterator ie = sizeSet.end(); + std::set::iterator ii = sizeSet.begin(); + std::set::iterator ie = sizeSet.end(); for (; ii != ie; ++ii) { sizes.push_back(*ii); } @@ -273,7 +273,7 @@ bool isBookshelfSymbol(unsigned char c) { return symbols[(int)c] != 0; } -bool readBSLine(istream& is, vector& tokens) { +bool readBSLine(std::istream& is, vector& tokens) { tokens.clear(); string line; while (is && tokens.empty()) { @@ -332,7 +332,7 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) } logger.info("dir = %s", directory.c_str()); - ifstream fs(auxFile.c_str()); + std::ifstream fs(auxFile.c_str()); if (!fs.good()) { logger.error("cannot open file: %s", auxFile.c_str()); return false; @@ -440,7 +440,7 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) this->dieHY = INT_MIN; unsigned int minRowXStep = INT_MAX; for (int i = 0; i < bsData.nRows; i++) { - Row* row = this->addRow("core_SITE_ROW_" + to_string(i), "core", bsData.rowX[i], bsData.rowY[i]); + Row* row = this->addRow("core_SITE_ROW_" + std::to_string(i), "core", bsData.rowX[i], bsData.rowY[i]); row->xStep(bsData.rowXStep[i]); row->yStep(bsData.rowHeight[i]); row->xNum(bsData.rowSites[i]); @@ -523,7 +523,7 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) m2direction = (this->bsRouteInfo.capV[1] > 0) ? 'v' : 'h'; } for (unsigned i = 0; i != nLayers; ++i) { - Layer& layer = this->addLayer(string("M").append(to_string(i + 1)), 'r'); + Layer& layer = this->addLayer(string("M").append(std::to_string(i + 1)), 'r'); // if (!i) { // layer.direction = 'x'; // layer.track.direction = 'x'; @@ -558,7 +558,7 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) if (i + 1 == nLayers) { break; } else { - this->addLayer(string("N").append(to_string(i + 1)), 'c'); + this->addLayer(string("N").append(std::to_string(i + 1)), 'c'); } } @@ -690,7 +690,7 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) } bool Database::readBSNodes(const std::string& file) { logger.info("reading nodes"); - ifstream fs(file.c_str()); + std::ifstream fs(file.c_str()); if (!fs.good()) { logger.error("cannot open file: %s", file.c_str()); return false; @@ -768,7 +768,7 @@ bool Database::readBSNodes(const std::string& file) { bool Database::readBSNets(const std::string& file) { logger.info("reading net"); - ifstream fs(file.c_str()); + std::ifstream fs(file.c_str()); if (!fs.good()) { logger.error("cannot open file: %s", file.c_str()); return false; @@ -821,7 +821,7 @@ bool Database::readBSNets(const std::string& file) { string tpName; if (pinName == "" && typeID >= 0) { - stringstream ss; + std::stringstream ss; ss << bsData.typeNPins[typeID]; pinName = ss.str(); // logger.info("pinname = %s", pinName.c_str()); @@ -865,7 +865,7 @@ bool Database::readBSNets(const std::string& file) { bool Database::readBSScl(const std::string& file) { logger.info("reading scl"); - ifstream fs(file.c_str()); + std::ifstream fs(file.c_str()); if (!fs.good()) { logger.error("cannot open file: %s", file.c_str()); return false; @@ -909,7 +909,7 @@ bool Database::readBSScl(const std::string& file) { bool Database::readBSRoute(const std::string& file) { logger.info("reading route"); - ifstream fs(file.c_str()); + std::ifstream fs(file.c_str()); if (!fs.good()) { logger.error("cannot open file: %s", file.c_str()); return false; @@ -1004,7 +1004,7 @@ bool Database::readBSRoute(const std::string& file) { bool Database::readBSShapes(const std::string& file) { logger.info("reading shapes"); - ifstream fs(file.c_str()); + std::ifstream fs(file.c_str()); if (!fs.good()) { logger.error("cannot open file: %s", file.c_str()); return false; @@ -1039,7 +1039,7 @@ bool Database::readBSShapes(const std::string& file) { bool Database::readBSWts(const std::string& file) { logger.info("reading weights"); - ifstream fs(file.c_str()); + std::ifstream fs(file.c_str()); if (!fs.good()) { logger.error("cannot open file: %s", file.c_str()); return false; @@ -1051,7 +1051,7 @@ bool Database::readBSWts(const std::string& file) { bool Database::readBSPl(const std::string& file) { logger.info("reading placement"); - ifstream fs(file.c_str()); + std::ifstream fs(file.c_str()); if (!fs.good()) { logger.error("cannot open file: %s", file.c_str()); return false; @@ -1085,7 +1085,7 @@ bool Database::readBSPl(const std::string& file) { } bool Database::writeBSPl(const std::string& file) { - ofstream fs(file.c_str()); + std::ofstream fs(file.c_str()); if (!fs.good()) { logger.error("cannot open file: %s", file.c_str()); return false; @@ -1093,8 +1093,8 @@ bool Database::writeBSPl(const std::string& file) { fs << "UCLA pl 1.0\n"; fs << "# User : Chinese University of Hong Kong\n\n"; for (auto cell : this->cells) { - fs << '\t' << left << setw(60) << cell->name() << right << setw(8) << cell->lx() / siteW << setw(8) - << cell->ly() / siteW << " : N"; + fs << '\t' << std::left << std::setw(60) << cell->name() << std::right << std::setw(8) << cell->lx() / siteW + << std::setw(8) << cell->ly() / siteW << " : N"; if (cell->fixed()) { if (cell->width() / siteW == 1 && cell->height() / siteW == 1) { fs << " /FIXED_NI"; @@ -1102,7 +1102,7 @@ bool Database::writeBSPl(const std::string& file) { fs << " /FIXED"; } } - fs << endl; + fs << std::endl; } fs.close(); return true; diff --git a/cpp_to_py/common/io/file_constraints.cpp b/cpp_to_py/common/io/file_constraints.cpp index e2513da..19635cd 100644 --- a/cpp_to_py/common/io/file_constraints.cpp +++ b/cpp_to_py/common/io/file_constraints.cpp @@ -4,7 +4,7 @@ using namespace db; bool Database::readConstraints(const std::string& file) { string buffer; - ifstream ifs(file.c_str()); + std::ifstream ifs(file.c_str()); if (!ifs.good()) { logger.error("cannot open constraint file: %s", file.c_str()); return false; @@ -35,7 +35,7 @@ bool Database::readConstraints(const std::string& file) { } bool Database::readSize(const std::string& file) { - ifstream fs(file.c_str()); + std::ifstream fs(file.c_str()); if (!fs.good()) { logger.error("cannot open size file: %s", file.c_str()); return false; diff --git a/cpp_to_py/common/io/file_lefdef_db.cpp b/cpp_to_py/common/io/file_lefdef_db.cpp index 233f7ab..8475b93 100644 --- a/cpp_to_py/common/io/file_lefdef_db.cpp +++ b/cpp_to_py/common/io/file_lefdef_db.cpp @@ -261,7 +261,7 @@ bool Database::readDEF(const std::string& file) { bool Database::readDEFPG(const std::string& file) { // shape of pre-routed PG mesh is not supported by the reader string buffer; - ifstream ifs(file.c_str()); + std::ifstream ifs(file.c_str()); if (!ifs.good()) { logger.error("Unable to open DEF PG file: %s", file.c_str()); return false; @@ -373,34 +373,34 @@ bool Database::readDEFPG(const std::string& file) { return true; } -bool Database::writeComponents(ofstream& ofs) { +bool Database::writeComponents(std::ofstream& ofs) { int nCells = cells.size(); - ofs << "COMPONENTS " << nCells << " ;" << endl; - // ofs << "COMPONENTS " << nCells << " ;" << endl; + ofs << "COMPONENTS " << nCells << " ;" << std::endl; + // ofs << "COMPONENTS " << nCells << " ;" << std::endl; for (int i = 0; i < nCells; i++) { Cell* cell = cells[i]; #ifdef WRITE_BUFFER - ostringstream oss; + std::ostringstream oss; #else - ofstream& oss = ofs; + std::ofstream& oss = ofs; #endif - oss << " - " << cell->name() << " " << cell->ctype()->name << endl; - // ofs << " - " << cell->name() << " " << cell->ctype()->name << endl; + oss << " - " << cell->name() << " " << cell->ctype()->name << std::endl; + // ofs << " - " << cell->name() << " " << cell->ctype()->name << std::endl; if (cell->fixed()) { oss << " + FIXED ( " << cell->lx() << " " << cell->ly() << " ) " << getOrient(cell->orient()) << " ;" - << endl; + << std::endl; // ofs << " + FIXED ( " << cell->lx() << " " << cell->ly() << " ) " // << getOrient(cell->orient()) - // << " ;" << endl; + // << " ;" << std::endl; } else if (cell->placed()) { oss << " + PLACED ( " << cell->lx() << " " << cell->ly() << " ) " << getOrient(cell->orient()) << " ;" - << endl; + << std::endl; // ofs << " + PLACED ( " << cell->lx() << " " << cell->ly() << " ) " // << getOrient(cell->orient()) - // << " ;" << endl; + // << " ;" << std::endl; } else { - oss << " + UNPLACED ;" << endl; - // ofs << " + UNPLACED ;" << endl; + oss << " + UNPLACED ;" << std::endl; + // ofs << " + UNPLACED ;" << std::endl; } #ifdef WRITE_BUFFER string lines = oss.str(); @@ -415,7 +415,7 @@ bool Database::writeComponents(ofstream& ofs) { } bool Database::writeICCAD2017(const string& inputDef, const string& outputDef) { - ifstream ifs(inputDef.c_str()); + std::ifstream ifs(inputDef.c_str()); if (!ifs.good()) { logger.error("Unable to create/open DEF: %s", inputDef.c_str()); return false; @@ -425,7 +425,7 @@ bool Database::writeICCAD2017(const string& inputDef, const string& outputDef) { logger.info("reading %s", inputDef.c_str()); #endif - ofstream ofs(outputDef.c_str()); + std::ofstream ofs(outputDef.c_str()); if (!ofs.good()) { logger.error("Unable to create/open DEF: %s", outputDef.c_str()); return false; @@ -434,18 +434,18 @@ bool Database::writeICCAD2017(const string& inputDef, const string& outputDef) { string line; while (getline(ifs, line)) { - istringstream iss(line); + std::istringstream iss(line); string s; if (!(iss >> s)) { - ofs << line << endl; + ofs << line << std::endl; continue; } else if (s != "COMPONENTS") { - ofs << line << endl; + ofs << line << std::endl; continue; } writeComponents(ofs); while (getline(ifs, line)) { - istringstream iss(line); + std::istringstream iss(line); if (iss >> s && s == "END") { break; } @@ -456,7 +456,7 @@ bool Database::writeICCAD2017(const string& inputDef, const string& outputDef) { } bool Database::writeICCAD2017(const string& outputDef) { - ofstream ofs(outputDef.c_str(), ios::app); + std::ofstream ofs(outputDef.c_str(), std::ios::app); if (!ofs.good()) { logger.error("Unable to create/open DEF: %s", outputDef.c_str()); return false; @@ -465,24 +465,24 @@ bool Database::writeICCAD2017(const string& outputDef) { writeComponents(ofs); // just replace the information of components, while others keep remain. - ofs << "END DESIGN\n\n" << endl; + ofs << "END DESIGN\n\n" << std::endl; ofs.close(); return true; } bool Database::writeDEF(const string& file) { - ofstream ofs(file.c_str()); + std::ofstream ofs(file.c_str()); if (!ofs.good()) { logger.error("Unable to create/open DEF: %s", file.c_str()); return false; } logger.info("writing %s", file.c_str()); - ofs << "VERSION 5.8 ;" << endl; - ofs << "DIVIDERCHAR \"/\" ;" << endl; - ofs << "BUSBITCHARS \"[]\" ;" << endl; - ofs << "DESIGN " << designName << " ;" << endl; + ofs << "VERSION 5.8 ;" << std::endl; + ofs << "DIVIDERCHAR \"/\" ;" << std::endl; + ofs << "BUSBITCHARS \"[]\" ;" << std::endl; + ofs << "DESIGN " << designName << " ;" << std::endl; ofs << "UNITS DISTANCE MICRONS " << (int)DBU_Micron << " ; \n\n"; ofs << "DIEAREA ( " << dieLX << ' ' << dieLY << " ) ( " << dieHX << ' ' << dieHY << " ) ;\n\n"; @@ -492,7 +492,7 @@ bool Database::writeDEF(const string& file) { ofs << " DO " << row->xNum() << " BY " << row->yNum() << " STEP " << row->xStep() << ' ' << row->yStep() << " ;\n"; } - ofs << endl; + ofs << std::endl; for (Track* track : tracks) { ofs << "TRACKS " << track->macro() << ' ' << track->start << " DO " << track->num << " STEP " << track->step @@ -502,9 +502,9 @@ bool Database::writeDEF(const string& file) { } ofs << ";\n"; } - ofs << endl; + ofs << std::endl; - ostringstream ossv; + std::ostringstream ossv; unsigned nVias = 0; for (ViaType* via : viatypes) { if (!via->isDef()) { @@ -542,7 +542,7 @@ bool Database::writeDEF(const string& file) { } ofs << "END NONDEFAULTRULES\n\n"; - ostringstream ossr; + std::ostringstream ossr; unsigned nRegions = 0; for (Region* region : regions) { if (region->name() == "default") { @@ -597,7 +597,7 @@ bool Database::writeDEF(const string& file) { } } - ofs << "END DESIGN" << endl; + ofs << "END DESIGN" << std::endl; ofs.close(); return true; @@ -608,7 +608,7 @@ bool Database::writeDEF(const string& file) { /***********************************/ /// a buffered writing scheme -bool Database::writeBuffer(ofstream& ofs, const string& line) { +bool Database::writeBuffer(std::ofstream& ofs, const string& line) { const char* b = line.c_str(); size_t n = line.size(); while (_bufferSize + n > _bufferCapacity) // output exceeds the capacity @@ -633,7 +633,7 @@ bool Database::writeBuffer(ofstream& ofs, const string& line) { return true; } -void Database::writeBufferFlush(ofstream& ofs) { +void Database::writeBufferFlush(std::ofstream& ofs) { if (_bufferSize) // remember to write the rest content in the buffer { ofs.write(_buffer, _bufferSize); @@ -679,7 +679,7 @@ int readLefUnits(lefrCallbackType_e c, lefiUnits* unit, lefiUserData ud) { int readLefProp(lefrCallbackType_e c, lefiProp* prop, lefiUserData ud) { Database* db = (Database*)ud; if (prop->lefiProp::hasString() && !strcmp(prop->lefiProp::propName(), "LEF58_CELLEDGESPACINGTABLE")) { - stringstream sstable(prop->lefiProp::string()); + std::stringstream sstable(prop->lefiProp::string()); string buffer; while (!sstable.eof()) { @@ -1021,12 +1021,12 @@ int readLefPin(lefrCallbackType_e c, lefiPin* pin, lefiUserData ud) { PinType* pintype = celltype->addPin(name, direction, type); - set nodes; + std::set nodes; Layer* layer = nullptr; lefiGeomRect* rect = nullptr; lefiGeomPolygon* polygon = nullptr; lefiGeometries* geom = pin->port(0); - vector> poly; + vector> poly; unsigned bj = 0; bool has45 = false; for (unsigned i = 0; i != (unsigned)geom->numItems(); ++i) { @@ -1095,10 +1095,10 @@ int readLefPin(lefrCallbackType_e c, lefiPin* pin, lefiUserData ud) { nodes.emplace(poly[j].first, poly[j].second, dir); } while (nodes.size()) { - set::iterator pk; - set::iterator pl; - set::iterator pm; - set::iterator pn; + std::set::iterator pk; + std::set::iterator pl; + std::set::iterator pm; + std::set::iterator pn; while (nodes.size()) { pk = nodes.begin(); @@ -1118,12 +1118,12 @@ int readLefPin(lefrCallbackType_e c, lefiPin* pin, lefiUserData ud) { } if (nodes.size() < 4) { - cout << "Error when partitioning rectangles." << endl; - cout << "Remaining points: "; + std::cout << "Error when partitioning rectangles." << std::endl; + std::cout << "Remaining points: "; for (const Point& p : nodes) { printf("(%d, %d), ", p.x, p.y); } - cout << endl; + std::cout << std::endl; break; } @@ -1219,7 +1219,7 @@ int readLefMacro(lefrCallbackType_e c, lefiMacro* macro, lefiUserData ud) { for (int i = 0; i < macro->numProperties(); ++i) { if (!strcmp(macro->propName(i), "LEF58_EDGETYPE")) { - stringstream ssedgetype(macro->propValue(i)); + std::stringstream ssedgetype(macro->propValue(i)); string buffer; while (!ssedgetype.eof()) { ssedgetype >> buffer; diff --git a/cpp_to_py/common/io/file_verilog.cpp b/cpp_to_py/common/io/file_verilog.cpp index d956730..1db5448 100644 --- a/cpp_to_py/common/io/file_verilog.cpp +++ b/cpp_to_py/common/io/file_verilog.cpp @@ -30,7 +30,7 @@ bool isVerilogSymbol(unsigned char c) { } return symbols[(int)c] != 0; } -bool readVerilogLine(istream &is, vector &tokens) { +bool readVerilogLine(std::istream &is, vector &tokens) { tokens.clear(); string line; while (is && tokens.empty()) { @@ -73,7 +73,7 @@ bool readVerilogLine(istream &is, vector &tokens) { bool Database::readVerilog(const std::string &file) { logger.info("Reading verilog..."); - ifstream fs(file.c_str()); + std::ifstream fs(file.c_str()); if (!fs.good()) { logger.error("cannot open verilog file: %s", file.c_str()); return false; diff --git a/cpp_to_py/draw_placement/Drawer.cpp b/cpp_to_py/draw_placement/Drawer.cpp index 7197632..8dd885c 100644 --- a/cpp_to_py/draw_placement/Drawer.cpp +++ b/cpp_to_py/draw_placement/Drawer.cpp @@ -2,6 +2,10 @@ // Adapt from https://github.com/limbo018/DREAMPlace/blob/master/dreamplace/ops/draw_place/src/PlaceDrawer.h #include "Drawer.h" +#include +#include +#include +#include Drawer::Drawer(const std::vector>& ele_type_to_rgba_vec, const std::string& filename_, diff --git a/cpp_to_py/draw_placement/Drawer.h b/cpp_to_py/draw_placement/Drawer.h index 355da7f..b1f054c 100644 --- a/cpp_to_py/draw_placement/Drawer.h +++ b/cpp_to_py/draw_placement/Drawer.h @@ -1,4 +1,21 @@ -#include "global.h" +#pragma once + +// STL libraries +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using index_type = int64_t; + class Drawer { private: std::unordered_map> type_to_rgba; diff --git a/cpp_to_py/draw_placement/draw_placement.cpp b/cpp_to_py/draw_placement/draw_placement.cpp index 1583df0..5ea0db4 100644 --- a/cpp_to_py/draw_placement/draw_placement.cpp +++ b/cpp_to_py/draw_placement/draw_placement.cpp @@ -1,4 +1,5 @@ #include "Drawer.h" +#include bool DrawGlobalPlacement( const std::vector& node_pos_x, diff --git a/cpp_to_py/gpudp/PyBindCppMain.cpp b/cpp_to_py/gpudp/PyBindCppMain.cpp index 68ed5c2..a7f5b35 100644 --- a/cpp_to_py/gpudp/PyBindCppMain.cpp +++ b/cpp_to_py/gpudp/PyBindCppMain.cpp @@ -1,6 +1,9 @@ #include "common/common.h" #include "common/db/Database.h" #include "gpudp/db/dp_torch.h" +#include +#include +#include namespace Xplace { diff --git a/cpp_to_py/gpudp/db/dp_torch.h b/cpp_to_py/gpudp/db/dp_torch.h index 774eebf..e0ce4d2 100644 --- a/cpp_to_py/gpudp/db/dp_torch.h +++ b/cpp_to_py/gpudp/db/dp_torch.h @@ -1,5 +1,6 @@ #pragma once +#include #include "common/common.h" #include "common/db/Database.h" diff --git a/cpp_to_py/gpudp/lg/filler_legalize.cpp b/cpp_to_py/gpudp/lg/filler_legalize.cpp index d57f0e7..34ab1dd 100644 --- a/cpp_to_py/gpudp/lg/filler_legalize.cpp +++ b/cpp_to_py/gpudp/lg/filler_legalize.cpp @@ -206,7 +206,7 @@ void fillerLegalization(DPTorchRawDB& at_db) { // sort all blanks and create blank bucket list int maxDegree = 0; - robin_hood::unordered_map>> blank_bucket_list; + robin_hood::unordered_map>> blank_bucket_list; for (int i = 0; i < num_blanks_x * num_blanks_y; i += 1) { std::vector>& blanks = bin_blanks.at(i); for (unsigned int j = 0; j < blanks.size(); ++j) { @@ -219,7 +219,7 @@ void fillerLegalization(DPTorchRawDB& at_db) { logger.info("%s maxDegree = %d", "Blanks", maxDegree); // sorted filler cell id - vector fillers_to_blank(db.num_movable_nodes - db.num_conn_movable_nodes); + std::vector fillers_to_blank(db.num_movable_nodes - db.num_conn_movable_nodes); for (int i = 0; i < db.num_movable_nodes - db.num_conn_movable_nodes; i += 1) { fillers_to_blank[i] = db.num_conn_movable_nodes + i; } diff --git a/cpp_to_py/gpugr/PyBindCppMain.cpp b/cpp_to_py/gpugr/PyBindCppMain.cpp index 65f1fe6..b2393c4 100644 --- a/cpp_to_py/gpugr/PyBindCppMain.cpp +++ b/cpp_to_py/gpugr/PyBindCppMain.cpp @@ -3,6 +3,9 @@ #include "gpugr/db/GRDatabase.h" #include "gpugr/gr/RouteForce.h" #include "flute.h" +#include +#include +#include namespace Xplace { diff --git a/cpp_to_py/gpugr/db/GRDatabase.cpp b/cpp_to_py/gpugr/db/GRDatabase.cpp index c6ea54d..3bf178b 100644 --- a/cpp_to_py/gpugr/db/GRDatabase.cpp +++ b/cpp_to_py/gpugr/db/GRDatabase.cpp @@ -191,7 +191,7 @@ void GRDatabase::setupCapacity() { void GRDatabase::setupCapacityBookshelf() { capacity.resize(gridGraphSize, 0); for (int i = 0; i < nLayers; i++) { - int oricap = max(rawdb.bsRouteInfo.capH[i], rawdb.bsRouteInfo.capV[i]); + int oricap = std::max(rawdb.bsRouteInfo.capH[i], rawdb.bsRouteInfo.capV[i]); float cap = oricap / (layerPitch[i]); if ((i & 1) ^ m1direction) { for (int j = 0; j < xSize; j++) { @@ -380,8 +380,8 @@ void GRDatabase::addCellObs(std::vector& allObs, db::Cell* cell) { } } -tuple GRDatabase::getOrientOffset(int orient, int lx, int ly, int hx, int hy) { - tuple offset; // lx, ly, hx, hy +std::tuple GRDatabase::getOrientOffset(int orient, int lx, int ly, int hx, int hy) { + std::tuple offset; // lx, ly, hx, hy // 0:N, 1:W, 2:S, 3:E, 4:FN, 5:FW, 6:FS, 7:FE, -1:NONE switch (orient) { case 0: // N @@ -470,7 +470,7 @@ void GRDatabase::markObs(std::vector& allObs, wireUsage.resize(gridGraphSize, 0); wireTotalLength.resize(gridGraphSize, 0); - vector> layerToObjIdx(nLayers); + std::vector> layerToObjIdx(nLayers); for (unsigned i = 0; i < allObs.size(); i++) { int l = allObs[i].layer; if (l < obsStartLayer) continue; @@ -480,7 +480,7 @@ void GRDatabase::markObs(std::vector& allObs, auto& t = tracks[l]; int dir = (l & 1) ^ m1direction; - vector, int>>>> markingBufferLUT; + std::vector, int>>>> markingBufferLUT; auto searchLowerBoundTrack = [&](int p) { int pos = lower_bound(t.begin(), t.end(), p) - t.begin(); @@ -545,8 +545,8 @@ void GRDatabase::markObs(std::vector& allObs, utils::IntervalT trackIntvl = rangeSearchTracks(obsBox[1 - dir], l); if (!trackIntvl.IsValid()) continue; - int jmin = max(grBox[dir].low - 1, 0); - int jmax = min(grBox[dir].high, (dir == 0 ? xSize : ySize) - 2); + int jmin = std::max(grBox[dir].low - 1, 0); + int jmax = std::min(grBox[dir].high, (dir == 0 ? xSize : ySize) - 2); for (int i = grBox[1 - dir].low; i <= grBox[1 - dir].high; i++) { utils::IntervalT gridTrackIntvl(searchLowerBoundTrack(gridlines[1 - dir][i]), searchLowerBoundTrack(gridlines[1 - dir][i + 1]) - 1); @@ -570,7 +570,7 @@ void GRDatabase::markObs(std::vector& allObs, for (int j = 0; j < markingBufferLUT[i].size(); j++) { if (markingBufferLUT[i][j].size() == 0) continue; const auto& buf = markingBufferLUT[i][j]; - vector trackBlocked(gridTrackIntvl.range() + 1, 0); // blocked track length + std::vector trackBlocked(gridTrackIntvl.range() + 1, 0); // blocked track length for (auto& pair : buf) { for (int k = pair.first.low; k <= pair.first.high; k++) { trackBlocked[k - gridTrackIntvl.low] += pair.second; @@ -599,16 +599,16 @@ void GRDatabase::markObsBookShelf(std::vector& allObs, wireUsage.resize(gridGraphSize, 0); wireTotalLength.resize(gridGraphSize, 0); - vector> layerToObjIdx(nLayers); + std::vector> layerToObjIdx(nLayers); for (unsigned i = 0; i < allObs.size(); i++) { int l = allObs[i].layer; if (l < obsStartLayer) continue; layerToObjIdx[allObs[i].layer].push_back(i); } - vector layer2oricap(nLayers, 0.0); + std::vector layer2oricap(nLayers, 0.0); for (int i = 0; i < nLayers; i++) { - int oricap = max(rawdb.bsRouteInfo.capH[i], rawdb.bsRouteInfo.capV[i]); + int oricap = std::max(rawdb.bsRouteInfo.capH[i], rawdb.bsRouteInfo.capV[i]); float cap = oricap / (layerPitch[i]); layer2oricap[i] = oricap; } @@ -616,7 +616,7 @@ void GRDatabase::markObsBookShelf(std::vector& allObs, for (int l = obsStartLayer; l < nLayers; l++) { int dir = (l & 1) ^ m1direction; - vector>>> markingBufferLUT; + std::vector>>> markingBufferLUT; markingBufferLUT.resize((dir == 0 ? ySize : xSize)); int lutInnerSize = (dir == 0 ? xSize : ySize); for (auto& e : markingBufferLUT) { @@ -645,8 +645,8 @@ void GRDatabase::markObsBookShelf(std::vector& allObs, continue; } utils::BoxT grBox(xmin, ymin, xmax, ymax); - int jmin = max(grBox[dir].low - 1, 0); - int jmax = min(grBox[dir].high, (dir == 0 ? xSize : ySize) - 2); + int jmin = std::max(grBox[dir].low - 1, 0); + int jmax = std::min(grBox[dir].high, (dir == 0 ? xSize : ySize) - 2); for (int i = grBox[1 - dir].low; i <= grBox[1 - dir].high; i++) { utils::IntervalT gridIntvl(gridlines[1 - dir][i], gridlines[1 - dir][i + 1]); utils::IntervalT blockedIntvl = gridIntvl.IntersectWith(obsBox[1 - dir]); @@ -664,7 +664,7 @@ void GRDatabase::markObsBookShelf(std::vector& allObs, for (int j = 0; j < markingBufferLUT[i].size(); j++) { if (markingBufferLUT[i][j].size() == 0) continue; utils::IntervalT gridIntvl(gridlines[1 - dir][i], gridlines[1 - dir][i + 1]); - vector>& buf = markingBufferLUT[i][j]; + std::vector>& buf = markingBufferLUT[i][j]; int ovlpLen = 0; if (buf.size() > 1) { std::stable_sort( @@ -675,10 +675,10 @@ void GRDatabase::markObsBookShelf(std::vector& allObs, for (int bufIdx = 1; bufIdx < buf.size(); bufIdx++) { utils::IntervalT& curIntvl = buf[bufIdx]; if (curIntvl.low == tmpIntvl.low) { - tmpIntvl.high = max(tmpIntvl.high, curIntvl.high); + tmpIntvl.high = std::max(tmpIntvl.high, curIntvl.high); } else if (curIntvl.low > tmpIntvl.low) { if (curIntvl.low <= tmpIntvl.high) { - tmpIntvl.high = max(tmpIntvl.high, curIntvl.high); + tmpIntvl.high = std::max(tmpIntvl.high, curIntvl.high); } else { ovlpLen += tmpIntvl.range(); tmpIntvl.low = curIntvl.low; @@ -698,12 +698,12 @@ void GRDatabase::markObsBookShelf(std::vector& allObs, float blocked = floor((float)ovlpLen * (1.0 - rawdb.bsRouteInfo.blockagePorosity)); float availableSpace = ((float)gridIntvl.range() - blocked) / (float)gridIntvl.range(); int adjustedCap = layer2oricap[l] * availableSpace; - adjustedCap = max(0, adjustedCap); + adjustedCap = std::max(0, adjustedCap); int numTracksAvailable = adjustedCap / layerPitch[l]; float bcount = capacity[l * nMaxGrid * nMaxGrid + i * nMaxGrid + j] - (float)numTracksAvailable; // Assign value, we suppose tracks are completely blocked wireUsage[l * nMaxGrid * nMaxGrid + i * nMaxGrid + j] = - min(bcount, capacity[l * nMaxGrid * nMaxGrid + i * nMaxGrid + j]); + std::min(bcount, capacity[l * nMaxGrid * nMaxGrid + i * nMaxGrid + j]); wireTotalLength[l * nMaxGrid * nMaxGrid + i * nMaxGrid + j] = wireDist[l * nMaxGrid * nMaxGrid + i * nMaxGrid + j] * wireUsage[l * nMaxGrid * nMaxGrid + i * nMaxGrid + j]; @@ -1036,9 +1036,9 @@ void GRDatabase::writeGuides(std::string outputFile) { int l = p / nMaxGrid / nMaxGrid, x = p % (nMaxGrid * nMaxGrid) / nMaxGrid, y = p % nMaxGrid; if (!(l & 1) ^ m1direction) std::swap(x, y); // int xmin = x, xmax = x, ymin = y, ymax = y; - int lmin = max(0, l - 2), lmax = min(nLayers - 1, l + 2); - int xmin = max(0, x - 1), xmax = min(xSize - 1, x + 1); - int ymin = max(0, y - 1), ymax = min(ySize - 1, y + 1); + int lmin = std::max(0, l - 2), lmax = std::min(nLayers - 1, l + 2); + int xmin = std::max(0, x - 1), xmax = std::min(xSize - 1, x + 1); + int ymin = std::max(0, y - 1), ymax = std::min(ySize - 1, y + 1); for (int i = lmin; i <= lmax; i++) singleGuide(xmin, xmax, ymin, ymax, i); } }; diff --git a/cpp_to_py/gpugr/db/GRDatabase.h b/cpp_to_py/gpugr/db/GRDatabase.h index c2c4256..7f4f501 100644 --- a/cpp_to_py/gpugr/db/GRDatabase.h +++ b/cpp_to_py/gpugr/db/GRDatabase.h @@ -92,7 +92,7 @@ public: void writeGuides(std::string outputFile); int encodeId(int l, int x, int y); - tuple getOrientOffset(int orient, int lx, int ly, int hx, int hy); + std::tuple getOrientOffset(int orient, int lx, int ly, int hx, int hy); int getEOLSpace(int width, int l); int getParallelRunSpace(int l, int width, int length); utils::PointT getObsMargin(RectOnLayer box, AggrParaRunSpace aggr); diff --git a/cpp_to_py/gpugr/gr/GPURouter.cu b/cpp_to_py/gpugr/gr/GPURouter.cu index 5ba1c04..1f3d87f 100644 --- a/cpp_to_py/gpugr/gr/GPURouter.cu +++ b/cpp_to_py/gpugr/gr/GPURouter.cu @@ -90,7 +90,7 @@ void GPURouter::setUnitViaMultiplier(float value) { unitViaMultiplier = value; } -void GPURouter::setUnitVioCost(vector& values, float discount) { +void GPURouter::setUnitVioCost(std::vector& values, float discount) { //printf("??? setUnitVioCost %.2f\n", discount); float temp[100]; for(int i = 0; i < LAYER; i++) @@ -106,9 +106,9 @@ void GPURouter::setUnitViaCost(float value) { unitViaCost = value; } -void GPURouter::setMap(const vector &cap, const vector &wir, const vector &fixedL, const vector &fix) { +void GPURouter::setMap(const std::vector &cap, const std::vector &wir, const std::vector &fixedL, const std::vector &fix) { int gridGraphSize = LAYER * N * N; - auto copy = [&] (const vector &vec, float *target) { + auto copy = [&] (const std::vector &vec, float *target) { cudaMemcpy(target, vec.data(), gridGraphSize * sizeof(float), cudaMemcpyHostToDevice); }; copy(cap, capacity); @@ -187,7 +187,7 @@ __global__ void calculateCoarseVia(float *cell_resource, int *coarseVia, int *wi else sum += cell_resource[layer * N * N + j * N + i]; - ans += 1.0 / max(0.1, sum / (maxx - minx + 1) / (maxy - miny + 1)); + ans += 1.0 / max((float)0.1, sum / (maxx - minx + 1) / (maxy - miny + 1)); sum = 0; for(int i = minx; i <= maxx; i++) for(int j = miny; j <= maxy; j++) @@ -195,7 +195,7 @@ __global__ void calculateCoarseVia(float *cell_resource, int *coarseVia, int *wi sum += cell_resource[(layer + 1) * N * N + i * N + j]; else sum += cell_resource[(layer + 1) * N * N + j * N + i]; - ans += 1.0 / max(0.1, sum / (maxx - minx + 1) / (maxy - miny + 1)); + ans += 1.0 / max((float)0.1, sum / (maxx - minx + 1) / (maxy - miny + 1)); coarseVia[layer * xsize * ysize + x * ysize + y] = 100 * ans; } } @@ -243,7 +243,7 @@ __global__ void traceBack(int *modifiedWire, int *modifiedVia, dtype *dist, int } //if(netId == debug) // printf("Start tracing result: %d %d %d\n", p / N / N, p % (N * N) / N, p % N); - maxval = max(maxval, 1.0 * dist[p]); + maxval = std::max(maxval, 1.0 * dist[p]); int expected = p; while(dist[expected] > 0) expected = prev[expected]; @@ -554,12 +554,12 @@ __global__ void generateBatch(int n, int *minx, int *maxx, int *miny, int *maxy, } } -void GPURouter::route(vector &nets, int iter) { +void GPURouter::route(std::vector &nets, int iter) { logger.info("GPU Routing start... DIRECTION: %d", DIRECTION); double prtime = 0, prpreparetime = 0, batchgentime = 0, timer2 = 0; - vector netsToRoute; + std::vector netsToRoute; if(iter > 0) { logger.info("Maze Routing..."); ripupOverflowNets<<>> (isOverflowNet, routes, routesOffset, wires, vias, NET_NUM); @@ -584,7 +584,7 @@ void GPURouter::route(vector &nets, int iter) { markUnrouteUsage<<>> (allpins, vias, cnt); cudaDeviceSynchronize();*/ } - vector batchSizes; + std::vector batchSizes; { double t = clock(); constexpr bool check_vis_correctness = false; @@ -674,8 +674,8 @@ void GPURouter::route(vector &nets, int iter) { // for(int i = net.lowerx; i <= net.upperx; i++) // for(int j = net.lowery; j <= net.uppery; j++) // if(vis[i][j]) return false; - for(int i = max(0, net.lowerx - margin); i <= net.upperx + margin; i++) - for(int j = max(0, net.lowery - margin); j <= net.uppery + margin; j++) + for(int i = std::max(0, net.lowerx - margin); i <= net.upperx + margin; i++) + for(int j = std::max(0, net.lowery - margin); j <= net.uppery + margin; j++) if(vis[i][j]) return false; /*} else { for(int i = net.lowerx; i <= net.upperx; i++) { @@ -689,8 +689,8 @@ void GPURouter::route(vector &nets, int iter) { auto insert = [&] (int netId) { //double t = clock(); const auto &net = nets[netId]; - int xl = max(0, net.lowerx - margin), xr = net.upperx + margin; - int yl = max(0, net.lowery - margin), yr = net.uppery + margin; + int xl = std::max(0, net.lowerx - margin), xr = net.upperx + margin; + int yl = std::max(0, net.lowery - margin), yr = net.uppery + margin; //int blockL = yl / LEN - (yl % LEN == 0), blockR = yr / LEN + (yr % LEN == 0); for(int i = xl; i <= xr; i++) { for(int j = yl; j <= yr; j++) { @@ -709,8 +709,8 @@ void GPURouter::route(vector &nets, int iter) { }; auto remove = [&] (int netId) { const auto &net = nets[netId]; - int xl = max(0, net.lowerx - margin), xr = net.upperx + margin; - int yl = max(0, net.lowery - margin), yr = net.uppery + margin; + int xl = std::max(0, net.lowerx - margin), xr = net.upperx + margin; + int yl = std::max(0, net.lowery - margin), yr = net.uppery + margin; //int blockL = yl / LEN - (yl % LEN == 0), blockR = yr / LEN + (yr % LEN == 0); for(int i = xl; i <= xr; i++) { for(int j = yl; j <= yr; j++) { @@ -880,7 +880,7 @@ void GPURouter::route(vector &nets, int iter) { } } -void GPURouter::setFromNets(vector &nets, int numPlPin_) { +void GPURouter::setFromNets(std::vector &nets, int numPlPin_) { NET_NUM = nets.size(); pinNumCPU = new int[NET_NUM]; routesOffsetCPU = new int[NET_NUM + 1]; @@ -929,15 +929,15 @@ void GPURouter::setFromNets(vector &nets, int numPlPin_) { cudaDeviceSynchronize(); } -void GPURouter::setToNets(vector &nets) { +void GPURouter::setToNets(std::vector &nets) { int *routesCPU = new int[routesOffsetCPU[NET_NUM]]; int mx = 0; cudaMemcpy(routesCPU, routes, sizeof(int) * routesOffsetCPU[NET_NUM], cudaMemcpyDeviceToHost); int num_net_use_too_many_route = 0; for(size_t netId = 0; netId < nets.size(); netId++) { - vector wires, vias; + std::vector wires, vias; int *routesSub = routesCPU + routesOffsetCPU[netId]; - mx = max(mx, routesSub[0] / pinNumCPU[netId]); + mx = std::max(mx, routesSub[0] / pinNumCPU[netId]); if(routesSub[0] > routesOffsetCPU[netId + 1] - routesOffsetCPU[netId]) { num_net_use_too_many_route++; // std::cerr << "ERROR: too many routesSub! Please set MAX_ROUTE_LEN_PER_PIN larger than " << routesSub[0] / pinNumCPU[netId] << std::endl; diff --git a/cpp_to_py/gpugr/gr/GPURouter.h b/cpp_to_py/gpugr/gr/GPURouter.h index ecea28d..ecc73f6 100644 --- a/cpp_to_py/gpugr/gr/GPURouter.h +++ b/cpp_to_py/gpugr/gr/GPURouter.h @@ -2,6 +2,7 @@ #include "MazeRoute.h" #include "PatternRoute.h" #include "common/common.h" +#include #include "gpugr/db/GrNet.h" namespace gr { @@ -20,15 +21,15 @@ public: void initialize( int device_id, int layer, int x, int y, int N_, int cgxsize_, int cgysize_, int direction, int csrn_scale); - void setMap(const vector &cap, - const vector &wir, - const vector &fixedL, - const vector &fix); - void setFromNets(vector &nets, int numPlPin_); - void setToNets(vector &nets); - void route(vector &nets, int iterleft); + void setMap(const std::vector &cap, + const std::vector &wir, + const std::vector &fixedL, + const std::vector &fix); + void setFromNets(std::vector &nets, int numPlPin_); + void setToNets(std::vector &nets); + void route(std::vector &nets, int iterleft); void setUnitViaMultiplier(float w); - void setUnitVioCost(vector& cost, float discount); + void setUnitVioCost(std::vector& cost, float discount); void setLogisticSlope(float value); void setUnitViaCost(float value); void query(); diff --git a/cpp_to_py/gpugr/gr/GPURouterTorch.cu b/cpp_to_py/gpugr/gr/GPURouterTorch.cu index 13ca9aa..bdddf33 100644 --- a/cpp_to_py/gpugr/gr/GPURouterTorch.cu +++ b/cpp_to_py/gpugr/gr/GPURouterTorch.cu @@ -1,5 +1,6 @@ #include "GPURouter.h" #include "InCellUsage.cuh" +#include namespace gr { @@ -126,7 +127,7 @@ __global__ void compGcellRouteForce( } // TODO: 1) should we also consider X direction? // 2) consider via cost? - float cost = unit_wire_cost / min(cap_map_2d[j][ly], 0.2); + float cost = unit_wire_cost / min(cap_map_2d[j][ly], (float)0.2); grad += cost * route_gradmat[1][j][ly] * mask_map[j][ly] * cur_dist_weight; total_weight += cur_dist_weight; } @@ -141,7 +142,7 @@ __global__ void compGcellRouteForce( } else { cur_dist_weight = dist_weights[j - ly]; } - float cost = unit_wire_cost / min(cap_map_2d[lx][j], 0.2); + float cost = unit_wire_cost / min(cap_map_2d[lx][j], (float)0.2); grad += cost * route_gradmat[0][lx][j] * mask_map[lx][j] * cur_dist_weight; total_weight += cur_dist_weight; } diff --git a/cpp_to_py/gpugr/gr/PatternRoute.cpp b/cpp_to_py/gpugr/gr/PatternRoute.cpp index a8f8510..c34c374 100644 --- a/cpp_to_py/gpugr/gr/PatternRoute.cpp +++ b/cpp_to_py/gpugr/gr/PatternRoute.cpp @@ -347,9 +347,9 @@ int prepare(double &count, */ } else { if (x1 == x2) - for (int t = min(y1, y2); t < max(y1, y2); t++) cnty[x1][t]++; + for (int t = std::min(y1, y2); t < std::max(y1, y2); t++) cnty[x1][t]++; else - for (int t = min(x1, x2); t < max(x1, x2); t++) cntx[t][y2]++; + for (int t = std::min(x1, x2); t < std::max(x1, x2); t++) cntx[t][y2]++; } } free(flutetree.branch); diff --git a/cpp_to_py/gpugr/gr/RouteForce.cpp b/cpp_to_py/gpugr/gr/RouteForce.cpp index 0c3dafc..91f244e 100644 --- a/cpp_to_py/gpugr/gr/RouteForce.cpp +++ b/cpp_to_py/gpugr/gr/RouteForce.cpp @@ -44,7 +44,7 @@ void RouteForce::run_ggr() { if (iter == 0) { router.setUnitViaMultiplier(1); } else { - router.setUnitViaMultiplier(max(100 / pow(5, iter - 1), 4.0)); + router.setUnitViaMultiplier(std::max(100 / pow(5, iter - 1), 4.0)); router.setUnitVioCost(_unitShortVioCost, rrrInitVioCostDiscount + (1.0 - rrrInitVioCostDiscount) / (rrrIterLimit - 1) * iter); } diff --git a/cpp_to_py/io_parser/BindHelper.h b/cpp_to_py/io_parser/BindHelper.h index 9b11a85..18d5aae 100644 --- a/cpp_to_py/io_parser/BindHelper.h +++ b/cpp_to_py/io_parser/BindHelper.h @@ -3,7 +3,9 @@ #include "common/db/Database.h" #include "io_parser/gp/GPDatabase.h" -namespace py = pybind11; +#include +#include +#include namespace Xplace { diff --git a/cpp_to_py/io_parser/PyBindCppMain.cpp b/cpp_to_py/io_parser/PyBindCppMain.cpp index 4766bd2..dcc00a4 100644 --- a/cpp_to_py/io_parser/PyBindCppMain.cpp +++ b/cpp_to_py/io_parser/PyBindCppMain.cpp @@ -2,7 +2,7 @@ namespace Xplace { -bool loadParams(const py::dict& kwargs) { +bool loadParams(const pybind11::dict& kwargs) { db::setting.reset(); // ----- design related options ----- @@ -31,7 +31,7 @@ bool loadParams(const py::dict& kwargs) { for (auto lef_py : kwargs["lefs"]) { auto lef = lef_py.cast(); db::setting.LefFiles.emplace_back(lef); - } + } } if (kwargs.contains("constraints")) { @@ -112,7 +112,7 @@ bool loadParams(const py::dict& kwargs) { return true; } -std::tuple, std::shared_ptr> start_all(const py::dict& kwargs) { +std::tuple, std::shared_ptr> start_all(const pybind11::dict& kwargs) { bool load_status = loadParams(kwargs); if (!load_status) { throw std::invalid_argument("Received invalid params. Please check!"); diff --git a/cpp_to_py/io_parser/gp/GPDatabase.h b/cpp_to_py/io_parser/gp/GPDatabase.h index 0c77cef..44a212f 100644 --- a/cpp_to_py/io_parser/gp/GPDatabase.h +++ b/cpp_to_py/io_parser/gp/GPDatabase.h @@ -1,4 +1,5 @@ #pragma once +#include #include "common/common.h" #include "common/db/Database.h" diff --git a/cpp_to_py/routedp/PyBindCppMain.cpp b/cpp_to_py/routedp/PyBindCppMain.cpp index 31ae01c..6d151e8 100644 --- a/cpp_to_py/routedp/PyBindCppMain.cpp +++ b/cpp_to_py/routedp/PyBindCppMain.cpp @@ -1,3 +1,4 @@ +#include #include "common/common.h" #include "common/db/Database.h" #include "flute.h" diff --git a/src/detail_placement.py b/src/detail_placement.py index 8f1eeba..b6ac062 100644 --- a/src/detail_placement.py +++ b/src/detail_placement.py @@ -361,7 +361,7 @@ def macro_legalization_main(node_pos: torch.Tensor, data: PlaceData, args, logge # Commit result commit_to_node_pos(node_pos, data, lg_rawdb) torch.cuda.synchronize(node_pos.device) - logger.info("***** Finish Macro Legalization, HPWL: %.4E Time: %.4f *****" % ( + logger.info("***** Finish Macro Legalization, HPWL: %.6E Time: %.4f *****" % ( get_obj_hpwl(node_pos, data, args).item(), time.time() - ml_time )) @@ -419,7 +419,7 @@ def run_lg(node_pos: torch.Tensor, data: PlaceData, args, logger): # Commit result commit_to_node_pos(node_pos, data, lg_rawdb) torch.cuda.synchronize(node_pos.device) - logger.info("***** Finish Legalization, HPWL: %.4E Time: %.4f *****" % ( + logger.info("***** Finish Legalization, HPWL: %.6E Time: %.4f *****" % ( get_obj_hpwl(node_pos, data, args).item(), time.time() - gl_time )) @@ -492,7 +492,7 @@ def run_dp(node_pos: torch.Tensor, data: PlaceData, args, logger): # update dp_rawdb for next step dp_func and update the final solution dp_rawdb.commit() commit_to_node_pos(node_pos, data, dp_rawdb) - logger.info("***** Finish %s, HPWL: %.4E Time: %.4f *****" % ( + logger.info("***** Finish %s, HPWL: %.6E Time: %.4f *****" % ( func_name, get_obj_hpwl(node_pos, data, args).item(), time.time() - start_time )) @@ -545,7 +545,7 @@ def run_dp_route_opt(node_pos: torch.Tensor, gpdb, rawdb, ps, data: PlaceData, a logger.error("Check failed in %s. Rollback to previous DP iteration." % func_name) node_pos[mov_lhs:mov_rhs].data.copy_(node_pos_bk[mov_lhs:mov_rhs]) - logger.info("***** Finish %s, HPWL: %.4E Time: %.4f *****" % ( + logger.info("***** Finish %s, HPWL: %.6E Time: %.4f *****" % ( func_name, get_obj_hpwl(node_pos, data, args).item(), time.time() - start_time )) @@ -674,7 +674,7 @@ def external_detail_placement(input_file, data: PlaceData, args, logger, eval_mo else: logger.info("Finish external detailed placement. LG+DP Time: %.2f seconds" % (dp_end_time - dp_start_time)) - logger.info("After DP, HPWL: %.4E" % dp_hpwl) + logger.info("After DP, HPWL: %.6E" % dp_hpwl) logger.info("Write detail placement in %s" % dp_out_file) # del gpdb, rawdb # logger.info("Evaluating detail placement result...") @@ -684,7 +684,7 @@ def external_detail_placement(input_file, data: PlaceData, args, logger, eval_mo # hpwl = get_obj_hpwl(data.node_pos, data, args).item() # info = (iteration + 1, hpwl, data.design_name) # draw_fig_with_cairo_cpp(data.node_pos, data.node_size, data, info, args) - # logger.info("After DP, HPWL: %.4E" % hpwl) + # logger.info("After DP, HPWL: %.6E" % hpwl) dp_time = dp_end_time - dp_start_time if dp_end_time is not None else 0.0 @@ -716,7 +716,7 @@ def default_detail_placement(node_pos, gpdb, rawdb, ps, data: PlaceData, args, l info = ("%d_dp" % (ps.iter + 1), dp_hpwl, data.design_name) if args.draw_placement: draw_fig_with_cairo_cpp(node_pos, data.node_size, data, info, args) - logger.info("After DP, HPWL: %.4E" % dp_hpwl) + logger.info("After DP, HPWL: %.6E" % dp_hpwl) lg_time = lg_end_time - lg_start_time dp_time = dp_end_time - dp_start_time @@ -769,7 +769,7 @@ def detail_placement_main(node_pos, gpdb, rawdb, ps, data: PlaceData, args, logg ext_dp_hpwl, top5overflow, _ = external_detail_placement( dp_out_file, data, args, logger, eval_mode=True, dp_engine_name=args.eval_engine ) - logger.info("External engine evaluated DP HPWL: %.4E Top-5 OVFL: %.2f" % + logger.info("External engine evaluated DP HPWL: %.6E Top-5 OVFL: %.2f" % (ext_dp_hpwl, top5overflow)) dp_hpwl = ext_dp_hpwl else: diff --git a/src/run_placement_nesterov.py b/src/run_placement_nesterov.py index 85041e3..c0d8803 100644 --- a/src/run_placement_nesterov.py +++ b/src/run_placement_nesterov.py @@ -164,7 +164,7 @@ def run_placement_main_nesterov(args, logger): if args.draw_placement: info = ("%d_mixed_gp" % (iteration + 1), hpwl, data.design_name) draw_fig_with_cairo_cpp(node_pos, data.node_size, data, info, args) - logger.info("After Mixed-GP, best solution eval, exact HPWL: %.4E exact Overflow: %.4f" % (hpwl, overflow)) + logger.info("After Mixed-GP, best solution eval, exact HPWL: %.6E exact Overflow: %.4f" % (hpwl, overflow)) # Run macro legalization to change node_pos inplace macro_legalization_main(node_pos, data, args, logger) if args.draw_placement: @@ -375,7 +375,7 @@ def run_placement_main_nesterov(args, logger): gp_end_time = time.time() gp_time = gp_end_time - gp_start_time gp_per_iter = gp_time / (iteration + 1) - logger.info("GP Stop! #Iters %d masked_hpwl: %.4E overflow: %.4f GP Time: %.4fs perIterTime: %.6fs" % + logger.info("GP Stop! #Iters %d masked_hpwl: %.6E overflow: %.4f GP Time: %.4fs perIterTime: %.6fs" % (iteration, hpwl, overflow, gp_time, gp_time / (iteration + 1)) ) @@ -385,7 +385,7 @@ def run_placement_main_nesterov(args, logger): info = ("%d_gp" % (iteration + 1), hpwl, data.design_name) if args.draw_placement: draw_fig_with_cairo_cpp(node_pos, data.node_size, data, info, args) - logger.info("After GP, best solution eval, exact HPWL: %.4E exact Overflow: %.4f" % (hpwl, overflow)) + logger.info("After GP, best solution eval, exact HPWL: %.6E exact Overflow: %.4f" % (hpwl, overflow)) ps.visualize(args, logger) gp_hpwl = hpwl gp_time = gp_end_time - gp_start_time