From 7538bb81438bad69f25b8dd6d2cf41fd5916bc84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Mon, 29 Dec 2025 17:14:26 +0000 Subject: [PATCH 1/2] mpl: check for merge cluster sizes before merging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Mai --- src/mpl/src/clusterEngine.cpp | 18 +++++++++++++++--- src/mpl/src/clusterEngine.h | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/mpl/src/clusterEngine.cpp b/src/mpl/src/clusterEngine.cpp index 8c96d8e469b..d7b05b10425 100644 --- a/src/mpl/src/clusterEngine.cpp +++ b/src/mpl/src/clusterEngine.cpp @@ -1710,17 +1710,19 @@ void ClusteringEngine::mergeChildrenBelowThresholds( for (auto& small_child : small_children) { small_children_ids.push_back(small_child->getId()); } + // Firstly we perform Type 1 merge for (int i = 0; i < num_small_children; i++) { Cluster* close_cluster = findSingleWellFormedConnectedCluster( small_children[i], small_children_ids); - if (close_cluster && attemptMerge(close_cluster, small_children[i])) { + if (close_cluster != nullptr + && mergeHonorsMaxThresholds(close_cluster, small_children[i]) + && attemptMerge(close_cluster, small_children[i])) { cluster_class[i] = close_cluster->getId(); } } // Then we perform Type 2 merge - std::vector new_small_children; for (int i = 0; i < num_small_children; i++) { if (cluster_class[i] == -1) { // the cluster has not been merged for (int j = i + 1; j < num_small_children; j++) { @@ -1728,7 +1730,9 @@ void ClusteringEngine::mergeChildrenBelowThresholds( continue; } - if (sameConnectionSignature(small_children[i], small_children[j])) { + if (mergeHonorsMaxThresholds(small_children[i], small_children[j]) + && sameConnectionSignature(small_children[i], + small_children[j])) { if (attemptMerge(small_children[i], small_children[j])) { cluster_class[j] = i; } else { @@ -1746,6 +1750,7 @@ void ClusteringEngine::mergeChildrenBelowThresholds( } // Then we perform Type 3 merge: merge all dust cluster + std::vector new_small_children; const int dust_cluster_std_cell = 10; for (int i = 0; i < num_small_children; i++) { if (cluster_class[i] == -1) { // the cluster has not been merged @@ -1815,6 +1820,13 @@ void ClusteringEngine::mergeChildrenBelowThresholds( "Finished merging clusters"); } +bool ClusteringEngine::mergeHonorsMaxThresholds(const Cluster* a, + const Cluster* b) const +{ + return a->getNumMacro() + b->getNumMacro() <= max_macro_ + && a->getNumStdCell() + b->getNumStdCell() <= max_std_cell_; +} + bool ClusteringEngine::sameConnectionSignature(Cluster* a, Cluster* b) const { std::vector a_neighbors = findNeighbors(a, /* ignore */ b); diff --git a/src/mpl/src/clusterEngine.h b/src/mpl/src/clusterEngine.h index 55b68f7063a..6dac5dda120 100644 --- a/src/mpl/src/clusterEngine.h +++ b/src/mpl/src/clusterEngine.h @@ -214,6 +214,7 @@ class ClusteringEngine bool partitionerSolutionIsFullyUnbalanced(const std::vector& solution, int num_other_cluster_vertices); void mergeChildrenBelowThresholds(std::vector& small_children); + bool mergeHonorsMaxThresholds(const Cluster* a, const Cluster* b) const; bool sameConnectionSignature(Cluster* a, Cluster* b) const; bool strongConnection(Cluster* a, Cluster* b, From b2a2369ddb81d5986b582eb70ac28e3c53ff5e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Tue, 30 Dec 2025 13:47:32 +0000 Subject: [PATCH 2/2] formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Mai --- src/mpl/src/clusterEngine.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mpl/src/clusterEngine.cpp b/src/mpl/src/clusterEngine.cpp index d7b05b10425..340ecf2c2e9 100644 --- a/src/mpl/src/clusterEngine.cpp +++ b/src/mpl/src/clusterEngine.cpp @@ -1710,7 +1710,7 @@ void ClusteringEngine::mergeChildrenBelowThresholds( for (auto& small_child : small_children) { small_children_ids.push_back(small_child->getId()); } - + // Firstly we perform Type 1 merge for (int i = 0; i < num_small_children; i++) { Cluster* close_cluster = findSingleWellFormedConnectedCluster( @@ -1823,8 +1823,8 @@ void ClusteringEngine::mergeChildrenBelowThresholds( bool ClusteringEngine::mergeHonorsMaxThresholds(const Cluster* a, const Cluster* b) const { - return a->getNumMacro() + b->getNumMacro() <= max_macro_ - && a->getNumStdCell() + b->getNumStdCell() <= max_std_cell_; + return ((a->getNumMacro() + b->getNumMacro()) <= max_macro_) + && ((a->getNumStdCell() + b->getNumStdCell()) <= max_std_cell_); } bool ClusteringEngine::sameConnectionSignature(Cluster* a, Cluster* b) const