Refine cpp code to avoid always including torch and pybind

This commit is contained in:
liulixinkerry 2024-06-05 16:11:25 +08:00
parent 8e7c817f46
commit 7e6a0b0ba7
35 changed files with 225 additions and 197 deletions

View File

@ -30,19 +30,8 @@
#include <thread>
// Torch library
#include <torch/extension.h>
// utils
#include "common/utils/utils.h"
// Pybind11
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <pybind11/numpy.h>
using namespace std;
using utils::assert_msg;
using utils::logger;

View File

@ -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() << ')';
}
};

View File

@ -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<string, NDR*>::const_iterator mi = ndrs.find(name);
std::map<string, NDR*>::const_iterator mi = ndrs.find(name);
if (mi == ndrs.end()) {
return nullptr;
}

View File

@ -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<Net*> nets;
vector<Row*> rows;
vector<Region*> regions;
map<string, NDR*> ndrs;
std::map<string, NDR*> ndrs;
vector<SNet*> snets;
vector<Track*> 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);

View File

@ -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<Rectangle>& 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<Rectangle>& 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;
}
}

View File

@ -34,7 +34,7 @@ public:
static void sliceH(vector<Rectangle>& rects);
static void sliceV(vector<Rectangle>& 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<int, Geometry> _map;
std::map<int, Geometry> _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<int, Geometry>::const_iterator begin() const noexcept { return _map.begin(); }
map<int, Geometry>::const_iterator end() const noexcept { return _map.end(); }
map<int, Geometry>::const_iterator find(const int k) const { return _map.find(k); }
std::map<int, Geometry>::const_iterator begin() const noexcept { return _map.begin(); }
std::map<int, Geometry>::const_iterator end() const noexcept { return _map.end(); }
std::map<int, Geometry>::const_iterator find(const int k) const { return _map.find(k); }
const Geometry& at(const int k) const { return _map.at(k); }

View File

@ -109,7 +109,7 @@ void Net::addPin(Pin* pin) {
/***** PowerNet *****/
void PowerNet::addRail(SNet* snet, int lx, int hx, int y) {
map<int, SNet*>::iterator rail = rails.find(y);
std::map<int, SNet*>::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<int, SNet*>::iterator topRail = rails.find(hy);
std::map<int, SNet*>::iterator topRail = rails.find(hy);
if (topRail != rails.end()) {
topPower = topRail->second->type;
} else {
valid = false;
}
map<int, SNet*>::iterator botRail = rails.find(ly);
std::map<int, SNet*>::iterator botRail = rails.find(ly);
if (botRail != rails.end()) {
botPower = botRail->second->type;
} else {

View File

@ -26,7 +26,7 @@ public:
unsigned toNode;
// path = [<direction,len>]
// direction : N,S,E,W,U,D
vector<pair<char, int>> path;
vector<std::pair<char, int>> path;
NetRouteSegment(const unsigned fromi = 0, const unsigned toi = 0, const char dir = '\0', const unsigned len = 0);

View File

@ -104,10 +104,10 @@ utils::PointT<int> 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);
}

View File

@ -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);
}

View File

@ -44,7 +44,7 @@ private:
public:
string name = "";
set<Geometry> rects;
std::set<Geometry> rects;
ViaRule rule;
ViaType(const string& name = "", const bool isDef = false) : isDef_(isDef), name(name) {}

View File

@ -54,7 +54,7 @@ public:
int tileH;
double blockagePorosity;
vector<int> IOPinRouteLayer;
vector<pair<int, vector<int>>> routeBlkgs; // cellID, BlockedLayers
vector<std::pair<int, vector<int>>> routeBlkgs; // cellID, BlockedLayers
BookshelfData() {
nCells = 0;
@ -163,8 +163,8 @@ public:
}
void estimateSiteSize() {
set<int> sizeSet;
set<int> heightSet;
std::set<int> sizeSet;
std::set<int> heightSet;
for (int i = 0; i < nCells; i++) {
if (!typeStdCell[i]) {
@ -186,8 +186,8 @@ public:
vector<int> sizes;
vector<int> heights;
set<int>::iterator ii = sizeSet.begin();
set<int>::iterator ie = sizeSet.end();
std::set<int>::iterator ii = sizeSet.begin();
std::set<int>::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<string>& tokens) {
bool readBSLine(std::istream& is, vector<string>& 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;

View File

@ -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;

View File

@ -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<Point> nodes;
std::set<Point> nodes;
Layer* layer = nullptr;
lefiGeomRect* rect = nullptr;
lefiGeomPolygon* polygon = nullptr;
lefiGeometries* geom = pin->port(0);
vector<pair<int, int>> poly;
vector<std::pair<int, int>> 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<Point>::iterator pk;
set<Point>::iterator pl;
set<Point>::iterator pm;
set<Point>::iterator pn;
std::set<Point>::iterator pk;
std::set<Point>::iterator pl;
std::set<Point>::iterator pm;
std::set<Point>::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;

View File

@ -30,7 +30,7 @@ bool isVerilogSymbol(unsigned char c) {
}
return symbols[(int)c] != 0;
}
bool readVerilogLine(istream &is, vector<string> &tokens) {
bool readVerilogLine(std::istream &is, vector<string> &tokens) {
tokens.clear();
string line;
while (is && tokens.empty()) {
@ -73,7 +73,7 @@ bool readVerilogLine(istream &is, vector<string> &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;

View File

@ -2,6 +2,10 @@
// Adapt from https://github.com/limbo018/DREAMPlace/blob/master/dreamplace/ops/draw_place/src/PlaceDrawer.h
#include "Drawer.h"
#include <cairo-pdf.h>
#include <cairo-ps.h>
#include <cairo-svg.h>
#include <cairo.h>
Drawer::Drawer(const std::vector<std::tuple<std::string, double, double, double, double>>& ele_type_to_rgba_vec,
const std::string& filename_,

View File

@ -1,4 +1,21 @@
#include "global.h"
#pragma once
// STL libraries
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
using index_type = int64_t;
class Drawer {
private:
std::unordered_map<std::string, std::tuple<double, double, double, double>> type_to_rgba;

View File

@ -1,4 +1,5 @@
#include "Drawer.h"
#include <pybind11/pybind11.h>
bool DrawGlobalPlacement(
const std::vector<double>& node_pos_x,

View File

@ -1,6 +1,9 @@
#include "common/common.h"
#include "common/db/Database.h"
#include "gpudp/db/dp_torch.h"
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
namespace Xplace {

View File

@ -1,5 +1,6 @@
#pragma once
#include <torch/extension.h>
#include "common/common.h"
#include "common/db/Database.h"

View File

@ -206,7 +206,7 @@ void fillerLegalization(DPTorchRawDB& at_db) {
// sort all blanks and create blank bucket list
int maxDegree = 0;
robin_hood::unordered_map<int, vector<FillerBlank<float>>> blank_bucket_list;
robin_hood::unordered_map<int, std::vector<FillerBlank<float>>> blank_bucket_list;
for (int i = 0; i < num_blanks_x * num_blanks_y; i += 1) {
std::vector<FillerBlank<float>>& 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<int> fillers_to_blank(db.num_movable_nodes - db.num_conn_movable_nodes);
std::vector<int> 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;
}

View File

@ -3,6 +3,9 @@
#include "gpugr/db/GRDatabase.h"
#include "gpugr/gr/RouteForce.h"
#include "flute.h"
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
namespace Xplace {

View File

@ -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<RectOnLayer>& allObs, db::Cell* cell) {
}
}
tuple<int, int, int, int> GRDatabase::getOrientOffset(int orient, int lx, int ly, int hx, int hy) {
tuple<int, int, int, int> offset; // lx, ly, hx, hy
std::tuple<int, int, int, int> GRDatabase::getOrientOffset(int orient, int lx, int ly, int hx, int hy) {
std::tuple<int, int, int, int> 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<RectOnLayer>& allObs,
wireUsage.resize(gridGraphSize, 0);
wireTotalLength.resize(gridGraphSize, 0);
vector<vector<int>> layerToObjIdx(nLayers);
std::vector<std::vector<int>> 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<RectOnLayer>& allObs,
auto& t = tracks[l];
int dir = (l & 1) ^ m1direction;
vector<vector<vector<std::pair<utils::IntervalT<int>, int>>>> markingBufferLUT;
std::vector<std::vector<std::vector<std::pair<utils::IntervalT<int>, 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<RectOnLayer>& allObs,
utils::IntervalT<int> 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<int> gridTrackIntvl(searchLowerBoundTrack(gridlines[1 - dir][i]),
searchLowerBoundTrack(gridlines[1 - dir][i + 1]) - 1);
@ -570,7 +570,7 @@ void GRDatabase::markObs(std::vector<RectOnLayer>& allObs,
for (int j = 0; j < markingBufferLUT[i].size(); j++) {
if (markingBufferLUT[i][j].size() == 0) continue;
const auto& buf = markingBufferLUT[i][j];
vector<int> trackBlocked(gridTrackIntvl.range() + 1, 0); // blocked track length
std::vector<int> 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<RectOnLayer>& allObs,
wireUsage.resize(gridGraphSize, 0);
wireTotalLength.resize(gridGraphSize, 0);
vector<vector<int>> layerToObjIdx(nLayers);
std::vector<std::vector<int>> 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<float> layer2oricap(nLayers, 0.0);
std::vector<float> 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<RectOnLayer>& allObs,
for (int l = obsStartLayer; l < nLayers; l++) {
int dir = (l & 1) ^ m1direction;
vector<vector<vector<utils::IntervalT<int>>>> markingBufferLUT;
std::vector<std::vector<std::vector<utils::IntervalT<int>>>> 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<RectOnLayer>& allObs,
continue;
}
utils::BoxT<int> 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<int> gridIntvl(gridlines[1 - dir][i], gridlines[1 - dir][i + 1]);
utils::IntervalT<int> blockedIntvl = gridIntvl.IntersectWith(obsBox[1 - dir]);
@ -664,7 +664,7 @@ void GRDatabase::markObsBookShelf(std::vector<RectOnLayer>& allObs,
for (int j = 0; j < markingBufferLUT[i].size(); j++) {
if (markingBufferLUT[i][j].size() == 0) continue;
utils::IntervalT<int> gridIntvl(gridlines[1 - dir][i], gridlines[1 - dir][i + 1]);
vector<utils::IntervalT<int>>& buf = markingBufferLUT[i][j];
std::vector<utils::IntervalT<int>>& buf = markingBufferLUT[i][j];
int ovlpLen = 0;
if (buf.size() > 1) {
std::stable_sort(
@ -675,10 +675,10 @@ void GRDatabase::markObsBookShelf(std::vector<RectOnLayer>& allObs,
for (int bufIdx = 1; bufIdx < buf.size(); bufIdx++) {
utils::IntervalT<int>& 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<RectOnLayer>& 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);
}
};

View File

@ -92,7 +92,7 @@ public:
void writeGuides(std::string outputFile);
int encodeId(int l, int x, int y);
tuple<int, int, int, int> getOrientOffset(int orient, int lx, int ly, int hx, int hy);
std::tuple<int, int, int, int> 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<int> getObsMargin(RectOnLayer box, AggrParaRunSpace aggr);

View File

@ -90,7 +90,7 @@ void GPURouter::setUnitViaMultiplier(float value) {
unitViaMultiplier = value;
}
void GPURouter::setUnitVioCost(vector<float>& values, float discount) {
void GPURouter::setUnitVioCost(std::vector<float>& 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<float> &cap, const vector<float> &wir, const vector<float> &fixedL, const vector<float> &fix) {
void GPURouter::setMap(const std::vector<float> &cap, const std::vector<float> &wir, const std::vector<float> &fixedL, const std::vector<float> &fix) {
int gridGraphSize = LAYER * N * N;
auto copy = [&] (const vector<float> &vec, float *target) {
auto copy = [&] (const std::vector<float> &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<GrNet> &nets, int iter) {
void GPURouter::route(std::vector<GrNet> &nets, int iter) {
logger.info("GPU Routing start... DIRECTION: %d", DIRECTION);
double prtime = 0, prpreparetime = 0, batchgentime = 0, timer2 = 0;
vector<int> netsToRoute;
std::vector<int> netsToRoute;
if(iter > 0) {
logger.info("Maze Routing...");
ripupOverflowNets<<<BLOCK_NUMBER(NET_NUM), BLOCK_SIZE>>> (isOverflowNet, routes, routesOffset, wires, vias, NET_NUM);
@ -584,7 +584,7 @@ void GPURouter::route(vector<GrNet> &nets, int iter) {
markUnrouteUsage<<<BLOCK_NUMBER(cnt), BLOCK_SIZE>>> (allpins, vias, cnt);
cudaDeviceSynchronize();*/
}
vector<int> batchSizes;
std::vector<int> batchSizes;
{
double t = clock();
constexpr bool check_vis_correctness = false;
@ -674,8 +674,8 @@ void GPURouter::route(vector<GrNet> &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<GrNet> &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<GrNet> &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<GrNet> &nets, int iter) {
}
}
void GPURouter::setFromNets(vector<GrNet> &nets, int numPlPin_) {
void GPURouter::setFromNets(std::vector<GrNet> &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<GrNet> &nets, int numPlPin_) {
cudaDeviceSynchronize();
}
void GPURouter::setToNets(vector<GrNet> &nets) {
void GPURouter::setToNets(std::vector<GrNet> &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<int> wires, vias;
std::vector<int> 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;

View File

@ -2,6 +2,7 @@
#include "MazeRoute.h"
#include "PatternRoute.h"
#include "common/common.h"
#include <torch/extension.h>
#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<float> &cap,
const vector<float> &wir,
const vector<float> &fixedL,
const vector<float> &fix);
void setFromNets(vector<GrNet> &nets, int numPlPin_);
void setToNets(vector<GrNet> &nets);
void route(vector<GrNet> &nets, int iterleft);
void setMap(const std::vector<float> &cap,
const std::vector<float> &wir,
const std::vector<float> &fixedL,
const std::vector<float> &fix);
void setFromNets(std::vector<GrNet> &nets, int numPlPin_);
void setToNets(std::vector<GrNet> &nets);
void route(std::vector<GrNet> &nets, int iterleft);
void setUnitViaMultiplier(float w);
void setUnitVioCost(vector<float>& cost, float discount);
void setUnitVioCost(std::vector<float>& cost, float discount);
void setLogisticSlope(float value);
void setUnitViaCost(float value);
void query();

View File

@ -1,5 +1,6 @@
#include "GPURouter.h"
#include "InCellUsage.cuh"
#include <torch/extension.h>
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;
}

View File

@ -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);

View File

@ -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);
}

View File

@ -3,7 +3,9 @@
#include "common/db/Database.h"
#include "io_parser/gp/GPDatabase.h"
namespace py = pybind11;
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
namespace Xplace {

View File

@ -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<std::string>();
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<db::Database>, std::shared_ptr<gp::GPDatabase>> start_all(const py::dict& kwargs) {
std::tuple<std::shared_ptr<db::Database>, std::shared_ptr<gp::GPDatabase>> start_all(const pybind11::dict& kwargs) {
bool load_status = loadParams(kwargs);
if (!load_status) {
throw std::invalid_argument("Received invalid params. Please check!");

View File

@ -1,4 +1,5 @@
#pragma once
#include <torch/extension.h>
#include "common/common.h"
#include "common/db/Database.h"

View File

@ -1,3 +1,4 @@
#include <torch/extension.h>
#include "common/common.h"
#include "common/db/Database.h"
#include "flute.h"

View File

@ -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:

View File

@ -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