Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
05e54ef
gpl: initiate fix incremental,
gudeh Feb 28, 2026
d4fdb07
gpl: handle fixed instances
gudeh Mar 2, 2026
a84da87
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 2, 2026
647db21
gpl: use PB isFixed()
gudeh Mar 3, 2026
d072917
gpl: no need to ignore locked instances
gudeh Mar 3, 2026
1a6acde
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 3, 2026
3320759
gpl: increase init density penalty for incremental second stage (with…
gudeh Mar 3, 2026
fe269e6
gpl: generate one gif for each incremental stage
gudeh Mar 3, 2026
917608d
gpl: update test after incremental mode fix
gudeh Mar 3, 2026
bdfe18c
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 3, 2026
66101ec
gpl: remove unecessary code
gudeh Mar 3, 2026
4d82f35
gpl: initial place handle fixed instances
gudeh Mar 3, 2026
0066e25
odb: update test after gpl incremental modification
gudeh Mar 3, 2026
d98a62c
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 3, 2026
cd4d5dd
gpl: update test after inital placement modifiation
gudeh Mar 4, 2026
fe8ee36
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 4, 2026
f54bcaf
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 6, 2026
93a0e2a
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 6, 2026
39015ba
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 9, 2026
724d85f
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 10, 2026
f5b3eb4
test: update after gpl incremental fix
gudeh Mar 10, 2026
636a7a9
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 10, 2026
fe1aa0f
Merge remote-tracking branch 'private/master' into gpl-fix-incremental
gudeh Mar 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 75 additions & 36 deletions src/gpl/src/initialPlace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ void InitialPlace::createSparseMatrix()
instLocVecY_(idx) = inst->cy();

fixedInstForceVecX_(idx) = fixedInstForceVecY_(idx) = 0;

if (inst->isLocked()) {
listX.emplace_back(idx, idx, 1.0f);
listY.emplace_back(idx, idx, 1.0f);
fixedInstForceVecX_(idx) = inst->cx();
fixedInstForceVecY_(idx) = inst->cy();
}
Comment on lines +287 to +292

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While adding a diagonal term to the matrix for locked instances is a step towards fixing their positions, this implementation is incomplete and may not work as intended. The subsequent loop that processes nets will add significant forces from connected movable instances, effectively pulling the 'locked' instances away from their fixed positions. With large net weights, a locked instance's position will be dominated by its neighbors rather than its specified fixed location.

To correctly fix the instances, they should be treated as fixed terminals throughout the matrix construction. This means the net processing loop should not add any matrix terms for connections involving locked instances; instead, they should contribute to the right-hand side (force vector) for any movable instances they are connected to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The secure-CI run with ID 5 should address this. I am waiting for it to finish to make sure it is no-op, as expected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secure-CI proves no-op
image

}

// for each net
Expand Down Expand Up @@ -325,24 +332,40 @@ void InitialPlace::createSparseMatrix()

// both pin cames from instance
if (pin1->isPlaceInstConnected() && pin2->isPlaceInstConnected()) {
const int inst1 = pin1->getInstance()->getExtId();
const int inst2 = pin2->getInstance()->getExtId();

listX.emplace_back(inst1, inst1, weightX);
listX.emplace_back(inst2, inst2, weightX);

listX.emplace_back(inst1, inst2, -weightX);
listX.emplace_back(inst2, inst1, -weightX);

fixedInstForceVecX_(inst1)
+= -weightX
* ((pin1->cx() - pin1->getInstance()->cx())
- (pin2->cx() - pin2->getInstance()->cx()));

fixedInstForceVecX_(inst2)
+= -weightX
* ((pin2->cx() - pin2->getInstance()->cx())
- (pin1->cx() - pin1->getInstance()->cx()));
Instance* instance1 = pin1->getInstance();
Instance* instance2 = pin2->getInstance();
const int inst1 = instance1->getExtId();
const int inst2 = instance2->getExtId();
const bool locked1 = instance1->isLocked();
const bool locked2 = instance2->isLocked();

if (!locked1 && !locked2) {
// Both movable: standard B2B matrix terms
listX.emplace_back(inst1, inst1, weightX);
listX.emplace_back(inst2, inst2, weightX);
listX.emplace_back(inst1, inst2, -weightX);
listX.emplace_back(inst2, inst1, -weightX);

fixedInstForceVecX_(inst1)
+= -weightX
* ((pin1->cx() - instance1->cx())
- (pin2->cx() - instance2->cx()));
fixedInstForceVecX_(inst2)
+= -weightX
* ((pin2->cx() - instance2->cx())
- (pin1->cx() - instance1->cx()));
} else if (locked1 && !locked2) {
// inst1 is fixed: treat pin1 as a fixed terminal for inst2
listX.emplace_back(inst2, inst2, weightX);
fixedInstForceVecX_(inst2)
+= weightX * (pin1->cx() - (pin2->cx() - instance2->cx()));
} else if (!locked1 && locked2) {
// inst2 is fixed: treat pin2 as a fixed terminal for inst1
listX.emplace_back(inst1, inst1, weightX);
fixedInstForceVecX_(inst1)
+= weightX * (pin2->cx() - (pin1->cx() - instance1->cx()));
}
// both locked: no matrix or RHS contribution needed
}
// pin1 from IO port / pin2 from Instance
else if (!pin1->isPlaceInstConnected()
Expand Down Expand Up @@ -379,24 +402,40 @@ void InitialPlace::createSparseMatrix()

// both pin cames from instance
if (pin1->isPlaceInstConnected() && pin2->isPlaceInstConnected()) {
const int inst1 = pin1->getInstance()->getExtId();
const int inst2 = pin2->getInstance()->getExtId();

listY.emplace_back(inst1, inst1, weightY);
listY.emplace_back(inst2, inst2, weightY);

listY.emplace_back(inst1, inst2, -weightY);
listY.emplace_back(inst2, inst1, -weightY);

fixedInstForceVecY_(inst1)
+= -weightY
* ((pin1->cy() - pin1->getInstance()->cy())
- (pin2->cy() - pin2->getInstance()->cy()));

fixedInstForceVecY_(inst2)
+= -weightY
* ((pin2->cy() - pin2->getInstance()->cy())
- (pin1->cy() - pin1->getInstance()->cy()));
Instance* instance1 = pin1->getInstance();
Instance* instance2 = pin2->getInstance();
const int inst1 = instance1->getExtId();
const int inst2 = instance2->getExtId();
const bool locked1 = instance1->isLocked();
const bool locked2 = instance2->isLocked();

if (!locked1 && !locked2) {
// Both movable: standard B2B matrix terms
listY.emplace_back(inst1, inst1, weightY);
listY.emplace_back(inst2, inst2, weightY);
listY.emplace_back(inst1, inst2, -weightY);
listY.emplace_back(inst2, inst1, -weightY);

fixedInstForceVecY_(inst1)
+= -weightY
* ((pin1->cy() - instance1->cy())
- (pin2->cy() - instance2->cy()));
fixedInstForceVecY_(inst2)
+= -weightY
* ((pin2->cy() - instance2->cy())
- (pin1->cy() - instance1->cy()));
} else if (locked1 && !locked2) {
// inst1 is fixed: treat pin1 as a fixed terminal for inst2
listY.emplace_back(inst2, inst2, weightY);
fixedInstForceVecY_(inst2)
+= weightY * (pin1->cy() - (pin2->cy() - instance2->cy()));
} else if (!locked1 && locked2) {
// inst2 is fixed: treat pin2 as a fixed terminal for inst1
listY.emplace_back(inst1, inst1, weightY);
fixedInstForceVecY_(inst1)
+= weightY * (pin2->cy() - (pin1->cy() - instance1->cy()));
}
// both locked: no matrix or RHS contribution needed
}
// pin1 from IO port / pin2 from Instance
else if (!pin1->isPlaceInstConnected()
Expand Down
24 changes: 21 additions & 3 deletions src/gpl/src/nesterovBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,9 @@ NesterovBase::NesterovBase(
}

for (Instance* inst : gCell->insts()) {
inst->setLocation(pb_inst->lx() + x_offset, pb_inst->ly() + y_offset);
if (!inst->isLocked()) {
inst->setLocation(pb_inst->lx() + x_offset, pb_inst->ly() + y_offset);
}
}
gCell->updateLocations();
nb_gcells_.emplace_back(nbc_.get(), nbc_->getGCellIndex(gCell));
Expand Down Expand Up @@ -2821,6 +2823,12 @@ void NesterovBase::updateSingleGradient(
}

GCell* gCell = nb_gcells_.at(gCellIndex);
if (gCell->isLocked()) {
wireLengthGrads[gCellIndex] = FloatPoint(0, 0);
densityGrads[gCellIndex] = FloatPoint(0, 0);
sumGrads[gCellIndex] = FloatPoint(0, 0);
return;
}

wireLengthGrads[gCellIndex]
= nbc_->getWireLengthGradientWA(gCell, wlCoeffX, wlCoeffY);
Expand Down Expand Up @@ -2852,6 +2860,11 @@ void NesterovBase::updateInitialPrevSLPCoordi()
for (size_t i = 0; i < nb_gcells_.size(); i++) {
GCell* curGCell = nb_gcells_[i];

if (curGCell->isLocked()) {
prevSLPCoordi_[i] = curSLPCoordi_[i];
continue;
}

float prevCoordiX
= curSLPCoordi_[i].x
- (npVars_->initialPrevCoordiUpdateCoef * curSLPSumGrads_[i].x);
Expand Down Expand Up @@ -3061,6 +3074,13 @@ void NesterovBase::nesterovUpdateCoordinates(float coeff)

// fill in nextCoordinates with given stepLength_
for (size_t k = 0; k < nb_gcells_.size(); k++) {
GCell* curGCell = nb_gcells_[k];
if (curGCell->isLocked()) {
nextCoordi_[k] = curCoordi_[k];
nextSLPCoordi_[k] = curSLPCoordi_[k];
continue;
}

FloatPoint nextCoordi(
curSLPCoordi_[k].x + stepLength_ * curSLPSumGrads_[k].x,
curSLPCoordi_[k].y + stepLength_ * curSLPSumGrads_[k].y);
Expand All @@ -3069,8 +3089,6 @@ void NesterovBase::nesterovUpdateCoordinates(float coeff)
nextCoordi.x + coeff * (nextCoordi.x - curCoordi_[k].x),
nextCoordi.y + coeff * (nextCoordi.y - curCoordi_[k].y));

GCell* curGCell = nb_gcells_[k];

nextCoordi_[k]
= FloatPoint(getDensityCoordiLayoutInsideX(curGCell, nextCoordi.x),
getDensityCoordiLayoutInsideY(curGCell, nextCoordi.y));
Expand Down
1 change: 1 addition & 0 deletions src/gpl/src/nesterovBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ class NesterovBase
bool checkConvergence(int gpl_iter_count,
int routability_gpl_iter_count,
RouteBase* rb);
void resetConverged() { isConverged_ = false; }

bool checkDivergence();
void saveSnapshot();
Expand Down
17 changes: 12 additions & 5 deletions src/gpl/src/nesterovPlace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,6 @@ void NesterovPlace::updateIterGraphics(
}
}

if (npVars_.debug_generate_images && iter == 0) {
std::string gif_path = fmt::format("{}/placement.gif", reports_dir);
placement_gif_key_ = graphics_->gifStart(gif_path);
}

if (npVars_.debug_generate_images && iter % 10 == 0) {
odb::Rect region;
int width_px = 500;
Expand Down Expand Up @@ -831,6 +826,7 @@ bool NesterovPlace::isConverged(int gpl_iter_count,
if (num_region_converge == nbVec_.size()) {
if (graphics_ && graphics_->enabled() && npVars_.debug_generate_images) {
graphics_->gifEnd(placement_gif_key_);
placement_gif_key_ = -1;
}
return true;
}
Expand Down Expand Up @@ -1035,6 +1031,7 @@ int NesterovPlace::doNesterovPlace(int start_iter)
nb->setIter(start_iter);
nb->setMaxPhiCoefChanged(false);
nb->resetMinSumOverflow();
nb->resetConverged();
original_area += nb->getNesterovInstsArea();
}

Expand All @@ -1044,6 +1041,16 @@ int NesterovPlace::doNesterovPlace(int start_iter)
= reports_dir + "/gpl_routability_driven";

cleanReportsDirs(timing_driven_dir, routability_driven_dir);
if (graphics_ && graphics_->enabled() && npVars_.debug
&& npVars_.debug_generate_images) {
if (placement_gif_key_ != -1) {
graphics_->gifEnd(placement_gif_key_);
}
const std::string gif_name
= (start_iter == 0) ? "placement.gif" : "placement_stage2.gif";
placement_gif_key_
= graphics_->gifStart(fmt::format("{}/{}", reports_dir, gif_name));
}
if (graphics_ && graphics_->enabled() && npVars_.debug_generate_images) {
updateDb();
std::string label = fmt::format("init_nesterov");
Expand Down
61 changes: 38 additions & 23 deletions src/gpl/src/replace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,29 @@ void Replace::doIncrementalPlace(const int threads, const PlaceOptions& options)
{
checkHasCoreRows();
log_->info(GPL, 6, "Execute incremental mode global placement.");
if (pbc_ == nullptr) {
int placed_cnt = 0;
int unplaced_cnt = 0;
bool is_pbc_new = (pbc_ == nullptr);

if (is_pbc_new) {
pbc_ = std::make_shared<PlacerBaseCommon>(db_, options, log_);
}

// Count placed vs unplaced, and conditionally lock them down
auto block = db_->getChip()->getBlock();
for (auto inst : block->getInsts()) {
auto status = inst->getPlacementStatus();
if (status == odb::dbPlacementStatus::PLACED) {
if (is_pbc_new) {
pbc_->dbToPb(inst)->lock();
}
++placed_cnt;
} else if (!status.isPlaced()) {
++unplaced_cnt;
}
}

if (is_pbc_new) {
pbVec_.push_back(std::make_shared<PlacerBase>(db_, pbc_, log_, true));

for (auto pd : db_->getChip()->getBlock()->getRegions()) {
Expand All @@ -101,20 +121,6 @@ void Replace::doIncrementalPlace(const int threads, const PlaceOptions& options)
}
}

// Lock down already placed objects
int placed_cnt = 0;
int unplaced_cnt = 0;
auto block = db_->getChip()->getBlock();
for (auto inst : block->getInsts()) {
auto status = inst->getPlacementStatus();
if (status == odb::dbPlacementStatus::PLACED) {
pbc_->dbToPb(inst)->lock();
++placed_cnt;
} else if (!status.isPlaced()) {
++unplaced_cnt;
}
}

log_->info(GPL, 154, "Identified {} placed instances", placed_cnt);
log_->info(GPL, 155, "Identified {} not placed instances", unplaced_cnt);

Expand All @@ -130,21 +136,30 @@ void Replace::doIncrementalPlace(const int threads, const PlaceOptions& options)
// Roughly place the unplaced objects (allow more overflow).
// Limit iterations to prevent objects drifting too far or
// non-convergence.
PlaceOptions rough_options = options;
rough_options.overflow = std::max(options.overflow, 0.2f);
rough_options.nesterovPlaceMaxIter = 300;
PlaceOptions locked_options = options;
locked_options.overflow = std::max(options.overflow, 0.2f);
locked_options.nesterovPlaceMaxIter = 300;

doInitialPlace(threads, rough_options);
const int iter = doNesterovPlace(threads, rough_options);
// Use uniform density for incremental runs to fill gaps effectively
if (!options.uniformTargetDensityMode) {
locked_options.uniformTargetDensityMode = true;
}

doInitialPlace(threads, locked_options);
const int iter = doNesterovPlace(threads, locked_options);

// Finish the overflow resolution from the rough placement
// Finish the overflow resolution from the locked placement
log_->info(GPL, 133, "Unlocking all instances");
for (auto& pb : pbVec_) {
pb->unlockAll();
}

if (options.overflow < rough_options.overflow) {
doNesterovPlace(threads, options, iter + 1);
if (options.overflow < locked_options.overflow) {
PlaceOptions final_options = options;
final_options.uniformTargetDensityMode = true;
final_options.initDensityPenaltyFactor = 1;

doNesterovPlace(threads, final_options, iter + 1);
}
}

Expand Down
Loading
Loading