Skip to content

Commit a46bcb2

Browse files
authored
Merge pull request #9441 from gudeh/dpl-debug-deep-iterative
dpl: debug deep iterative and new paintings
2 parents 9f79f99 + 87610bf commit a46bcb2

8 files changed

Lines changed: 304 additions & 48 deletions

File tree

src/dpl/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ detailed_placement
3232
| `-max_displacement` | Max distance that an instance can be moved (in microns) when finding a site where it can be placed. Either set one value for both directions or set `{disp_x disp_y}` for individual directions. The default values are `{0, 0}`, and the allowed values within are integers `[0, MAX_INT]`. |
3333
| `-disallow_one_site_gaps` | Option is deprecated. |
3434
| `-report_file_name` | File name for saving the report to (e.g. `report.json`.) |
35+
| `-incremental` | By default DPL initiates with all instances unplaced. With this flag DPL will check for already legalized instances and set them as placed. |
3536

3637
### Set Placement Padding
3738

src/dpl/include/dpl/Opendp.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class Opendp
106106
// max_displacment is in sites. use zero for defaults.
107107
void detailedPlacement(int max_displacement_x,
108108
int max_displacement_y,
109-
const std::string& report_file_name = std::string(""));
109+
const std::string& report_file_name = std::string(""),
110+
bool incremental = false);
110111
void reportLegalizationStats() const;
111112

112113
void setPaddingGlobal(int left, int right);
@@ -115,6 +116,7 @@ class Opendp
115116
void setDebug(std::unique_ptr<dpl::DplObserver>& observer);
116117
void setJumpMoves(int jump_moves);
117118
void setIterativePlacement(bool iterative);
119+
void setDeepIterativePlacement(bool deep_iterative);
118120

119121
// Global padding.
120122
int padGlobalLeft() const;
@@ -216,7 +218,7 @@ class Opendp
216218
bool checkOverlap(const Node* cell, const DbuRect& rect) const;
217219
static bool isInside(const odb::Rect& cell, const odb::Rect& box);
218220
bool isInside(const Node* cell, const odb::Rect& rect) const;
219-
PixelPt searchNearestSite(const Node* cell, GridX x, GridY y) const;
221+
PixelPt diamondSearch(const Node* cell, GridX x, GridY y) const;
220222
int calcDist(GridPt p0, GridPt p1) const;
221223
bool canBePlaced(const Node* cell, GridX bin_x, GridY bin_y) const;
222224
bool checkRegionOverlap(const Node* cell,
@@ -236,6 +238,7 @@ class Opendp
236238
int distChange(const Node* cell, DbuX x, DbuY y) const;
237239
bool swapCells(Node* cell1, Node* cell2);
238240
bool refineMove(Node* cell);
241+
void deepIterativePause(const std::string& message, bool only_print = false);
239242

240243
DbuPt legalPt(const Node* cell, const DbuPt& pt) const;
241244
GridPt legalGridPt(const Node* cell, const DbuPt& pt) const;
@@ -309,6 +312,7 @@ class Opendp
309312
// Place fillers
310313
dbMasterSeq filterFillerMasters(const dbMasterSeq& filler_masters) const;
311314
MasterByImplant splitByImplant(const dbMasterSeq& filler_masters);
315+
void setInitialGridCells();
312316
void setGridCells();
313317
dbMasterSeq& gapFillers(odb::dbTechLayer* implant,
314318
GridX gap,
@@ -383,7 +387,10 @@ class Opendp
383387
std::unique_ptr<DplObserver> debug_observer_;
384388
std::unique_ptr<Node> dummy_cell_;
385389
int jump_moves_ = 0;
390+
int move_count_ = 1;
386391
bool iterative_placement_ = false;
392+
bool deep_iterative_placement_ = false;
393+
bool incremental_ = false;
387394

388395
// Magic numbers
389396
static constexpr double group_refine_percent_ = .05;

src/dpl/src/Opendp.cpp

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <iterator>
1111
#include <memory>
1212
#include <string>
13+
#include <unordered_set>
1314
#include <utility>
1415
#include <vector>
1516

@@ -93,6 +94,14 @@ void Opendp::setIterativePlacement(const bool iterative)
9394
iterative_placement_ = iterative;
9495
}
9596

97+
void Opendp::setDeepIterativePlacement(const bool deep_iterative)
98+
{
99+
deep_iterative_placement_ = deep_iterative;
100+
if (deep_iterative) {
101+
iterative_placement_ = true;
102+
}
103+
}
104+
96105
void Opendp::setJournal(Journal* journal)
97106
{
98107
journal_ = journal;
@@ -105,13 +114,17 @@ Journal* Opendp::getJournal() const
105114

106115
void Opendp::detailedPlacement(const int max_displacement_x,
107116
const int max_displacement_y,
108-
const std::string& report_file_name)
117+
const std::string& report_file_name,
118+
bool incremental)
109119
{
120+
incremental_ = incremental;
110121
importDb();
111122
adjustNodesOrient();
112-
for (const auto& node : network_->getNodes()) {
113-
if (node->getType() == Node::CELL && !node->isFixed()) {
114-
node->setPlaced(false);
123+
if (!incremental_) {
124+
for (const auto& node : network_->getNodes()) {
125+
if (node->getType() == Node::CELL && !node->isFixed()) {
126+
node->setPlaced(false);
127+
}
115128
}
116129
}
117130

@@ -339,6 +352,78 @@ void Opendp::findOverlapInRtree(const bgBox& queryBox,
339352
std::back_inserter(overlaps));
340353
}
341354

355+
void Opendp::setInitialGridCells()
356+
{
357+
std::unordered_set<Node*> conflicted;
358+
const DbuX site_width = grid_->getSiteWidth();
359+
360+
// Check which cells are missaligned with rows
361+
for (auto& node : network_->getNodes()) {
362+
if (node->getType() == Node::CELL && !node->isFixed() && node->isPlaced()) {
363+
const GridX x = grid_->gridX(node.get());
364+
const GridY y = grid_->gridSnapDownY(node.get());
365+
if (node->getLeft() != gridToDbu(x, site_width)
366+
|| node->getBottom() != grid_->gridYToDbu(y)
367+
|| !canBePlaced(node.get(), x, y)) {
368+
conflicted.insert(node.get());
369+
}
370+
}
371+
}
372+
373+
// Check which cells are overlapping with other cells
374+
for (auto& node : network_->getNodes()) {
375+
if (node->getType() == Node::CELL && !node->isFixed() && node->isPlaced()) {
376+
if (conflicted.contains(node.get())) {
377+
continue;
378+
}
379+
380+
bool node_conflicted = false;
381+
grid_->visitCellPixels(
382+
*node, false, [&](Pixel* pixel, [[maybe_unused]] bool padded) {
383+
if (pixel->cell != nullptr && pixel->cell != node.get()) {
384+
node_conflicted = true;
385+
if (!pixel->cell->isFixed()) {
386+
conflicted.insert(pixel->cell);
387+
}
388+
} else {
389+
pixel->cell = node.get();
390+
}
391+
});
392+
393+
if (node_conflicted) {
394+
conflicted.insert(node.get());
395+
}
396+
}
397+
}
398+
399+
for (GridY y{0}; y < grid_->getRowCount(); y++) {
400+
for (GridX x{0}; x < grid_->getRowSiteCount(); x++) {
401+
Pixel& pixel = grid_->pixel(y, x);
402+
if (pixel.cell != nullptr && !pixel.cell->isFixed()) {
403+
pixel.cell = nullptr;
404+
}
405+
}
406+
}
407+
408+
for (auto& node : network_->getNodes()) {
409+
if (node->getType() == Node::CELL && !node->isFixed() && node->isPlaced()) {
410+
if (conflicted.find(node.get()) == conflicted.end()) {
411+
// This cell is perfectly legal and has no conflicts.
412+
grid_->visitCellPixels(
413+
*node, false, [&](Pixel* pixel, [[maybe_unused]] bool padded) {
414+
pixel->cell = node.get();
415+
pixel->util = 1.0;
416+
});
417+
grid_->paintCellPadding(node.get());
418+
} else {
419+
// This cell is either illegal or was part of an overlap conflict.
420+
// Unplace it.
421+
unplaceCell(node.get());
422+
}
423+
}
424+
}
425+
}
426+
342427
void Opendp::setFixedGridCells()
343428
{
344429
for (auto& cell : network_->getNodes()) {

src/dpl/src/Opendp.i

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ namespace dpl {
2626
void
2727
detailed_placement_cmd(int max_displacment_x,
2828
int max_displacment_y,
29-
const char* report_file_name){
29+
const char* report_file_name,
30+
bool incremental){
3031
dpl::Opendp *opendp = ord::OpenRoad::openRoad()->getOpendp();
31-
opendp->detailedPlacement(max_displacment_x, max_displacment_y, std::string(report_file_name));
32+
opendp->detailedPlacement(max_displacment_x, max_displacment_y, std::string(report_file_name), incremental);
3233
}
3334

3435
void
@@ -99,14 +100,17 @@ void
99100
set_debug_cmd(float min_displacement,
100101
const odb::dbInst* debug_instance,
101102
int jump_moves,
102-
bool iterative_placement)
103+
bool iterative_placement,
104+
bool deep_iterative_placement,
105+
bool paint_pixels)
103106
{
104107
dpl::Opendp* opendp = ord::OpenRoad::openRoad()->getOpendp();
105108
opendp->setJumpMoves(jump_moves);
106109
opendp->setIterativePlacement(iterative_placement);
110+
opendp->setDeepIterativePlacement(deep_iterative_placement);
107111
if (dpl::Graphics::guiActive()) {
108112
std::unique_ptr<DplObserver> graphics = std::make_unique<dpl::Graphics>(
109-
opendp, min_displacement, debug_instance);
113+
opendp, min_displacement, debug_instance, paint_pixels);
110114
opendp->setDebug(graphics);
111115
}
112116
}

src/dpl/src/Opendp.tcl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
sta::define_cmd_args "detailed_placement" { \
55
[-max_displacement disp|{disp_x disp_y}] \
66
[-disallow_one_site_gaps] \
7+
[-incremental] \
78
[-report_file_name file_name]}
89

910
proc detailed_placement { args } {
1011
sta::parse_key_args "detailed_placement" args \
11-
keys {-max_displacement -report_file_name} flags {-disallow_one_site_gaps}
12+
keys {-max_displacement -report_file_name} flags {-disallow_one_site_gaps -incremental}
1213

1314
if { [info exists keys(-max_displacement)] } {
1415
set max_displacement $keys(-max_displacement)
@@ -47,7 +48,7 @@ proc detailed_placement { args } {
4748
set max_displacement_y [expr [ord::microns_to_dbu $max_displacement_y] \
4849
/ [$site getHeight]]
4950
dpl::detailed_placement_cmd $max_displacement_x $max_displacement_y \
50-
$file_name
51+
$file_name [info exists flags(-incremental)]
5152
dpl::report_legalization_stats
5253
} else {
5354
utl::error "DPL" 27 "no rows defined in design. Use initialize_floorplan to add rows."
@@ -297,7 +298,7 @@ namespace eval dpl {
297298
# measured as a multiple of row_height.
298299
proc detailed_placement_debug { args } {
299300
sta::parse_key_args "detailed_placement_debug" args \
300-
keys {-instance -min_displacement -jump_moves} flags {-iterative}
301+
keys {-instance -min_displacement -jump_moves} flags {-iterative -deep_iterative -paint_pixels}
301302

302303

303304
if { [info exists keys(-min_displacement)] } {
@@ -323,7 +324,9 @@ proc detailed_placement_debug { args } {
323324
set debug_instance "NULL"
324325
}
325326

326-
dpl::set_debug_cmd $min_displacement $debug_instance $jump_moves [info exists flags(-iterative)]
327+
dpl::set_debug_cmd $min_displacement $debug_instance $jump_moves \
328+
[info exists flags(-iterative)] [info exists flags(-deep_iterative)] \
329+
[info exists flags(-paint_pixels)]
327330
}
328331

329332
proc get_masters_arg { arg_name arg } {

0 commit comments

Comments
 (0)