Skip to content

Commit b439714

Browse files
committed
mpl: add debug chart for cost components vs iteration
Only drawing area, outline, and wire length for clarity. Points are only added where pauses occur to limit the number of updates. Signed-off-by: Matt Liberty <[email protected]>
1 parent 862863d commit b439714

File tree

7 files changed

+58
-10
lines changed

7 files changed

+58
-10
lines changed

src/gui/include/gui/gui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ class Chart
591591
virtual void setYAxisMin(const std::vector<std::optional<double>>& mins) = 0;
592592
// One y per series. The order matches y_labels in addChart
593593
virtual void addPoint(double x, const std::vector<double>& ys) = 0;
594+
virtual void clearPoints() = 0;
594595

595596
virtual void addVerticalMarker(double x, const Painter::Color& color) = 0;
596597

src/gui/src/chartsWidget.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class GuiChart : public Chart
3737
void setYAxisFormats(const std::vector<std::string>& formats) override;
3838
void setYAxisMin(const std::vector<std::optional<double>>& mins) override;
3939
void addPoint(double x, const std::vector<double>& ys) override;
40+
void clearPoints() override;
4041

4142
void addVerticalMarker(double x, const Painter::Color& color) override;
4243

@@ -48,6 +49,14 @@ class GuiChart : public Chart
4849
double y_min{std::numeric_limits<double>::max()};
4950
double y_max{std::numeric_limits<double>::lowest()};
5051
bool has_min{false};
52+
53+
void clear()
54+
{
55+
series->clear();
56+
y_min = std::numeric_limits<double>::max();
57+
y_max = std::numeric_limits<double>::lowest();
58+
has_min = false;
59+
}
5160
};
5261

5362
void addSeries(const std::string& label);
@@ -144,6 +153,15 @@ void GuiChart::addPoint(const double x, const std::vector<double>& ys)
144153
}
145154
}
146155

156+
void GuiChart::clearPoints()
157+
{
158+
for (Series& series : series_) {
159+
series.clear();
160+
}
161+
x_min_ = std::numeric_limits<double>::max();
162+
x_max_ = std::numeric_limits<double>::lowest();
163+
}
164+
147165
void GuiChart::addVerticalMarker(const double x, const Painter::Color& color)
148166
{
149167
QLineSeries* vline = new QLineSeries();
@@ -1047,4 +1065,4 @@ void HistogramView::contextMenuEvent(QContextMenuEvent* event)
10471065
}
10481066
}
10491067

1050-
} // namespace gui
1068+
} // namespace gui

src/mpl/src/MplObserver.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ class MplObserver
2424
virtual void startCoarse() {}
2525
virtual void startFine() {}
2626

27-
virtual void startSA() {}
27+
virtual void startSA(const char* type,
28+
int max_num_step,
29+
int num_perturb_per_step)
30+
{
31+
}
2832
virtual void saStep(const std::vector<SoftMacro>& macros) {}
2933
virtual void saStep(const std::vector<HardMacro>& macros) {}
3034
virtual void endSA(float norm_cost) {}

src/mpl/src/SACoreHardMacro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ SACoreHardMacro::SACoreHardMacro(PhysicalHierarchy* tree,
6060
void SACoreHardMacro::run()
6161
{
6262
if (graphics_) {
63-
graphics_->startSA();
63+
graphics_->startSA("hard", max_num_step_, num_perturb_per_step_);
6464
}
6565

6666
fastSA();

src/mpl/src/SACoreSoftMacro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ SACoreSoftMacro::SACoreSoftMacro(PhysicalHierarchy* tree,
8080
void SACoreSoftMacro::run()
8181
{
8282
if (graphics_) {
83-
graphics_->startSA();
83+
graphics_->startSA("soft", max_num_step_, num_perturb_per_step_);
8484
}
8585

8686
fastSA();

src/mpl/src/graphics.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ Graphics::Graphics(bool coarse,
3636
block_(block),
3737
logger_(logger)
3838
{
39-
gui::Gui::get()->registerRenderer(this);
39+
gui::Gui* gui = gui::Gui::get();
40+
gui->registerRenderer(this);
41+
42+
// Setup the chart
43+
chart_ = gui->addChart("MPL", "Iteration", {"Area", "Outline", "WireLength"});
44+
chart_->setXAxisFormat("%d");
45+
chart_->setYAxisFormats({"%.2e", "%.2e", "%.2e"});
46+
chart_->setYAxisMin({0, 0, 0});
4047
}
4148

4249
void Graphics::startCoarse()
@@ -49,7 +56,9 @@ void Graphics::startFine()
4956
active_ = fine_;
5057
}
5158

52-
void Graphics::startSA()
59+
void Graphics::startSA(const char* type,
60+
const int max_num_step,
61+
const int num_perturb_per_step)
5362
{
5463
if (!active_) {
5564
return;
@@ -63,9 +72,14 @@ void Graphics::startSA()
6372
return;
6473
}
6574

66-
logger_->report("------ Start ------");
75+
logger_->report("------ Start {} ------", type);
76+
logger_->report("max_num_step = {} num_perturb_per_step = {}",
77+
max_num_step,
78+
num_perturb_per_step);
6779
best_norm_cost_ = std::numeric_limits<float>::max();
6880
skipped_ = 0;
81+
chart_->clearPoints();
82+
iter_ = 0;
6983
}
7084

7185
void Graphics::endSA(const float norm_cost)
@@ -85,7 +99,7 @@ void Graphics::endSA(const float norm_cost)
8599
if (skipped_ > 0) {
86100
logger_->report("Skipped to end: {}", skipped_);
87101
}
88-
logger_->report("------ End ------");
102+
logger_->report("------ End (Iter {}) ------", iter_);
89103
report(norm_cost);
90104
gui::Gui::get()->pause();
91105
}
@@ -195,6 +209,7 @@ void Graphics::penaltyCalculated(float norm_cost)
195209
if (!active_) {
196210
return;
197211
}
212+
iter_++;
198213

199214
if (is_skipping_) {
200215
return;
@@ -207,7 +222,13 @@ void Graphics::penaltyCalculated(float norm_cost)
207222
bool drawing_last_step = skip_steps_ && !is_skipping_;
208223

209224
if (norm_cost < best_norm_cost_ || drawing_last_step) {
210-
logger_->report("------ Penalty ------");
225+
const float area = area_penalty_ ? area_penalty_.value().value : 0;
226+
const float outline = outline_penalty_ ? outline_penalty_.value().value : 0;
227+
const float wirelength
228+
= wirelength_penalty_ ? wirelength_penalty_.value().value : 0;
229+
chart_->addPoint(iter_, {area, outline, wirelength});
230+
231+
logger_->report("------ Penalty (Iter {}) ------", iter_);
211232
report(norm_cost);
212233

213234
if (skipped_ > 0) {

src/mpl/src/graphics.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class Graphics : public gui::Renderer, public MplObserver
3030
void startCoarse() override;
3131
void startFine() override;
3232

33-
void startSA() override;
33+
void startSA(const char* type,
34+
int max_num_step,
35+
int num_perturb_per_step) override;
3436
void saStep(const std::vector<SoftMacro>& macros) override;
3537
void saStep(const std::vector<HardMacro>& macros) override;
3638
void endSA(float norm_cost) override;
@@ -117,6 +119,7 @@ class Graphics : public gui::Renderer, public MplObserver
117119
std::vector<odb::Rect> blocked_regions_for_pins_;
118120
BoundaryRegionList available_regions_for_unconstrained_pins_;
119121
ClusterToBoundaryRegionMap io_cluster_to_constraint_;
122+
gui::Chart* chart_{nullptr};
120123

121124
// In Soft SA, we're shaping/placing the children of a certain parent,
122125
// so for this case, the current cluster is actually the current parent.
@@ -149,6 +152,7 @@ class Graphics : public gui::Renderer, public MplObserver
149152

150153
float best_norm_cost_ = 0;
151154
int skipped_ = 0;
155+
int iter_ = 0;
152156

153157
Cluster* root_ = nullptr;
154158
};

0 commit comments

Comments
 (0)