Skip to content

Commit 9f8fcfe

Browse files
committed
grt: split up CUGR::route
Signed-off-by: Matt Liberty <[email protected]>
1 parent 33f400e commit 9f8fcfe

File tree

2 files changed

+84
-81
lines changed

2 files changed

+84
-81
lines changed

src/grt/src/cugr/include/CUGR.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class CUGR
6666
NetRouteMap getRoutes();
6767

6868
private:
69+
void updateOverflowNets(std::vector<int>& netIndices);
70+
void patternRoute(std::vector<int>& netIndices);
71+
void patternRouteWithDetours(std::vector<int>& netIndices);
72+
void mazeRoute(std::vector<int>& netIndices);
6973
void sortNetIndices(std::vector<int>& netIndices) const;
7074
void getGuides(const GRNet* net,
7175
std::vector<std::pair<int, grt::BoxT>>& guides);

src/grt/src/cugr/src/CUGR.cpp

Lines changed: 80 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,20 @@ void CUGR::init(const int min_routing_layer, const int max_routing_layer)
5050
}
5151
}
5252

53-
void CUGR::route()
53+
void CUGR::updateOverflowNets(std::vector<int>& netIndices)
5454
{
55-
std::vector<int> netIndices;
56-
netIndices.reserve(gr_nets_.size());
55+
netIndices.clear();
5756
for (const auto& net : gr_nets_) {
58-
netIndices.push_back(net->getIndex());
57+
if (grid_graph_->checkOverflow(net->getRoutingTree()) > 0) {
58+
netIndices.push_back(net->getIndex());
59+
}
5960
}
60-
// Stage 1: Pattern routing
61+
logger_->report(
62+
"{} / {} gr_nets_ have overflows.", netIndices.size(), gr_nets_.size());
63+
}
64+
65+
void CUGR::patternRoute(std::vector<int>& netIndices)
66+
{
6167
logger_->report("stage 1: pattern routing");
6268
sortNetIndices(netIndices);
6369
for (const int netIndex : netIndices) {
@@ -69,89 +75,82 @@ void CUGR::route()
6975
grid_graph_->commitTree(gr_nets_[netIndex]->getRoutingTree());
7076
}
7177

72-
netIndices.clear();
73-
for (const auto& net : gr_nets_) {
74-
if (grid_graph_->checkOverflow(net->getRoutingTree()) > 0) {
75-
netIndices.push_back(net->getIndex());
76-
}
78+
updateOverflowNets(netIndices);
79+
}
80+
81+
void CUGR::patternRouteWithDetours(std::vector<int>& netIndices)
82+
{
83+
if (netIndices.empty()) {
84+
return;
85+
}
86+
logger_->report("stage 2: pattern routing with possible detours");
87+
// (2d) direction -> x -> y -> has overflow?
88+
GridGraphView<bool> congestionView;
89+
grid_graph_->extractCongestionView(congestionView);
90+
sortNetIndices(netIndices);
91+
for (const int netIndex : netIndices) {
92+
GRNet* net = gr_nets_[netIndex].get();
93+
grid_graph_->commitTree(net->getRoutingTree(), true);
94+
PatternRoute patternRoute(net, grid_graph_.get(), stt_builder_, constants_);
95+
patternRoute.constructSteinerTree();
96+
patternRoute.constructRoutingDAG();
97+
// KEY DIFFERENCE compared to stage 1 (patternRoute)
98+
patternRoute.constructDetours(congestionView);
99+
patternRoute.run();
100+
grid_graph_->commitTree(net->getRoutingTree());
77101
}
78-
logger_->report(
79-
"{} / {} gr_nets_ have overflows.", netIndices.size(), gr_nets_.size());
80102

81-
// Stage 2: Pattern routing with possible detours
82-
if (!netIndices.empty()) {
83-
logger_->report("stage 2: pattern routing with possible detours");
84-
GridGraphView<bool>
85-
congestionView; // (2d) direction -> x -> y -> has overflow?
86-
grid_graph_->extractCongestionView(congestionView);
87-
// for (const int netIndex : netIndices) {
88-
// GRNet& net = gr_nets_[netIndex];
89-
// grid_graph_->commitTree(net->getRoutingTree(), true);
90-
// }
91-
sortNetIndices(netIndices);
92-
for (const int netIndex : netIndices) {
93-
GRNet* net = gr_nets_[netIndex].get();
94-
grid_graph_->commitTree(net->getRoutingTree(), true);
95-
PatternRoute patternRoute(
96-
net, grid_graph_.get(), stt_builder_, constants_);
97-
patternRoute.constructSteinerTree();
98-
patternRoute.constructRoutingDAG();
99-
patternRoute.constructDetours(
100-
congestionView); // KEY DIFFERENCE compared to stage 1
101-
patternRoute.run();
102-
grid_graph_->commitTree(net->getRoutingTree());
103-
}
103+
updateOverflowNets(netIndices);
104+
}
104105

105-
netIndices.clear();
106-
for (const auto& net : gr_nets_) {
107-
if (grid_graph_->checkOverflow(net->getRoutingTree()) > 0) {
108-
netIndices.push_back(net->getIndex());
109-
}
110-
}
111-
logger_->report(
112-
"{} / {} gr_nets_ have overflows.", netIndices.size(), gr_nets_.size());
106+
void CUGR::mazeRoute(std::vector<int>& netIndices)
107+
{
108+
if (netIndices.empty()) {
109+
return;
110+
}
111+
logger_->report("stage 3: maze routing on sparsified routing graph");
112+
for (const int netIndex : netIndices) {
113+
grid_graph_->commitTree(gr_nets_[netIndex]->getRoutingTree(), true);
113114
}
115+
GridGraphView<CostT> wireCostView;
116+
grid_graph_->extractWireCostView(wireCostView);
117+
sortNetIndices(netIndices);
118+
SparseGrid grid(10, 10, 0, 0);
119+
for (const int netIndex : netIndices) {
120+
GRNet* net = gr_nets_[netIndex].get();
121+
MazeRoute mazeRoute(net, grid_graph_.get());
122+
mazeRoute.constructSparsifiedGraph(wireCostView, grid);
123+
mazeRoute.run();
124+
std::shared_ptr<SteinerTreeNode> tree = mazeRoute.getSteinerTree();
125+
assert(tree != nullptr);
126+
127+
PatternRoute patternRoute(net, grid_graph_.get(), stt_builder_, constants_);
128+
patternRoute.setSteinerTree(tree);
129+
patternRoute.constructRoutingDAG();
130+
patternRoute.run();
114131

115-
// Stage 3: maze routing on sparsified routing graph
116-
if (!netIndices.empty()) {
117-
logger_->report("stage 3: maze routing on sparsified routing graph");
118-
for (const int netIndex : netIndices) {
119-
grid_graph_->commitTree(gr_nets_[netIndex]->getRoutingTree(), true);
120-
}
121-
GridGraphView<CostT> wireCostView;
122-
grid_graph_->extractWireCostView(wireCostView);
123-
sortNetIndices(netIndices);
124-
SparseGrid grid(10, 10, 0, 0);
125-
for (const int netIndex : netIndices) {
126-
GRNet* net = gr_nets_[netIndex].get();
127-
// grid_graph_->commitTree(net->getRoutingTree(), true);
128-
// grid_graph_->updateWireCostView(wireCostView, net->getRoutingTree());
129-
MazeRoute mazeRoute(net, grid_graph_.get());
130-
mazeRoute.constructSparsifiedGraph(wireCostView, grid);
131-
mazeRoute.run();
132-
std::shared_ptr<SteinerTreeNode> tree = mazeRoute.getSteinerTree();
133-
assert(tree != nullptr);
134-
135-
PatternRoute patternRoute(
136-
net, grid_graph_.get(), stt_builder_, constants_);
137-
patternRoute.setSteinerTree(tree);
138-
patternRoute.constructRoutingDAG();
139-
patternRoute.run();
140-
141-
grid_graph_->commitTree(net->getRoutingTree());
142-
grid_graph_->updateWireCostView(wireCostView, net->getRoutingTree());
143-
grid.step();
144-
}
145-
netIndices.clear();
146-
for (const auto& net : gr_nets_) {
147-
if (grid_graph_->checkOverflow(net->getRoutingTree()) > 0) {
148-
netIndices.push_back(net->getIndex());
149-
}
150-
}
151-
logger_->report(
152-
"{} / {} gr_nets_ have overflows.", netIndices.size(), gr_nets_.size());
132+
grid_graph_->commitTree(net->getRoutingTree());
133+
grid_graph_->updateWireCostView(wireCostView, net->getRoutingTree());
134+
grid.step();
135+
}
136+
137+
updateOverflowNets(netIndices);
138+
}
139+
140+
void CUGR::route()
141+
{
142+
std::vector<int> netIndices;
143+
netIndices.reserve(gr_nets_.size());
144+
for (const auto& net : gr_nets_) {
145+
netIndices.push_back(net->getIndex());
153146
}
154147

148+
patternRoute(netIndices);
149+
150+
patternRouteWithDetours(netIndices);
151+
152+
mazeRoute(netIndices);
153+
155154
printStatistics();
156155
if (constants_.write_heatmap) {
157156
grid_graph_->write();

0 commit comments

Comments
 (0)