Skip to content

dpl: diamond recovery minor details - #12314

Open
gudeh wants to merge 9 commits into
The-OpenROAD-Project:masterfrom
gudeh:dpl-diamond-recovery
Open

gudeh wants to merge 9 commits into
The-OpenROAD-Project:masterfrom
gudeh:dpl-diamond-recovery

Conversation

@gudeh

@gudeh gudeh commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Negotiation legalizer uses the former diamond search algorithm to legalize instances which Negotiation wasn't able to.

This PR makes a few changes to diamond recovery:

  • Also runs diamond recovery when phase 2 reaches its iteration limit (previously it only stopped).
  • Fixes the "recovered X/Y" count: it now rechecks legality after recovery instead of counting diamondSearch successes, so cells made legal by moving a neighbor are counted.
  • On non-convergence, prints each remaining illegal instance (name, master, location).
  • Refactor some duplicated code.

Type of Change

  • Refactoring

Impact

Placement changes only when phase 2 hits its iteration limit; otherwise only log output changes

Verification

  • I have verified that the local build succeeds (./etc/Build.sh).
  • I have run the relevant tests and they pass.
  • My code follows the repository's formatting guidelines.
  • I have signed my commits (DCO).

Related Issues

Addresses issue #12262, originated from #12233

fix counter for diamond recoveries (if two cells were conflicting on DRC only one of them was being counted).
retuilize some duplicated code.
print instance names which were not sucessfully legalized.

Signed-off-by: Augusto Berndt <augusto.berndt@precisioninno.com>
Signed-off-by: Augusto Berndt <augusto.berndt@precisioninno.com>
@gudeh
gudeh requested a review from a team as a code owner November 16, 2026 20:34
@gudeh
gudeh requested a review from osamahammad21 November 16, 2026 20:34

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the stall recovery logic in NegotiationLegalizer by introducing helper lambdas (is_stalled and recover_stall) and a helper method (collectIllegalCells) to reduce code duplication between Phase 1 and Phase 2. It also improves logging by printing detailed information about illegal nodes when negotiation fails to converge, and updates diamondRecovery to accurately report the number of recovered cells by rechecking their legality. The review feedback suggests maintaining unique log message IDs across different phases by passing the message ID as a parameter to recover_stall, and optimizing collectIllegalCells by reserving memory for the returned vector.

Comment on lines +176 to +188
auto recover_stall = [&](const int phase, const int violations) {
print_last_if_needed();
const std::vector<int> illegal_cells = collectIllegalCells(active);
logger_->warn(utl::DPL,
700,
"Negotiation phase {}: violations stuck at {} for 3 "
"consecutive iterations. Using diamond search for {} "
"remaining illegal cells.",
phase,
violations,
illegal_cells.size());
diamondRecovery(illegal_cells);
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In OpenROAD, log message IDs should be unique to allow precise tracking and documentation. Reusing message ID 700 for both Phase 1 and Phase 2 stall warnings violates this convention. Consider passing the message ID as a parameter to recover_stall so that Phase 1 can use 700 and Phase 2 can use 702 as originally defined.

Suggested change
auto recover_stall = [&](const int phase, const int violations) {
print_last_if_needed();
const std::vector<int> illegal_cells = collectIllegalCells(active);
logger_->warn(utl::DPL,
700,
"Negotiation phase {}: violations stuck at {} for 3 "
"consecutive iterations. Using diamond search for {} "
"remaining illegal cells.",
phase,
violations,
illegal_cells.size());
diamondRecovery(illegal_cells);
};
auto recover_stall = [&](const int phase, const int msg_id, const int violations) {
print_last_if_needed();
const std::vector<int> illegal_cells = collectIllegalCells(active);
logger_->warn(utl::DPL,
msg_id,
"Negotiation phase {}: violations stuck at {} for 3 "
"consecutive iterations. Using diamond search for {} "
"remaining illegal cells.",
phase,
violations,
illegal_cells.size());
diamondRecovery(illegal_cells);
};

Comment on lines +212 to +214
if (is_stalled(phase_1_violations)) {
recover_stall(1, phase_1_violations);
break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the call to recover_stall to pass the unique message ID 700 for Phase 1.

Suggested change
if (is_stalled(phase_1_violations)) {
recover_stall(1, phase_1_violations);
break;
if (is_stalled(phase_1_violations)) {
recover_stall(1, 700, phase_1_violations);
break;
}

Comment on lines +257 to +260
if (is_stalled(phase_2_violations)) {
finish_ = Finish::kPhase2Recovery;
recover_stall(2, phase_2_violations);
break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the call to recover_stall to pass the unique message ID 702 for Phase 2.

Suggested change
if (is_stalled(phase_2_violations)) {
finish_ = Finish::kPhase2Recovery;
recover_stall(2, phase_2_violations);
break;
if (is_stalled(phase_2_violations)) {
finish_ = Finish::kPhase2Recovery;
recover_stall(2, 702, phase_2_violations);
break;
}

Comment on lines +1147 to +1157
std::vector<int> NegotiationLegalizer::collectIllegalCells(
const std::vector<int>& cells) const
{
std::vector<int> illegal;
for (const int idx : cells) {
if (!cells_[idx].fixed && !isCellLegal(idx)) {
illegal.push_back(idx);
}
}
return illegal;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid potential multiple reallocations of the illegal vector during the loop, consider reserving memory upfront using cells.size() as an upper bound.

Suggested change
std::vector<int> NegotiationLegalizer::collectIllegalCells(
const std::vector<int>& cells) const
{
std::vector<int> illegal;
for (const int idx : cells) {
if (!cells_[idx].fixed && !isCellLegal(idx)) {
illegal.push_back(idx);
}
}
return illegal;
}
std::vector<int> NegotiationLegalizer::collectIllegalCells(
const std::vector<int>& cells) const
{
std::vector<int> illegal;
illegal.reserve(cells.size());
for (const int idx : cells) {
if (!cells_[idx].fixed && !isCellLegal(idx)) {
illegal.push_back(idx);
}
}
return illegal;
}

Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
@eder-matheus

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T21:32:05.925041Z 4044dcf Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 4044dcfc23

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@osamahammad21 osamahammad21 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave merging to you once you handle the requested change

Comment thread openroad/dpl/src/Opendp.cpp Outdated
Comment on lines +299 to +305
for (const Node* node : illegal_nodes) {
logger_->report(" {} ({}) at dbu ({}, {})",
node->name(),
node->getDbInst()->getMaster()->getName(),
(core_.xMin() + node->getLeft()).v,
(core_.yMin() + node->getBottom()).v);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could get out of hand if the number of illegal nodes is very high. saveFailures should already have the detailed list of the failing nodes, so I don't think it's needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants