Skip to content

Commit

Permalink
mpl2: add option to draw SA for a specific cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Koucher <arthurkoucher@precisioninno.com>
  • Loading branch information
AcKoucher committed Nov 11, 2024
1 parent dcba578 commit 7bb8aff
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/mpl2/include/mpl2/rtl_mp.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class MacroPlacer2
void setDebugShowBundledNets(bool show_bundled_nets);
void setDebugSkipSteps(bool skip_steps);
void setDebugOnlyFinalResult(bool only_final_result);
void setDebugTargetClusterId(int target_cluster_id);

private:
std::unique_ptr<HierRTLMP> hier_rtlmp_;
Expand Down
2 changes: 2 additions & 0 deletions src/mpl2/src/Mpl2Observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ class Mpl2Observer
virtual void setSkipSteps(bool skip_steps) {}
virtual void doNotSkip() {}
virtual void setOnlyFinalResult(bool skip_to_end) {}
virtual void setTargetClusterId(int target_cluster_id) {}
virtual void setOutline(const odb::Rect& outline) {}
virtual void setCurrentCluster(Cluster* current_cluster) {}

virtual void setAreaPenalty(const Penalty& penalty) {}
virtual void setBoundaryPenalty(const Penalty& penalty) {}
Expand Down
27 changes: 27 additions & 0 deletions src/mpl2/src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ void Graphics::startSA()
return;
}

if (target_cluster_id_ != -1 && !isTargetCluster()) {
return;
}

logger_->report("------ Start ------");
best_norm_cost_ = std::numeric_limits<float>::max();
skipped_ = 0;
Expand All @@ -90,6 +94,10 @@ void Graphics::endSA(const float norm_cost)
return;
}

if (target_cluster_id_ != -1 && !isTargetCluster()) {
return;
}

if (skipped_ > 0) {
logger_->report("Skipped to end: {}", skipped_);
}
Expand All @@ -98,6 +106,11 @@ void Graphics::endSA(const float norm_cost)
gui::Gui::get()->pause();
}

bool Graphics::isTargetCluster()
{
return current_cluster_->getId() == target_cluster_id_;
}

void Graphics::saStep(const std::vector<SoftMacro>& macros)
{
if (only_final_result_) {
Expand Down Expand Up @@ -216,6 +229,10 @@ void Graphics::penaltyCalculated(float norm_cost)
return;
}

if (target_cluster_id_ != -1 && !isTargetCluster()) {
return;
}

bool drawing_last_step = skip_steps_ && !is_skipping_;

if (norm_cost < best_norm_cost_ || drawing_last_step) {
Expand Down Expand Up @@ -567,6 +584,11 @@ void Graphics::setBundledNets(const std::vector<BundledNet>& bundled_nets)
bundled_nets_ = bundled_nets;
}

void Graphics::setTargetClusterId(const int target_cluster_id)
{
target_cluster_id_ = target_cluster_id;
}

void Graphics::setOutline(const odb::Rect& outline)
{
if (only_final_result_) {
Expand All @@ -576,6 +598,11 @@ void Graphics::setOutline(const odb::Rect& outline)
outline_ = outline;
}

void Graphics::setCurrentCluster(Cluster* current_cluster)
{
current_cluster_ = current_cluster;
}

void Graphics::eraseDrawing()
{
// Ensure we don't try to access the clusters after they were deleted
Expand Down
8 changes: 7 additions & 1 deletion src/mpl2/src/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ class Graphics : public gui::Renderer, public Mpl2Observer
void setSkipSteps(bool skip_steps) override;
void doNotSkip() override;
void setOnlyFinalResult(bool only_final_result) override;

void setTargetClusterId(int target_cluster_id) override;
void setOutline(const odb::Rect& outline) override;
void setCurrentCluster(Cluster* current_cluster) override;

void eraseDrawing() override;

Expand All @@ -102,6 +103,7 @@ class Graphics : public gui::Renderer, public Mpl2Observer
std::vector<SoftMacro>& soft,
std::vector<std::vector<odb::Rect>>& outlines,
int level);
bool isTargetCluster();

template <typename T>
void report(const char* name, const std::optional<T>& value);
Expand All @@ -113,7 +115,11 @@ class Graphics : public gui::Renderer, public Mpl2Observer
std::vector<mpl2::Rect> placement_blockages_;
std::vector<BundledNet> bundled_nets_;
odb::Rect outline_;
int target_cluster_id_{-1};
std::vector<std::vector<odb::Rect>> outlines_;
// In Soft SA, we're shaping/placing the children of a certain parent,
// so for this case, the current cluster is actually the current parent.
Cluster* current_cluster_{nullptr};

bool active_ = true;
bool coarse_;
Expand Down
31 changes: 31 additions & 0 deletions src/mpl2/src/hier_rtlmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ void HierRTLMP::calculateChildrenTilings(Cluster* parent)
"Done visiting children of {}",
parent->getName());
}

if (graphics_) {
graphics_->setCurrentCluster(parent);
}

// if the current cluster is the root cluster,
// the shape is fixed, i.e., the fixed die.
// Thus, we do not need to determine the shapes for it
Expand Down Expand Up @@ -700,6 +705,10 @@ void HierRTLMP::calculateMacroTilings(Cluster* cluster)
return;
}

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_
Expand Down Expand Up @@ -1172,6 +1181,10 @@ void HierRTLMP::runHierarchicalMacroPlacement(Cluster* parent)
return;
}

if (graphics_) {
graphics_->setCurrentCluster(parent);
}

for (auto& cluster : parent->getChildren()) {
clustering_engine_->updateInstancesAssociation(cluster.get());
}
Expand Down Expand Up @@ -2156,6 +2169,10 @@ void HierRTLMP::runHierarchicalMacroPlacementWithoutBusPlanning(Cluster* parent)
return;
}

if (graphics_) {
graphics_->setCurrentCluster(parent);
}

for (auto& cluster : parent->getChildren()) {
clustering_engine_->updateInstancesAssociation(cluster.get());
}
Expand Down Expand Up @@ -2657,6 +2674,11 @@ void HierRTLMP::runEnhancedHierarchicalMacroPlacement(Cluster* parent)
return;
}
}

if (graphics_) {
graphics_->setCurrentCluster(parent);
}

// Place children clusters
// map children cluster to soft macro
for (auto& cluster : parent->getChildren()) {
Expand Down Expand Up @@ -3372,6 +3394,10 @@ void HierRTLMP::placeMacros(Cluster* cluster)
"Place macros in cluster: {}",
cluster->getName());

if (graphics_) {
graphics_->setCurrentCluster(cluster);
}

UniqueClusterVector macro_clusters; // needed to calculate connections
std::vector<HardMacro*> hard_macros = cluster->getHardMacros();
std::vector<HardMacro> sa_macros;
Expand Down Expand Up @@ -4098,6 +4124,11 @@ void HierRTLMP::setDebugOnlyFinalResult(bool only_final_result)
graphics_->setOnlyFinalResult(only_final_result);
}

void HierRTLMP::setDebugTargetClusterId(const int target_cluster_id)
{
graphics_->setTargetClusterId(target_cluster_id);
}

odb::Rect HierRTLMP::micronsToDbu(const Rect& micron_rect)
{
return odb::Rect(block_->micronsToDbu(micron_rect.xMin()),
Expand Down
1 change: 1 addition & 0 deletions src/mpl2/src/hier_rtlmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class HierRTLMP
void setDebugShowBundledNets(bool show_bundled_nets);
void setDebugSkipSteps(bool skip_steps);
void setDebugOnlyFinalResult(bool only_final_result);
void setDebugTargetClusterId(int target_cluster_id);
void setBusPlanningOn(bool bus_planning_on);

void setNumThreads(int threads) { num_threads_ = threads; }
Expand Down
4 changes: 3 additions & 1 deletion src/mpl2/src/mpl.i
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ void set_debug_cmd(odb::dbBlock* block,
bool fine,
bool show_bundled_nets,
bool skip_steps,
bool only_final_result)
bool only_final_result,
int target_cluster_id)
{
auto macro_placer = getMacroPlacer2();
std::unique_ptr<Mpl2Observer> graphics
Expand All @@ -138,6 +139,7 @@ void set_debug_cmd(odb::dbBlock* block,
macro_placer->setDebugShowBundledNets(show_bundled_nets);
macro_placer->setDebugSkipSteps(skip_steps);
macro_placer->setDebugOnlyFinalResult(only_final_result);
macro_placer->setDebugTargetClusterId(target_cluster_id);
}

void
Expand Down
10 changes: 8 additions & 2 deletions src/mpl2/src/mpl.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ proc parse_macro_name { cmd macro_name } {

proc mpl_debug { args } {
sta::parse_key_args "mpl_debug" args \
keys {} \
keys { -target_cluster_id target_cluster_id } \
flags {-coarse -fine -show_bundled_nets \
-skip_steps -only_final_result} ;# checker off

Expand All @@ -322,11 +322,17 @@ proc mpl_debug { args } {
}
set block [ord::get_db_block]

set target_cluster_id -1
if { [info exists keys(-target_cluster_id)] } {
set target_cluster_id $keys(-target_cluster_id)
}

mpl2::set_debug_cmd $block \
$coarse \
$fine \
[info exists flags(-show_bundled_nets)] \
[info exists flags(-skip_steps)] \
[info exists flags(-only_final_result)]
[info exists flags(-only_final_result)] \
$target_cluster_id
}
}
5 changes: 5 additions & 0 deletions src/mpl2/src/rtl_mp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,9 @@ void MacroPlacer2::setDebugOnlyFinalResult(bool only_final_result)
hier_rtlmp_->setDebugOnlyFinalResult(only_final_result);
}

void MacroPlacer2::setDebugTargetClusterId(const int target_cluster_id)
{
hier_rtlmp_->setDebugTargetClusterId(target_cluster_id);
}

} // namespace mpl2

0 comments on commit 7bb8aff

Please sign in to comment.