Skip to content

Commit f11f922

Browse files
committed
pad: add custom comparator for GridGraphEdge set to prevent non-determinism
Signed-off-by: Eder Monteiro <emrmonteiro@precisioninno.com>
1 parent 065077a commit f11f922

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

src/pad/src/RDLRouter.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void RDLRouter::route(const std::vector<odb::dbNet*>& nets)
381381
makeGraph();
382382

383383
// Determine access points
384-
std::unordered_map<odb::Point, std::set<GridGraphEdge>> remove_edges;
384+
std::unordered_map<odb::Point, GridGraphEdgeSet> remove_edges;
385385
for (auto& [net, iterm_targets] : routing_targets_) {
386386
for (auto& [iterm, targets] : iterm_targets) {
387387
for (auto& target : targets) {
@@ -797,7 +797,7 @@ static odb::Point getValidGridPoint(
797797
}
798798

799799
void RDLRouter::cleanupGraphEdges(
800-
const std::unordered_map<odb::Point, std::set<GridGraphEdge>>& edges)
800+
const std::unordered_map<odb::Point, GridGraphEdgeSet>& edges)
801801
{
802802
if (edges.empty()) {
803803
return;
@@ -824,7 +824,7 @@ void RDLRouter::cleanupGraphEdges(
824824

825825
void RDLRouter::populateTerminalAccessPoints(
826826
RouteTarget& target,
827-
std::unordered_map<odb::Point, std::set<GridGraphEdge>>& edges) const
827+
std::unordered_map<odb::Point, GridGraphEdgeSet>& edges) const
828828
{
829829
// determine new access point in graph
830830
std::set<odb::Point> snap_pts;
@@ -1181,10 +1181,9 @@ bool RDLRouter::is45DegreeEdge(const odb::Point& pt0,
11811181
return RDLRoute::is45DegreeEdge(pt0, pt1);
11821182
}
11831183

1184-
std::set<GridGraphEdge> RDLRouter::getVertexEdges(
1185-
const GridGraphVertex& vertex) const
1184+
GridGraphEdgeSet RDLRouter::getVertexEdges(const GridGraphVertex& vertex) const
11861185
{
1187-
std::set<GridGraphEdge> edges;
1186+
GridGraphEdgeSet edges;
11881187

11891188
GridGraph::out_edge_iterator oit, oend;
11901189
std::tie(oit, oend) = boost::out_edges(vertex, graph_);
@@ -1203,7 +1202,7 @@ std::set<GridGraphEdge> RDLRouter::getVertexEdges(
12031202
std::vector<RDLRouter::GridEdge> RDLRouter::commitRoute(
12041203
const std::vector<GridGraphVertex>& route)
12051204
{
1206-
std::set<GridGraphEdge> edges;
1205+
GridGraphEdgeSet edges;
12071206
for (const auto& v : route) {
12081207
const auto v_edges = getVertexEdges(v);
12091208
edges.insert(v_edges.begin(), v_edges.end());

src/pad/src/RDLRouter.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#pragma once
55

6+
#include <algorithm>
67
#include <cstdint>
78
#include <map>
89
#include <memory>
@@ -67,6 +68,24 @@ using GridWeightMap
6768
using GridGraphVertex = GridGraph::vertex_descriptor;
6869
using GridGraphEdge = GridGraph::edge_descriptor;
6970

71+
// Order edges by (source, target) vertex indices; the descriptor's default
72+
// operator< compares a heap pointer, giving build-dependent iteration.
73+
struct GridGraphEdgeLess
74+
{
75+
bool operator()(const GridGraphEdge& lhs, const GridGraphEdge& rhs) const
76+
{
77+
const auto lhs_lo = std::min(lhs.m_source, lhs.m_target);
78+
const auto lhs_hi = std::max(lhs.m_source, lhs.m_target);
79+
const auto rhs_lo = std::min(rhs.m_source, rhs.m_target);
80+
const auto rhs_hi = std::max(rhs.m_source, rhs.m_target);
81+
if (lhs_lo != rhs_lo) {
82+
return lhs_lo < rhs_lo;
83+
}
84+
return lhs_hi < rhs_hi;
85+
}
86+
};
87+
using GridGraphEdgeSet = std::set<GridGraphEdge, GridGraphEdgeLess>;
88+
7089
struct RouteTarget
7190
{
7291
// center point of the target shape
@@ -213,11 +232,11 @@ class RDLRouter
213232

214233
void populateTerminalAccessPoints(
215234
RouteTarget& target,
216-
std::unordered_map<odb::Point, std::set<GridGraphEdge>>& edges) const;
235+
std::unordered_map<odb::Point, GridGraphEdgeSet>& edges) const;
217236
void cleanupTerminalAccessPoints(odb::dbITerm* iterm,
218237
std::vector<RouteTarget>& targets) const;
219238
void cleanupGraphEdges(
220-
const std::unordered_map<odb::Point, std::set<GridGraphEdge>>& edges);
239+
const std::unordered_map<odb::Point, GridGraphEdgeSet>& edges);
221240
std::set<odb::Point> generateTerminalAccessPoints(const odb::Point& pt,
222241
bool do_x) const;
223242
TerminalAccess insertTerminalAccess(const RouteTarget& target,
@@ -227,7 +246,7 @@ class RDLRouter
227246
odb::PtrMap<odb::dbITerm, std::vector<RouteTarget>> generateRoutingTargets(
228247
odb::dbNet* net) const;
229248
odb::dbTechLayer* getOtherLayer(odb::dbTechVia* via) const;
230-
std::set<GridGraphEdge> getVertexEdges(const GridGraphVertex& vertex) const;
249+
GridGraphEdgeSet getVertexEdges(const GridGraphVertex& vertex) const;
231250

232251
void buildIntialRouteSet();
233252
int reportFailedRoutes(

src/pad/test/rdl_route_failed.ok

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[INFO PAD-0037] End of routing iteration 7: 89.5% complete
1616
[INFO PAD-0037] End of routing iteration 8: 89.0% complete
1717
[INFO PAD-0037] End of routing iteration 9: 88.8% complete
18-
[INFO PAD-0037] End of routing iteration 10: 88.8% complete
18+
[INFO PAD-0037] End of routing iteration 10: 88.4% complete
1919
[WARNING PAD-0006] Failed to route the following 17 nets:
2020
DVDD
2121
BUMP_11_3/PAD -> u_v18_6/DVDD, u_v18_7/DVDD, u_v18_5/DVDD, u_v18_4/DVDD, u_v18_8/DVDD, ... (67 possible terminals)
@@ -27,6 +27,7 @@
2727
BUMP_15_11/PAD -> u_vzz_15/DVSS, u_vzz_16/DVSS, u_vzz_14/DVSS, u_vzz_13/DVSS, u_vzz_12/DVSS, ... (67 possible terminals)
2828
BUMP_15_7/PAD -> u_vzz_12/DVSS, u_vzz_13/DVSS, u_vzz_11/DVSS, u_vzz_14/DVSS, u_vzz_10/DVSS, ... (67 possible terminals)
2929
BUMP_1_9/PAD -> u_vzz_29/DVSS, u_vzz_30/DVSS, u_vzz_28/DVSS, u_vzz_31/DVSS, u_vzz_27/DVSS, ... (67 possible terminals)
30+
BUMP_8_15/PAD -> u_vzz_21/DVSS, u_vzz_22/DVSS, u_vzz_20/DVSS, u_vzz_23/DVSS, u_vzz_24/DVSS, ... (67 possible terminals)
3031
VSS
3132
BUMP_14_9/PAD -> u_vss_6/VSS, u_vss_5/VSS, u_vss_7/VSS, u_vss_4/VSS, u_vss_8/VSS, ... (33 possible terminals)
3233
BUMP_16_6/PAD -> u_vss_5/VSS, u_vss_6/VSS, u_vss_4/VSS, u_vss_7/VSS, u_vss_3/VSS, ... (33 possible terminals)

0 commit comments

Comments
 (0)