From 92e55924c4a8789d99fe0961867197c1d27aaa3c Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Fri, 23 Apr 2010 13:13:22 +0000 Subject: [PATCH] * ./knik: - Bug: In MatrixVertex::getLineIndex() and getColumnIndex(), in regular mode, when the Y/X coordinate is exactly on the upper right angle, return the inferior index (instead of superior which is out of bounds). - Change: In MatrixVertex, RoutingGrid & KnikEngine, replace the _lowerLeftX & _lowerLeftY by a complete copy of the Cell's abutment box. Makes easier for getLineIndex() to find out of bound coordinates. - Change: In KnikEngine & LoadSolution add a time/memory measurement, for Kite statistics. --- knik/src/Graph.cpp | 2 +- knik/src/KnikEngine.cpp | 32 +++++++++---- knik/src/LoadSolution.cpp | 6 +++ knik/src/MatrixVertex.cpp | 89 +++++++++++++++++++++++------------- knik/src/knik/KnikEngine.h | 10 +++- knik/src/knik/MatrixVertex.h | 3 +- knik/src/knik/RoutingGrid.h | 65 ++++++++++++++++---------- 7 files changed, 134 insertions(+), 73 deletions(-) diff --git a/knik/src/Graph.cpp b/knik/src/Graph.cpp index db232c33..9f24c8d2 100644 --- a/knik/src/Graph.cpp +++ b/knik/src/Graph.cpp @@ -364,7 +364,7 @@ Vertex* Graph::getVertex ( Point p ) Vertex* Graph::getVertex ( DbU::Unit x, DbU::Unit y ) // ************************************************** { - return getVertex ( Point ( x, y ) ); + return getVertex ( Point(x,y) ); } unsigned Graph::getGridLength ( Segment* segment ) diff --git a/knik/src/KnikEngine.cpp b/knik/src/KnikEngine.cpp index 6713ca68..ad3e0d3d 100644 --- a/knik/src/KnikEngine.cpp +++ b/knik/src/KnikEngine.cpp @@ -61,6 +61,7 @@ #include "crlcore/Utilities.h" #include "crlcore/ToolBox.h" +#include "crlcore/Measures.h" #include "knik/Configuration.h" #include "knik/Edge.h" @@ -75,6 +76,8 @@ namespace Knik { + using CRL::addMeasure; + //globale variables unsigned __congestion__; unsigned __precongestion__; @@ -264,19 +267,24 @@ void KnikEngine::initGlobalRouting() __initialized__ = true; } -void KnikEngine::createRoutingGrid ( unsigned nbXTiles - , unsigned nbYTiles - , DbU::Unit lowerLeftX - , DbU::Unit lowerLeftY - , DbU::Unit tileWidth - , DbU::Unit tileHeight - , unsigned hcapacity - , unsigned vcapacity ) -// ****************************************************** +void KnikEngine::createRoutingGrid ( unsigned nbXTiles + , unsigned nbYTiles + , const Box& boundingBox + , DbU::Unit tileWidth + , DbU::Unit tileHeight + , unsigned hcapacity + , unsigned vcapacity ) { - _routingGrid = RoutingGrid::create ( nbXTiles, nbYTiles, lowerLeftX, lowerLeftY, tileWidth, tileHeight, hcapacity, vcapacity ); + _routingGrid = RoutingGrid::create ( nbXTiles + , nbYTiles + , boundingBox + , tileWidth + , tileHeight + , hcapacity + , vcapacity ); } + void KnikEngine::createRoutingGraph() // ********************************** { @@ -341,6 +349,7 @@ void KnikEngine::printTime() << "s [+" << (_timer.getIncrease()>>10) << "Ko/" << (_timer.getMemorySize()>>10) << "Ko])" << endl; + } // void KnikEngine::showEstimateOccupancy() // // ************************************* @@ -1011,6 +1020,9 @@ void KnikEngine::run() reroute(); done = analyseRouting(); } + + addMeasure ( getCell(), "knikT", _timer.getCombTime () ); + addMeasure ( getCell(), "knikS", (_timer.getMemorySize() >> 20) ); } void KnikEngine::Route() diff --git a/knik/src/LoadSolution.cpp b/knik/src/LoadSolution.cpp index ce8a59fe..c5b59011 100644 --- a/knik/src/LoadSolution.cpp +++ b/knik/src/LoadSolution.cpp @@ -37,6 +37,7 @@ #include "hurricane/UpdateSession.h" #include "crlcore/Utilities.h" +#include "crlcore/Measures.h" #include "knik/Configuration.h" #include "knik/Graph.h" @@ -412,6 +413,8 @@ namespace { namespace Knik { + using CRL::addMeasure; + void KnikEngine::loadSolution ( const string& fileName ) { @@ -421,6 +424,9 @@ namespace Knik { SolutionParser parser ( this, loadFileName ); parser.load (); + + addMeasure ( getCell(), "knikT", 0.0 ); + addMeasure ( getCell(), "knikS", 0 ); } diff --git a/knik/src/MatrixVertex.cpp b/knik/src/MatrixVertex.cpp index c2730a0b..bdc508c0 100644 --- a/knik/src/MatrixVertex.cpp +++ b/knik/src/MatrixVertex.cpp @@ -24,8 +24,7 @@ MatrixVertex::MatrixVertex ( Graph* routingGraph ) , _nbYTiles(0) , _tileWidth(0) , _tileHeight(0) - , _lowerLeftX(0) - , _lowerLeftY(0) + , _boundingBox(0,0,1,1) , _routingGraph(routingGraph) { } @@ -76,7 +75,7 @@ void MatrixVertex::_preDestroy() //{ // if ( _yInit ) // throw Error ("MatrixVertex::createYRegular(): cannot initialize Y vector twice."); -// _lowerLeftY = routingGrid->getLowerLeftY(); +// _boundingBox.getYMin() = routingGrid->getLowerLeftY(); // _nbYTiles = routingGrid->getNbYTiles(); // _tileHeight = routingGrid->getTileHeight(); // _yRegular = true; @@ -92,16 +91,15 @@ Vertex* MatrixVertex::createRegularMatrix ( RoutingGrid* routingGrid ) if ( _xInit || _yInit ) throw Error ("MatrixVertex::createRegularMatrix(): cannot initialize matrix twice."); - _lowerLeftX = routingGrid->getLowerLeftX(); - _lowerLeftY = routingGrid->getLowerLeftY(); - _nbXTiles = routingGrid->getNbXTiles(); - _nbYTiles = routingGrid->getNbYTiles(); - _tileWidth = routingGrid->getTileWidth(); - _tileHeight = routingGrid->getTileHeight(); - _xInit = true; // XXX Nécessaire pour les fonctions comme getLineIndex - _yInit = true; - _xRegular = true; // XXX Nécessaire pour les fonctions comme getLineIndex - _yRegular = true; + _boundingBox = routingGrid->getBoundingBox(); + _nbXTiles = routingGrid->getNbXTiles(); + _nbYTiles = routingGrid->getNbYTiles(); + _tileWidth = routingGrid->getTileWidth(); + _tileHeight = routingGrid->getTileHeight(); + _xInit = true; // XXX Nécessaire pour les fonctions comme getLineIndex + _yInit = true; + _xRegular = true; // XXX Nécessaire pour les fonctions comme getLineIndex + _yRegular = true; DbU::Unit halfWidth = _tileWidth / 2; DbU::Unit halfHeight = _tileHeight / 2; @@ -110,7 +108,7 @@ Vertex* MatrixVertex::createRegularMatrix ( RoutingGrid* routingGrid ) for ( unsigned j = 0 ; j < _nbYTiles ; j++ ) { vector vect; for ( unsigned i = 0 ; i < _nbXTiles ; i++ ) { - Point position ( _lowerLeftX+(i*_tileWidth)+halfWidth, _lowerLeftY+(j*_tileHeight)+halfHeight ); + Point position ( _boundingBox.getXMin()+(i*_tileWidth)+halfWidth, _boundingBox.getYMin()+(j*_tileHeight)+halfHeight ); // on cree le vertex Vertex* vertex = _routingGraph->createVertex ( position, halfWidth, halfHeight ); assert ( vertex ); @@ -148,8 +146,7 @@ Vertex* MatrixVertex::createRegularMatrix () DbU::Unit sliceHeight = AllianceFramework::get()->getCellGauge()->getSliceHeight(); DbU::Unit cellWidth = cell->getAbutmentBox().getWidth(); DbU::Unit cellHeight = cell->getAbutmentBox().getHeight(); - _lowerLeftX = cell->getAbutmentBox().getXMin(); - _lowerLeftY = cell->getAbutmentBox().getYMin(); + _boundingBox = cell->getAbutmentBox(); _nbXTiles = (unsigned int)ceil(float(cellWidth) / float(sliceHeight)); _nbYTiles = (unsigned int)ceil(float(cellHeight) / float(sliceHeight)); _tileWidth = sliceHeight; @@ -165,8 +162,7 @@ Vertex* MatrixVertex::createRegularMatrix () // << " - this : " << (void*)this << endl // << " - cellWidth : " << cellWidth << endl // << " - cellHeight : " << cellHeight << endl -// << " - lowerLeftX : " << _lowerLeftX << endl -// << " - lowerLeftY : " << _lowerLeftY << endl +// << " - boundingBox : " << _boundingBox << endl // << " - nbXTiles : " << _nbXTiles << endl // << " - nbYTiles : " << _nbYTiles << endl // << " - tileWidth : " << _tileWidth << endl @@ -181,7 +177,7 @@ Vertex* MatrixVertex::createRegularMatrix () for ( unsigned i = 0 ; i < _nbXTiles ; i++ ) { DbU::Unit halfWidth = (i == _nbXTiles - 1)?_latestTileWidth/2:_tileWidth/2; DbU::Unit halfHeight = (j == _nbYTiles - 1)?_latestTileHeight/2:_tileHeight/2; - Point position ( _lowerLeftX+(i*_tileWidth)+halfWidth, _lowerLeftY+(j*_tileHeight)+halfHeight ); + Point position ( _boundingBox.getXMin()+(i*_tileWidth)+halfWidth, _boundingBox.getYMin()+(j*_tileHeight)+halfHeight ); // on cree le vertex Vertex* vertex = _routingGraph->createVertex ( position, halfWidth, halfHeight ); assert ( vertex ); @@ -293,24 +289,37 @@ unsigned int MatrixVertex::getLineIndex ( DbU::Unit y ) // *********************************************** { assert(_yInit ); - + if ( _yRegular ) { -// cerr << "y:" << DbU::getValueString(y-_lowerLeftY) << "/" << DbU::getValueString(_tileHeight) -// << "=" << (DbU::getLambda(y-_lowerLeftY)/_tileHeight) -// << "<=>" << (unsigned int)floor((y-_lowerLeftY)/_tileHeight) << endl; - return (unsigned int)floor((y-_lowerLeftY)/_tileHeight); +// cerr << "y:" << DbU::getValueString(y-_boundingBox.getYMin()) << "/" << DbU::getValueString(_tileHeight) +// << "=" << (DbU::getLambda(y-_boundingBox.getYMin())/_tileHeight) +// << "<=>" << (unsigned int)floor((y-_boundingBox.getYMin())/_tileHeight) << endl; + if ( (y < _boundingBox.getYMin()) or (y > _boundingBox.getYMax()) ) + throw Error ("MatrixVertex::getLineIndex(): search value (%s) is out of bounds [%s,%s]." + ,DbU::getValueString(y).c_str() + ,DbU::getValueString(_boundingBox.getYMin()).c_str() + ,DbU::getValueString(_boundingBox.getYMax()).c_str()); + + unsigned int index = (unsigned int)floor((y-_boundingBox.getYMin())/_tileHeight); + if ( y == _boundingBox.getYMax() ) --index; + + return index; } + assert(is_sorted(_linesIndexes.begin(), _linesIndexes.end())); - if ( y == (*_linesIndexes.rbegin()).first ) - return (*_linesIndexes.rbegin()).second-1; + if ( _linesIndexes.empty() ); + throw Error ( "MatrixVertex::getLineIndex(): Indexes map is empty." ); + pair result = equal_range (_linesIndexes.begin(), _linesIndexes.end() , pair(y,0), MatrixVertex::IndexComp()); if ( result.second == _linesIndexes.begin() ) throw Error ("MatrixVertex::getLineIndex(): search value (%s) is lower than lowest bound (%s)." - ,getString(y).c_str(),getString((*_linesIndexes.begin()).first).c_str()); + ,DbU::getValueString(y).c_str() + ,DbU::getValueString((*_linesIndexes.begin()).first).c_str()); if ( result.second == _linesIndexes.end() ) throw Error ("MatrixVertex::getLineIndex(): search value (%s) is upper than uppest bound (%s)." - ,getString(y).c_str(),getString((*_linesIndexes.rbegin()).first).c_str()); + ,DbU::getValueString(y).c_str() + ,DbU::getValueString((*_linesIndexes.rbegin()).first).c_str()); return ((*result.second).second-1); } @@ -319,14 +328,28 @@ unsigned int MatrixVertex::getColumnIndex ( DbU::Unit x ) // ************************************************* { assert(_xInit ); + + unsigned int maxIndex = (*_columnsIndexes.rbegin()).second - 1; + if ( _xRegular ) { -// cerr << "x:" << DbU::getValueString(x-DbU::lambda(_lowerLeftX)) << "/" << _tileWidth << "=" << (DbU::getLambda(x-DbU::lambda(_lowerLeftX))/_tileWidth) -// << "<=>" << (unsigned int)floor(DbU::getLambda(x-DbU::lambda(_lowerLeftX))/_tileWidth) << endl; - return (unsigned int)floor((x-_lowerLeftX)/_tileWidth); +// cerr << "x:" << DbU::getValueString(x-DbU::lambda(_boundingBox.getXMin())) << "/" << _tileWidth << "=" << (DbU::getLambda(x-DbU::lambda(_lowerLeftX))/_tileWidth) +// << "<=>" << (unsigned int)floor(DbU::getLambda(x-DbU::lambda(_boundingBox.getXMin()))/_tileWidth) << endl; + if ( (x < _boundingBox.getXMin()) or (x > _boundingBox.getXMax()) ) + throw Error ("MatrixVertex::getColumnIndex(): search value (%s) is out of bounds [%s,%s]." + ,DbU::getValueString(x).c_str() + ,DbU::getValueString(_boundingBox.getXMin()).c_str() + ,DbU::getValueString(_boundingBox.getXMax()).c_str()); + + unsigned int index = (unsigned int)floor((x-_boundingBox.getXMin())/_tileWidth); + if ( x == _boundingBox.getXMax() ) --index; + + return index; } + assert(is_sorted(_columnsIndexes.begin(),_columnsIndexes.end())); - if ( x == (*_columnsIndexes.rbegin()).first ) - return (*_columnsIndexes.rbegin()).second-1; + if ( _columnsIndexes.empty() ); + throw Error ( "MatrixVertex::getColumnIndex(): Indexes map is empty." ); + pair result = equal_range (_columnsIndexes.begin(), _columnsIndexes.end() , pair(x,0), MatrixVertex::IndexComp()); if ( result.second == _columnsIndexes.begin() ) diff --git a/knik/src/knik/KnikEngine.h b/knik/src/knik/KnikEngine.h index 797f83da..29dd4a27 100644 --- a/knik/src/knik/KnikEngine.h +++ b/knik/src/knik/KnikEngine.h @@ -52,6 +52,7 @@ using Hurricane::Timer; using Hurricane::Name; using Hurricane::DbU; using Hurricane::Point; +using Hurricane::Box; using Hurricane::Net; using Hurricane::Segment; using Hurricane::Contact; @@ -168,8 +169,13 @@ typedef vector NetVector; void initGlobalRouting(); // Making it public, so it can be called earlier and then capacities on edges can be ajusted void run(); void Route(); - void createRoutingGrid ( unsigned nbXTiles, unsigned nbYTiles - , DbU::Unit lowerLeftX, DbU::Unit lowerLeftY, DbU::Unit tileWidth, DbU::Unit tileHeight, unsigned hcapacity, unsigned vcapacity ); + void createRoutingGrid ( unsigned nbXTiles + , unsigned nbYTiles + , const Box& boundingBox + , DbU::Unit tileWidth + , DbU::Unit tileHeight + , unsigned hcapacity + , unsigned vcapacity ); void updateEdgeCapacity ( unsigned col1, unsigned row1, unsigned col2, unsigned row2, unsigned capacity ); void increaseEdgeCapacity ( unsigned col1, unsigned row1, unsigned col2, unsigned row2, int capacity ); void insertSegment ( Segment* segment ); diff --git a/knik/src/knik/MatrixVertex.h b/knik/src/knik/MatrixVertex.h index 004c4b5d..789fa468 100644 --- a/knik/src/knik/MatrixVertex.h +++ b/knik/src/knik/MatrixVertex.h @@ -38,8 +38,7 @@ namespace Knik { unsigned _nbYTiles; DbU::Unit _tileWidth; DbU::Unit _tileHeight; - DbU::Unit _lowerLeftX; - DbU::Unit _lowerLeftY; + Box _boundingBox; Graph* _routingGraph; vector< vector > _matrix; vector< pair > _linesIndexes; diff --git a/knik/src/knik/RoutingGrid.h b/knik/src/knik/RoutingGrid.h index 78bde2d3..8a721577 100644 --- a/knik/src/knik/RoutingGrid.h +++ b/knik/src/knik/RoutingGrid.h @@ -14,8 +14,7 @@ namespace Knik { private: unsigned _nbXTiles; unsigned _nbYTiles; - DbU::Unit _lowerLeftX; - DbU::Unit _lowerLeftY; + Box _boundingBox; DbU::Unit _tileWidth; DbU::Unit _tileHeight; unsigned _hcapacity; @@ -24,37 +23,53 @@ namespace Knik { // Constructors & Destructors // ************************** protected: - RoutingGrid ( unsigned nbXTiles, unsigned nbYTiles, DbU::Unit lowerLeftX, DbU::Unit lowerLeftY - , DbU::Unit tileWidth, DbU::Unit tileHeight, unsigned hcapacity, unsigned vcapacity ) - : _nbXTiles ( nbXTiles ) - , _nbYTiles ( nbYTiles ) - , _lowerLeftX ( lowerLeftX ) - , _lowerLeftY ( lowerLeftY ) - , _tileWidth ( tileWidth ) - , _tileHeight ( tileHeight ) - , _hcapacity ( hcapacity ) - , _vcapacity ( vcapacity ) - {}; + RoutingGrid ( unsigned nbXTiles + , unsigned nbYTiles + , const Box& boundingBox + , DbU::Unit tileWidth + , DbU::Unit tileHeight + , unsigned hcapacity + , unsigned vcapacity ) + : _nbXTiles (nbXTiles) + , _nbYTiles (nbYTiles) + , _boundingBox(boundingBox) + , _tileWidth (tileWidth) + , _tileHeight (tileHeight) + , _hcapacity (hcapacity) + , _vcapacity (vcapacity) + { }; ~RoutingGrid () {}; public: - static RoutingGrid* create ( unsigned nbXTiles, unsigned nbYTiles, DbU::Unit lowerLeftX - , DbU::Unit lowerLeftY, DbU::Unit tileWidth, DbU::Unit tileHeight, unsigned hcapacity, unsigned vcapacity ) + static RoutingGrid* create ( unsigned nbXTiles + , unsigned nbYTiles + , const Box& boundingBox + , DbU::Unit tileWidth + , DbU::Unit tileHeight + , unsigned hcapacity + , unsigned vcapacity ) { - RoutingGrid* _routingGrid = new RoutingGrid ( nbXTiles, nbYTiles, lowerLeftX, lowerLeftY, tileWidth, tileHeight, hcapacity, vcapacity ); - return _routingGrid; + RoutingGrid* _routingGrid = new RoutingGrid ( nbXTiles + , nbYTiles + , boundingBox + , tileWidth + , tileHeight + , hcapacity + , vcapacity ); + return _routingGrid; }; // Accessors // ********* public: - unsigned getNbXTiles() { return _nbXTiles; }; - unsigned getNbYTiles() { return _nbYTiles; }; - DbU::Unit getLowerLeftX() { return _lowerLeftX; }; - DbU::Unit getLowerLeftY() { return _lowerLeftY; }; - DbU::Unit getTileWidth() { return _tileWidth; }; - DbU::Unit getTileHeight() { return _tileHeight; }; - unsigned getHCapacity() { return _hcapacity; }; - unsigned getVCapacity() { return _vcapacity; }; + unsigned getNbXTiles() { return _nbXTiles; }; + unsigned getNbYTiles() { return _nbYTiles; }; + const Box& getBoundingBox() const { return _boundingBox; } + DbU::Unit getLowerLeftX() { return _boundingBox.getXMin(); }; + DbU::Unit getLowerLeftY() { return _boundingBox.getYMin(); }; + DbU::Unit getTileWidth() { return _tileWidth; }; + DbU::Unit getTileHeight() { return _tileHeight; }; + unsigned getHCapacity() { return _hcapacity; }; + unsigned getVCapacity() { return _vcapacity; }; // Modifiers // *********