Skip to content

Commit 0785636

Browse files
authored
Merge pull request #8777 from gudeh/gpl-debug-colors
gpl: debug mode colors and charts
2 parents 3bcda77 + 9908a51 commit 0785636

File tree

4 files changed

+96
-59
lines changed

4 files changed

+96
-59
lines changed

src/gpl/src/graphicsImpl.cpp

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ void GraphicsImpl::debugForNesterovPlace(
7878

7979
if (enabled()) {
8080
// Setup the chart
81-
chart_ = gui::Gui::get()->addChart(
82-
"GPL", "Iteration", {"HPWL (μm)", "Overflow"});
83-
chart_->setXAxisFormat("%d");
84-
chart_->setYAxisFormats({"%.2e", "%.2f"});
85-
chart_->setYAxisMin({std::nullopt, 0});
86-
87-
// Useful for debugging multiple NesterovBase: Density penalty and PhiCoef
88-
if (logger_->debugCheck(utl::GPL, "penaltyPlot", 1)) {
81+
gui::Gui* gui = gui::Gui::get();
82+
main_chart_ = gui->addChart("GPL", "Iteration", {"HPWL (μm)", "Overflow"});
83+
main_chart_->setXAxisFormat("%d");
84+
main_chart_->setYAxisFormats({"%.2e", "%.2f"});
85+
main_chart_->setYAxisMin({std::nullopt, 0});
86+
87+
// Useful for debugging : Density penalty and PhiCoef
88+
if (logger_->debugCheck(utl::GPL, "debugPlot", 1)) {
8989
if (!nbVec_.empty()) {
90-
std::vector<std::string> series_names;
91-
series_names.reserve(nbVec_.size());
90+
std::vector<std::string> region_names;
91+
region_names.reserve(nbVec_.size());
9292
for (size_t i = 0; i < nbVec_.size(); ++i) {
9393
std::string name;
9494
if (nbVec_[i] && nbVec_[i]->getPb() && nbVec_[i]->getPb()->group()) {
@@ -97,24 +97,23 @@ void GraphicsImpl::debugForNesterovPlace(
9797
} else {
9898
name = fmt::format("nb[{}]", i);
9999
}
100-
series_names.push_back(name);
100+
region_names.push_back(name);
101101
}
102-
density_chart_ = gui::Gui::get()->addChart(
103-
"GPL Density Penalty", "Iteration", series_names);
102+
density_chart_ = gui->addChart(
103+
"GPL Density Penalty", "Iteration", {"DensityPenalty", "phiCoef"});
104104
density_chart_->setXAxisFormat("%d");
105-
std::vector<std::string> y_formats(nbVec_.size(), "%.3f");
106-
density_chart_->setYAxisFormats(y_formats);
107-
std::vector<std::optional<double>> y_mins(nbVec_.size(), 0.0);
108-
density_chart_->setYAxisMin(y_mins);
109-
110-
phi_chart_ = gui::Gui::get()->addChart(
111-
"GPL PhiCoef", "Iteration", series_names);
112-
phi_chart_->setXAxisFormat("%d");
113-
phi_chart_->setYAxisFormats(y_formats);
114-
phi_chart_->setYAxisMin(y_mins);
105+
density_chart_->setYAxisFormats({"%.2e", "%.2f"});
106+
density_chart_->setYAxisMin({0.0, nbc_->getNbVars().minPhiCoef});
107+
108+
stepLength_chart_ = gui->addChart(
109+
"GPL StepLength",
110+
"Iteration",
111+
{"StepLength", "CoordiDistance", "GradDistance", "Std area"});
112+
stepLength_chart_->setXAxisFormat("%d");
113+
stepLength_chart_->setYAxisFormats({"%.2e", "%.2f", "%.2f"});
114+
stepLength_chart_->setYAxisMin({0.0, 0.0, 0.0});
115115
}
116116
}
117-
118117
initHeatmap();
119118
if (inst) {
120119
for (size_t idx = 0; idx < nbc_->getGCells().size(); ++idx) {
@@ -285,10 +284,19 @@ void GraphicsImpl::drawSingleGCell(const GCell* gCell,
285284
// Highlight modified instances (overrides base color, unless selected)
286285
switch (gCell->changeType()) {
287286
case GCell::GCellChange::kRoutability:
288-
color = {255, 255, 255, 100}; // White
287+
color = gui::Painter::kWhite;
288+
break;
289+
case GCell::GCellChange::kNewInstance:
290+
color = gui::Painter::kDarkRed;
291+
break;
292+
case GCell::GCellChange::kDownsize:
293+
color = gui::Painter::kDarkBlue;
289294
break;
290-
case GCell::GCellChange::kTimingDriven:
291-
color = {180, 150, 255, 100}; // Light purple
295+
case GCell::GCellChange::kUpsize:
296+
color = gui::Painter::kOrange;
297+
break;
298+
case GCell::GCellChange::kResizeNoChange:
299+
color = gui::Painter::kDarkYellow;
292300
break;
293301
default:
294302
if (gCell->isInstance()) {
@@ -538,48 +546,57 @@ void GraphicsImpl::reportSelected()
538546
void GraphicsImpl::addIter(const int iter, const double overflow)
539547
{
540548
odb::dbBlock* block = pbc_->db()->getChip()->getBlock();
541-
chart_->addPoint(iter, {block->dbuToMicrons(nbc_->getHpwl()), overflow});
549+
main_chart_->addPoint(iter, {block->dbuToMicrons(nbc_->getHpwl()), overflow});
542550

543-
// Add density penalties snapshot for each NesterovBase
544-
if (logger_->debugCheck(utl::GPL, "penaltyPlot", 1)) {
551+
if (logger_->debugCheck(utl::GPL, "debugPlot", 1)) {
545552
if (density_chart_) {
546-
std::vector<double> penalties;
547-
penalties.reserve(nbVec_.size());
548-
for (const auto& nb : nbVec_) {
549-
double penalty
550-
= nb ? static_cast<double>(nb->getDensityPenalty()) : 0.0;
551-
penalties.push_back(penalty);
553+
std::vector<double> values;
554+
if (!nbVec_.empty() && nbVec_[0]) {
555+
values.push_back((static_cast<double>(nbVec_[0]->getDensityPenalty())));
556+
values.push_back(static_cast<double>(nbVec_[0]->getStoredPhiCoef()));
557+
} else {
558+
values.push_back(0.0);
559+
values.push_back(0.0);
552560
}
553-
density_chart_->addPoint(iter, penalties);
561+
density_chart_->addPoint(iter, values);
554562
}
555563

556-
if (phi_chart_) {
557-
std::vector<double> coefs;
558-
coefs.reserve(nbVec_.size());
559-
for (const auto& nb : nbVec_) {
560-
double coef = nb ? static_cast<double>(nb->getStoredPhiCoef()) : 0.0;
561-
coefs.push_back(coef);
564+
if (stepLength_chart_) {
565+
std::vector<double> values;
566+
if (!nbVec_.empty() && nbVec_[0]) {
567+
values.push_back(static_cast<double>(nbVec_[0]->getStoredStepLength()));
568+
values.push_back(
569+
static_cast<double>(nbVec_[0]->getStoredCoordiDistance()));
570+
values.push_back(
571+
static_cast<double>(nbVec_[0]->getStoredGradDistance()));
572+
values.push_back(
573+
static_cast<double>(nbVec_[0]->getNesterovInstsArea()));
574+
} else {
575+
values.push_back(0.0);
576+
values.push_back(0.0);
577+
values.push_back(0.0);
578+
values.push_back(0.0);
562579
}
563-
phi_chart_->addPoint(iter, coefs);
580+
stepLength_chart_->addPoint(iter, values);
564581
}
565582
}
566583
}
567584

568585
void GraphicsImpl::addTimingDrivenIter(const int iter)
569586
{
570-
chart_->addVerticalMarker(iter, gui::Painter::kTurquoise);
587+
main_chart_->addVerticalMarker(iter, gui::Painter::kTurquoise);
571588
}
572589

573590
void GraphicsImpl::addRoutabilitySnapshot(int iter)
574591
{
575-
chart_->addVerticalMarker(iter, gui::Painter::kYellow);
592+
main_chart_->addVerticalMarker(iter, gui::Painter::kYellow);
576593
}
577594

578595
void GraphicsImpl::addRoutabilityIter(const int iter, const bool revert)
579596
{
580597
gui::Painter::Color color
581598
= revert ? gui::Painter::kRed : gui::Painter::kGreen;
582-
chart_->addVerticalMarker(iter, color);
599+
main_chart_->addVerticalMarker(iter, color);
583600
}
584601

585602
void GraphicsImpl::cellPlotImpl(bool pause)

src/gpl/src/graphicsImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ class GraphicsImpl : public gpl::AbstractGraphics,
169169
LineSegs mbff_edges_;
170170
std::vector<odb::dbInst*> mbff_cluster_;
171171
Mode mode_;
172-
gui::Chart* chart_{nullptr};
172+
gui::Chart* main_chart_{nullptr};
173173
gui::Chart* density_chart_{nullptr};
174174
gui::Chart* phi_chart_{nullptr};
175+
gui::Chart* stepLength_chart_{nullptr};
175176
bool debug_on_ = false;
176177

177178
void initHeatmap();

src/gpl/src/nesterovBase.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,19 +2452,18 @@ float NesterovBase::getStepLength(
24522452
const std::vector<FloatPoint>& curSLPCoordi_,
24532453
const std::vector<FloatPoint>& curSLPSumGrads_)
24542454
{
2455-
float coordiDistance = getDistance(prevSLPCoordi_, curSLPCoordi_);
2456-
float gradDistance = getDistance(prevSLPSumGrads_, curSLPSumGrads_);
2457-
2455+
coordiDistance_ = getDistance(prevSLPCoordi_, curSLPCoordi_);
2456+
gradDistance_ = getDistance(prevSLPSumGrads_, curSLPSumGrads_);
24582457
debugPrint(log_,
24592458
GPL,
24602459
"getStepLength",
24612460
1,
2462-
"CoordinateDistance: {:g}",
2463-
coordiDistance);
2464-
debugPrint(
2465-
log_, GPL, "getStepLength", 1, "GradientDistance: {:g}", gradDistance);
2461+
"CoordinateDis {:g}, GradientDist {:g}, StepLength: {:g}",
2462+
coordiDistance_,
2463+
gradDistance_,
2464+
stepLength_);
24662465

2467-
return coordiDistance / gradDistance;
2466+
return coordiDistance_ / gradDistance_;
24682467
}
24692468

24702469
// to execute following function,
@@ -3137,6 +3136,13 @@ void NesterovBaseCommon::resizeGCell(odb::dbInst* db_inst)
31373136
= static_cast<int64_t>(gcell->dx()) * static_cast<int64_t>(gcell->dy());
31383137
int64_t area_change = newCellArea - prevCellArea;
31393138
delta_area_ += area_change;
3139+
if (area_change > 0) {
3140+
gcell->setAreaChangeType(GCell::GCellChange::kUpsize);
3141+
} else if (area_change < 0) {
3142+
gcell->setAreaChangeType(GCell::GCellChange::kDownsize);
3143+
} else {
3144+
gcell->setAreaChangeType(GCell::GCellChange::kResizeNoChange);
3145+
}
31403146
}
31413147

31423148
void NesterovBase::updateGCellState(float wlCoeffX, float wlCoeffY)
@@ -3269,6 +3275,7 @@ size_t NesterovBaseCommon::createCbkGCell(odb::dbInst* db_inst)
32693275
* static_cast<int64_t>(gcell_ptr->dy());
32703276
delta_area_ += area_change;
32713277
new_gcells_count_++;
3278+
gcell_ptr->setAreaChangeType(GCell::GCellChange::kNewInstance);
32723279
return gCellStor_.size() - 1;
32733280
}
32743281

src/gpl/src/nesterovBase.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class GCell
5959
kNone,
6060
kRoutability,
6161
kTimingDriven,
62+
kNewInstance,
63+
kDownsize,
64+
kUpsize,
65+
kResizeNoChange
6266
};
6367

6468
// instance cells
@@ -882,6 +886,8 @@ class NesterovBaseCommon
882886
deleted_gcells_count_ = 0;
883887
}
884888

889+
NesterovBaseVars& getNbVars() { return nbVars_; }
890+
885891
private:
886892
NesterovBaseVars nbVars_;
887893
std::shared_ptr<PlacerBaseCommon> pbc_;
@@ -1072,6 +1078,9 @@ class NesterovBase
10721078
void setTrueReprintIterHeader() { reprint_iter_header_ = true; }
10731079
float getPhiCoef(float scaledDiffHpwl) const;
10741080
float getStoredPhiCoef() const { return phiCoef_; }
1081+
float getStoredStepLength() const { return stepLength_; }
1082+
float getStoredCoordiDistance() const { return coordiDistance_; }
1083+
float getStoredGradDistance() const { return gradDistance_; }
10751084

10761085
bool checkConvergence(int gpl_iter_count,
10771086
int routability_gpl_iter_count,
@@ -1182,6 +1191,12 @@ class NesterovBase
11821191
float targetDensity_ = 0;
11831192
float uniformTargetDensity_ = 0;
11841193

1194+
// StepLength parameters (also included in the np debugPrint)
1195+
// alpha
1196+
float stepLength_ = 0;
1197+
float coordiDistance_ = 0;
1198+
float gradDistance_ = 0;
1199+
11851200
// Nesterov loop data for each region, using parallel vectors
11861201
// SLP is Step Length Prediction.
11871202
//
@@ -1227,9 +1242,6 @@ class NesterovBase
12271242
float wireLengthGradSum_ = 0;
12281243
float densityGradSum_ = 0;
12291244

1230-
// alpha
1231-
float stepLength_ = 0;
1232-
12331245
// opt_phi_cof
12341246
float densityPenalty_ = 0;
12351247

0 commit comments

Comments
 (0)