Skip to content
Open
1 change: 1 addition & 0 deletions src/dpl/include/dpl/Opendp.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ class Opendp
bool deep_iterative_debug_ = false;
bool incremental_ = false;
bool use_negotiation_ = false;
int total_moves_ = 0;

// Magic numbers
static constexpr double group_refine_percent_ = .05;
Expand Down
2 changes: 2 additions & 0 deletions src/dpl/src/NegotiationLegalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class NegotiationLegalizer
[[nodiscard]] double avgDisplacement() const;
[[nodiscard]] int maxDisplacement() const;
[[nodiscard]] int numViolations() const;
[[nodiscard]] int totalMoves() const { return total_moves_; }

private:
// Initialisation
Expand Down Expand Up @@ -265,6 +266,7 @@ class NegotiationLegalizer
int adj_window_{kAdjWindow};
int num_threads_{1};
bool run_abacus_{false};
int total_moves_{0};

// Mutable profiling accumulators for findBestLocation breakdown (seconds).
mutable double prof_init_search_s_{0};
Expand Down
1 change: 1 addition & 0 deletions src/dpl/src/NegotiationLegalizerPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ int NegotiationLegalizer::negotiationIter(std::vector<int>& activeCells,
pct(overhead));
}

total_moves_ += moves_count;
logger_->report(
"Negotiation iteration {}: total overflow {}.", iter, totalOverflow);
if (opendp_->iterative_debug_ && debug_observer_) {
Expand Down
20 changes: 14 additions & 6 deletions src/dpl/src/Opendp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ void Opendp::detailedPlacement(const int max_displacement_x,
negotiation.numViolations());
}

total_moves_ = negotiation.totalMoves();
findDisplacementStats();
updateDbInstLocations();
}
reportLegalizationStats();
}

void Opendp::updateDbInstLocations()
Expand All @@ -255,34 +257,40 @@ void Opendp::updateDbInstLocations()

void Opendp::reportLegalizationStats() const
{
logger_->report("Placement Analysis");
logger_->report("Detailed Placement Analysis");
logger_->report("---------------------------------");
const std::string legalizer_name
= use_negotiation_ ? "negotiation" : "diamond search";
logger_->report("legalizer {}", legalizer_name);
logger_->metric("dpl__legalizer__type", legalizer_name);
logger_->report("total moves {:10d}", total_moves_);
logger_->metric("dpl__total__moves", total_moves_);
logger_->report("total displacement {:10.1f} u",
block_->dbuToMicrons(displacement_sum_));
logger_->metric("design__instance__displacement__total",
logger_->metric("dpl__instance__displacement__total",
block_->dbuToMicrons(displacement_sum_));
logger_->report("average displacement {:10.1f} u",
block_->dbuToMicrons(displacement_avg_));
logger_->metric("design__instance__displacement__mean",
logger_->metric("dpl__instance__displacement__mean",
block_->dbuToMicrons(displacement_avg_));
logger_->report("max displacement {:10.1f} u",
block_->dbuToMicrons(displacement_max_));
logger_->metric("design__instance__displacement__max",
logger_->metric("dpl__instance__displacement__max",
block_->dbuToMicrons(displacement_max_));
logger_->report("original HPWL {:10.1f} u",
block_->dbuToMicrons(hpwl_before_));
odb::WireLengthEvaluator eval(block_);
const double hpwl_legal = eval.hpwl();
logger_->report("legalized HPWL {:10.1f} u",
block_->dbuToMicrons(hpwl_legal));
logger_->metric("route__wirelength__estimated",
block_->dbuToMicrons(hpwl_legal));
const int hpwl_delta
= (hpwl_before_ == 0.0)
? 0.0
: round((hpwl_legal - hpwl_before_) / hpwl_before_ * 100);
logger_->report("delta HPWL {:10} %", hpwl_delta);
logger_->report("");
logger_->metric("route__wirelength__estimated",
block_->dbuToMicrons(hpwl_legal));
logger_->metric("dpl__hpwl__delta", hpwl_legal - hpwl_before_);
logger_->metric("dpl__hpwl__delta__percent", hpwl_delta);
}
Expand Down
1 change: 0 additions & 1 deletion src/dpl/src/Opendp.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ proc detailed_placement { args } {
$file_name [info exists flags(-incremental)] \
[info exists flags(-use_negotiation)] \
[info exists flags(-abacus)]
dpl::report_legalization_stats
} else {
utl::error "DPL" 27 "no rows defined in design. Use initialize_floorplan to add rows."
}
Expand Down
98 changes: 57 additions & 41 deletions src/dpl/src/Optdp.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2021-2025, The OpenROAD Authors

#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <unordered_map>
Comment thread
gudeh marked this conversation as resolved.

#include "dpl/Opendp.h"
#include "odb/util.h"
Expand All @@ -14,38 +17,6 @@
#include "optimization/detailed_manager.h"

namespace dpl {
namespace {
void reportHPWL(utl::Logger* logger,
const double dbu_micron,
const int64_t hpwlBefore,
const int64_t hpwlAfter,
const int64_t hpwlBefore_x,
const int64_t hpwlAfter_x,
const int64_t hpwlBefore_y,
const int64_t hpwlAfter_y)
{
logger->report("Detailed Improvement Results");
logger->report("------------------------------------------");
logger->report("Original HPWL {:10.1f} u ({:10.1f}, {:10.1f})",
hpwlBefore / dbu_micron,
hpwlBefore_x / dbu_micron,
hpwlBefore_y / dbu_micron);
logger->report("Final HPWL {:10.1f} u ({:10.1f}, {:10.1f})",
hpwlAfter / dbu_micron,
hpwlAfter_x / dbu_micron,
hpwlAfter_y / dbu_micron);
const double hpwl_delta = (hpwlAfter - hpwlBefore) / (double) hpwlBefore;
const double hpwl_delta_x
= (hpwlAfter_x - hpwlBefore_x) / (double) hpwlBefore_x;
const double hpwl_delta_y
= (hpwlAfter_y - hpwlBefore_y) / (double) hpwlBefore_y;
logger->report("Delta HPWL {:10.1f} % ({:10.1f}, {:10.1f})",
hpwl_delta * 100.0,
hpwl_delta_x * 100.0,
hpwl_delta_y * 100.0);
logger->report("");
}
} // namespace

////////////////////////////////////////////////////////////////
void Opendp::improvePlacement(const int seed,
Expand Down Expand Up @@ -120,6 +91,17 @@ void Opendp::improvePlacement(const int seed,
debug_observer_->redrawAndPause();
}

// Snapshot positions before improvement for displacement tracking.
odb::dbBlock* block = db_->getChip()->getBlock();
std::unordered_map<odb::dbInst*, odb::Point> pos_before;
Comment thread
gudeh marked this conversation as resolved.
Comment thread
gudeh marked this conversation as resolved.
for (odb::dbInst* inst : block->getInsts()) {
if (!inst->isFixed()) {
int x, y;
inst->getLocation(x, y);
pos_before[inst] = {x, y};
}
}

// Run the script.
Detailed dt(dtParams);
dt.improve(mgr);
Expand All @@ -132,19 +114,53 @@ void Opendp::improvePlacement(const int seed,
// Write solution back.
updateDbInstLocations();

// Compute displacement stats.
int64_t disp_sum = 0;
int64_t disp_max = 0;
int moved = 0;
for (auto& [inst, before] : pos_before) {
int x, y;
inst->getLocation(x, y);
const int64_t disp = std::abs(x - before.x()) + std::abs(y - before.y());
if (disp > 0) {
disp_sum += disp;
disp_max = std::max(disp_max, disp);
moved++;
}
}
const double dbu_micron = db_->getTech()->getDbUnitsPerMicron();
const double disp_total_um = disp_sum / dbu_micron;
const double disp_avg_um = moved > 0 ? disp_sum / (dbu_micron * moved) : 0.0;
const double disp_max_um = disp_max / dbu_micron;

// Get final hpwl.
int64_t hpwlAfter_x = 0;
int64_t hpwlAfter_y = 0;
const int64_t hpwlAfter = eval.hpwl(hpwlAfter_x, hpwlAfter_y);
const double dbu_micron = db_->getTech()->getDbUnitsPerMicron();
reportHPWL(logger_,
dbu_micron,
hpwlBefore,
hpwlAfter,
hpwlBefore_x,
hpwlAfter_x,
hpwlBefore_y,
hpwlAfter_y);
const int hpwl_delta_pct
= (hpwlBefore == 0)
? 0
: round((hpwlAfter - hpwlBefore) / (double) hpwlBefore * 100);
Comment thread
gudeh marked this conversation as resolved.
Outdated

Comment thread
gudeh marked this conversation as resolved.
Comment thread
gudeh marked this conversation as resolved.
const int total_attempts = mgr.getTotalAttempts();
logger_->report("Place Optimization Analysis");
logger_->report("---------------------------------");
logger_->report("total attempts {:10d}", total_attempts);
logger_->report("relocated cells {:10d}", moved);
logger_->report("total displacement {:10.1f} u", disp_total_um);
logger_->report("average displacement {:10.1f} u", disp_avg_um);
logger_->report("max displacement {:10.1f} u", disp_max_um);
logger_->report("original HPWL {:10.1f} u", hpwlBefore / dbu_micron);
logger_->report("improved HPWL {:10.1f} u", hpwlAfter / dbu_micron);
logger_->report("delta HPWL {:10} %", hpwl_delta_pct);
logger_->report("");
logger_->metric("dpo__total__attempts", total_attempts);
logger_->metric("dpo__relocated__cells", moved);
logger_->metric("dpo__design__instance__displacement__total", disp_total_um);
logger_->metric("dpo__design__instance__displacement__mean", disp_avg_um);
logger_->metric("dpo__design__instance__displacement__max", disp_max_um);
logger_->metric("dpo__hpwl__delta", hpwlAfter - hpwlBefore);
logger_->metric("dpo__hpwl__delta__percent", hpwl_delta_pct);
}
Comment thread
gudeh marked this conversation as resolved.

////////////////////////////////////////////////////////////////
Expand Down
10 changes: 8 additions & 2 deletions src/dpl/src/Place.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ void Opendp::place()
std::ranges::sort(sorted_cells, CellPlaceOrderLess(core_, this));

int count = 0;
int moves = 0;
for (Node* cell : sorted_cells) {
if (iterative_debug_) {
count++;
Expand All @@ -390,6 +391,7 @@ void Opendp::place()
100.0 * count / sorted_cells.size());
}

const odb::Point pos_before = getDplLocation(cell);
bool diamond_move = diamondMove(cell);
bool rip_up_move = false;

Expand All @@ -403,17 +405,21 @@ void Opendp::place()
}
diamond_move == 1 ? success_diamond_move++ : failed_diamond_move++;

if (getDplLocation(cell) != pos_before) {
moves++;
}

if (iterative_debug_) {
odb::Point initial_location = getOdbLocation(cell);
odb::Point final_location = getDplLocation(cell);
float len = odb::Point::squaredDistance(initial_location, final_location);
float len = odb::Point::squaredDistance(pos_before, final_location);
if (len > 0) {
report_placement(cell, diamond_move, rip_up_move);
}
}
}

const size_t total_cells = sorted_cells.size();
total_moves_ = moves;
const int success_rip_up = failed_diamond_move - failed_rip_up;

logger_->report("Movements Summary");
Expand Down
1 change: 1 addition & 0 deletions src/dpl/src/optimization/detailed_global.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ void DetailedGlobalSwap::stats()
attempts_,
swaps_,
moves_);
mgr_->addAttempts(attempts_);
}

} // namespace dpl
1 change: 1 addition & 0 deletions src/dpl/src/optimization/detailed_global_legacy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ void DetailedGlobalSwap::stats()
attempts_,
swaps_,
moves_);
mgr_->addAttempts(attempts_);
}

} // namespace legacy
Expand Down
3 changes: 3 additions & 0 deletions src/dpl/src/optimization/detailed_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ class DetailedMgr
bool alignPos(const Node* ndi, DbuX& xi, DbuX xl, DbuX xr);
int getMoveLimit() { return moveLimit_; }
void setMoveLimit(unsigned int newMoveLimit) { moveLimit_ = newMoveLimit; }
void addAttempts(int n) { total_attempts_ += n; }
int getTotalAttempts() const { return total_attempts_; }

// Journal operations
Journal& getJournal() { return journal_; }
Expand Down Expand Up @@ -389,6 +391,7 @@ class DetailedMgr

// For generating a move list... (size = moveLimit_)
int moveLimit_;
int total_attempts_ = 0;
};

} // namespace dpl
2 changes: 2 additions & 0 deletions src/dpl/src/optimization/detailed_random.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ void RandomGenerator::stats()
attempts_,
swaps_,
moves_);
mgr_->addAttempts(attempts_);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -792,6 +793,7 @@ void DisplacementGenerator::stats()
attempts_,
swaps_,
moves_);
mgr_->addAttempts(attempts_);
}

} // namespace dpl
1 change: 1 addition & 0 deletions src/dpl/src/optimization/detailed_vertical.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ void DetailedVerticalSwap::stats()
attempts_,
swaps_,
moves_);
mgr_->addAttempts(attempts_);
}

} // namespace dpl
Loading