Skip to content

Commit 378f996

Browse files
authored
Merge pull request #9004 from AcKoucher/mpl-nets
mpl: refactor BundledNet builders
2 parents 182f51b + 207f4e6 commit 378f996

File tree

3 files changed

+59
-57
lines changed

3 files changed

+59
-57
lines changed

src/mpl/src/clusterEngine.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ struct PhysicalHierarchy
120120
float cluster_size_ratio{0.0f};
121121
float cluster_size_tolerance{0.0f};
122122

123-
// Virtual connection weight between each macro cluster
124-
// and its corresponding standard-cell cluster to bias
125-
// the macro placer to place them together.
126-
const float virtual_weight = 10.0f;
127-
128123
const int io_bundles_per_edge = 5;
129124
};
130125

src/mpl/src/hier_rtlmp.cpp

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,13 +1390,10 @@ void HierRTLMP::placeChildren(Cluster* parent, bool ignore_std_cell_area)
13901390
graphics_->setOutline(micronsToDbu(block_, outline));
13911391
}
13921392

1393-
// Suppose the region, fence, guide has been mapped to cooresponding macros
1394-
// This step is done when we enter the Hier-RTLMP program
1395-
std::map<std::string, int> soft_macro_id_map; // cluster_name, macro_id
1393+
SoftMacroNameToIdMap soft_macro_id_map;
13961394
std::map<int, Rect> fences;
13971395
std::map<int, Rect> guides;
13981396
std::vector<SoftMacro> macros;
1399-
std::vector<BundledNet> nets;
14001397

14011398
std::vector<Rect> blockages = findBlockagesWithinOutline(outline);
14021399
eliminateOverlaps(blockages);
@@ -1486,39 +1483,7 @@ void HierRTLMP::placeChildren(Cluster* parent, bool ignore_std_cell_area)
14861483

14871484
clustering_engine_->rebuildConnections();
14881485

1489-
// add the virtual connections (the weight related to IOs and macros belong to
1490-
// the same cluster)
1491-
for (const auto& [cluster1, cluster2] : parent->getVirtualConnections()) {
1492-
BundledNet net(
1493-
soft_macro_id_map[tree_->maps.id_to_cluster[cluster1]->getName()],
1494-
soft_macro_id_map[tree_->maps.id_to_cluster[cluster2]->getName()],
1495-
tree_->virtual_weight);
1496-
nets.push_back(net);
1497-
}
1498-
1499-
// convert the connections between clusters to SoftMacros
1500-
for (auto& cluster : parent->getChildren()) {
1501-
const int src_id = cluster->getId();
1502-
const std::string src_name = cluster->getName();
1503-
for (auto& [cluster_id, weight] : cluster->getConnectionsMap()) {
1504-
debugPrint(logger_,
1505-
MPL,
1506-
"hierarchical_macro_placement",
1507-
3,
1508-
" Cluster connection: {} {} {} ",
1509-
cluster->getName(),
1510-
tree_->maps.id_to_cluster[cluster_id]->getName(),
1511-
weight);
1512-
const std::string name = tree_->maps.id_to_cluster[cluster_id]->getName();
1513-
if (src_id > cluster_id) {
1514-
BundledNet net(
1515-
soft_macro_id_map[src_name], soft_macro_id_map[name], weight);
1516-
nets.push_back(net);
1517-
}
1518-
}
1519-
}
1520-
1521-
// merge nets to reduce runtime
1486+
BundledNetList nets = buildBundledNets(parent, soft_macro_id_map);
15221487
mergeNets(nets);
15231488

15241489
std::string file_name_prefix
@@ -2113,9 +2078,7 @@ void HierRTLMP::placeMacros(Cluster* cluster)
21132078
clustering_engine_->rebuildConnections();
21142079

21152080
createFixedTerminals(outline, macro_clusters, cluster_to_macro, sa_macros);
2116-
2117-
std::vector<BundledNet> nets
2118-
= computeBundledNets(macro_clusters, cluster_to_macro);
2081+
BundledNetList nets = buildBundledNets(macro_clusters, cluster_to_macro);
21192082

21202083
if (graphics_) {
21212084
graphics_->setBundledNets(nets);
@@ -2375,19 +2338,55 @@ void HierRTLMP::createFixedTerminals(const Rect& outline,
23752338
}
23762339
}
23772340

2378-
std::vector<BundledNet> HierRTLMP::computeBundledNets(
2379-
const UniqueClusterVector& macro_clusters,
2380-
const std::map<int, int>& cluster_to_macro)
2341+
BundledNetList HierRTLMP::buildBundledNets(
2342+
Cluster* parent,
2343+
const SoftMacroNameToIdMap& soft_macro_id_map) const
2344+
{
2345+
BundledNetList nets;
2346+
const float virtual_connections_weight = 10.0f;
2347+
2348+
for (const auto& [a_id, b_id] : parent->getVirtualConnections()) {
2349+
Cluster* a = tree_->maps.id_to_cluster.at(a_id);
2350+
Cluster* b = tree_->maps.id_to_cluster.at(b_id);
2351+
const int macro_a_id = soft_macro_id_map.at(a->getName());
2352+
const int macro_b_id = soft_macro_id_map.at(b->getName());
2353+
2354+
nets.emplace_back(macro_a_id, macro_b_id, virtual_connections_weight);
2355+
}
2356+
2357+
for (const auto& child : parent->getChildren()) {
2358+
const int source_macro_id = soft_macro_id_map.at(child->getName());
2359+
const ConnectionsMap& connections_map = child->getConnectionsMap();
2360+
2361+
for (const auto& [cluster_id, connection_weight] : connections_map) {
2362+
Cluster* target_cluster = tree_->maps.id_to_cluster.at(cluster_id);
2363+
const int target_macro_id
2364+
= soft_macro_id_map.at(target_cluster->getName());
2365+
2366+
// As connections are undirected and therefore exist in both directions,
2367+
// this check prevents connections from being taken twice into account.
2368+
if (child->getId() > target_cluster->getId()) {
2369+
nets.emplace_back(source_macro_id, target_macro_id, connection_weight);
2370+
}
2371+
}
2372+
}
2373+
2374+
return nets;
2375+
}
2376+
2377+
BundledNetList HierRTLMP::buildBundledNets(
2378+
const UniqueClusterVector& clusters,
2379+
const ClusterToMacroMap& cluster_to_macro) const
23812380
{
23822381
std::vector<BundledNet> nets;
23832382

2384-
for (auto& macro_cluster : macro_clusters) {
2385-
const int src_id = macro_cluster->getId();
2383+
for (const auto& cluster : clusters) {
2384+
const int source_macro_id = cluster_to_macro.at(cluster->getId());
2385+
const ConnectionsMap& connections_map = cluster->getConnectionsMap();
23862386

2387-
for (auto [cluster_id, weight] : macro_cluster->getConnectionsMap()) {
2388-
BundledNet net(
2389-
cluster_to_macro.at(src_id), cluster_to_macro.at(cluster_id), weight);
2390-
nets.push_back(net);
2387+
for (const auto& [cluster_id, connection_weight] : connections_map) {
2388+
const int target_macro_id = cluster_to_macro.at(cluster_id);
2389+
nets.emplace_back(source_macro_id, target_macro_id, connection_weight);
23912390
}
23922391
}
23932392

src/mpl/src/hier_rtlmp.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class SACoreSoftMacro;
4242
class SACoreHardMacro;
4343

4444
using BoundaryToRegionsMap = std::map<Boundary, std::queue<odb::Rect>>;
45+
using SoftMacroNameToIdMap = std::map<std::string, int>;
46+
using ClusterToMacroMap = std::map<int, int>; // cluster_id -> macro_id
47+
using BundledNetList = std::vector<BundledNet>;
4548

4649
// The parameters necessary to compute one coordinate of the new
4750
// origin for aligning the macros' pins to the track-grid
@@ -209,9 +212,14 @@ class HierRTLMP
209212
const UniqueClusterVector& macro_clusters,
210213
std::map<int, int>& cluster_to_macro,
211214
std::vector<HardMacro>& sa_macros);
212-
std::vector<BundledNet> computeBundledNets(
213-
const UniqueClusterVector& macro_clusters,
214-
const std::map<int, int>& cluster_to_macro);
215+
// For cluster placement.
216+
BundledNetList buildBundledNets(
217+
Cluster* parent,
218+
const SoftMacroNameToIdMap& soft_macro_id_map) const;
219+
// For macro placement.
220+
BundledNetList buildBundledNets(
221+
const UniqueClusterVector& clusters,
222+
const ClusterToMacroMap& cluster_to_macro) const;
215223
SequencePair computeArraySequencePair(Cluster* cluster,
216224
bool& array_has_empty_space);
217225

0 commit comments

Comments
 (0)