Skip to content

Commit ab7e0e1

Browse files
authored
Merge pull request #8344 from The-OpenROAD-Project-staging/cugr-refactor4
Cugr refactor4
2 parents 1015e1f + ef3454b commit ab7e0e1

File tree

6 files changed

+60
-50
lines changed

6 files changed

+60
-50
lines changed

src/grt/src/cugr/src/GridGraph.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,10 @@ CostT GridGraph::getViaCost(const int layer_index, const PointT loc) const
352352
return cost;
353353
}
354354

355-
void GridGraph::selectAccessPoints(
356-
const GRNet* net,
357-
robin_hood::unordered_map<uint64_t, AccessPoint>& selected_access_points)
358-
const
355+
AccessPointSet GridGraph::selectAccessPoints(const GRNet* net) const
359356
{
360-
selected_access_points.clear();
357+
AccessPointHash hasher(y_size_);
358+
AccessPointSet selected_access_points(0, hasher);
361359
// cell hash (2d) -> access point, fixed layer interval
362360
selected_access_points.reserve(net->getNumPins());
363361
const auto& boundingBox = net->getBoundingBox();
@@ -395,11 +393,9 @@ void GridGraph::selectAccessPoints(
395393
logger_->warn(utl::GRT, 274, "pin is hard to access.");
396394
}
397395
const PointT selectedPoint = accessPoints[bestIndex];
398-
const uint64_t hash = hashCell(selectedPoint.x(), selectedPoint.y());
399-
if (selected_access_points.find(hash) == selected_access_points.end()) {
400-
selected_access_points.emplace(hash, AccessPoint{selectedPoint, {}});
401-
}
402-
IntervalT& fixedLayerInterval = selected_access_points[hash].layers;
396+
const AccessPoint ap{selectedPoint, {}};
397+
auto it = selected_access_points.emplace(ap).first;
398+
IntervalT& fixedLayerInterval = it->layers;
403399
for (const auto& point : accessPoints) {
404400
if (point.x() == selectedPoint.x() && point.y() == selectedPoint.y()) {
405401
fixedLayerInterval.Update(point.getLayerIdx());
@@ -408,10 +404,11 @@ void GridGraph::selectAccessPoints(
408404
}
409405
// Extend the fixed layers to 2 layers higher to facilitate track switching
410406
for (auto& accessPoint : selected_access_points) {
411-
IntervalT& fixedLayers = accessPoint.second.layers;
407+
IntervalT& fixedLayers = accessPoint.layers;
412408
fixedLayers.SetHigh(
413409
std::min(fixedLayers.high() + 2, (int) getNumLayers() - 1));
414410
}
411+
return selected_access_points;
415412
}
416413

417414
void GridGraph::commit(const int layer_index,

src/grt/src/cugr/src/GridGraph.h

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,38 @@ class GRNet;
2121
template <typename Type>
2222
class GridGraphView;
2323

24+
struct AccessPoint
25+
{
26+
PointT point;
27+
IntervalT layers;
28+
};
29+
30+
// Only hash and compare on the point, not the layers
31+
class AccessPointHash
32+
{
33+
public:
34+
AccessPointHash(int y_size) : y_size_(y_size) {}
35+
36+
std::size_t operator()(const AccessPoint& ap) const
37+
{
38+
return robin_hood::hash_int(ap.point.x() * y_size_ + ap.point.y());
39+
}
40+
41+
private:
42+
const uint64_t y_size_;
43+
};
44+
45+
struct AccessPointEqual
46+
{
47+
bool operator()(const AccessPoint& lhs, const AccessPoint& rhs) const
48+
{
49+
return lhs.point == rhs.point;
50+
}
51+
};
52+
53+
using AccessPointSet
54+
= robin_hood::unordered_set<AccessPoint, AccessPointHash, AccessPointEqual>;
55+
2456
struct GraphEdge
2557
{
2658
CapacityT getResource() const { return capacity - demand; }
@@ -53,10 +85,6 @@ class GridGraph
5385
return ((uint64_t) point.getLayerIdx() * x_size_ + point.x()) * y_size_
5486
+ point.y();
5587
};
56-
uint64_t hashCell(const int x, const int y) const
57-
{
58-
return (uint64_t) x * y_size_ + y;
59-
}
6088
int getGridline(const int dimension, const int index) const
6189
{
6290
return gridlines_[dimension][index];
@@ -75,15 +103,7 @@ class GridGraph
75103
CostT getUnitViaCost() const { return unit_via_cost_; }
76104

77105
// Misc
78-
struct AccessPoint
79-
{
80-
PointT point;
81-
IntervalT layers;
82-
};
83-
84-
void selectAccessPoints(const GRNet* net,
85-
robin_hood::unordered_map<uint64_t, AccessPoint>&
86-
selected_access_points) const;
106+
AccessPointSet selectAccessPoints(const GRNet* net) const;
87107

88108
// Methods for updating demands
89109
void commitTree(const std::shared_ptr<GRTreeNode>& tree, bool rip_up = false);

src/grt/src/cugr/src/MazeRoute.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ void SparseGraph::init(const GridGraphView<CostT>& wire_cost_view,
2323
const SparseGrid& grid)
2424
{
2525
// 0. Create pseudo pins
26-
robin_hood::unordered_map<uint64_t, GridGraph::AccessPoint>
27-
selectedAccessPoints;
28-
grid_graph_->selectAccessPoints(net_, selectedAccessPoints);
26+
const auto selectedAccessPoints = grid_graph_->selectAccessPoints(net_);
2927
pseudo_pins_.reserve(selectedAccessPoints.size());
3028
for (const auto& selectedPoint : selectedAccessPoints) {
31-
pseudo_pins_.push_back(selectedPoint.second);
29+
pseudo_pins_.push_back(selectedPoint);
3230
}
3331

3432
// 1. Collect additional routing grid lines

src/grt/src/cugr/src/MazeRoute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SparseGraph
4848
void init(const GridGraphView<CostT>& wire_cost_view, const SparseGrid& grid);
4949
int getNumVertices() const { return vertices_.size(); }
5050
int getNumPseudoPins() const { return pseudo_pins_.size(); }
51-
GridGraph::AccessPoint getPseudoPin(int pin_index) const
51+
AccessPoint getPseudoPin(int pin_index) const
5252
{
5353
return pseudo_pins_[pin_index];
5454
}
@@ -81,7 +81,7 @@ class SparseGraph
8181
GRNet* net_;
8282
const GridGraph* grid_graph_;
8383

84-
std::vector<GridGraph::AccessPoint> pseudo_pins_;
84+
std::vector<AccessPoint> pseudo_pins_;
8585

8686
std::vector<int> xs_;
8787
std::vector<int> ys_;

src/grt/src/cugr/src/PatternRoute.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,21 @@ std::string PatternRoutingNode::getPythonString(
7979

8080
void PatternRoute::constructSteinerTree()
8181
{
82-
robin_hood::unordered_map<uint64_t, GridGraph::AccessPoint>
83-
selectedAccessPoints;
84-
grid_graph_->selectAccessPoints(net_, selectedAccessPoints);
82+
auto selectedAccessPoints = grid_graph_->selectAccessPoints(net_);
8583

8684
const int degree = selectedAccessPoints.size();
8785
if (degree == 1) {
88-
for (auto& accessPoint : selectedAccessPoints) {
89-
steiner_tree_ = std::make_shared<SteinerTreeNode>(
90-
accessPoint.second.point, accessPoint.second.layers);
91-
}
86+
const auto& accessPoint = *selectedAccessPoints.begin();
87+
steiner_tree_ = std::make_shared<SteinerTreeNode>(accessPoint.point,
88+
accessPoint.layers);
9289
return;
9390
}
9491

9592
std::vector<int> xs;
9693
std::vector<int> ys;
9794
for (auto& accessPoint : selectedAccessPoints) {
98-
xs.push_back(accessPoint.second.point.x());
99-
ys.push_back(accessPoint.second.point.y());
95+
xs.push_back(accessPoint.point.x());
96+
ys.push_back(accessPoint.point.y());
10097
}
10198

10299
stt::Tree flutetree = stt_builder_->flute(xs, ys, flute_accuracy_);
@@ -139,10 +136,10 @@ void PatternRoute::constructSteinerTree()
139136
constructTree(current, curIndex, nextIndex);
140137
}
141138
// Set fixed layer interval
142-
const uint64_t hash
143-
= grid_graph_->hashCell(current->x(), current->y());
144-
if (selectedAccessPoints.find(hash) != selectedAccessPoints.end()) {
145-
current->setFixedLayers(selectedAccessPoints[hash].layers);
139+
const AccessPoint current_pt{{current->x(), current->y()}, {}};
140+
if (auto it = selectedAccessPoints.find(current_pt);
141+
it != selectedAccessPoints.end()) {
142+
current->setFixedLayers(it->layers);
146143
}
147144
// Connect current to parent
148145
if (parent == nullptr) {

src/grt/src/cugr/src/geo.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ using utl::format_as;
2020
class PointT
2121
{
2222
public:
23-
PointT(int x = std::numeric_limits<int>::max(),
24-
int y = std::numeric_limits<int>::max())
25-
: x_(x), y_(y)
26-
{
27-
}
23+
PointT() = default;
24+
PointT(int x, int y) : x_(x), y_(y) {}
25+
2826
bool IsValid() { return *this != PointT(); }
2927

3028
int x() const { return x_; }
@@ -71,8 +69,8 @@ class PointT
7169
}
7270

7371
private:
74-
int x_;
75-
int y_;
72+
int x_{std::numeric_limits<int>::max()};
73+
int y_{std::numeric_limits<int>::max()};
7674
};
7775

7876
// Interval template

0 commit comments

Comments
 (0)