Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

DB.h

Go to the documentation of this file.
00001 /**************************************************************************
00002 ***    
00003 *** Copyright (c) 1995-2000 Regents of the University of California,
00004 ***               Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan,
00006 ***               Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov
00007 ***
00008 ***  Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
00009 ***  Original Affiliation:   UCLA, Computer Science Department,
00010 ***                          Los Angeles, CA 90095-1596 USA
00011 ***
00012 ***  Permission is hereby granted, free of charge, to any person obtaining 
00013 ***  a copy of this software and associated documentation files (the
00014 ***  "Software"), to deal in the Software without restriction, including
00015 ***  without limitation 
00016 ***  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
00017 ***  and/or sell copies of the Software, and to permit persons to whom the 
00018 ***  Software is furnished to do so, subject to the following conditions:
00019 ***
00020 ***  The above copyright notice and this permission notice shall be included
00021 ***  in all copies or substantial portions of the Software.
00022 ***
00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00030 ***
00031 ***
00032 ***************************************************************************/
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 #ifndef DB_H
00048 #define DB_H
00049 
00050 #include <vector>
00051 #include <algorithm>
00052 #include <math.h>
00053 #include <stdlib.h>
00054 #include "Nets.h"
00055 #include "Nodes.h"
00056 
00057 
00058 namespace parquetfp
00059 {
00060    class DB
00061    {
00062    protected:
00063       Nodes* _nodes;
00064       Nets* _nets;
00065   
00066       Nodes* _nodesBestCopy;
00067 
00068       // cached copies of sum(area of all nodes)
00069       mutable double _area;
00070       mutable bool _initArea;
00071 
00072       double _rowHeight;   //rowHeight to snap the soln to
00073       double _siteSpacing; //site spacing to snap the soln to
00074 
00075    public:
00076       bool successAR;
00077       DB(char* baseName);
00078       DB(DB * db, vector<int>& subBlocksIndices, Point& dbLoc, double reqdAR);
00079       DB(void);
00080 
00081       //makes a copy of db2. compresses multiple 2-pin nets
00082       //between modules regardless of pin-offset. use only when pin-offsets
00083       //are inconsequential
00084       DB(DB& db2, bool compressDB=false);
00085 
00086       ~DB();
00087 
00088       DB& operator=(DB& db2);
00089       void clean(void);
00090 
00091       unsigned getNumNodes(void) const;
00092       Nodes* getNodes(void);
00093       Nets* getNets(void);
00094 
00095       vector<double> getNodeWidths() const;
00096       vector<double> getNodeHeights() const;
00097       vector<double> getXLocs() const;
00098       vector<double> getYLocs() const;
00099 
00100       // hhchan: more efficient (safer) getters 
00101       inline double getNodeArea(unsigned index) const;
00102       inline double getNodeWidth(unsigned index) const;
00103       inline double getNodeHeight(unsigned index) const;
00104       inline double getXLoc(unsigned index) const;
00105       inline double getYLoc(unsigned index) const;
00106       inline ORIENT getOrient(unsigned index) const;
00107 
00108       inline double getNodeMaxAR(unsigned index) const;
00109       inline double getNodeMinAR(unsigned index) const;
00110       inline double getNodeAR(unsigned index) const;
00111 
00112       inline bool isMacro(unsigned index) const;
00113       inline bool isOrientFixed(unsigned index) const;
00114       inline bool isNodeSoft(unsigned index) const;
00115       inline bool isNodeHard(unsigned index) const;
00116 
00117       // hhchan: safer setters
00118       inline void setNodeWidth(unsigned index, double width);
00119       inline void setNodeHeight(unsigned index, double height);
00120       inline void setNodeAR(unsigned index, double ar);
00121       
00122       inline void setXLoc(unsigned index, double newX);
00123       inline void setYLoc(unsigned index, double newY);
00124       inline void setOrient(unsigned index,
00125                             ORIENT newOrient, bool ignoreNets = false);
00126       inline void setOrient(unsigned index,
00127                             const char* newOrient, bool ignoreNets = false);
00128 
00129       Point getBottomLeftCorner() const;
00130       Point getTopRightCorner() const;
00131 
00132       // pack to one of the corners
00133       // - use only interface fcns of SPeval, hence not efficient at all
00134       // - not meant to used in the critical loop
00135       // WARNING: assume the vectors of of size [NUM_CORNERS][getNumNodes()]
00136       enum Corner {BOTTOM_LEFT, BOTTOM_RIGHT, TOP_LEFT, TOP_RIGHT, NUM_CORNERS};
00137       inline static string toString(Corner corner);
00138       void packToCorner(vector< vector<double> >& xlocsAt,
00139                         vector< vector<double> >& ylocsAt) const;
00140 
00141       // optimize HPWL by the corner
00142       void cornerOptimizeDesign();
00143 
00144       // get total area of ALL nodes
00145       double getNodesArea(void) const;
00146       double getRowHeight(void) const;
00147       double getSiteSpacing(void) const;
00148       void setRowHeight(double rowHeight);
00149       void setSiteSpacing(double siteSpacing);
00150 
00151       // slim:       xloc, yloc, orient, width, height (but not the orig's)
00152       // location:   xloc, yloc
00153       // dimensions: width, height (but not the orig's)
00154       // TRUE ~ succeed in updating, FALSE otherwise
00155       inline bool updateNodeSlim(int index, const Node& newNode);
00156       inline bool updateNodeLocation(int index,
00157                                      double xloc, double yloc);
00158       inline bool updateNodeDimensions(int index,
00159                                        double width, double height);
00160       
00161       void updatePlacement(const vector<double>& xloc,
00162                            const vector<double>& yloc);
00163       void initPlacement(const Point& loc);      
00164       void updateSlacks(const vector<double>& xSlack,
00165                         const vector<double>& ySlack);
00166 
00167       // plot in gnuplot format
00168       void plot(char* fileName, double area, double whitespace, double aspectRatio,
00169                 double time, double HPWL,
00170                 bool plotSlacks, bool plotNets, bool plotNames) const;
00171 
00172       // save the data in Capo format
00173       void saveCapo(char *baseFileName, double reqdAR=1, double reqdWS=30) const;  
00174       void saveCapoNets(char* baseFileName) const;
00175 
00176       // save data in floorplan format
00177       void save(char* baseFileName) const; 
00178       void saveNets(char* baseFileName) const;
00179       void saveWts(char* baseFileName) const;
00180 
00181       void saveBestCopyPl(char* baseFileName) const;
00182       void saveInBestCopy(void); // non-const since it modifies "successAR"
00183 
00184       double evalHPWL(bool useWts=true) const;  //assumes that placement is updated
00185       //assumes that placement is updated & terminals to be moved to floorplan edges
00186       double evalHPWL(double xSize, double ySize, bool useWts=true) const;
00187       double evalArea(void) const;  //assumes that placement is updated
00188       double getXSize(void) const;
00189       double getYSize(void) const;
00190       double getAvgHeight(void) const;
00191 
00192       // optimize the BL-corner of the design
00193       void shiftOptimizeDesign(double outlineWidth,
00194                                double outlineHeight); // deduce BL-corner from DB
00195       void shiftOptimizeDesign(const Point& bottomLeft,
00196                                const Point& topRight); 
00197       
00198       void shiftDesign(Point& offset); //shift the entire placement by an offset
00199 
00200       void expandDesign(double maxWidth, double maxHeight);
00201       //expand entire design to occupy the new dimensions. only locations of blocks
00202       //are altered
00203   
00204       //marks all nodes with height > avgHeight as macros
00205       void markTallNodesAsMacros(double maxHeight);
00206 
00207       //reduce the core cells area of design excluding macros to maxWS whitespace
00208       //assumes macros are marked using DB::markTallNodesAsMacros()
00209       void reduceCoreCellsArea(double layoutArea, double maxWS);
00210 
00211       //this function gets the dimension of the FP only considering the macros
00212       double getXSizeWMacroOnly();
00213       double getYSizeWMacroOnly();
00214 
00215       double getXMaxWMacroOnly();
00216       double getYMaxWMacroOnly();
00217 
00218    private:
00219       // help function of shiftOptimizeDesign()
00220       double getOptimalRangeStart(bool isHorizontal);
00221    };
00222 
00223    // ---------------
00224    // IMPLEMENTATIONS
00225    // ---------------
00226    double DB::getNodeArea(unsigned index) const
00227    {   return getNodeWidth(index) * getNodeHeight(index); }
00228    
00229    double DB::getNodeWidth(unsigned index) const
00230    {   return _nodes->getNodeWidth(index); }
00231 
00232    double DB::getNodeHeight(unsigned index) const
00233    {   return _nodes->getNodeHeight(index); }
00234 
00235    double DB::getXLoc(unsigned index) const
00236    {   return (_nodes->getNode(index)).getX(); }
00237 
00238    double DB::getYLoc(unsigned index) const
00239    {   return (_nodes->getNode(index)).getY(); }
00240 
00241    ORIENT DB::getOrient(unsigned index) const
00242    {   return (_nodes->getNode(index)).getOrient(); }
00243 
00244    double DB::getNodeMinAR(unsigned index) const
00245    {   return (_nodes->getNode(index)).getminAR(); }
00246 
00247    double DB::getNodeMaxAR(unsigned index) const
00248    {   return (_nodes->getNode(index)).getmaxAR(); }
00249 
00250    double DB::getNodeAR(unsigned index) const
00251    {   return getNodeWidth(index) / getNodeHeight(index); }
00252    
00253    bool DB::isMacro(unsigned index) const
00254    {   return (_nodes->getNode(index)).isMacro(); }
00255 
00256    bool DB::isOrientFixed(unsigned index) const
00257    {   return (_nodes->getNode(index)).isOrientFixed(); }
00258 
00259    bool DB::isNodeSoft(unsigned index) const
00260    {   return getNodeMaxAR(index) - getNodeMinAR(index) > 1e-6; }
00261 
00262    bool DB::isNodeHard(unsigned index) const
00263    {   return !isNodeSoft(index); }
00264    // -----------------------------------------------------
00265    void DB::setNodeWidth(unsigned index, double width)
00266    {   (_nodes->getNode(index)).putWidth(width); }
00267    
00268    void DB::setNodeHeight(unsigned index, double height)
00269    {   (_nodes->getNode(index)).putHeight(height); }
00270 
00271    void DB::setNodeAR(unsigned index, double ar)
00272    {
00273       const double area = getNodeArea(index);
00274       setNodeWidth(index, sqrt(area * ar));
00275       setNodeHeight(index, sqrt(area / ar));
00276    }
00277    
00278    void DB::setXLoc(unsigned index, double newX)
00279    {   (_nodes->getNode(index)).putX(newX); }
00280    
00281    void DB::setYLoc(unsigned index, double newY)
00282    {   (_nodes->getNode(index)).putY(newY); }
00283    
00284    void DB::setOrient(unsigned index, ORIENT newOrient, bool ignoreNets)
00285    {
00286       if (ignoreNets)
00287          (_nodes->getNode(index)).putOrient(newOrient);
00288       else      
00289          _nodes->changeOrient(index, newOrient, *_nets);
00290    }
00291    
00292    void DB::setOrient(unsigned index, const char *newOrient, bool ignoreNets)
00293    {
00294       setOrient(index,
00295                 toOrient(const_cast< char* >(newOrient)), ignoreNets);
00296    }
00297    // -----------------------------------------------------
00298    bool DB::updateNodeSlim(int index,
00299                            const Node& newNode)
00300    {
00301       if (index < int(_nodes->getNumNodes()))
00302       {
00303          Node& oldNode = _nodes->getNode(index);
00304          
00305          oldNode.putX(newNode.getX());
00306          oldNode.putY(newNode.getY());
00307          oldNode.changeOrient(newNode.getOrient(), *_nets);
00308          oldNode.putWidth(newNode.getWidth());
00309          oldNode.putHeight(newNode.getHeight());
00310          return true;
00311       }
00312       else
00313          return false;
00314    }
00315    // -----------------------------------------------------
00316    bool DB::updateNodeLocation(int index,
00317                                double xloc, double yloc)
00318    {
00319       if (index < int(_nodes->getNumNodes()))
00320       {
00321          Node& oldNode = _nodes->getNode(index);
00322          oldNode.putX(xloc);
00323          oldNode.putY(yloc);
00324          return true;
00325       }
00326       else
00327          return false;
00328    }
00329    // -----------------------------------------------------
00330    bool DB::updateNodeDimensions(int index,
00331                                  double width, double height)
00332    {
00333       if (index <int( _nodes->getNumNodes()))
00334       {
00335          Node& oldNode = _nodes->getNode(index);
00336 
00337          oldNode.putWidth(width);
00338          oldNode.putHeight(height);
00339          return true;
00340       }
00341       else
00342          return false;
00343    }
00344    // -----------------------------------------------------
00345    string DB::toString(DB::Corner corner)
00346    {
00347       switch (corner)
00348       {
00349       case BOTTOM_LEFT: return "bottom-left";
00350       case BOTTOM_RIGHT: return "bottom-right";
00351       case TOP_LEFT: return "top-left";
00352       case TOP_RIGHT: return "top-right";
00353       default: return "INVALID CORNER";
00354       }
00355    }
00356    // -----------------------------------------------------
00357 }
00358 // using namespace parquetfp;
00359 
00360 #endif 

Generated on Mon Apr 25 01:09:24 2005 for Parquete by doxygen 1.3.2