Skip to content

Commit 14141dd

Browse files
committed
grt: fix mem leaks in cugr
Signed-off-by: Matt Liberty <[email protected]>
1 parent 544981e commit 14141dd

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed

src/grt/src/GlobalRouter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void GlobalRouter::clear()
141141
GlobalRouter::~GlobalRouter()
142142
{
143143
delete fastroute_;
144+
delete cugr_;
144145
delete grid_;
145146
for (auto [ignored, net] : db_net_map_) {
146147
delete net;

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <csignal>
55
#include <fstream>
66
#include <iostream>
7+
#include <memory>
78
#include <mutex>
89
#include <set>
910
#include <sstream>
@@ -66,6 +67,7 @@ class CUGR
6667
CUGR(odb::dbDatabase* db,
6768
utl::Logger* log,
6869
stt::SteinerTreeBuilder* stt_builder);
70+
~CUGR();
6971
void init(int min_routing_layer, int max_routing_layer);
7072
void route();
7173
void write(const std::string& guide_file);
@@ -77,9 +79,9 @@ class CUGR
7779
std::vector<std::pair<int, grt::BoxT>>& guides);
7880
void printStatistics() const;
7981

80-
Design* design_ = nullptr;
81-
GridGraph* grid_graph_ = nullptr;
82-
std::vector<GRNet*> gr_nets_;
82+
std::unique_ptr<Design> design_;
83+
std::unique_ptr<GridGraph> grid_graph_;
84+
std::vector<std::unique_ptr<GRNet>> gr_nets_;
8385

8486
odb::dbDatabase* db_;
8587
utl::Logger* logger_;

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,42 @@ CUGR::CUGR(odb::dbDatabase* db,
2020
{
2121
}
2222

23+
CUGR::~CUGR() = default;
24+
2325
void CUGR::init(const int min_routing_layer, const int max_routing_layer)
2426
{
25-
design_ = new Design(
27+
design_ = std::make_unique<Design>(
2628
db_, logger_, constants_, min_routing_layer, max_routing_layer);
27-
grid_graph_ = new GridGraph(design_, constants_);
29+
grid_graph_ = std::make_unique<GridGraph>(design_.get(), constants_);
2830
// Instantiate the global routing netlist
2931
const std::vector<CUGRNet>& baseNets = design_->getAllNets();
3032
gr_nets_.reserve(baseNets.size());
3133
for (const CUGRNet& baseNet : baseNets) {
32-
gr_nets_.push_back(new GRNet(baseNet, design_, grid_graph_));
34+
gr_nets_.push_back(std::make_unique<GRNet>(baseNet, grid_graph_.get()));
3335
}
3436
}
3537

3638
void CUGR::route()
3739
{
3840
std::vector<int> netIndices;
3941
netIndices.reserve(gr_nets_.size());
40-
for (GRNet* net : gr_nets_) {
42+
for (const auto& net : gr_nets_) {
4143
netIndices.push_back(net->getIndex());
4244
}
4345
// Stage 1: Pattern routing
4446
logger_->report("stage 1: pattern routing");
4547
sortNetIndices(netIndices);
4648
for (const int netIndex : netIndices) {
4749
PatternRoute patternRoute(
48-
gr_nets_[netIndex], grid_graph_, stt_builder_, constants_);
50+
gr_nets_[netIndex].get(), grid_graph_.get(), stt_builder_, constants_);
4951
patternRoute.constructSteinerTree();
5052
patternRoute.constructRoutingDAG();
5153
patternRoute.run();
5254
grid_graph_->commitTree(gr_nets_[netIndex]->getRoutingTree());
5355
}
5456

5557
netIndices.clear();
56-
for (GRNet* net : gr_nets_) {
58+
for (const auto& net : gr_nets_) {
5759
if (grid_graph_->checkOverflow(net->getRoutingTree()) > 0) {
5860
netIndices.push_back(net->getIndex());
5961
}
@@ -73,9 +75,10 @@ void CUGR::route()
7375
// }
7476
sortNetIndices(netIndices);
7577
for (const int netIndex : netIndices) {
76-
GRNet* net = gr_nets_[netIndex];
78+
GRNet* net = gr_nets_[netIndex].get();
7779
grid_graph_->commitTree(net->getRoutingTree(), true);
78-
PatternRoute patternRoute(net, grid_graph_, stt_builder_, constants_);
80+
PatternRoute patternRoute(
81+
net, grid_graph_.get(), stt_builder_, constants_);
7982
patternRoute.constructSteinerTree();
8083
patternRoute.constructRoutingDAG();
8184
patternRoute.constructDetours(
@@ -85,7 +88,7 @@ void CUGR::route()
8588
}
8689

8790
netIndices.clear();
88-
for (GRNet* net : gr_nets_) {
91+
for (const auto& net : gr_nets_) {
8992
if (grid_graph_->checkOverflow(net->getRoutingTree()) > 0) {
9093
netIndices.push_back(net->getIndex());
9194
}
@@ -98,24 +101,24 @@ void CUGR::route()
98101
if (!netIndices.empty()) {
99102
std::cout << "stage 3: maze routing on sparsified routing graph\n";
100103
for (const int netIndex : netIndices) {
101-
GRNet* net = gr_nets_[netIndex];
102-
grid_graph_->commitTree(net->getRoutingTree(), true);
104+
grid_graph_->commitTree(gr_nets_[netIndex]->getRoutingTree(), true);
103105
}
104106
GridGraphView<CostT> wireCostView;
105107
grid_graph_->extractWireCostView(wireCostView);
106108
sortNetIndices(netIndices);
107109
SparseGrid grid(10, 10, 0, 0);
108110
for (const int netIndex : netIndices) {
109-
GRNet* net = gr_nets_[netIndex];
111+
GRNet* net = gr_nets_[netIndex].get();
110112
// grid_graph_->commitTree(net->getRoutingTree(), true);
111113
// grid_graph_->updateWireCostView(wireCostView, net->getRoutingTree());
112-
MazeRoute mazeRoute(net, grid_graph_);
114+
MazeRoute mazeRoute(net, grid_graph_.get());
113115
mazeRoute.constructSparsifiedGraph(wireCostView, grid);
114116
mazeRoute.run();
115117
std::shared_ptr<SteinerTreeNode> tree = mazeRoute.getSteinerTree();
116118
assert(tree != nullptr);
117119

118-
PatternRoute patternRoute(net, grid_graph_, stt_builder_, constants_);
120+
PatternRoute patternRoute(
121+
net, grid_graph_.get(), stt_builder_, constants_);
119122
patternRoute.setSteinerTree(tree);
120123
patternRoute.constructRoutingDAG();
121124
patternRoute.run();
@@ -125,7 +128,7 @@ void CUGR::route()
125128
grid.step();
126129
}
127130
netIndices.clear();
128-
for (GRNet* net : gr_nets_) {
131+
for (const auto& net : gr_nets_) {
129132
if (grid_graph_->checkOverflow(net->getRoutingTree()) > 0) {
130133
netIndices.push_back(net->getIndex());
131134
}
@@ -145,9 +148,9 @@ void CUGR::write(const std::string& guide_file)
145148
area_of_pin_patches_ = 0;
146149
area_of_wire_patches_ = 0;
147150
std::stringstream ss;
148-
for (const GRNet* net : gr_nets_) {
151+
for (const auto& net : gr_nets_) {
149152
std::vector<std::pair<int, BoxT>> guides;
150-
getGuides(net, guides);
153+
getGuides(net.get(), guides);
151154

152155
ss << net->getName() << std::endl;
153156
ss << "(" << std::endl;
@@ -171,7 +174,7 @@ void CUGR::write(const std::string& guide_file)
171174
NetRouteMap CUGR::getRoutes()
172175
{
173176
NetRouteMap routes;
174-
for (const GRNet* net : gr_nets_) {
177+
for (const auto& net : gr_nets_) {
175178
if (net->getNumPins() < 2) {
176179
continue;
177180
}
@@ -366,7 +369,7 @@ void CUGR::printStatistics() const
366369
std::vector<std::vector<int>>(
367370
grid_graph_->getSize(0),
368371
std::vector<int>(grid_graph_->getSize(1), 0)));
369-
for (GRNet* net : gr_nets_) {
372+
for (const auto& net : gr_nets_) {
370373
GRTreeNode::preorder(
371374
net->getRoutingTree(), [&](const std::shared_ptr<GRTreeNode>& node) {
372375
for (const auto& child : node->children) {

src/grt/src/cugr/src/GRNet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace grt {
66

7-
GRNet::GRNet(const CUGRNet& baseNet, Design* design, GridGraph* gridGraph)
7+
GRNet::GRNet(const CUGRNet& baseNet, GridGraph* gridGraph)
88
{
99
index_ = baseNet.getIndex();
1010
db_net_ = baseNet.getDbNet();

src/grt/src/cugr/src/GRNet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace grt {
1010
class GRNet
1111
{
1212
public:
13-
GRNet(const CUGRNet& baseNet, Design* design, GridGraph* gridGraph);
13+
GRNet(const CUGRNet& baseNet, GridGraph* gridGraph);
1414

1515
int getIndex() const { return index_; }
1616
odb::dbNet* getDbNet() const { return db_net_; }

0 commit comments

Comments
 (0)