Skip to content

Commit

Permalink
Merge pull request The-OpenROAD-Project#5047 from The-OpenROAD-Projec…
Browse files Browse the repository at this point in the history
…t-staging/grid-dbu-rect

Grid dbu rect
  • Loading branch information
maliberty authored May 5, 2024
2 parents 94ec7cc + fc73cf4 commit 4efc41f
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 86 deletions.
13 changes: 7 additions & 6 deletions src/dpl/include/dpl/Opendp.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ using DbuY = TypedCoordinate<DbuYType>;

struct GridPt;
struct DbuPt;
struct DbuRect;

using dbMasterSeq = vector<dbMaster*>;

Expand Down Expand Up @@ -194,12 +195,12 @@ class Opendp
void initGrid();
std::string printBgBox(const boost::geometry::model::box<bgPoint>& queryBox);
void detailedPlacement();
DbuPt nearestPt(const Cell* cell, const Rect* rect) const;
int distToRect(const Cell* cell, const Rect* rect) const;
DbuPt nearestPt(const Cell* cell, const DbuRect& rect) const;
int distToRect(const Cell* cell, const Rect& rect) const;
static bool checkOverlap(const Rect& cell, const Rect& box);
bool checkOverlap(const Cell* cell, const Rect* rect) const;
bool checkOverlap(const Cell* cell, const DbuRect& rect) const;
static bool isInside(const Rect& cell, const Rect& box);
bool isInside(const Cell* cell, const Rect* rect) const;
bool isInside(const Cell* cell, const Rect& rect) const;
PixelPt diamondSearch(const Cell* cell, GridX x, GridY y) const;
void diamondSearchSide(const Cell* cell,
GridX x,
Expand Down Expand Up @@ -288,11 +289,11 @@ class Opendp
const vector<Cell*>& placement_failures);

void rectDist(const Cell* cell,
const Rect* rect,
const Rect& rect,
// Return values.
int* x,
int* y) const;
int rectDist(const Cell* cell, const Rect* rect) const;
int rectDist(const Cell* cell, const Rect& rect) const;
void checkOneSiteDbMaster();
void deleteGrid();
// Cell initial location wrt core origin.
Expand Down
34 changes: 34 additions & 0 deletions src/dpl/src/Coordinates.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ struct DbuPt
DbuY y{0};
};

struct DbuRect
{
DbuRect(const Rect& rect)
: xl(rect.xMin()), yl(rect.yMin()), xh(rect.xMax()), yh(rect.yMax())
{
}
DbuX dx() const { return xh - xl; }
DbuY dy() const { return yh - yl; }
DbuX xl{0};
DbuY yl{0};
DbuX xh{0};
DbuY yh{0};
};

inline bool operator==(const DbuPt& p1, const DbuPt& p2)
{
return std::tie(p1.x, p1.y) == std::tie(p2.x, p2.y);
Expand All @@ -163,6 +177,26 @@ inline DbuY gridToDbu(GridY y, DbuY scale)
return DbuY{y.v * scale.v};
}

inline GridX dbuToGridCeil(DbuX x, DbuX divisor)
{
return GridX{divCeil(x.v, divisor.v)};
}

inline GridX dbuToGridFloor(DbuX x, DbuX divisor)
{
return GridX{divFloor(x.v, divisor.v)};
}

inline GridY dbuToGridCeil(DbuY y, DbuY divisor)
{
return GridY{divCeil(y.v, divisor.v)};
}

inline GridY dbuToGridFloor(DbuY y, DbuY divisor)
{
return GridY{divFloor(y.v, divisor.v)};
}

inline int sumXY(DbuX x, DbuY y)
{
return x.v + y.v;
Expand Down
46 changes: 23 additions & 23 deletions src/dpl/src/Opendp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ void Opendp::groupAssignCellRegions()
const DbuX site_width = grid_->getSiteWidth();
if (!group.cells_.empty()) {
auto group_cell = group.cells_.at(0);
const Rect core = grid_->getCore();
const int max_row_site_count = divFloor(core.dx(), site_width.v);
const DbuRect core = grid_->getCore();
const GridX max_row_site_count = dbuToGridFloor(core.dx(), site_width);
const DbuY row_height = grid_->getRowHeight(group_cell);
const int row_count = divFloor(core.dy(), row_height.v);
const GridY row_count = dbuToGridFloor(core.dy(), row_height);
const int64_t site_area
= row_height.v * static_cast<int64_t>(site_width.v);
const auto gmk = grid_->getGridMapKey(group_cell);
Expand All @@ -357,7 +357,7 @@ void Opendp::groupAssignCellRegions()
cell_area += cell->area();

for (Rect& rect : group.region_boundaries) {
if (isInside(cell, &rect)) {
if (isInside(cell, rect)) {
cell->region_ = &rect;
}
}
Expand Down Expand Up @@ -434,47 +434,47 @@ void Opendp::groupInitPixels()
const GridInfo& grid_info = grid_->getInfoMap().at(gmk);
const int grid_index = grid_info.getGridIndex();
const DbuX site_width = grid_->getSiteWidth();
for (const Rect& rect : group.region_boundaries) {
for (const DbuRect rect : group.region_boundaries) {
debugPrint(logger_,
DPL,
"detailed",
1,
"Group {} region [x{} y{}] [x{} y{}]",
group.name,
rect.xMin(),
rect.yMin(),
rect.xMax(),
rect.yMax());
const GridY row_start{divCeil(rect.yMin(), row_height.v)};
const GridY row_end{divFloor(rect.yMax(), row_height.v)};
rect.xl,
rect.yl,
rect.xh,
rect.yh);
const GridY row_start{dbuToGridCeil(rect.yl, row_height)};
const GridY row_end{dbuToGridFloor(rect.yh, row_height)};

for (GridY k{row_start}; k < row_end; k++) {
const GridX col_start{divCeil(rect.xMin(), site_width.v)};
const GridX col_end{divFloor(rect.xMax(), site_width.v)};
const GridX col_start{dbuToGridCeil(rect.xl, site_width)};
const GridX col_end{dbuToGridFloor(rect.xh, site_width)};

for (GridX l{col_start}; l < col_end; l++) {
Pixel* pixel = grid_->gridPixel(grid_index, l, k);
pixel->util += 1.0;
}
if (rect.xMin() % site_width.v != 0) {
if (rect.xl % site_width != 0) {
Pixel* pixel = grid_->gridPixel(grid_index, col_start, k);
pixel->util -= (rect.xMin() % site_width.v)
/ static_cast<double>(site_width.v);
pixel->util
-= (rect.xl % site_width).v / static_cast<double>(site_width.v);
}
if (rect.xMax() % site_width.v != 0) {
if (rect.xh % site_width != 0) {
Pixel* pixel = grid_->gridPixel(grid_index, col_end - 1, k);
pixel->util -= ((site_width.v - rect.xMax()) % site_width.v)
pixel->util -= ((site_width - rect.xh) % site_width).v
/ static_cast<double>(site_width.v);
}
}
}
for (Rect& rect : group.region_boundaries) {
const GridY row_start{divCeil(rect.yMin(), row_height.v)};
const GridY row_end{divFloor(rect.yMax(), row_height.v)};
for (const DbuRect rect : group.region_boundaries) {
const GridY row_start{dbuToGridCeil(rect.yl, row_height)};
const GridY row_end{dbuToGridFloor(rect.yh, row_height)};

for (GridY k{row_start}; k < row_end; k++) {
const int col_start = divCeil(rect.xMin(), site_width.v);
const int col_end = divFloor(rect.xMax(), site_width.v);
const GridX col_start = dbuToGridCeil(rect.xl, site_width);
const GridX col_end = dbuToGridFloor(rect.xh, site_width);

// Assign group to each pixel.
for (GridX l{col_start}; l < col_end; l++) {
Expand Down
Loading

0 comments on commit 4efc41f

Please sign in to comment.