From 5d71d7857c44333193712e7ecfeba5bf6cf8e8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Fri, 26 Dec 2025 21:47:11 +0000 Subject: [PATCH 01/10] mpl: include tight packing tilings for all macro clsuters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Mai --- src/mpl/src/hier_rtlmp.cpp | 49 +++++++++++++++++++++++++------------- src/mpl/src/hier_rtlmp.h | 2 +- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp index 5a3e8546ee2..b06cdc8c593 100644 --- a/src/mpl/src/hier_rtlmp.cpp +++ b/src/mpl/src/hier_rtlmp.cpp @@ -654,8 +654,10 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) return; } + TilingList tight_packing_tilings = getTightPackingTilings(cluster); + if (cluster->isArrayOfInterconnectedMacros()) { - setTightPackingTilings(cluster); + cluster->setTilings(tight_packing_tilings); return; } @@ -806,34 +808,36 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) cluster->getName()); } - TilingList tilings_list(tilings_set.begin(), tilings_set.end()); - std::ranges::sort(tilings_list, isAreaSmaller); + TilingList valid_tilings(tilings_set.begin(), tilings_set.end()); + std::ranges::sort(valid_tilings, isAreaSmaller); - for (auto& tiling : tilings_list) { + for (auto& tiling : valid_tilings) { debugPrint(logger_, MPL, "coarse_shaping", 2, - "width: {}, height: {}", + "width: {}, height: {}, area: {}, aspect_ratio: {}", tiling.width(), - tiling.height()); + tiling.height(), + tiling.area(), + tiling.aspectRatio()); } // we only keep the minimum area tiling since all the macros has the same size // later this can be relaxed. But this may cause problems because the // minimizing the wirelength may leave holes near the boundary - TilingList new_tilings_list; - float first_tiling_area = tilings_list.front().area(); - for (auto& tiling : tilings_list) { - if (tiling.area() <= first_tiling_area) { - new_tilings_list.push_back(tiling); + TilingList tilings = std::move(tight_packing_tilings); + int64_t min_tiling_area = valid_tilings.front().area(); + for (auto& tiling : valid_tilings) { + if (tiling.area() <= min_tiling_area) { + tilings.push_back(tiling); } } - tilings_list = std::move(new_tilings_list); - cluster->setTilings(tilings_list); - std::string line = "Tiling for hard cluster " + cluster->getName() + " "; - for (auto& tiling : tilings_list) { + cluster->setTilings(tilings); + + std::string line = "Tiling for hard cluster " + cluster->getName() + "\n"; + for (auto& tiling : tilings) { line += " < " + std::to_string(tiling.width()) + " , "; line += std::to_string(tiling.height()) + " > "; } @@ -842,13 +846,19 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) } // Used only for arrays of interconnected macros. -void HierRTLMP::setTightPackingTilings(Cluster* macro_array) +TilingList HierRTLMP::getTightPackingTilings(Cluster* cluster) { TilingList tight_packing_tilings; +<<<<<<< HEAD int num_macro = macro_array->getNumMacro(); float macro_width = macro_array->getHardMacros().front()->getWidth(); float macro_height = macro_array->getHardMacros().front()->getHeight(); +======= + int num_macro = static_cast(cluster->getNumMacro()); + float macro_width = cluster->getHardMacros().front()->getWidth(); + float macro_height = cluster->getHardMacros().front()->getHeight(); +>>>>>>> 0ab84211bf (mpl: include tight packing tilings for all macro clsuters) const odb::Rect outline = tree_->root->getBBox(); @@ -865,10 +875,15 @@ void HierRTLMP::setTightPackingTilings(Cluster* macro_array) tight_packing_tilings.emplace_back(columns * macro_width, rows * macro_height); } + if (rows * macro_width <= outline.dx() + && columns * macro_height <= outline.dy()) { + tight_packing_tilings.emplace_back(rows * macro_width, + columns * macro_height); + } } } - macro_array->setTilings(tight_packing_tilings); + return tight_packing_tilings; } void HierRTLMP::searchAvailableRegionsForUnconstrainedPins() diff --git a/src/mpl/src/hier_rtlmp.h b/src/mpl/src/hier_rtlmp.h index 6921a237875..5ed18791c67 100644 --- a/src/mpl/src/hier_rtlmp.h +++ b/src/mpl/src/hier_rtlmp.h @@ -145,7 +145,7 @@ class HierRTLMP void calculateChildrenTilings(Cluster* parent); void calculateMacroTilings(Cluster* cluster); IntervalList computeWidthIntervals(const TilingList& tilings); - void setTightPackingTilings(Cluster* macro_array); + TilingList getTightPackingTilings(Cluster* cluster); void searchAvailableRegionsForUnconstrainedPins(); BoundaryToRegionsMap getBoundaryToBlockedRegionsMap( const std::vector& blocked_regions_for_pins) const; From 0c2bb5ca705002bd14ec04969fac5d601c5f3ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Fri, 26 Dec 2025 22:05:58 +0000 Subject: [PATCH 02/10] mpl: remove dupes from macro cluster tilings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Mai --- src/mpl/src/hier_rtlmp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp index b06cdc8c593..fada6138759 100644 --- a/src/mpl/src/hier_rtlmp.cpp +++ b/src/mpl/src/hier_rtlmp.cpp @@ -829,11 +829,12 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) TilingList tilings = std::move(tight_packing_tilings); int64_t min_tiling_area = valid_tilings.front().area(); for (auto& tiling : valid_tilings) { - if (tiling.area() <= min_tiling_area) { + if (tiling.area() <= min_tiling_area && std::ranges::find(tilings, tiling) == tilings.end()) { tilings.push_back(tiling); } } + cluster->setTilings(tilings); std::string line = "Tiling for hard cluster " + cluster->getName() + "\n"; From bafe6dde40d18e91c5d8678e66f5e766f7703b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Mon, 5 Jan 2026 21:25:08 +0000 Subject: [PATCH 03/10] mpl: remove size_tolerance 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 | 12 ++++++------ src/mpl/src/hier_rtlmp.cpp | 6 ------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/mpl/src/clusterEngine.cpp b/src/mpl/src/clusterEngine.cpp index 340ecf2c2e9..69578394953 100644 --- a/src/mpl/src/clusterEngine.cpp +++ b/src/mpl/src/clusterEngine.cpp @@ -1227,8 +1227,8 @@ void ClusteringEngine::multilevelAutocluster(Cluster* parent) if (level_ == 0) { const int leaf_max_std_cell = tree_->base_max_std_cell - / std::pow(tree_->cluster_size_ratio, tree_->max_level - 1) - * (1 + size_tolerance_); + / std::pow(tree_->cluster_size_ratio, tree_->max_level - 1); + // * (1 + size_tolerance_); if (parent->getNumStdCell() < leaf_max_std_cell) { force_split_root = true; debugPrint(logger_, @@ -1295,10 +1295,10 @@ void ClusteringEngine::updateSizeThresholds() // We define the tolerance to improve the robustness of our hierarchical // clustering - max_macro_ *= (1 + size_tolerance_); - min_macro_ *= (1 - size_tolerance_); - max_std_cell_ *= (1 + size_tolerance_); - min_std_cell_ *= (1 - size_tolerance_); + // max_macro_ *= (1 + size_tolerance_); + // min_macro_ *= (1 - size_tolerance_); + // max_std_cell_ *= (1 + size_tolerance_); + // min_std_cell_ *= (1 - size_tolerance_); if (min_macro_ <= 0) { min_macro_ = 1; diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp index fada6138759..d25e2d922f8 100644 --- a/src/mpl/src/hier_rtlmp.cpp +++ b/src/mpl/src/hier_rtlmp.cpp @@ -851,15 +851,9 @@ TilingList HierRTLMP::getTightPackingTilings(Cluster* cluster) { TilingList tight_packing_tilings; -<<<<<<< HEAD - int num_macro = macro_array->getNumMacro(); - float macro_width = macro_array->getHardMacros().front()->getWidth(); - float macro_height = macro_array->getHardMacros().front()->getHeight(); -======= int num_macro = static_cast(cluster->getNumMacro()); float macro_width = cluster->getHardMacros().front()->getWidth(); float macro_height = cluster->getHardMacros().front()->getHeight(); ->>>>>>> 0ab84211bf (mpl: include tight packing tilings for all macro clsuters) const odb::Rect outline = tree_->root->getBBox(); From e57ea8a7a03fa9180d46b0fcd2bdf5b86f959e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Wed, 7 Jan 2026 20:33:28 +0000 Subject: [PATCH 04/10] mpl: remove old comments 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 | 8 -------- src/mpl/src/clusterEngine.h | 1 - 2 files changed, 9 deletions(-) diff --git a/src/mpl/src/clusterEngine.cpp b/src/mpl/src/clusterEngine.cpp index 69578394953..ba9ea03d258 100644 --- a/src/mpl/src/clusterEngine.cpp +++ b/src/mpl/src/clusterEngine.cpp @@ -1228,7 +1228,6 @@ void ClusteringEngine::multilevelAutocluster(Cluster* parent) const int leaf_max_std_cell = tree_->base_max_std_cell / std::pow(tree_->cluster_size_ratio, tree_->max_level - 1); - // * (1 + size_tolerance_); if (parent->getNumStdCell() < leaf_max_std_cell) { force_split_root = true; debugPrint(logger_, @@ -1293,13 +1292,6 @@ void ClusteringEngine::updateSizeThresholds() max_std_cell_ = tree_->base_max_std_cell / coarse_factor; min_std_cell_ = tree_->base_min_std_cell / coarse_factor; - // We define the tolerance to improve the robustness of our hierarchical - // clustering - // max_macro_ *= (1 + size_tolerance_); - // min_macro_ *= (1 - size_tolerance_); - // max_std_cell_ *= (1 + size_tolerance_); - // min_std_cell_ *= (1 - size_tolerance_); - if (min_macro_ <= 0) { min_macro_ = 1; max_macro_ = min_macro_ * tree_->cluster_size_ratio / 2.0; diff --git a/src/mpl/src/clusterEngine.h b/src/mpl/src/clusterEngine.h index 6dac5dda120..f7c7c71bc48 100644 --- a/src/mpl/src/clusterEngine.h +++ b/src/mpl/src/clusterEngine.h @@ -309,7 +309,6 @@ class ClusteringEngine int min_macro_{0}; int max_std_cell_{0}; int min_std_cell_{0}; - const float size_tolerance_ = 0.1; // Variables for data flow DataFlow data_connections_; From 65f03e6e05c3720ef9864ac348642c20eb530d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Wed, 7 Jan 2026 20:49:48 +0000 Subject: [PATCH 05/10] mpl: minor adjustments to macro cluster coarse shaping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Mai --- src/mpl/src/hier_rtlmp.cpp | 321 ++++++++++++++++++------------------- 1 file changed, 158 insertions(+), 163 deletions(-) diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp index d25e2d922f8..4ff019bffd5 100644 --- a/src/mpl/src/hier_rtlmp.cpp +++ b/src/mpl/src/hier_rtlmp.cpp @@ -654,187 +654,182 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) return; } - TilingList tight_packing_tilings = getTightPackingTilings(cluster); + TilingList tilings = getTightPackingTilings(cluster); - if (cluster->isArrayOfInterconnectedMacros()) { - cluster->setTilings(tight_packing_tilings); - return; - } - - if (graphics_) { - graphics_->setCurrentCluster(cluster); - } + if (!cluster->isArrayOfInterconnectedMacros()) { + if (graphics_) { + graphics_->setCurrentCluster(cluster); + } - // otherwise call simulated annealing to determine tilings - // set the action probabilities - const float action_sum = pos_swap_prob_ + neg_swap_prob_ + double_swap_prob_ - + exchange_swap_prob_; + const float action_sum = pos_swap_prob_ + neg_swap_prob_ + double_swap_prob_ + + exchange_swap_prob_; - const odb::Rect outline( - 0, 0, tree_->root->getWidth(), tree_->root->getHeight()); + const odb::Rect outline( + 0, 0, tree_->root->getWidth(), tree_->root->getHeight()); - // update macros - std::vector macros; - macros.reserve(hard_macros.size()); - for (auto& macro : hard_macros) { - macros.push_back(*macro); - } - int num_perturb_per_step = (macros.size() > num_perturb_per_step_ / 10) + // update macros + std::vector macros; + macros.reserve(hard_macros.size()); + for (auto& macro : hard_macros) { + macros.push_back(*macro); + } + int num_perturb_per_step = (macros.size() > num_perturb_per_step_ / 10) + ? macros.size() + : num_perturb_per_step_ / 10; + if (cluster->getParent() == nullptr) { + num_perturb_per_step = (macros.size() > num_perturb_per_step_ / 5) ? macros.size() - : num_perturb_per_step_ / 10; - if (cluster->getParent() == nullptr) { - num_perturb_per_step = (macros.size() > num_perturb_per_step_ / 5) - ? macros.size() - : num_perturb_per_step_ / 5; - } - - // To generate different macro tilings, we vary the outline constraints - // we first vary the outline width while keeping outline_height fixed - // Then we vary the outline height while keeping outline_width fixed - // We vary the outline of cluster to generate different tilings - std::vector vary_factor_list{1.0}; - float vary_step = 1.0 / num_runs_; // change the outline by at most halfly - for (int i = 1; i < num_runs_; i++) { - vary_factor_list.push_back(1.0 - i * vary_step); - } - int remaining_runs = num_runs_; - int run_id = 0; - while (remaining_runs > 0) { - HardSAVector sa_batch; - const int run_thread - = graphics_ ? 1 : std::min(remaining_runs, num_threads_); - for (int i = 0; i < run_thread; i++) { - const odb::Rect new_outline( - 0, 0, outline.dx() * vary_factor_list[run_id++], outline.dy()); - if (graphics_) { - graphics_->setOutline(new_outline); + : num_perturb_per_step_ / 5; + } + + // To generate different macro tilings, we vary the outline constraints + // we first vary the outline width while keeping outline_height fixed + // Then we vary the outline height while keeping outline_width fixed + // We vary the outline of cluster to generate different tilings + std::vector vary_factor_list{1.0}; + float vary_step = 1.0 / num_runs_; // change the outline by at most halfly + for (int i = 1; i < num_runs_; i++) { + vary_factor_list.push_back(1.0 - i * vary_step); + } + int remaining_runs = num_runs_; + int run_id = 0; + while (remaining_runs > 0) { + HardSAVector sa_batch; + const int run_thread + = graphics_ ? 1 : std::min(remaining_runs, num_threads_); + for (int i = 0; i < run_thread; i++) { + const odb::Rect new_outline( + 0, 0, outline.dx() * vary_factor_list[run_id++], outline.dy()); + if (graphics_) { + graphics_->setOutline(new_outline); + } + std::unique_ptr sa = std::make_unique( + tree_.get(), + new_outline, + macros, + shaping_core_weights_, + pos_swap_prob_ / action_sum, + neg_swap_prob_ / action_sum, + double_swap_prob_ / action_sum, + exchange_swap_prob_ / action_sum, + init_prob_, + max_num_step_, + num_perturb_per_step, + random_seed_ + run_id, + graphics_.get(), + logger_, + block_); + sa_batch.push_back(std::move(sa)); } - std::unique_ptr sa - = std::make_unique(tree_.get(), - new_outline, - macros, - shaping_core_weights_, - pos_swap_prob_ / action_sum, - neg_swap_prob_ / action_sum, - double_swap_prob_ / action_sum, - exchange_swap_prob_ / action_sum, - init_prob_, - max_num_step_, - num_perturb_per_step, - random_seed_ + run_id, - graphics_.get(), - logger_, - block_); - sa_batch.push_back(std::move(sa)); - } - if (sa_batch.size() == 1) { - runSA(sa_batch[0].get()); - } else { - // multi threads - std::vector threads; - threads.reserve(sa_batch.size()); - for (auto& sa : sa_batch) { - threads.emplace_back(runSA, sa.get()); + if (sa_batch.size() == 1) { + runSA(sa_batch[0].get()); + } else { + // multi threads + std::vector threads; + threads.reserve(sa_batch.size()); + for (auto& sa : sa_batch) { + threads.emplace_back(runSA, sa.get()); + } + for (auto& th : threads) { + th.join(); + } } - for (auto& th : threads) { - th.join(); + // add macro tilings + for (auto& sa : sa_batch) { + if (sa->fitsIn(outline)) { + tilings_set.insert({sa->getWidth(), sa->getHeight()}); + } } - } - // add macro tilings - for (auto& sa : sa_batch) { - if (sa->fitsIn(outline)) { - tilings_set.insert({sa->getWidth(), sa->getHeight()}); + remaining_runs -= run_thread; + } + // change the outline height while keeping outline width fixed + remaining_runs = num_runs_; + run_id = 0; + while (remaining_runs > 0) { + HardSAVector sa_batch; + const int run_thread + = graphics_ ? 1 : std::min(remaining_runs, num_threads_); + for (int i = 0; i < run_thread; i++) { + const odb::Rect new_outline( + 0, 0, outline.dx(), outline.dy() * vary_factor_list[run_id++]); + if (graphics_) { + graphics_->setOutline(new_outline); + } + std::unique_ptr sa = std::make_unique( + tree_.get(), + new_outline, + macros, + shaping_core_weights_, + pos_swap_prob_ / action_sum, + neg_swap_prob_ / action_sum, + double_swap_prob_ / action_sum, + exchange_swap_prob_ / action_sum, + init_prob_, + max_num_step_, + num_perturb_per_step, + random_seed_ + run_id, + graphics_.get(), + logger_, + block_); + sa_batch.push_back(std::move(sa)); } - } - remaining_runs -= run_thread; - } - // change the outline height while keeping outline width fixed - remaining_runs = num_runs_; - run_id = 0; - while (remaining_runs > 0) { - HardSAVector sa_batch; - const int run_thread - = graphics_ ? 1 : std::min(remaining_runs, num_threads_); - for (int i = 0; i < run_thread; i++) { - const odb::Rect new_outline( - 0, 0, outline.dx(), outline.dy() * vary_factor_list[run_id++]); - if (graphics_) { - graphics_->setOutline(new_outline); + if (sa_batch.size() == 1) { + runSA(sa_batch[0].get()); + } else { + // multi threads + std::vector threads; + threads.reserve(sa_batch.size()); + for (auto& sa : sa_batch) { + threads.emplace_back(runSA, sa.get()); + } + for (auto& th : threads) { + th.join(); + } } - std::unique_ptr sa - = std::make_unique(tree_.get(), - new_outline, - macros, - shaping_core_weights_, - pos_swap_prob_ / action_sum, - neg_swap_prob_ / action_sum, - double_swap_prob_ / action_sum, - exchange_swap_prob_ / action_sum, - init_prob_, - max_num_step_, - num_perturb_per_step, - random_seed_ + run_id, - graphics_.get(), - logger_, - block_); - sa_batch.push_back(std::move(sa)); - } - if (sa_batch.size() == 1) { - runSA(sa_batch[0].get()); - } else { - // multi threads - std::vector threads; - threads.reserve(sa_batch.size()); + // add macro tilings for (auto& sa : sa_batch) { - threads.emplace_back(runSA, sa.get()); - } - for (auto& th : threads) { - th.join(); - } - } - // add macro tilings - for (auto& sa : sa_batch) { - if (sa->fitsIn(outline)) { - tilings_set.insert({sa->getWidth(), sa->getHeight()}); + if (sa->fitsIn(outline)) { + tilings_set.insert({sa->getWidth(), sa->getHeight()}); + } } + remaining_runs -= run_thread; } - remaining_runs -= run_thread; - } - - if (tilings_set.empty()) { - logger_->error(MPL, - 4, - "No valid tilings for hard macro cluster: {}", - cluster->getName()); - } - TilingList valid_tilings(tilings_set.begin(), tilings_set.end()); - std::ranges::sort(valid_tilings, isAreaSmaller); + if (tilings_set.empty()) { + logger_->error(MPL, + 4, + "No valid tilings for hard macro cluster: {}", + cluster->getName()); + } - for (auto& tiling : valid_tilings) { - debugPrint(logger_, - MPL, - "coarse_shaping", - 2, - "width: {}, height: {}, area: {}, aspect_ratio: {}", - tiling.width(), - tiling.height(), - tiling.area(), - tiling.aspectRatio()); - } + TilingList valid_tilings(tilings_set.begin(), tilings_set.end()); + std::ranges::sort(valid_tilings, isAreaSmaller); - // we only keep the minimum area tiling since all the macros has the same size - // later this can be relaxed. But this may cause problems because the - // minimizing the wirelength may leave holes near the boundary - TilingList tilings = std::move(tight_packing_tilings); - int64_t min_tiling_area = valid_tilings.front().area(); - for (auto& tiling : valid_tilings) { - if (tiling.area() <= min_tiling_area && std::ranges::find(tilings, tiling) == tilings.end()) { - tilings.push_back(tiling); + for (auto& tiling : valid_tilings) { + debugPrint(logger_, + MPL, + "coarse_shaping", + 2, + "width: {}, height: {}, area: {}, aspect_ratio: {}", + tiling.width(), + tiling.height(), + tiling.area(), + tiling.aspectRatio()); + } + + // we only keep the minimum area tiling since all the macros has the same + // size later this can be relaxed. But this may cause problems because the + // minimizing the wirelength may leave holes near the boundary + int64_t min_tiling_area = valid_tilings.front().area(); + for (auto& tiling : valid_tilings) { + if (tiling.area() <= min_tiling_area + && std::ranges::find(tilings, tiling) == tilings.end()) { + tilings.push_back(tiling); + } } } - + std::ranges::sort(tilings, isAreaSmaller); cluster->setTilings(tilings); std::string line = "Tiling for hard cluster " + cluster->getName() + "\n"; @@ -864,7 +859,7 @@ TilingList HierRTLMP::getTightPackingTilings(Cluster* cluster) // We don't consider tilings for right angle rotation orientations, // because they're not allowed in our macro placer. - // Tiling needs to fit inside outline + // Tiling needs to fit inside outline. if (columns * macro_width <= outline.dx() && rows * macro_height <= outline.dy()) { tight_packing_tilings.emplace_back(columns * macro_width, From 7d5e86b44667d22a5259ef9db15e0b57e33adeb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Fri, 9 Jan 2026 22:22:37 +0000 Subject: [PATCH 06/10] mpl: remove annealing from macro cluster coarse shaping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Mai --- src/mpl/src/hier_rtlmp.cpp | 249 +++++-------------------------------- src/mpl/src/hier_rtlmp.h | 4 +- 2 files changed, 31 insertions(+), 222 deletions(-) diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp index 4ff019bffd5..a503e3b465b 100644 --- a/src/mpl/src/hier_rtlmp.cpp +++ b/src/mpl/src/hier_rtlmp.cpp @@ -635,240 +635,47 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) } std::vector hard_macros = cluster->getHardMacros(); - TilingSet tilings_set; - - if (hard_macros.size() == 1) { - int width = hard_macros[0]->getWidth(); - int height = hard_macros[0]->getHeight(); - - TilingList tilings; - tilings.emplace_back(width, height); - cluster->setTilings(tilings); - - debugPrint(logger_, - MPL, - "coarse_shaping", - 1, - "{} has only one macro, set tiling according to macro with halo", - cluster->getName()); - return; - } - - TilingList tilings = getTightPackingTilings(cluster); - - if (!cluster->isArrayOfInterconnectedMacros()) { - if (graphics_) { - graphics_->setCurrentCluster(cluster); - } - - const float action_sum = pos_swap_prob_ + neg_swap_prob_ + double_swap_prob_ - + exchange_swap_prob_; - - const odb::Rect outline( - 0, 0, tree_->root->getWidth(), tree_->root->getHeight()); - - // update macros - std::vector macros; - macros.reserve(hard_macros.size()); - for (auto& macro : hard_macros) { - macros.push_back(*macro); - } - int num_perturb_per_step = (macros.size() > num_perturb_per_step_ / 10) - ? macros.size() - : num_perturb_per_step_ / 10; - if (cluster->getParent() == nullptr) { - num_perturb_per_step = (macros.size() > num_perturb_per_step_ / 5) - ? macros.size() - : num_perturb_per_step_ / 5; - } - - // To generate different macro tilings, we vary the outline constraints - // we first vary the outline width while keeping outline_height fixed - // Then we vary the outline height while keeping outline_width fixed - // We vary the outline of cluster to generate different tilings - std::vector vary_factor_list{1.0}; - float vary_step = 1.0 / num_runs_; // change the outline by at most halfly - for (int i = 1; i < num_runs_; i++) { - vary_factor_list.push_back(1.0 - i * vary_step); - } - int remaining_runs = num_runs_; - int run_id = 0; - while (remaining_runs > 0) { - HardSAVector sa_batch; - const int run_thread - = graphics_ ? 1 : std::min(remaining_runs, num_threads_); - for (int i = 0; i < run_thread; i++) { - const odb::Rect new_outline( - 0, 0, outline.dx() * vary_factor_list[run_id++], outline.dy()); - if (graphics_) { - graphics_->setOutline(new_outline); - } - std::unique_ptr sa = std::make_unique( - tree_.get(), - new_outline, - macros, - shaping_core_weights_, - pos_swap_prob_ / action_sum, - neg_swap_prob_ / action_sum, - double_swap_prob_ / action_sum, - exchange_swap_prob_ / action_sum, - init_prob_, - max_num_step_, - num_perturb_per_step, - random_seed_ + run_id, - graphics_.get(), - logger_, - block_); - sa_batch.push_back(std::move(sa)); - } - if (sa_batch.size() == 1) { - runSA(sa_batch[0].get()); - } else { - // multi threads - std::vector threads; - threads.reserve(sa_batch.size()); - for (auto& sa : sa_batch) { - threads.emplace_back(runSA, sa.get()); - } - for (auto& th : threads) { - th.join(); - } - } - // add macro tilings - for (auto& sa : sa_batch) { - if (sa->fitsIn(outline)) { - tilings_set.insert({sa->getWidth(), sa->getHeight()}); - } - } - remaining_runs -= run_thread; - } - // change the outline height while keeping outline width fixed - remaining_runs = num_runs_; - run_id = 0; - while (remaining_runs > 0) { - HardSAVector sa_batch; - const int run_thread - = graphics_ ? 1 : std::min(remaining_runs, num_threads_); - for (int i = 0; i < run_thread; i++) { - const odb::Rect new_outline( - 0, 0, outline.dx(), outline.dy() * vary_factor_list[run_id++]); - if (graphics_) { - graphics_->setOutline(new_outline); - } - std::unique_ptr sa = std::make_unique( - tree_.get(), - new_outline, - macros, - shaping_core_weights_, - pos_swap_prob_ / action_sum, - neg_swap_prob_ / action_sum, - double_swap_prob_ / action_sum, - exchange_swap_prob_ / action_sum, - init_prob_, - max_num_step_, - num_perturb_per_step, - random_seed_ + run_id, - graphics_.get(), - logger_, - block_); - sa_batch.push_back(std::move(sa)); - } - if (sa_batch.size() == 1) { - runSA(sa_batch[0].get()); - } else { - // multi threads - std::vector threads; - threads.reserve(sa_batch.size()); - for (auto& sa : sa_batch) { - threads.emplace_back(runSA, sa.get()); - } - for (auto& th : threads) { - th.join(); - } - } - // add macro tilings - for (auto& sa : sa_batch) { - if (sa->fitsIn(outline)) { - tilings_set.insert({sa->getWidth(), sa->getHeight()}); - } - } - remaining_runs -= run_thread; - } - - if (tilings_set.empty()) { - logger_->error(MPL, - 4, - "No valid tilings for hard macro cluster: {}", - cluster->getName()); - } + int number_of_macros = hard_macros.size(); + int width = hard_macros.front()->getWidth(); + int height = hard_macros.front()->getHeight(); - TilingList valid_tilings(tilings_set.begin(), tilings_set.end()); - std::ranges::sort(valid_tilings, isAreaSmaller); + TilingList tilings = getTightPackingTilings(width, height, number_of_macros); - for (auto& tiling : valid_tilings) { - debugPrint(logger_, - MPL, - "coarse_shaping", - 2, - "width: {}, height: {}, area: {}, aspect_ratio: {}", - tiling.width(), - tiling.height(), - tiling.area(), - tiling.aspectRatio()); - } - - // we only keep the minimum area tiling since all the macros has the same - // size later this can be relaxed. But this may cause problems because the - // minimizing the wirelength may leave holes near the boundary - int64_t min_tiling_area = valid_tilings.front().area(); - for (auto& tiling : valid_tilings) { - if (tiling.area() <= min_tiling_area - && std::ranges::find(tilings, tiling) == tilings.end()) { - tilings.push_back(tiling); - } - } + if (tilings.size() == 0) { + TilingList extra_tilings + = getTightPackingTilings(width, height, number_of_macros + 1); + tilings.insert(tilings.end(), extra_tilings.begin(), extra_tilings.end()); } - std::ranges::sort(tilings, isAreaSmaller); cluster->setTilings(tilings); - std::string line = "Tiling for hard cluster " + cluster->getName() + "\n"; - for (auto& tiling : tilings) { - line += " < " + std::to_string(tiling.width()) + " , "; - line += std::to_string(tiling.height()) + " > "; + if (logger_->debugCheck(MPL, "coarse_shaping", 2)) { + std::string line = "Tiling for hard cluster " + cluster->getName() + + " with " + std::to_string(number_of_macros) + + " macros.\n"; + for (auto& tiling : tilings) { + line += " < " + std::to_string(tiling.width()) + " , "; + line += std::to_string(tiling.height()) + " > "; + } + line += "\n"; + debugPrint(logger_, MPL, "coarse_shaping", 2, "{}", line); } - line += "\n"; - debugPrint(logger_, MPL, "coarse_shaping", 2, "{}", line); } -// Used only for arrays of interconnected macros. -TilingList HierRTLMP::getTightPackingTilings(Cluster* cluster) +TilingList HierRTLMP::getTightPackingTilings(int width, + int height, + int number_of_macros) { TilingList tight_packing_tilings; - - int num_macro = static_cast(cluster->getNumMacro()); - float macro_width = cluster->getHardMacros().front()->getWidth(); - float macro_height = cluster->getHardMacros().front()->getHeight(); - const odb::Rect outline = tree_->root->getBBox(); - int columns = 0; - for (int rows = 1; rows < std::sqrt(num_macro) + 1; rows++) { - if (num_macro % rows == 0) { - columns = num_macro / rows; - - // We don't consider tilings for right angle rotation orientations, - // because they're not allowed in our macro placer. - // Tiling needs to fit inside outline. - if (columns * macro_width <= outline.dx() - && rows * macro_height <= outline.dy()) { - tight_packing_tilings.emplace_back(columns * macro_width, - rows * macro_height); - } - if (rows * macro_width <= outline.dx() - && columns * macro_height <= outline.dy()) { - tight_packing_tilings.emplace_back(rows * macro_width, - columns * macro_height); + int rows = 0; + for (int cols = 1; cols <= number_of_macros; cols++) { + if (number_of_macros % cols == 0) { + rows = number_of_macros / cols; + + if (cols * width <= outline.dx() && rows * height <= outline.dy()) { + tight_packing_tilings.emplace_back(cols * width, rows * height); } } } diff --git a/src/mpl/src/hier_rtlmp.h b/src/mpl/src/hier_rtlmp.h index 5ed18791c67..edbe5cefdd4 100644 --- a/src/mpl/src/hier_rtlmp.h +++ b/src/mpl/src/hier_rtlmp.h @@ -145,7 +145,9 @@ class HierRTLMP void calculateChildrenTilings(Cluster* parent); void calculateMacroTilings(Cluster* cluster); IntervalList computeWidthIntervals(const TilingList& tilings); - TilingList getTightPackingTilings(Cluster* cluster); + TilingList getTightPackingTilings(int width, + int height, + int number_of_macros); void searchAvailableRegionsForUnconstrainedPins(); BoundaryToRegionsMap getBoundaryToBlockedRegionsMap( const std::vector& blocked_regions_for_pins) const; From 01e0f06ff1a237a21257d86d33c515ca39ac66af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Mon, 12 Jan 2026 19:08:13 +0000 Subject: [PATCH 07/10] mpl: error if no tiling is found for macro cluster MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Mai --- src/mpl/src/hier_rtlmp.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp index a503e3b465b..205d8dd2d04 100644 --- a/src/mpl/src/hier_rtlmp.cpp +++ b/src/mpl/src/hier_rtlmp.cpp @@ -647,6 +647,17 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) tilings.insert(tilings.end(), extra_tilings.begin(), extra_tilings.end()); } + if (tilings.size() == 0) { + logger_->error(MPL, + 4, + "Unable to fit cluster {} within outline. Macro height: {}, " + "width: {}, number of macros: {}.", + cluster->getName(), + width, + height, + number_of_macros); + } + cluster->setTilings(tilings); if (logger_->debugCheck(MPL, "coarse_shaping", 2)) { From 0e67816234afcb5338c47d35b7dbb3a95cbaa6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Mon, 12 Jan 2026 19:17:56 +0000 Subject: [PATCH 08/10] mpl: update names for clarity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Mai --- src/mpl/src/hier_rtlmp.cpp | 27 +++++++++++++++------------ src/mpl/src/hier_rtlmp.h | 6 +++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp index 205d8dd2d04..e704ad8865d 100644 --- a/src/mpl/src/hier_rtlmp.cpp +++ b/src/mpl/src/hier_rtlmp.cpp @@ -636,14 +636,15 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) std::vector hard_macros = cluster->getHardMacros(); int number_of_macros = hard_macros.size(); - int width = hard_macros.front()->getWidth(); - int height = hard_macros.front()->getHeight(); + int macro_width = hard_macros.front()->getWidth(); + int macro_height = hard_macros.front()->getHeight(); - TilingList tilings = getTightPackingTilings(width, height, number_of_macros); + TilingList tilings = generateTilingsForMacroCluster( + macro_width, macro_height, number_of_macros); if (tilings.size() == 0) { - TilingList extra_tilings - = getTightPackingTilings(width, height, number_of_macros + 1); + TilingList extra_tilings = generateTilingsForMacroCluster( + macro_width, macro_height, number_of_macros + 1); tilings.insert(tilings.end(), extra_tilings.begin(), extra_tilings.end()); } @@ -653,8 +654,8 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) "Unable to fit cluster {} within outline. Macro height: {}, " "width: {}, number of macros: {}.", cluster->getName(), - width, - height, + macro_width, + macro_height, number_of_macros); } @@ -673,9 +674,9 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) } } -TilingList HierRTLMP::getTightPackingTilings(int width, - int height, - int number_of_macros) +TilingList HierRTLMP::generateTilingsForMacroCluster(int macro_width, + int macro_height, + int number_of_macros) { TilingList tight_packing_tilings; const odb::Rect outline = tree_->root->getBBox(); @@ -685,8 +686,10 @@ TilingList HierRTLMP::getTightPackingTilings(int width, if (number_of_macros % cols == 0) { rows = number_of_macros / cols; - if (cols * width <= outline.dx() && rows * height <= outline.dy()) { - tight_packing_tilings.emplace_back(cols * width, rows * height); + if (cols * macro_width <= outline.dx() + && rows * macro_height <= outline.dy()) { + tight_packing_tilings.emplace_back(cols * macro_width, + rows * macro_height); } } } diff --git a/src/mpl/src/hier_rtlmp.h b/src/mpl/src/hier_rtlmp.h index edbe5cefdd4..df85ce99f68 100644 --- a/src/mpl/src/hier_rtlmp.h +++ b/src/mpl/src/hier_rtlmp.h @@ -145,9 +145,9 @@ class HierRTLMP void calculateChildrenTilings(Cluster* parent); void calculateMacroTilings(Cluster* cluster); IntervalList computeWidthIntervals(const TilingList& tilings); - TilingList getTightPackingTilings(int width, - int height, - int number_of_macros); + TilingList generateTilingsForMacroCluster(int macro_width, + int macro_height, + int number_of_macros); void searchAvailableRegionsForUnconstrainedPins(); BoundaryToRegionsMap getBoundaryToBlockedRegionsMap( const std::vector& blocked_regions_for_pins) const; From ed39a9dd4797dc83c51fe25317033267209ff21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Tue, 13 Jan 2026 01:13:17 +0000 Subject: [PATCH 09/10] mpl: changes size() == 0 calls to empty() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Mai --- src/mpl/src/hier_rtlmp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp index e704ad8865d..98133f2ca04 100644 --- a/src/mpl/src/hier_rtlmp.cpp +++ b/src/mpl/src/hier_rtlmp.cpp @@ -642,13 +642,13 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) TilingList tilings = generateTilingsForMacroCluster( macro_width, macro_height, number_of_macros); - if (tilings.size() == 0) { + if (tilings.empty()) { TilingList extra_tilings = generateTilingsForMacroCluster( macro_width, macro_height, number_of_macros + 1); tilings.insert(tilings.end(), extra_tilings.begin(), extra_tilings.end()); } - if (tilings.size() == 0) { + if (tilings.empty()) { logger_->error(MPL, 4, "Unable to fit cluster {} within outline. Macro height: {}, " From 75221b87fece368a9b78635204cd30a359d8a1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mai?= Date: Tue, 13 Jan 2026 15:49:06 +0000 Subject: [PATCH 10/10] mpl: remove uneeded insert call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Mai --- src/mpl/src/hier_rtlmp.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp index 98133f2ca04..8d09a145099 100644 --- a/src/mpl/src/hier_rtlmp.cpp +++ b/src/mpl/src/hier_rtlmp.cpp @@ -643,9 +643,8 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster) macro_width, macro_height, number_of_macros); if (tilings.empty()) { - TilingList extra_tilings = generateTilingsForMacroCluster( + tilings = generateTilingsForMacroCluster( macro_width, macro_height, number_of_macros + 1); - tilings.insert(tilings.end(), extra_tilings.begin(), extra_tilings.end()); } if (tilings.empty()) {