Skip to content

Commit 09a62d8

Browse files
authored
Merge pull request #10558 from The-OpenROAD-Project-staging/mpl-halo-on-pins
mpl: pin-aware macro halos
2 parents 9bb74d6 + 7cfb210 commit 09a62d8

78 files changed

Lines changed: 1681 additions & 1049 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/mpl/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ rtl_macro_placer
4545
[-report_directory report_directory]
4646
[-write_macro_placement file_name]
4747
[-keep_clustering_data]
48+
[-use_full_halo]
4849
```
4950

5051
#### Options
@@ -65,6 +66,7 @@ rtl_macro_placer
6566
| `-report_directory` | Save reports to this directory. |
6667
| `-write_macro_placement` | Generates a file with the design's macro placement in the format of calls for the `place_macro` command. |
6768
| `-keep_clustering_data` | Save the hierarchy generated by MPL's clustering engine in the form of dbGroups inside ODB. |
69+
| `-use_full_halo` | Remove pin awareness from halo assignment. |
6870

6971
#### Simulated Annealing Weight parameters
7072

‎src/mpl/include/mpl/rtl_mp.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ class MacroPlacer
6363
float target_util,
6464
float min_ar,
6565
const char* report_directory,
66-
bool keep_clustering_data);
66+
bool keep_clustering_data,
67+
bool use_full_halo);
68+
6769
void blockMacroChannels();
70+
6871
void placeMacro(odb::dbInst* inst,
6972
const float& x_origin,
7073
const float& y_origin,

‎src/mpl/src/clusterEngine.cpp‎

Lines changed: 143 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ void ClusteringEngine::setTree(PhysicalHierarchy* tree)
8686

8787
void ClusteringEngine::setHalos(
8888
const HardMacro::Halo& base_halo,
89+
const bool use_full_halo,
8990
const odb::PtrMap<odb::dbInst, HardMacro::Halo>& macro_to_halo)
9091
{
9192
base_halo_ = base_halo;
93+
use_full_halo_ = use_full_halo;
9294
macro_to_halo_ = macro_to_halo;
9395
}
9496

@@ -2063,6 +2065,7 @@ std::string ClusteringEngine::generateMacroAndCoreDimensionsTable(
20632065
void ClusteringEngine::createHardMacros()
20642066
{
20652067
const odb::Rect& core = block_->getCoreArea();
2068+
const int minimum_spacing = getMinimumSpacing();
20662069

20672070
for (odb::dbInst* inst : block_->getInsts()) {
20682071
if (inst->isBlock()) {
@@ -2082,18 +2085,7 @@ void ClusteringEngine::createHardMacros()
20822085
tree_->has_fixed_macros = true;
20832086
}
20842087

2085-
HardMacro::Halo halo;
2086-
if (macro_to_halo_.contains(inst)) {
2087-
halo = macro_to_halo_.at(inst);
2088-
} else if (inst->getHalo() != nullptr) {
2089-
const HardMacro::Halo inst_halo(inst->getHalo());
2090-
halo = inst_halo;
2091-
if (!inst->getHalo()->isSoft()) {
2092-
halo = inst_halo.floorTo(base_halo_);
2093-
}
2094-
} else {
2095-
halo = base_halo_;
2096-
}
2088+
HardMacro::Halo halo = buildMacroHalo(inst, minimum_spacing);
20972089

20982090
auto macro = std::make_unique<HardMacro>(inst, halo);
20992091

@@ -2163,6 +2155,145 @@ int ClusteringEngine::getNumberOfIOs(Cluster* target) const
21632155
return number_of_ios;
21642156
}
21652157

2158+
HardMacro::Halo ClusteringEngine::buildMacroHalo(odb::dbInst* inst,
2159+
int minimum_spacing) const
2160+
{
2161+
if (macro_to_halo_.contains(inst)) {
2162+
return macro_to_halo_.at(inst);
2163+
}
2164+
2165+
HardMacro::Halo full_halo;
2166+
if (inst->getHalo() != nullptr) {
2167+
odb::Rect inst_halo = inst->getHalo()->getBox();
2168+
if (inst->getHalo()->isSoft()) {
2169+
full_halo = HardMacro::Halo(inst->getHalo());
2170+
} else {
2171+
full_halo = {std::max(inst_halo.xMin(), base_halo_.left),
2172+
std::max(inst_halo.yMin(), base_halo_.bottom),
2173+
std::max(inst_halo.xMax(), base_halo_.right),
2174+
std::max(inst_halo.yMax(), base_halo_.top)};
2175+
}
2176+
} else {
2177+
full_halo = base_halo_;
2178+
}
2179+
2180+
if (use_full_halo_) {
2181+
return full_halo;
2182+
}
2183+
2184+
HardMacro::Halo halo(minimum_spacing);
2185+
2186+
odb::dbMaster* master = inst->getMaster();
2187+
2188+
for (odb::dbMTerm* mterm : master->getMTerms()) {
2189+
if (mterm->getSigType() != odb::dbSigType::SIGNAL) {
2190+
continue;
2191+
}
2192+
2193+
for (odb::dbMPin* mpin : mterm->getMPins()) {
2194+
for (odb::dbBox* box : mpin->getGeometry()) {
2195+
odb::Rect pin_rect = box->getBox();
2196+
2197+
std::vector<std::pair<int, Boundary>> dist_to_boundary{
2198+
{pin_rect.xMin(), Boundary::L},
2199+
{pin_rect.yMin(), Boundary::B},
2200+
{master->getWidth() - pin_rect.xMax(), Boundary::R},
2201+
{master->getHeight() - pin_rect.yMax(), Boundary::T}};
2202+
2203+
std::ranges::sort(dist_to_boundary);
2204+
2205+
Boundary closest = dist_to_boundary[0].second;
2206+
2207+
auto& candidate = dist_to_boundary[0];
2208+
auto& second_candidate = dist_to_boundary[1];
2209+
2210+
// When a pin is equally distant from two or more edges (i.e. in the
2211+
// corner) the pin's layer direction is used to choose between
2212+
// candidates
2213+
if (isEquidistantDifferentDirections(candidate, second_candidate)) {
2214+
auto direction
2215+
= (mpin->getGeometry().begin())->getTechLayer()->getDirection();
2216+
if (direction == odb::dbTechLayerDir::VERTICAL) {
2217+
closest = isVertical(candidate.second) ? second_candidate.second
2218+
: candidate.second;
2219+
} else {
2220+
closest = isVertical(candidate.second) ? candidate.second
2221+
: second_candidate.second;
2222+
}
2223+
}
2224+
2225+
switch (closest) {
2226+
case Boundary::B:
2227+
halo.bottom = full_halo.bottom;
2228+
break;
2229+
case Boundary::L:
2230+
halo.left = full_halo.left;
2231+
break;
2232+
case Boundary::T:
2233+
halo.top = full_halo.top;
2234+
break;
2235+
case Boundary::R:
2236+
halo.right = full_halo.right;
2237+
break;
2238+
}
2239+
}
2240+
}
2241+
}
2242+
2243+
// Adjust halo orientation for fixed macros here, since those
2244+
// are skipped during orientation improve and thus never properly adjusted
2245+
if (inst->getPlacementStatus().isFixed()) {
2246+
auto orient = inst->getOrient();
2247+
if (orient == odb::dbOrientType::MX || orient == odb::dbOrientType::R180) {
2248+
std::swap(halo.bottom, halo.top);
2249+
}
2250+
if (orient == odb::dbOrientType::MY || orient == odb::dbOrientType::R180) {
2251+
std::swap(halo.left, halo.right);
2252+
}
2253+
}
2254+
2255+
return halo;
2256+
}
2257+
2258+
int ClusteringEngine::getMinimumSpacing() const
2259+
{
2260+
int spacing = 0;
2261+
2262+
for (odb::dbInst* inst : block_->getInsts()) {
2263+
if (inst->isBlock()) {
2264+
odb::dbMaster* master = inst->getMaster();
2265+
2266+
for (odb::dbBox* obs : master->getObstructions()) {
2267+
if (auto layer = obs->getTechLayer()) {
2268+
spacing = std::max(spacing, layer->getSpacing());
2269+
}
2270+
}
2271+
2272+
for (odb::dbMTerm* mterm : master->getMTerms()) {
2273+
for (odb::dbMPin* mpin : mterm->getMPins()) {
2274+
for (odb::dbBox* geom : mpin->getGeometry()) {
2275+
if (auto layer = geom->getTechLayer()) {
2276+
spacing = std::max(spacing, layer->getSpacing());
2277+
}
2278+
}
2279+
}
2280+
}
2281+
}
2282+
}
2283+
return spacing;
2284+
}
2285+
2286+
bool ClusteringEngine::isEquidistantDifferentDirections(
2287+
std::pair<int, Boundary> candidate,
2288+
std::pair<int, Boundary> second_candidate) const
2289+
{
2290+
return (candidate.first == second_candidate.first)
2291+
&& ((isVertical(candidate.second)
2292+
&& !isVertical(second_candidate.second))
2293+
|| (!isVertical(candidate.second)
2294+
&& isVertical(second_candidate.second)));
2295+
}
2296+
21662297
///////////////////////////////////////////////
21672298

21682299
void ClusteringEngine::reportThresholds() const

‎src/mpl/src/clusterEngine.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class ClusteringEngine
106106

107107
void setTree(PhysicalHierarchy* tree);
108108
void setHalos(const HardMacro::Halo& base_halo,
109+
bool use_full_halo,
109110
const odb::PtrMap<odb::dbInst, HardMacro::Halo>& macro_to_halo);
110111

111112
// Methods to update the tree as the hierarchical
@@ -227,6 +228,12 @@ class ClusteringEngine
227228

228229
bool isValidNet(odb::dbNet* net);
229230

231+
HardMacro::Halo buildMacroHalo(odb::dbInst* inst, int minimum_spacing) const;
232+
int getMinimumSpacing() const;
233+
bool isEquidistantDifferentDirections(
234+
std::pair<int, Boundary> candidate,
235+
std::pair<int, Boundary> second_candidate) const;
236+
230237
odb::dbBlock* block_;
231238
utl::Logger* logger_;
232239
par::PartitionMgr* triton_part_;
@@ -255,6 +262,7 @@ class ClusteringEngine
255262
std::unordered_set<odb::dbInst*> ignorable_macros_;
256263

257264
HardMacro::Halo base_halo_;
265+
bool use_full_halo_{false};
258266
odb::PtrMap<odb::dbInst, HardMacro::Halo> macro_to_halo_;
259267
};
260268

0 commit comments

Comments
 (0)