Skip to content

Commit

Permalink
modified inside blockage criteria and added debug codes
Browse files Browse the repository at this point in the history
Signed-off-by: Cho Moon <[email protected]>
  • Loading branch information
precisionmoon committed Sep 28, 2023
1 parent 0469cde commit 3d38d93
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 44 deletions.
133 changes: 100 additions & 33 deletions src/cts/src/HTreeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ void HTreeBuilder::preSinkClustering(
options_->getSinkBuffer(),
legalCenter.getX() * wireSegmentUnit_,
legalCenter.getY() * wireSegmentUnit_);
if (logger_->debugCheck(CTS, "legalizer", 2) && (center != legalCenter)) {
// clang-format off
debugPrint(logger_, CTS, "legalizer", 2,
"preSinkClustering legalizeOneBuffer {}: {} => {}",
baseName + std::to_string(clusterCount),
center, legalCenter);
// clang-format on
}

if (!secondLevel) {
addFirstLevelSinkDriver(&rootBuffer);
Expand Down Expand Up @@ -355,12 +363,12 @@ void adjustToplevelTopology(Point<double>& a,
}
}

bool moveAlongBlockageBoundary(const Point<double>& parentPoint,
Point<double>& branchPoint,
double x1,
double y1,
double x2,
double y2)
bool HTreeBuilder::moveAlongBlockageBoundary(const Point<double>& parentPoint,
Point<double>& branchPoint,
double x1,
double y1,
double x2,
double y2)
{
double px = parentPoint.getX();
double py = parentPoint.getY();
Expand Down Expand Up @@ -394,6 +402,12 @@ bool moveAlongBlockageBoundary(const Point<double>& parentPoint,
if (abs(d1 - d2) < d1 / 100000) {
branchPoint.setX(u.getX());
branchPoint.setY(u.getY());
// clang-format off
debugPrint(logger_, CTS, "legalizer", 1,
"moveAlongBlockageBoundary: legalPoint {} is {} blockage ({:0.3f} {:0.3f}) ({:0.3f} {:0.3f})",
u, isInsideBbox(u.getX(), u.getY(), x1, y1, x2, y2) ?
"inside" : "outside", x1, y1, x2, y2);
// clang-format on
return true;
}
}
Expand Down Expand Up @@ -496,18 +510,11 @@ void HTreeBuilder::legalizeDummy()
= selectBestNewLocation(branchPoint, legal_locations, sinks);

double d = legalBranchPoint.computeDist(parentPoint);
debugPrint(
logger_,
CTS,
"legalizer",
1,
"legalizeDummy level index {}: {}->{} d={}, leng={}, ratio={}",
levelIdx,
branchPoint,
legalBranchPoint,
d,
leng,
d / leng);
// clang-format off
debugPrint(logger_, CTS, "legalizer", 1,
"legalizeDummy level index {}: {}->{} d={:0.3f}, leng={:0.3f}, ratio={:0.3f}",
levelIdx, branchPoint, legalBranchPoint, d, leng, d / leng);
// clang-format on
branchPoint.setX(legalBranchPoint.getX());
branchPoint.setY(legalBranchPoint.getY());
}
Expand Down Expand Up @@ -544,6 +551,11 @@ void HTreeBuilder::legalize()
if (levelIdx == 0) {
(void) moveAlongBlockageBoundary(
parentPoint, legalBranchPoint, x1, y1, x2, y2);
// clang-format off
debugPrint(logger_, CTS, "legalizer", 1,
" moveAlongBlockageBoundary for level 0 buffer:{} => {}",
branchPoint, legalBranchPoint);
// clang-format on
} else {
if (levelIdx == 1) {
leng = branchPoint.computeDist(parentPoint);
Expand All @@ -554,6 +566,18 @@ void HTreeBuilder::legalize()
findLegalPlacement(parentPoint, leng, x1, y1, x2, y2, points);
// choose the best new location
legalBranchPoint = selectBestNewLocation(branchPoint, points, sinks);
// clang-format off
debugPrint(logger_, CTS, "legalizer", 1,
"selectBestNewLocation point {} is {} blockage ({:0.3f} {:0.3f}) ({:0.3f} {:0.3f})",
legalBranchPoint,
isInsideBbox(legalBranchPoint.getX(),
legalBranchPoint.getY(),
x1, y1, x2, y2)? "inside" : "outside",
x1, y1, x2, y2);
debugPrint(logger_, CTS, "legalizer", 1,
" selectBestNewLocation for level 1 buffer: {} => {}",
branchPoint, legalBranchPoint);
// clang-format on
}
// update branchPoint
branchPoint.setX(legalBranchPoint.getX());
Expand Down Expand Up @@ -649,18 +673,12 @@ void HTreeBuilder::run(odb::dbDatabase* db)
legalize();
}
createClockSubNets();
debugPrint(logger_,
CTS,
"legalizer",
3,
"Htree file {} has been generated",
// clang-format off
debugPrint(logger_, CTS, "legalizer", 3, "Htree file {} has been generated",
plotHTree());
debugPrint(
logger_,
CTS,
"legalizer",
3,
"Run 'obsAwareCts.py cts.clk.buffer' to produce cts.clk.buffer.png");
debugPrint(logger_, CTS, "legalizer", 3,
"Run 'obsAwareCts.py cts.clk.buffer' to produce cts.clk.buffer.png");
// clang-format on
}

std::string HTreeBuilder::plotHTree()
Expand Down Expand Up @@ -1200,13 +1218,23 @@ void HTreeBuilder::refineBranchingPointsWithClustering(

void HTreeBuilder::createClockSubNets()
{
Point<double> legalCenter = legalizeOneBuffer(sinkRegion_.computeCenter(),
options_->getRootBuffer());
Point<double> center = sinkRegion_.computeCenter();
Point<double> legalCenter
= legalizeOneBuffer(center, options_->getRootBuffer());
const int centerX = legalCenter.getX() * wireSegmentUnit_;
const int centerY = legalCenter.getY() * wireSegmentUnit_;

ClockInst& rootBuffer = clock_.addClockBuffer(
"clkbuf_0", options_->getRootBuffer(), centerX, centerY);

if (logger_->debugCheck(CTS, "legalizer", 2) && (center != legalCenter)) {
// clang-format off
debugPrint(logger_, CTS, "legalizer", 2,
"createClockSubNets legalizeOneBuffer clkbuf_0: {} => {}",
center, legalCenter);
// clang-format on
}

addTreeLevelBuffer(&rootBuffer);
Clock::SubNet& rootClockSubNet = clock_.addSubNet("clknet_0");
rootClockSubNet.addInst(rootBuffer);
Expand All @@ -1219,6 +1247,16 @@ void HTreeBuilder::createClockSubNets()
Point<double> branchPoint) {
Point<double> legalBranchPoint
= legalizeOneBuffer(branchPoint, options_->getRootBuffer());
if (logger_->debugCheck(CTS, "legalizer", 2)
&& (branchPoint != legalBranchPoint)) {
// clang-format off
debugPrint(logger_, CTS, "legalizer", 2,
"createClockSubNets first level legalizeOneBuffer before "
"SegmentBuilder::builder clk_buf_1_{}_ : {} => {}",
std::to_string(idx), branchPoint, legalBranchPoint);
// clang-format on
}

SegmentBuilder builder("clkbuf_1_" + std::to_string(idx) + "_",
"clknet_1_" + std::to_string(idx) + "_",
legalCenter, // center may have moved, don't use
Expand Down Expand Up @@ -1257,6 +1295,17 @@ void HTreeBuilder::createClockSubNets()

Point<double> legalBranchPoint
= legalizeOneBuffer(branchPoint, options_->getRootBuffer());
if (logger_->debugCheck(CTS, "legalizer", 2)
&& (branchPoint != legalBranchPoint)) {
// clang-format off
debugPrint(logger_, CTS, "legalizer", 2,
"createClockSubNets legalizeOneBuffer before "
"SegmentBuilder::builder {}: {} => {}"
"clkbuf_"
+ std::to_string(levelIdx + 1) + "_" + std::to_string(idx)
+ "_", branchPoint, legalBranchPoint);
// clang-format on
}
SegmentBuilder builder("clkbuf_" + std::to_string(levelIdx + 1) + "_"
+ std::to_string(idx) + "_",
"clknet_" + std::to_string(levelIdx + 1) + "_"
Expand All @@ -1269,6 +1318,7 @@ void HTreeBuilder::createClockSubNets()
*techChar_,
wireSegmentUnit_,
this);

if (!options_->getTreeBuffer().empty()) {
builder.build(options_->getTreeBuffer());
} else {
Expand Down Expand Up @@ -1311,12 +1361,20 @@ void HTreeBuilder::createSingleBufferClockNet()
{
logger_->report(" Building single-buffer clock net.");

Point<double> legalCenter = legalizeOneBuffer(sinkRegion_.computeCenter(),
options_->getRootBuffer());
Point<double> center = sinkRegion_.computeCenter();
Point<double> legalCenter
= legalizeOneBuffer(center, options_->getRootBuffer());
const int centerX = legalCenter.getX() * wireSegmentUnit_;
const int centerY = legalCenter.getY() * wireSegmentUnit_;
ClockInst& rootBuffer = clock_.addClockBuffer(
"clkbuf_0", options_->getRootBuffer(), centerX, centerY);
if (logger_->debugCheck(CTS, "legalizer", 2) && (center != legalCenter)) {
// clang-format off
debugPrint(logger_, CTS, "legalizer", 2,
"createSingleBufferClockNet legalizeOneBuffer clkbuf_0: {} => {}",
center, legalCenter);
// clang-format on
}
addTreeLevelBuffer(&rootBuffer);
Clock::SubNet& clockSubNet = clock_.addSubNet("clknet_0");
clockSubNet.addInst(rootBuffer);
Expand Down Expand Up @@ -1445,6 +1503,15 @@ void SegmentBuilder::build(const std::string& forceBuffer)
buffMaster,
legalBufferLoc.getX() * techCharDistUnit_,
legalBufferLoc.getY() * techCharDistUnit_);
if (getTree()->getLogger()->debugCheck(CTS, "legalizer", 2)
&& (bufferLoc != legalBufferLoc)) {
// clang-format off
debugPrint(getTree()->getLogger(), CTS, "legalizer", 2,
" SegmentBuilder::build legalizeOneBuffer {}: {} => {}",
instPrefix_ + std::to_string(numBufferLevels_),
bufferLoc, legalBufferLoc);
// clang-format on
}
tree_->addTreeLevelBuffer(&newBuffer);

drivingSubNet_->addInst(newBuffer);
Expand Down
8 changes: 7 additions & 1 deletion src/cts/src/HTreeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class SegmentBuilder

Clock::SubNet* getDrivingSubNet() const { return drivingSubNet_; }
unsigned getNumBufferLevels() const { return numBufferLevels_; }
TreeBuilder* getTree() const { return tree_; }

private:
const std::string instPrefix_;
Expand Down Expand Up @@ -179,7 +180,12 @@ class HTreeBuilder : public TreeBuilder
}

void run(odb::dbDatabase* db) override;

bool moveAlongBlockageBoundary(const Point<double>& parentPoint,
Point<double>& branchPoint,
double x1,
double y1,
double x2,
double y2);
void legalize();
void legalizeDummy();
void plotSolution();
Expand Down
3 changes: 2 additions & 1 deletion src/cts/src/TreeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class TreeBuilder
double x2,
double y2)
{
if ((x > x1) && (x < x2) && (y > y1) && (y < y2)) {
if ((x >= x1) && (x <= x2) && (y >= y1) && (y <= y2)) {
return true;
}
return false;
Expand All @@ -133,6 +133,7 @@ class TreeBuilder
double& y2);
Point<double> legalizeOneBuffer(Point<double> bufferLoc,
const std::string& bufferName);
utl::Logger* getLogger() { return logger_; }

protected:
CtsOptions* options_ = nullptr;
Expand Down
31 changes: 30 additions & 1 deletion src/cts/src/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#pragma once

#include <iomanip>
#include <ostream>

namespace cts {
Expand Down Expand Up @@ -75,6 +76,15 @@ class Point
return dy;
}

bool equal(const Point<T>& other, double epsilon = 0.0000001f) const
{
if ((fabs(getX() - other.getX()) < epsilon)
&& (fabs(getY() - other.getY()) < epsilon)) {
return true;
}
return false;
}

bool operator<(const Point<T>& other) const
{
if (getX() != other.getX()) {
Expand All @@ -84,9 +94,28 @@ class Point
return getY() < other.getY();
}

bool operator==(const Point<T>& other) const
{
if (equal(other)) {
return true;
}

return false;
}

bool operator!=(const Point<T>& other) const
{
if (equal(other)) {
return false;
}

return true;
}

friend std::ostream& operator<<(std::ostream& out, const Point<T>& point)
{
out << "[(" << point.getX() << ", " << point.getY() << ")]";
out << "[(" << std::fixed << std::setprecision(3) << point.getX() << ", "
<< std::fixed << std::setprecision(3) << point.getY() << ")]";
return out;
}

Expand Down
8 changes: 4 additions & 4 deletions src/cts/test/array.ok
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,18 @@ TritonCTS forced slew degradation on these wires.
[INFO CTS-0098] Clock net "clk"
[INFO CTS-0099] Sinks 2475
[INFO CTS-0100] Leaf buffers 138
[INFO CTS-0101] Average sink wire length 10077.60 um
[INFO CTS-0101] Average sink wire length 10075.79 um
[INFO CTS-0102] Path depth 18 - 19
[INFO RSZ-0058] Using max wire length 707um.
[INFO RSZ-0047] Found 33 long wires.
[INFO RSZ-0048] Inserted 86 buffers in 33 nets.
Placement Analysis
---------------------------------
total displacement 2540.4 u
total displacement 2481.4 u
average displacement 0.9 u
max displacement 38.4 u
original HPWL 138837.0 u
legalized HPWL 139191.9 u
original HPWL 138822.4 u
legalized HPWL 139192.8 u
delta HPWL 0 %

Clock clk
Expand Down
8 changes: 4 additions & 4 deletions src/cts/test/array_no_blockages.ok
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,18 @@ TritonCTS forced slew degradation on these wires.
[INFO CTS-0098] Clock net "clk"
[INFO CTS-0099] Sinks 2475
[INFO CTS-0100] Leaf buffers 138
[INFO CTS-0101] Average sink wire length 10075.49 um
[INFO CTS-0101] Average sink wire length 10074.23 um
[INFO CTS-0102] Path depth 18 - 19
[INFO RSZ-0058] Using max wire length 707um.
[INFO RSZ-0047] Found 32 long wires.
[INFO RSZ-0048] Inserted 84 buffers in 32 nets.
Placement Analysis
---------------------------------
total displacement 1911.1 u
total displacement 1845.5 u
average displacement 0.7 u
max displacement 37.4 u
original HPWL 138112.5 u
legalized HPWL 138435.7 u
original HPWL 138097.7 u
legalized HPWL 138430.3 u
delta HPWL 0 %

Clock clk
Expand Down
4 changes: 4 additions & 0 deletions src/cts/test/check_buffers_blockages.ok
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ TritonCTS forced slew degradation on these wires.
[INFO CTS-0030] Number of static layers: 1.
[INFO CTS-0020] Wire segment unit: 14000 dbu (7 um).
[INFO CTS-0021] Distance between buffers: 7 units (100 um).
[DEBUG CTS-legalizer] preSinkClustering legalizeOneBuffer clkbuf_leaf_10: [(7.220, 8.032)] => [(7.220, 7.600)]
[INFO CTS-0019] Total number of sinks after clustering: 29.
[INFO CTS-0024] Normalized sink region: [(1.26757, 0.912143), (13.4493, 11.6927)].
[INFO CTS-0025] Width: 12.1817.
Expand All @@ -45,6 +46,9 @@ TritonCTS forced slew degradation on these wires.
[INFO CTS-0034] Segment length (rounded): 2.
Key: 12 inSlew: 1 inCap: 1 outSlew: 2 load: 1 length: 2 delay: 1
[INFO CTS-0032] Stop criterion found. Max number of sinks is 15.
[DEBUG CTS-legalizer] selectBestNewLocation point [(11.358, 7.302)] is outside blockage (10.326 7.800) (12.019 8.400)
[DEBUG CTS-legalizer] selectBestNewLocation for level 1 buffer: [(11.178, 8.122)] => [(11.358, 7.302)]
[DEBUG CTS-legalizer] createClockSubNets legalizeOneBuffer clkbuf_0: [(7.358, 6.302)] => [(7.358, 6.064)]
[INFO CTS-0035] Number of sinks covered: 29.
[DEBUG CTS-legalizer] Htree file cts.clk.buffer has been generated
[DEBUG CTS-legalizer] Run 'obsAwareCts.py cts.clk.buffer' to produce cts.clk.buffer.png
Expand Down

0 comments on commit 3d38d93

Please sign in to comment.