Skip to content

Commit

Permalink
Merge pull request The-OpenROAD-Project#4619 from The-OpenROAD-Projec…
Browse files Browse the repository at this point in the history
…t-staging/dpl-refactor

Dpl refactor
  • Loading branch information
maliberty authored Feb 5, 2024
2 parents d7492f5 + 0b88fb0 commit 80fd75d
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 86 deletions.
59 changes: 12 additions & 47 deletions src/dpl/include/dpl/Opendp.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,25 +245,6 @@ class GridInfo
const dbSite::RowPattern sites_;
};

// For optimize mirroring.
class NetBox
{
public:
NetBox() = default;
NetBox(dbNet* net, Rect box, bool ignore);
int64_t hpwl();
void saveBox();
void restoreBox();

dbNet* net_ = nullptr;
Rect box_;
Rect box_saved_;
bool ignore_ = false;
};

using NetBoxMap = unordered_map<dbNet*, NetBox>;
using NetBoxes = vector<NetBox*>;

////////////////////////////////////////////////////////////////

// Return value for grid searches.
Expand All @@ -287,8 +268,6 @@ class Opendp
Opendp(const Opendp&&) = delete;
Opendp& operator=(const Opendp&&) = delete;

Point pointOffMacro(const Cell& cell);
void convertDbToCell(dbInst* db_inst, Cell& cell);
void legalCellPos(dbInst* db_inst);
void initMacrosAndGrid();

Expand All @@ -301,6 +280,7 @@ class Opendp
const std::string& report_file_name = std::string(""),
bool disallow_one_site_gaps = false);
void reportLegalizationStats() const;

void setPaddingGlobal(int left, int right);
void setPadding(dbMaster* master, int left, int right);
void setPadding(dbInst* inst, int left, int right);
Expand All @@ -312,10 +292,7 @@ class Opendp
// Find instance/master/global padding value for an instance.
int padRight(dbInst* inst) const;
int padLeft(dbInst* inst) const;
// Return error count.
void processViolationsPtree(boost::property_tree::ptree& entry,
const std::vector<Cell*>& failures,
const std::string& violation_type = "") const;

void checkPlacement(bool verbose,
bool disallow_one_site_gaps = false,
const string& report_file_name = "");
Expand All @@ -329,21 +306,25 @@ class Opendp
const vector<Cell*>& placement_failures);
void fillerPlacement(dbMasterSeq* filler_masters, const char* prefix);
void removeFillers();
int64_t hpwl() const;
int64_t hpwl(dbNet* net) const;
void findDisplacementStats();
void optimizeMirroring();

private:
friend class OpendpTest_IsPlaced_Test;
friend class Graphics;
void findDisplacementStats();
Point pointOffMacro(const Cell& cell);
void convertDbToCell(dbInst* db_inst, Cell& cell);
const vector<Cell>& getCells() const { return cells_; }
Rect getCore() const { return core_; }
int getRowHeight() const { return row_height_; }
int getRowHeight(const Cell* cell) const;
int getSiteWidth() const { return site_width_; }
int getRowCount() const { return row_count_; }
int getRowSiteCount() const { return row_site_count_; }

private:
friend class OpendpTest_IsPlaced_Test;
// Return error count.
void processViolationsPtree(boost::property_tree::ptree& entry,
const std::vector<Cell*>& failures,
const std::string& violation_type = "") const;
void importDb();
void importClear();
Rect getBbox(dbInst* inst);
Expand Down Expand Up @@ -549,16 +530,6 @@ class Opendp
int row_height,
GridInfo grid_info);

// Optimizing mirroring
void findNetBoxes();
vector<dbInst*> findMirrorCandidates(NetBoxes& net_boxes);
int mirrorCandidates(vector<dbInst*>& mirror_candidates);
// Sum of ITerm hpwl's.
int64_t hpwl(dbInst* inst);
void updateNetBoxes(dbInst* inst);
void saveNetBoxes(dbInst* inst);
void restoreNetBoxes(dbInst* inst);

Logger* logger_ = nullptr;
dbDatabase* db_ = nullptr;
dbBlock* block_ = nullptr;
Expand Down Expand Up @@ -611,19 +582,13 @@ class Opendp
int64_t displacement_sum_ = 0;
int64_t displacement_max_ = 0;

// Optimiize mirroring.
NetBoxMap net_box_map_;

std::unique_ptr<DplObserver> debug_observer_;

// Magic numbers
static constexpr int bin_search_width_ = 10;
static constexpr double group_refine_percent_ = .05;
static constexpr double refine_percent_ = .02;
static constexpr int rand_seed_ = 777;
// Net bounding box siaz on nets with more instance terminals
// than this are ignored.
static constexpr int mirror_max_iterm_count_ = 100;
};

int divRound(int dividend, int divisor);
Expand Down
105 changes: 105 additions & 0 deletions src/dpl/include/dpl/OptMirror.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2024, Parallax Software, Inc.
// All rights reserved.
//
// BSD 3-Clause License
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
///////////////////////////////////////////////////////////////////////////////

#pragma once

#include <unordered_map>
#include <vector>

namespace utl {
class Logger;
}

#include "odb/db.h"

namespace dpl {

using odb::dbInst;
using odb::dbNet;
using odb::Rect;

using std::unordered_map;
using std::vector;

using utl::Logger;

class NetBox
{
public:
NetBox() = default;
NetBox(dbNet* net, Rect box, bool ignore);
int64_t hpwl();
void saveBox();
void restoreBox();

dbNet* net_ = nullptr;
Rect box_;
Rect box_saved_;
bool ignore_ = false;
};

using NetBoxMap = unordered_map<dbNet*, NetBox>;
using NetBoxes = vector<NetBox*>;

class OptimizeMirroring
{
public:
OptimizeMirroring(Logger* logger, odb::dbDatabase* db);

void run();

private:
int mirrorCandidates(vector<dbInst*>& mirror_candidates);
void findNetBoxes();
std::vector<dbInst*> findMirrorCandidates(NetBoxes& net_boxes);

void updateNetBoxes(dbInst* inst);
void saveNetBoxes(dbInst* inst);
void restoreNetBoxes(dbInst* inst);

int64_t hpwl(dbInst* inst); // Sum of ITerm hpwl's.
double dbuToMicrons(int64_t dbu) const;

Logger* logger_ = nullptr;
odb::dbDatabase* db_ = nullptr;
odb::dbBlock* block_ = nullptr;

NetBoxMap net_box_map_;

// Net bounding box size on nets with more instance terminals
// than this are ignored.
static constexpr int mirror_max_iterm_count_ = 100;
};

} // namespace dpl
30 changes: 10 additions & 20 deletions src/dpl/src/Opendp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include <map>

#include "DplObserver.h"
#include "dpl/OptMirror.h"
#include "odb/util.h"
#include "utl/Logger.h"

namespace dpl {
Expand Down Expand Up @@ -164,7 +166,8 @@ void Opendp::detailedPlacement(int max_displacement_x,
"the -disallow_one_site_gaps flag.");
}
}
hpwl_before_ = hpwl();
odb::WireLengthEvaluator eval(block_);
hpwl_before_ = eval.hpwl();
detailedPlacement();
// Save displacement stats before updating instance DB locations.
findDisplacementStats();
Expand Down Expand Up @@ -224,7 +227,8 @@ void Opendp::reportLegalizationStats() const
dbuToMicrons(displacement_max_));
logger_->report("original HPWL {:10.1f} u",
dbuToMicrons(hpwl_before_));
double hpwl_legal = hpwl();
odb::WireLengthEvaluator eval(block_);
double hpwl_legal = eval.hpwl();
logger_->report("legalized HPWL {:10.1f} u", dbuToMicrons(hpwl_legal));
logger_->metric("route__wirelength__estimated", dbuToMicrons(hpwl_legal));
int hpwl_delta
Expand Down Expand Up @@ -257,28 +261,14 @@ void Opendp::findDisplacementStats()
}
}

// Note that this does NOT use cell/core coordinates.
int64_t Opendp::hpwl() const
{
int64_t hpwl_sum = 0;
for (dbNet* net : block_->getNets()) {
hpwl_sum += hpwl(net);
}
return hpwl_sum;
}
////////////////////////////////////////////////////////////////

int64_t Opendp::hpwl(dbNet* net) const
void Opendp::optimizeMirroring()
{
if (net->getSigType().isSupply()) {
return 0;
}

Rect bbox = net->getTermBBox();
return bbox.dx() + bbox.dy();
OptimizeMirroring opt(logger_, db_);
opt.run();
}

////////////////////////////////////////////////////////////////

Point Opendp::initialLocation(const Cell* cell, bool padded) const
{
int loc_x, loc_y;
Expand Down
Loading

0 comments on commit 80fd75d

Please sign in to comment.