cts: tie-break dummy-cell sort for deterministic output#10656
Conversation
findCandidateDummyCells() gathers dummyCandidates by iterating the STA libraries, then sorts them by getInputCap() alone with the non-stable std::ranges::sort. findBestDummyCell() then takes the first candidate with the minimal |cap - deltaCap|, so among equal-cap candidates the choice depends on the unspecified sort order and varies run to run. Tie-break the sort on the cell name for a stable, reproducible pick. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request updates the sorting logic for dummyCandidates in TritonCTS::findCandidateDummyCells to include a tie-breaker based on cell names when input capacities are equal, ensuring stable output. The review feedback suggests optimizing this tie-breaker by using std::strcmp instead of constructing std::string objects to avoid unnecessary dynamic memory allocations.
| return false; | ||
| } | ||
| // dummyCandidates is unordered; tie-break for stable output. | ||
| return std::string(cell1->name()) < std::string(cell2->name()); |
There was a problem hiding this comment.
Constructing std::string objects inside the sort comparator on every comparison is inefficient because it can trigger dynamic memory allocations. Since <cstring> is already included, using std::strcmp is a much more efficient way to compare the cell names without any heap allocation overhead.
return std::strcmp(cell1->name(), cell2->name()) < 0;There was a problem hiding this comment.
We really should be using return cell1->id() < cell2->id()
string compares are by far the most expensive tie break.
|
/gemini propose fixes |
|
The proposed fix correctly addresses the non-determinism by adding a tie-break on the cell name. The logic is sound and effectively ensures a stable sort order. If you prefer a more concise implementation, you could use std::ranges::sort(
dummyCandidates,
[](const sta::LibertyCell* cell1, const sta::LibertyCell* cell2) {
return std::tie(getInputCap(cell1), std::string_view(cell1->name())) <
std::tie(getInputCap(cell2), std::string_view(cell2->name()));
});This approach is functionally equivalent and slightly more idiomatic for multi-key comparisons. |
Per review (gadfort), tie-break on LibertyCell::id() rather than the cell name: an integer compare instead of constructing a string per comparison. String compares are the most expensive tie-break, and id() matches the deterministic comparator style already used in Resizer.cc. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the sorting comparator for dummy candidates in TritonCTS.cpp to ensure a deterministic sort order. When the input capacitances of two cells are equal, it now falls back to comparing their cell IDs. I have no further feedback to provide as there are no review comments.
Per review, express the (input-cap, id) lexicographic order as a single std::make_tuple comparison instead of the explicit if-chain. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
|
Simplified the comparator to a single |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the sorting logic for dummy candidate cells in TritonCTS.cpp to ensure a deterministic sort order. By using std::tuple with both the input capacitance and the cell ID, the comparator now has a stable fallback when capacitances are equal. I have no feedback to provide.
Per review, use a direct (input-cap, id) compare with cached locals instead of std::make_tuple temporaries; also drops the <tuple> include. Matches the explicit comparator style in Resizer.cc. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the sorting comparator for dummy cell candidates in TritonCTS to ensure a deterministic sort order. When the input capacitances of two cells are equal, it now falls back to comparing their cell IDs. There are no review comments, so no additional feedback is provided.
|
@maliberty This was pr merge green, so should be irrelevant |
d66535c
into
The-OpenROAD-Project:master
findCandidateDummyCells()gathersdummyCandidatesby iterating the STA libraries, thenstd::ranges::sorts them bygetInputCap()alone.std::ranges::sortis not stable, andfindBestDummyCell()subsequently takes the first candidate with the minimal|cap - deltaCap|. So among candidates with equal input cap, the selected dummy cell depends on the unspecified sort order and varies run to run — a source of nondeterminism in CTS output.This tie-breaks the sort on the cell name so equal-cap candidates get a stable, reproducible order. Same shape as the previously-merged
OptMirrortie-break.