Skip to content

Commit 82c4484

Browse files
authored
Merge pull request #8208 from The-OpenROAD-Project-staging/grt-cugr-refactor
grt: minor refactoring cugr code
2 parents 07c8f3f + 79d041b commit 82c4484

File tree

7 files changed

+52
-91
lines changed

7 files changed

+52
-91
lines changed

src/grt/BUILD

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,9 @@ cc_library(
9696
],
9797
deps = [
9898
":groute",
99-
"//src/dbSta",
10099
"//src/odb",
101100
"//src/stt",
102101
"//src/utl",
103-
"@boost.container_hash",
104-
"@boost.geometry",
105-
"@boost.icl",
106-
"@boost.multi_array",
107102
],
108103
)
109104

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

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#pragma once
22

3-
#include "geo.h"
4-
#include "grt/GRoute.h"
5-
6-
// STL libraries
73
#include <bitset>
84
#include <csignal>
95
#include <fstream>
@@ -16,13 +12,8 @@
1612
#include <tuple>
1713
#include <vector>
1814

19-
// Boost libraries
20-
// #include <boost/functional/hash.hpp>
21-
#include <boost/geometry.hpp>
22-
#include <boost/geometry/geometries/box.hpp>
23-
#include <boost/geometry/geometries/point.hpp>
24-
#include <boost/geometry/index/rtree.hpp>
25-
15+
#include "geo.h"
16+
#include "grt/GRoute.h"
2617
#include "odb/geom.h"
2718

2819
namespace odb {
@@ -43,37 +34,30 @@ class Design;
4334
class GridGraph;
4435
class GRNet;
4536

46-
namespace bg = boost::geometry;
47-
namespace bgi = boost::geometry::index;
48-
49-
using boostPoint = bg::model::point<int, 2, bg::cs::cartesian>;
50-
using boostBox = bg::model::box<boostPoint>;
51-
using RTree = bgi::rtree<std::pair<boostBox, int>, bgi::rstar<32>>;
52-
5337
struct Constants
5438
{
55-
double weight_wire_length;
56-
double weight_via_number;
57-
double weight_short_area;
39+
double weight_wire_length = 0.5;
40+
double weight_via_number = 4.0;
41+
double weight_short_area = 500.0;
5842

59-
int min_routing_layer;
43+
int min_routing_layer = 1;
6044

61-
double cost_logistic_slope;
45+
double cost_logistic_slope = 1.0;
6246

6347
// allowed stem length increase to trunk length ratio
64-
double max_detour_ratio;
65-
int target_detour_count;
48+
double max_detour_ratio = 0.25;
49+
int target_detour_count = 20;
6650

67-
double via_multiplier;
51+
double via_multiplier = 2.0;
6852

69-
double maze_logistic_slope;
53+
double maze_logistic_slope = 0.5;
7054

71-
double pin_patch_threshold;
72-
int pin_patch_padding;
73-
double wire_patch_threshold;
74-
double wire_patch_inflation_rate;
55+
double pin_patch_threshold = 20.0;
56+
int pin_patch_padding = 1;
57+
double wire_patch_threshold = 2.0;
58+
double wire_patch_inflation_rate = 1.2;
7559

76-
bool write_heatmap;
60+
bool write_heatmap = false;
7761
};
7862

7963
class CUGR
@@ -93,8 +77,8 @@ class CUGR
9377
std::vector<std::pair<int, grt::BoxT<int>>>& guides);
9478
void printStatistics() const;
9579

96-
Design* design_;
97-
GridGraph* grid_graph_;
80+
Design* design_ = nullptr;
81+
GridGraph* grid_graph_ = nullptr;
9882
std::vector<GRNet*> gr_nets_;
9983

10084
odb::dbDatabase* db_;
@@ -103,8 +87,8 @@ class CUGR
10387

10488
Constants constants_;
10589

106-
int area_of_pin_patches_;
107-
int area_of_wire_patches_;
90+
int area_of_pin_patches_ = 0;
91+
int area_of_wire_patches_ = 0;
10892
};
10993

110-
} // namespace grt
94+
} // namespace grt

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class PointT
5858
bool operator==(const PointT& rhs) const { return x == rhs.x && y == rhs.y; }
5959
bool operator!=(const PointT& rhs) const { return !(*this == rhs); }
6060

61-
friend inline std::ostream& operator<<(std::ostream& os, const PointT& pt)
61+
friend std::ostream& operator<<(std::ostream& os, const PointT& pt)
6262
{
6363
os << "(" << pt.x << ", " << pt.y << ")";
6464
return os;
@@ -67,21 +67,21 @@ class PointT
6767

6868
// L-1 (Manhattan) distance between points
6969
template <typename T>
70-
inline T Dist(const PointT<T>& pt1, const PointT<T>& pt2)
70+
T Dist(const PointT<T>& pt1, const PointT<T>& pt2)
7171
{
7272
return std::abs(pt1.x - pt2.x) + std::abs(pt1.y - pt2.y);
7373
}
7474

7575
// L-2 (Euclidean) distance between points
7676
template <typename T>
77-
inline double L2Dist(const PointT<T>& pt1, const PointT<T>& pt2)
77+
double L2Dist(const PointT<T>& pt1, const PointT<T>& pt2)
7878
{
7979
return std::sqrt(std::pow(pt1.x - pt2.x, 2) + std::pow(pt1.y - pt2.y, 2));
8080
}
8181

8282
// L-inf distance between points
8383
template <typename T>
84-
inline T LInfDist(const PointT<T>& pt1, const PointT<T>& pt2)
84+
T LInfDist(const PointT<T>& pt1, const PointT<T>& pt2)
8585
{
8686
return std::max(std::abs(pt1.x - pt2.x), std::abs(pt1.y - pt2.y));
8787
}
@@ -226,8 +226,8 @@ class IntervalT
226226
}
227227
bool operator!=(const IntervalT& rhs) const { return !(*this == rhs); }
228228

229-
friend inline std::ostream& operator<<(std::ostream& os,
230-
const IntervalT<T>& interval)
229+
friend std::ostream& operator<<(std::ostream& os,
230+
const IntervalT<T>& interval)
231231
{
232232
os << "(" << interval.low << ", " << interval.high << ")";
233233
return os;
@@ -236,13 +236,13 @@ class IntervalT
236236

237237
// Distance between intervals/points (assume valid intervals)
238238
template <typename T>
239-
inline T Dist(const IntervalT<T>& intvl, const T val)
239+
T Dist(const IntervalT<T>& intvl, const T val)
240240
{
241241
return std::abs(intvl.GetNearestPointTo(val) - val);
242242
}
243243

244244
template <typename T>
245-
inline T Dist(const IntervalT<T>& int1, const IntervalT<T>& int2)
245+
T Dist(const IntervalT<T>& int1, const IntervalT<T>& int2)
246246
{
247247
if (int1.high <= int2.low) {
248248
return int2.low - int1.high;
@@ -391,7 +391,7 @@ class BoxT
391391
}
392392
bool operator!=(const BoxT& rhs) const { return !(*this == rhs); }
393393

394-
friend inline std::ostream& operator<<(std::ostream& os, const BoxT<T>& box)
394+
friend std::ostream& operator<<(std::ostream& os, const BoxT<T>& box)
395395
{
396396
os << "[x: " << box.x << ", y: " << box.y << "]";
397397
return os;
@@ -400,34 +400,34 @@ class BoxT
400400

401401
// L-1 (Manhattan) distance between boxes/points (assume valid boxes)
402402
template <typename T>
403-
inline T Dist(const BoxT<T>& box, const PointT<T>& point)
403+
T Dist(const BoxT<T>& box, const PointT<T>& point)
404404
{
405405
return Dist(box.x, point.x) + Dist(box.y, point.y);
406406
}
407407
template <typename T>
408-
inline T Dist(const BoxT<T>& box1, const BoxT<T>& box2)
408+
T Dist(const BoxT<T>& box1, const BoxT<T>& box2)
409409
{
410410
return Dist(box1.x, box2.x) + Dist(box1.y, box2.y);
411411
}
412412

413413
// L-2 (Euclidean) distance between boxes
414414
template <typename T>
415-
inline double L2Dist(const BoxT<T>& box1, const BoxT<T>& box2)
415+
double L2Dist(const BoxT<T>& box1, const BoxT<T>& box2)
416416
{
417417
return std::sqrt(std::pow(Dist(box1.x, box2.x), 2)
418418
+ std::pow(Dist(box1.y, box2.y), 2));
419419
}
420420

421421
// L-Inf (max) distance between boxes
422422
template <typename T>
423-
inline T LInfDist(const BoxT<T>& box1, const BoxT<T>& box2)
423+
T LInfDist(const BoxT<T>& box1, const BoxT<T>& box2)
424424
{
425425
return std::max(Dist(box1.x, box2.x), Dist(box1.y, box2.y));
426426
}
427427

428428
// Parallel run length between boxes
429429
template <typename T>
430-
inline T ParaRunLength(const BoxT<T>& box1, const BoxT<T>& box2)
430+
T ParaRunLength(const BoxT<T>& box1, const BoxT<T>& box2)
431431
{
432432
return std::max(box1.x.ParaRunLength(box2.x), box1.y.ParaRunLength(box2.y));
433433
}

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@ CUGR::CUGR(odb::dbDatabase* db,
1818
stt::SteinerTreeBuilder* stt_builder)
1919
: db_(db), logger_(log), stt_builder_(stt_builder)
2020
{
21-
constants_.weight_wire_length = 0.5;
22-
constants_.weight_via_number = 4.0;
23-
constants_.weight_short_area = 500.0;
24-
constants_.min_routing_layer = 1;
25-
constants_.cost_logistic_slope = 1.0;
26-
constants_.max_detour_ratio = 0.25;
27-
constants_.target_detour_count = 20;
28-
constants_.via_multiplier = 2.0;
29-
constants_.maze_logistic_slope = 0.5;
30-
constants_.pin_patch_threshold = 20.0;
31-
constants_.pin_patch_padding = 1;
32-
constants_.wire_patch_threshold = 2.0;
33-
constants_.wire_patch_inflation_rate = 1.2;
34-
constants_.write_heatmap = false;
3521
}
3622

3723
void CUGR::init(const int min_routing_layer, const int max_routing_layer)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ int GridGraph::getEdgeLength(unsigned direction, unsigned edge_index) const
262262
- grid_centers_[direction][edge_index];
263263
}
264264

265-
inline double GridGraph::logistic(const CapacityT& input,
266-
const double slope) const
265+
double GridGraph::logistic(const CapacityT& input, const double slope) const
267266
{
268267
return 1.0 / (1.0 + exp(input * slope));
269268
}

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,45 @@ struct GraphEdge
1616
CapacityT capacity{0};
1717
CapacityT demand{0};
1818

19-
GraphEdge() = default;
2019
CapacityT getResource() const { return capacity - demand; }
2120
};
2221

2322
class GridGraph
2423
{
2524
public:
2625
GridGraph(const Design* design, const Constants& constants);
27-
inline int getLibDBU() const { return lib_dbu_; }
28-
inline int getM2Pitch() const { return m2_pitch_; }
29-
inline unsigned getNumLayers() const { return num_layers_; }
30-
inline unsigned getSize(unsigned dimension) const
26+
int getLibDBU() const { return lib_dbu_; }
27+
int getM2Pitch() const { return m2_pitch_; }
28+
unsigned getNumLayers() const { return num_layers_; }
29+
unsigned getSize(unsigned dimension) const
3130
{
3231
return (dimension ? y_size_ : x_size_);
3332
}
34-
inline std::string getLayerName(int layer_index) const
33+
std::string getLayerName(int layer_index) const
3534
{
3635
return layer_names_[layer_index];
3736
}
38-
inline unsigned getLayerDirection(int layer_index) const
37+
unsigned getLayerDirection(int layer_index) const
3938
{
4039
return layer_directions_[layer_index];
4140
}
4241

43-
inline uint64_t hashCell(const GRPoint& point) const
42+
uint64_t hashCell(const GRPoint& point) const
4443
{
4544
return ((uint64_t) point.getLayerIdx() * x_size_ + point.x) * y_size_
4645
+ point.y;
4746
};
48-
inline uint64_t hashCell(const int x, const int y) const
47+
uint64_t hashCell(const int x, const int y) const
4948
{
5049
return (uint64_t) x * y_size_ + y;
5150
}
52-
inline int getGridline(const unsigned dimension, const int index) const
51+
int getGridline(const unsigned dimension, const int index) const
5352
{
5453
return gridlines_[dimension][index];
5554
}
5655
BoxT<int> getCellBox(PointT<int> point) const;
5756
BoxT<int> rangeSearchCells(const BoxT<int>& box) const;
58-
inline GraphEdge getEdge(const int layer_index,
59-
const int x,
60-
const int y) const
57+
GraphEdge getEdge(const int layer_index, const int x, const int y) const
6158
{
6259
return graph_edges_[layer_index][x][y];
6360
}
@@ -66,7 +63,7 @@ class GridGraph
6663
int getEdgeLength(unsigned direction, unsigned edge_index) const;
6764
CostT getWireCost(int layer_index, PointT<int> u, PointT<int> v) const;
6865
CostT getViaCost(int layer_index, PointT<int> loc) const;
69-
inline CostT getUnitViaCost() const { return unit_via_cost_; }
66+
CostT getUnitViaCost() const { return unit_via_cost_; }
7067

7168
// Misc
7269
void selectAccessPoints(
@@ -80,7 +77,7 @@ class GridGraph
8077
bool reverse = false);
8178

8279
// Checks
83-
inline bool checkOverflow(int layer_index, int x, int y) const
80+
bool checkOverflow(int layer_index, int x, int y) const
8481
{
8582
return getEdge(layer_index, x, y).getResource() < 0.0;
8683
}
@@ -137,14 +134,14 @@ class GridGraph
137134
// Find the rows/columns overlapping with [locInterval.low, locInterval.high]
138135

139136
// Utility functions for cost calculation
140-
inline CostT getUnitLengthWireCost() const { return unit_length_wire_cost_; }
137+
CostT getUnitLengthWireCost() const { return unit_length_wire_cost_; }
141138
// CostT getUnitViaCost() const { return unit_via_cost_; }
142-
inline CostT getUnitLengthShortCost(int layer_index) const
139+
CostT getUnitLengthShortCost(int layer_index) const
143140
{
144141
return unit_length_short_costs_[layer_index];
145142
}
146143

147-
inline double logistic(const CapacityT& input, double slope) const;
144+
double logistic(const CapacityT& input, double slope) const;
148145
CostT getWireCost(int layer_index,
149146
PointT<int> lower,
150147
CapacityT demand = 1.0) const;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SparseGraph
6767
GRPoint getPoint(const int vertex) const { return vertices_[vertex]; }
6868

6969
private:
70-
inline int getVertexIndex(int direction, int xi, int yi) const
70+
int getVertexIndex(int direction, int xi, int yi) const
7171
{
7272
return direction * xs_.size() * ys_.size() + yi * xs_.size() + xi;
7373
}

0 commit comments

Comments
 (0)