Skip to content

Commit

Permalink
[Just the Core Idea] mpl2: a bunch of debug stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Koucher <arthurckoucher@gmail.com>
  • Loading branch information
AcKoucher committed Nov 1, 2024
1 parent 6833b0f commit bbf8ce8
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/mpl2/src/Mpl2Observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class Mpl2Observer
virtual void doNotSkip() {}
virtual void setOnlyFinalResult(bool skip_to_end) {}
virtual void setOutline(const odb::Rect& outline) {}
virtual void setMicronOutline(const Rect& micron_outline) {}
virtual void setFloorplanDimensions(float width, float height) {}

virtual void setAreaPenalty(const Penalty& penalty) {}
virtual void setBoundaryPenalty(const Penalty& penalty) {}
Expand All @@ -93,8 +95,18 @@ class Mpl2Observer
virtual void setNotchPenalty(const Penalty& penalty) {}
virtual void setOutlinePenalty(const Penalty& penalty) {}
virtual void setWirelengthPenalty(const Penalty& penalty) {}
virtual void setCurrentRunId(int run_id) {}
virtual void setIsValid(bool is_valid) {}
virtual void setSequencePair(const SequencePair& sequence_pair) {}
virtual void setPreviousCost(float pre_cost) {}
virtual void setCurrentCost(float cost) {}
virtual void setEmptyBestValidResult(bool best_valid_result_is_empty) {}
virtual void setBestValidResult(const SequencePair& best_valid_result) {}
virtual void penaltyCalculated(float norm_cost) {}

virtual void reportNewBestValidResult() {}
virtual void reportChecks() {}

virtual void eraseDrawing() {}
};

Expand Down
8 changes: 8 additions & 0 deletions src/mpl2/src/SACoreSoftMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ void SACoreSoftMacro::calPenalty()
calNotchPenalty();
if (graphics_) {
graphics_->setAreaPenalty({area_weight_, getAreaPenalty()});
graphics_->setIsValid(isValid());
graphics_->setFloorplanDimensions(width_, height_);

SequencePair current_result;
current_result.pos_sequence = pos_seq_;
current_result.neg_sequence = neg_seq_;
graphics_->setSequencePair(current_result);

graphics_->penaltyCalculated(calNormCost());
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/mpl2/src/SimulatedAnnealingCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,10 @@ void SimulatedAnnealingCore<T>::fastSA()

SequencePair best_valid_result;
if (isValid()) {
logger_->report("Initial State Result is valid: {}", isValid());
logger_->report("\tOutline (Ceil): W {} H {}", outline_.getWidth(),
outline_.getHeight());
logger_->report("\tFloorplan: W {} H {}", width_, height_);
updateBestValidResult(best_valid_result);
}

Expand All @@ -590,10 +594,19 @@ void SimulatedAnnealingCore<T>::fastSA()
perturb();
cost = calNormCost();

if (graphics_) {
graphics_->setPreviousCost(pre_cost);
graphics_->setCurrentCost(cost);
graphics_->setEmptyBestValidResult(best_valid_result.pos_sequence.empty());
graphics_->reportChecks();
}

const bool keep_result
= cost < pre_cost || best_valid_result.pos_sequence.empty();

if (isValid() && keep_result) {
graphics_->setBestValidResult(best_valid_result);
graphics_->reportNewBestValidResult();
updateBestValidResult(best_valid_result);
}

Expand Down Expand Up @@ -650,6 +663,16 @@ void SimulatedAnnealingCore<T>::fastSA()
graphics_->doNotSkip();
}
calPenalty();

logger_->report("Found Best Valid Result");
logger_->report("\tFloorplan dimensions: W {} H {}",
width_,
height_);
logger_->report("\tOutline: W {} H {}",
outline_.getWidth(),
outline_.getHeight());
logger_->report("\tIs it really valid: {}",
isValid());
}

if (centralization_on_) {
Expand Down
142 changes: 136 additions & 6 deletions src/mpl2/src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include "graphics.h"

#include <sstream>
#include "object.h"
#include "utl/Logger.h"

Expand Down Expand Up @@ -95,7 +95,7 @@ void Graphics::endSA(const float norm_cost)
}
logger_->report("------ End ------");
report(norm_cost);
gui::Gui::get()->pause();
// gui::Gui::get()->pause();
}

void Graphics::saStep(const std::vector<SoftMacro>& macros)
Expand Down Expand Up @@ -134,6 +134,72 @@ void Graphics::report(const char* name, const std::optional<T>& value)
}
}

void Graphics::setPreviousCost(float pre_cost)
{
pre_cost_ = pre_cost;
}

void Graphics::setCurrentCost(float cost)
{
cost_ = cost;
}

void Graphics::setEmptyBestValidResult(bool best_valid_result_is_empty)
{
best_valid_result_is_empty_ = best_valid_result_is_empty;
}

void Graphics::setBestValidResult(const SequencePair& best_valid_result)
{
best_valid_result_ = best_valid_result;
}

void Graphics::reportChecks()
{
if (!is_desired_parent_) {
return;
}

if (!is_desired_run_) {
return;
}

logger_->report("Previous Cost = {}, Cost = {}", pre_cost_, cost_);
logger_->report("Best Valid Result is Empty = {}", best_valid_result_is_empty_);
}

void Graphics::reportNewBestValidResult()
{
if (!is_desired_parent_) {
return;
}

if (!is_desired_run_) {
return;
}

logger_->report("Keeping new best valid result:");

std::string pos_sequence = "\tPositive Sequence: ";
for (const auto& id : current_result_.pos_sequence) {
std::ostringstream oss;
oss << id;
pos_sequence += oss.str();
pos_sequence += '\t';
}
logger_->report("{}", pos_sequence);

std::string neg_sequence = "\tNegative Sequence: ";
for (const auto& id : current_result_.pos_sequence) {
std::ostringstream oss;
oss << id;
neg_sequence += oss.str();
neg_sequence += '\t';
}
logger_->report("{}", neg_sequence);

}

void Graphics::report(const float norm_cost)
{
report("Area", area_penalty_);
Expand All @@ -145,6 +211,30 @@ void Graphics::report(const float norm_cost)
report("Macro Blockage Penalty", macro_blockage_penalty_);
report("Notch Penalty", notch_penalty_);
report("Normalized Cost", std::optional<Penalty>({1.0f, norm_cost}));
logger_->report("Current Result");

std::string pos_sequence = "\tPositive Sequence: ";
for (const auto& id : current_result_.pos_sequence) {
std::ostringstream oss;
oss << id;
pos_sequence += oss.str();
pos_sequence += '\t';
}
logger_->report("{}", pos_sequence);

std::string neg_sequence = "\tNegative Sequence: ";
for (const auto& id : current_result_.pos_sequence) {
std::ostringstream oss;
oss << id;
neg_sequence += oss.str();
neg_sequence += '\t';
}
logger_->report("{}", neg_sequence);

logger_->report("Result is valid: {}", is_valid_);
logger_->report("\tOutline (Ceil): W {} H {}", micron_outline_.getWidth(),
micron_outline_.getHeight());
logger_->report("\tFloorplan: W {} H {}", width_, height_);
}

void Graphics::drawResult()
Expand Down Expand Up @@ -216,9 +306,25 @@ void Graphics::penaltyCalculated(float norm_cost)
return;
}

for (auto& macro : soft_macros_) {
auto cluster = macro.getCluster();
if (cluster) {
auto parent = cluster->getParent();
if (parent->getName() == "frontend/icache") {
is_desired_parent_ = true;
}
}
}

if (is_desired_parent_) {
is_desired_run_ = run_id_ == 18;
} else {
is_desired_run_ = false;
}

bool drawing_last_step = skip_steps_ && !is_skipping_;

if (norm_cost < best_norm_cost_ || drawing_last_step) {
if (is_desired_parent_ && is_desired_run_) {
logger_->report("------ Penalty ------");
report(norm_cost);

Expand All @@ -230,9 +336,7 @@ void Graphics::penaltyCalculated(float norm_cost)
const char* type = !soft_macros_.empty() ? "SoftMacro" : "HardMacro";
gui::Gui::get()->status(type);
gui::Gui::get()->redraw();
if (norm_cost < 0.99 * best_norm_cost_ || drawing_last_step) {
gui::Gui::get()->pause();
}
gui::Gui::get()->pause();
best_norm_cost_ = norm_cost;

if (drawing_last_step) {
Expand All @@ -243,6 +347,32 @@ void Graphics::penaltyCalculated(float norm_cost)
}
}

void Graphics::setIsValid(const bool is_valid)
{
is_valid_ = is_valid;
}

void Graphics::setCurrentRunId(const int run_id)
{
run_id_ = run_id;
}

void Graphics::setFloorplanDimensions(const float width, const float height)
{
width_ = width;
height_ = height;
}

void Graphics::setMicronOutline(const Rect& micron_outline)
{
micron_outline_ = micron_outline;
}

void Graphics::setSequencePair(const SequencePair& sequence_pair)
{
current_result_ = sequence_pair;
}

void Graphics::resetPenalties()
{
area_penalty_.reset();
Expand Down
28 changes: 28 additions & 0 deletions src/mpl2/src/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class Graphics : public gui::Renderer, public Mpl2Observer
void setNotchPenalty(const Penalty& penalty) override;
void setOutlinePenalty(const Penalty& penalty) override;
void setWirelengthPenalty(const Penalty& penalty) override;
void setCurrentRunId(int run_id) override;
void setIsValid(bool is_valid) override;
void setSequencePair(const SequencePair& sequence_pair) override;
void penaltyCalculated(float norm_cost) override;

void drawObjects(gui::Painter& painter) override;
Expand All @@ -86,6 +89,15 @@ class Graphics : public gui::Renderer, public Mpl2Observer
void setOnlyFinalResult(bool only_final_result) override;

void setOutline(const odb::Rect& outline) override;
void setMicronOutline(const Rect& micron_outline) override;
void setFloorplanDimensions(float width, float height) override;
void setPreviousCost(float pre_cost) override;
void setCurrentCost(float cost) override;
void setEmptyBestValidResult(bool best_valid_result_is_empty) override;
void setBestValidResult(const SequencePair& best_valid_result) override;

void reportNewBestValidResult() override;
void reportChecks() override;

void eraseDrawing() override;

Expand Down Expand Up @@ -113,7 +125,14 @@ class Graphics : public gui::Renderer, public Mpl2Observer
std::vector<mpl2::Rect> placement_blockages_;
std::vector<BundledNet> bundled_nets_;
odb::Rect outline_;
Rect micron_outline_;
std::vector<std::vector<odb::Rect>> outlines_;
SequencePair current_result_;
SequencePair best_valid_result_;

float pre_cost_{0.0f};
float cost_{0.0f};
bool best_valid_result_is_empty_{true};

bool active_ = true;
bool coarse_;
Expand All @@ -122,9 +141,18 @@ class Graphics : public gui::Renderer, public Mpl2Observer
bool skip_steps_;
bool is_skipping_;
bool only_final_result_;
bool is_valid_{false};
int run_id_{0};
odb::dbBlock* block_;
utl::Logger* logger_;

bool is_desired_parent_{false};
bool is_desired_run_{false};

// The dimensions of the current solution.
float width_{0.0f};
float height_{0.0f};

std::optional<int> max_level_;
std::optional<Penalty> outline_penalty_;
std::optional<Penalty> fence_penalty_;
Expand Down
5 changes: 5 additions & 0 deletions src/mpl2/src/hier_rtlmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,10 @@ void HierRTLMP::runHierarchicalMacroPlacementWithoutBusPlanning(Cluster* parent)
const int run_thread
= graphics_ ? 1 : std::min(remaining_runs, num_threads_);
for (int i = 0; i < run_thread; i++) {
if (graphics_) {
graphics_->setCurrentRunId(run_id);
}

debugPrint(logger_,
MPL,
"hierarchical_macro_placement",
Expand Down Expand Up @@ -3124,6 +3128,7 @@ void HierRTLMP::findOverlappingBlockages(std::vector<Rect>& macro_blockages,

if (graphics_) {
graphics_->setOutline(micronsToDbu(outline));
graphics_->setMicronOutline(outline);
graphics_->setMacroBlockages(macro_blockages);
graphics_->setPlacementBlockages(placement_blockages);
}
Expand Down

0 comments on commit bbf8ce8

Please sign in to comment.