diff --git a/CMakeLists.txt b/CMakeLists.txt index b91d361..1f1f36d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,7 @@ set (REPLACE_SRC src/fft.cpp src/fftsg.cpp src/fftsg2d.cpp - src/coordi.cpp + src/point.cpp src/plot.cpp src/logger.cpp ) diff --git a/src/coordi.cpp b/src/coordi.cpp deleted file mode 100644 index e887e06..0000000 --- a/src/coordi.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "coordi.h" - -namespace replace { - -FloatCoordi::FloatCoordi() : x(0), y(0) {} -FloatCoordi::FloatCoordi(float inputX, float inputY) { - x = inputX; - y = inputY; -} - -IntCoordi::IntCoordi() : x(0), y(0) {} -IntCoordi::IntCoordi(int inputX, int inputY) { - x = inputX; - y = inputY; -} -} - diff --git a/src/nesterovBase.cpp b/src/nesterovBase.cpp index cf3c2a6..e04ae41 100644 --- a/src/nesterovBase.cpp +++ b/src/nesterovBase.cpp @@ -1170,7 +1170,7 @@ NesterovBase::placerToNesterov(Pin* pin) { // gcell update void NesterovBase::updateGCellLocation( - std::vector& coordis) { + std::vector& coordis) { for(auto& coordi : coordis) { int idx = &coordi - &coordis[0]; gCells_[idx]->setLocation( coordi.x, coordi.y ); @@ -1180,7 +1180,7 @@ NesterovBase::updateGCellLocation( // gcell update void NesterovBase::updateGCellCenterLocation( - std::vector& coordis) { + std::vector& coordis) { for(auto& coordi : coordis) { int idx = &coordi - &coordis[0]; gCells_[idx]->setCenterLocation( coordi.x, coordi.y ); @@ -1189,7 +1189,7 @@ NesterovBase::updateGCellCenterLocation( void NesterovBase::updateGCellDensityCenterLocation( - std::vector& coordis) { + std::vector& coordis) { for(auto& coordi : coordis) { int idx = &coordi - &coordis[0]; gCells_[idx]->setDensityCenterLocation( @@ -1347,9 +1347,9 @@ NesterovBase::updateWireLengthForceWA( } // get x,y WA Gradient values with given GCell -FloatCoordi +FloatPoint NesterovBase::getWireLengthGradientWA(GCell* gCell, float wlCoeffX, float wlCoeffY) { - FloatCoordi gradientPair; + FloatPoint gradientPair; for(auto& gPin : gCell->gPins()) { auto tmpPair = getWireLengthGradientPinWA(gPin, wlCoeffX, wlCoeffY); @@ -1367,7 +1367,7 @@ NesterovBase::getWireLengthGradientWA(GCell* gCell, float wlCoeffX, float wlCoef // // You can't understand the following function // unless you read the (4.13) formula -FloatCoordi +FloatPoint NesterovBase::getWireLengthGradientPinWA(GPin* gPin, float wlCoeffX, float wlCoeffY) { float gradientMinX = 0, gradientMinY = 0; @@ -1422,34 +1422,34 @@ NesterovBase::getWireLengthGradientPinWA(GPin* gPin, float wlCoeffX, float wlCoe / ( waExpMaxSumY * waExpMaxSumY ); } - return FloatCoordi(gradientMinX - gradientMaxX, + return FloatPoint(gradientMinX - gradientMaxX, gradientMinY - gradientMaxY); } -FloatCoordi +FloatPoint NesterovBase::getWireLengthPreconditioner(GCell* gCell) { - return FloatCoordi( gCell->gPins().size(), + return FloatPoint( gCell->gPins().size(), gCell->gPins().size() ); } -FloatCoordi +FloatPoint NesterovBase::getDensityPreconditioner(GCell* gCell) { float areaVal = static_cast(gCell->dx()) * static_cast(gCell->dy()); - return FloatCoordi(areaVal, areaVal); + return FloatPoint(areaVal, areaVal); } // get GCells' electroForcePair // i.e. get DensityGradient with given GCell -FloatCoordi +FloatPoint NesterovBase::getDensityGradient(GCell* gCell) { std::pair pairX = bg_.getDensityMinMaxIdxX(gCell); std::pair pairY = bg_.getDensityMinMaxIdxY(gCell); - FloatCoordi electroForce; + FloatPoint electroForce; for(int i = pairX.first; i < pairX.second; i++) { for(int j = pairY.first; j < pairY.second; j++) { diff --git a/src/nesterovBase.h b/src/nesterovBase.h index aa1e613..6861087 100644 --- a/src/nesterovBase.h +++ b/src/nesterovBase.h @@ -5,7 +5,7 @@ #include #include -#include "coordi.h" +#include "point.h" namespace replace { @@ -730,14 +730,14 @@ public: // update gCells with lx, ly void updateGCellLocation( - std::vector& coordis); + std::vector& points); // update gCells with cx, cy void updateGCellCenterLocation( - std::vector& coordis); + std::vector& points); void updateGCellDensityCenterLocation( - std::vector& coordis); + std::vector& points); int binCntX() const; int binCntY() const; @@ -766,22 +766,22 @@ public: float wlCoeffX, float wlCoeffY); - FloatCoordi + FloatPoint getWireLengthGradientPinWA(GPin* gPin, float wlCoeffX, float wlCoeffY); - FloatCoordi + FloatPoint getWireLengthGradientWA(GCell* gCell, float wlCoeffX, float wlCoeffY); // for preconditioner - FloatCoordi + FloatPoint getWireLengthPreconditioner(GCell* gCell); - FloatCoordi + FloatPoint getDensityPreconditioner(GCell* gCell); - FloatCoordi + FloatPoint getDensityGradient(GCell* gCell); int64_t getHpwl(); diff --git a/src/nesterovPlace.cpp b/src/nesterovPlace.cpp index 25e4d81..6a6d4f1 100644 --- a/src/nesterovPlace.cpp +++ b/src/nesterovPlace.cpp @@ -11,10 +11,10 @@ using namespace std; namespace replace { static float -getDistance(vector& a, vector& b); +getDistance(vector& a, vector& b); static float -getSecondNorm(vector& a); +getSecondNorm(vector& a); NesterovPlaceVars::NesterovPlaceVars() : maxNesterovIter(2000), @@ -65,23 +65,23 @@ void NesterovPlace::init() { log_->procBegin("NesterovInit", 3); const int gCellSize = nb_->gCells().size(); - curSLPCoordi_.resize(gCellSize, FloatCoordi()); - curSLPWireLengthGrads_.resize(gCellSize, FloatCoordi()); - curSLPDensityGrads_.resize(gCellSize, FloatCoordi()); - curSLPSumGrads_.resize(gCellSize, FloatCoordi()); + curSLPCoordi_.resize(gCellSize, FloatPoint()); + curSLPWireLengthGrads_.resize(gCellSize, FloatPoint()); + curSLPDensityGrads_.resize(gCellSize, FloatPoint()); + curSLPSumGrads_.resize(gCellSize, FloatPoint()); - nextSLPCoordi_.resize(gCellSize, FloatCoordi()); - nextSLPWireLengthGrads_.resize(gCellSize, FloatCoordi()); - nextSLPDensityGrads_.resize(gCellSize, FloatCoordi()); - nextSLPSumGrads_.resize(gCellSize, FloatCoordi()); + nextSLPCoordi_.resize(gCellSize, FloatPoint()); + nextSLPWireLengthGrads_.resize(gCellSize, FloatPoint()); + nextSLPDensityGrads_.resize(gCellSize, FloatPoint()); + nextSLPSumGrads_.resize(gCellSize, FloatPoint()); - prevSLPCoordi_.resize(gCellSize, FloatCoordi()); - prevSLPWireLengthGrads_.resize(gCellSize, FloatCoordi()); - prevSLPDensityGrads_.resize(gCellSize, FloatCoordi()); - prevSLPSumGrads_.resize(gCellSize, FloatCoordi()); + prevSLPCoordi_.resize(gCellSize, FloatPoint()); + prevSLPWireLengthGrads_.resize(gCellSize, FloatPoint()); + prevSLPDensityGrads_.resize(gCellSize, FloatPoint()); + prevSLPSumGrads_.resize(gCellSize, FloatPoint()); - curCoordi_.resize(gCellSize, FloatCoordi()); - nextCoordi_.resize(gCellSize, FloatCoordi()); + curCoordi_.resize(gCellSize, FloatPoint()); + nextCoordi_.resize(gCellSize, FloatPoint()); for(auto& gCell : nb_->gCells()) { nb_->updateDensityCoordiLayoutInside( gCell ); @@ -89,7 +89,7 @@ void NesterovPlace::init() { curSLPCoordi_[idx] = prevSLPCoordi_[idx] = curCoordi_[idx] - = FloatCoordi(gCell->dCx(), gCell->dCy()); + = FloatPoint(gCell->dCx(), gCell->dCy()); } // bin update @@ -174,23 +174,23 @@ void NesterovPlace::init() { // clear reset void NesterovPlace::reset() { - vector ().swap(curSLPCoordi_); - vector ().swap(curSLPWireLengthGrads_); - vector ().swap(curSLPDensityGrads_); - vector ().swap(curSLPSumGrads_); + vector ().swap(curSLPCoordi_); + vector ().swap(curSLPWireLengthGrads_); + vector ().swap(curSLPDensityGrads_); + vector ().swap(curSLPSumGrads_); - vector ().swap(nextSLPCoordi_); - vector ().swap(nextSLPWireLengthGrads_); - vector ().swap(nextSLPDensityGrads_); - vector ().swap(nextSLPSumGrads_); + vector ().swap(nextSLPCoordi_); + vector ().swap(nextSLPWireLengthGrads_); + vector ().swap(nextSLPDensityGrads_); + vector ().swap(nextSLPSumGrads_); - vector ().swap(prevSLPCoordi_); - vector ().swap(prevSLPWireLengthGrads_); - vector ().swap(prevSLPDensityGrads_); - vector ().swap(prevSLPSumGrads_); + vector ().swap(prevSLPCoordi_); + vector ().swap(prevSLPWireLengthGrads_); + vector ().swap(prevSLPDensityGrads_); + vector ().swap(prevSLPSumGrads_); - vector ().swap(curCoordi_); - vector ().swap(nextCoordi_); + vector ().swap(curCoordi_); + vector ().swap(nextCoordi_); } // to execute following function, @@ -202,9 +202,9 @@ void NesterovPlace::reset() { // void NesterovPlace::updateGradients( - std::vector& sumGrads, - std::vector& wireLengthGrads, - std::vector& densityGrads) { + std::vector& sumGrads, + std::vector& wireLengthGrads, + std::vector& densityGrads) { wireLengthGradSum_ = 0; densityGradSum_ = 0; @@ -234,12 +234,12 @@ NesterovPlace::updateGradients( sumGrads[i].x = wireLengthGrads[i].x + densityPenalty_ * densityGrads[i].x; sumGrads[i].y = wireLengthGrads[i].y + densityPenalty_ * densityGrads[i].y; - FloatCoordi wireLengthPreCondi + FloatPoint wireLengthPreCondi = nb_->getWireLengthPreconditioner(gCell); - FloatCoordi densityPrecondi + FloatPoint densityPrecondi = nb_->getDensityPreconditioner(gCell); - FloatCoordi sumPrecondi( + FloatPoint sumPrecondi( wireLengthPreCondi.x + densityPenalty_ * densityPrecondi.x, wireLengthPreCondi.y + densityPenalty_ * densityPrecondi.y); @@ -323,25 +323,25 @@ NesterovPlace::doNesterovPlace() { // fill in nextCoordinates with given stepLength_ for(size_t k=0; kgCells().size(); k++) { - FloatCoordi nextCoordi( + FloatPoint nextCoordi( curSLPCoordi_[k].x + stepLength_ * curSLPSumGrads_[k].x, curSLPCoordi_[k].y + stepLength_ * curSLPSumGrads_[k].y ); - FloatCoordi nextSLPCoordi( + FloatPoint nextSLPCoordi( nextCoordi.x + coeff * (nextCoordi.x - curCoordi_[k].x), nextCoordi.y + coeff * (nextCoordi.y - curCoordi_[k].y)); GCell* curGCell = nb_->gCells()[k]; nextCoordi_[k] - = FloatCoordi( + = FloatPoint( nb_->getDensityCoordiLayoutInsideX( curGCell, nextCoordi.x), nb_->getDensityCoordiLayoutInsideY( curGCell, nextCoordi.y)); nextSLPCoordi_[k] - = FloatCoordi( + = FloatPoint( nb_->getDensityCoordiLayoutInsideX( curGCell, nextSLPCoordi.x), nb_->getDensityCoordiLayoutInsideY( @@ -486,7 +486,7 @@ NesterovPlace::updateInitialPrevSLPCoordi() { = curSLPCoordi_[i].y + npVars_.initialPrevCoordiUpdateCoef * curSLPSumGrads_[i].y; - FloatCoordi newCoordi( + FloatPoint newCoordi( nb_->getDensityCoordiLayoutInsideX( curGCell, prevCoordiX), nb_->getDensityCoordiLayoutInsideY( curGCell, prevCoordiY) ); @@ -536,10 +536,10 @@ NesterovPlace::updateNextIter() { float NesterovPlace::getStepLength( - std::vector& prevSLPCoordi_, - std::vector& prevSLPSumGrads_, - std::vector& curSLPCoordi_, - std::vector& curSLPSumGrads_ ) { + std::vector& prevSLPCoordi_, + std::vector& prevSLPSumGrads_, + std::vector& curSLPCoordi_, + std::vector& curSLPSumGrads_ ) { float coordiDistance = getDistance(prevSLPCoordi_, curSLPCoordi_); @@ -578,7 +578,7 @@ NesterovPlace::updateDb() { static float -getDistance(vector& a, vector& b) { +getDistance(vector& a, vector& b) { float sumDistance = 0.0f; for(size_t i=0; i& a, vector& b) { } static float -getSecondNorm(vector& a) { +getSecondNorm(vector& a) { float norm = 0; for(auto& coordi : a) { norm += coordi.x * coordi.x + coordi.y * coordi.y; diff --git a/src/nesterovPlace.h b/src/nesterovPlace.h index 1e8abe6..61a062c 100644 --- a/src/nesterovPlace.h +++ b/src/nesterovPlace.h @@ -1,7 +1,7 @@ #ifndef __REPLACE_NESTEROV_PLACE__ #define __REPLACE_NESTEROV_PLACE__ -#include "coordi.h" +#include "point.h" #include #include @@ -40,24 +40,24 @@ public: void doNesterovPlace(); void updateCoordi( - std::vector& coordi); + std::vector& coordi); void updateBins(); void updateWireLength(); void updateGradients( - std::vector& sumGrads, - std::vector& wireLengthGrads, - std::vector& densityGrads ); + std::vector& sumGrads, + std::vector& wireLengthGrads, + std::vector& densityGrads ); void updateWireLengthCoef(float overflow); void updateInitialPrevSLPCoordi(); float getStepLength( - std::vector& prevCoordi_, - std::vector& prevSumGrads_, - std::vector& curCoordi_, - std::vector& curSumGrads_ ); + std::vector& prevCoordi_, + std::vector& prevSumGrads_, + std::vector& curCoordi_, + std::vector& curSumGrads_ ); void updateNextIter(); float getPhiCoef(float scaledDiffHpwl); @@ -73,26 +73,26 @@ private: // SLP is Step Length Prediction. // // y_st, y_dst, y_wdst, w_pdst - std::vector curSLPCoordi_; - std::vector curSLPWireLengthGrads_; - std::vector curSLPDensityGrads_; - std::vector curSLPSumGrads_; + std::vector curSLPCoordi_; + std::vector curSLPWireLengthGrads_; + std::vector curSLPDensityGrads_; + std::vector curSLPSumGrads_; // y0_st, y0_dst, y0_wdst, y0_pdst - std::vector nextSLPCoordi_; - std::vector nextSLPWireLengthGrads_; - std::vector nextSLPDensityGrads_; - std::vector nextSLPSumGrads_; + std::vector nextSLPCoordi_; + std::vector nextSLPWireLengthGrads_; + std::vector nextSLPDensityGrads_; + std::vector nextSLPSumGrads_; // z_st, z_dst, z_wdst, z_pdst - std::vector prevSLPCoordi_; - std::vector prevSLPWireLengthGrads_; - std::vector prevSLPDensityGrads_; - std::vector prevSLPSumGrads_; + std::vector prevSLPCoordi_; + std::vector prevSLPWireLengthGrads_; + std::vector prevSLPDensityGrads_; + std::vector prevSLPSumGrads_; // x_st and x0_st - std::vector curCoordi_; - std::vector nextCoordi_; + std::vector curCoordi_; + std::vector nextCoordi_; float wireLengthGradSum_; float densityGradSum_; diff --git a/src/plot.cpp b/src/plot.cpp index d4cdef7..a612849 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -160,7 +160,7 @@ int PlotEnv::GetTotalImageHeight() { return imageHeight + 2 * yMargin; } -int PlotEnv::GetX(FloatCoordi &coord) { +int PlotEnv::GetX(FloatPoint &coord) { return (coord.x - pb_->die().dieLx()) * unitX + xMargin; } @@ -168,7 +168,7 @@ int PlotEnv::GetX(float coord) { return (coord - pb_->die().dieLx()) * unitX + xMargin; } -int PlotEnv::GetY(FloatCoordi &coord) { +int PlotEnv::GetY(FloatPoint &coord) { return (origHeight - (coord.y - pb_->die().dieLy())) * unitY + yMargin; } diff --git a/src/plot.h b/src/plot.h index f92f0cf..73b66a5 100644 --- a/src/plot.h +++ b/src/plot.h @@ -5,7 +5,7 @@ #include #include -#include "coordi.h" +#include "point.h" // // The following structure/header will be removed. @@ -87,9 +87,9 @@ class PlotEnv { void InitCellColors(std::string colorFile); int GetTotalImageWidth(); int GetTotalImageHeight(); - int GetX(FloatCoordi &coord); + int GetX(FloatPoint &coord); int GetX(float coord); - int GetY(FloatCoordi &coord); + int GetY(FloatPoint &coord); int GetY(float coord); void DrawModule(CImgObj *img, const unsigned char color[], float opacity); diff --git a/src/point.cpp b/src/point.cpp new file mode 100644 index 0000000..17ff0e9 --- /dev/null +++ b/src/point.cpp @@ -0,0 +1,17 @@ +#include "point.h" + +namespace replace { + +FloatPoint::FloatPoint() : x(0), y(0) {} +FloatPoint::FloatPoint(float inputX, float inputY) { + x = inputX; + y = inputY; +} + +IntPoint::IntPoint() : x(0), y(0) {} +IntPoint::IntPoint(int inputX, int inputY) { + x = inputX; + y = inputY; +} +} + diff --git a/src/coordi.h b/src/point.h similarity index 54% rename from src/coordi.h rename to src/point.h index cbd09a6..61b2a73 100644 --- a/src/coordi.h +++ b/src/point.h @@ -3,20 +3,20 @@ namespace replace { -class FloatCoordi { +class FloatPoint { public: float x; float y; - FloatCoordi(); - FloatCoordi(float x, float y); + FloatPoint(); + FloatPoint(float x, float y); }; -class IntCoordi { +class IntPoint { public: int x; int y; - IntCoordi(); - IntCoordi(int x, int y); + IntPoint(); + IntPoint(int x, int y); }; }