Skip to content

Commit df15ee7

Browse files
authored
Merge pull request #9637 from luis201420/cts_fix_improve_clustering
Cts fix improve automatic clustering
2 parents 35a0c35 + 399989e commit df15ee7

36 files changed

Lines changed: 1815 additions & 2112 deletions

‎src/cts/src/CtsOptions.cpp‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ void CtsOptions::inDbInstCreate(odb::dbInst* inst)
2626

2727
void CtsOptions::limitSinkClusteringSizes(unsigned limit)
2828
{
29+
unsigned new_size = limit;
2930
if (sinkClustersSizeSet_) {
30-
setSinkClusteringSize(std::min(limit, sinkClustersSize_));
31-
return;
31+
new_size = std::min(new_size, sinkClustersSize_);
3232
}
33-
auto lowerBound = std::ranges::lower_bound(sinkClusteringSizes_, limit);
34-
sinkClusteringSizes_.erase(lowerBound, sinkClusteringSizes_.end());
35-
sinkClusteringSizes_.push_back(limit);
33+
setSinkClusteringSize(new_size);
3634
}
3735

3836
void CtsOptions::recordBuffer(odb::dbMaster* master, MasterType type)

‎src/cts/src/CtsOptions.h‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ class CtsOptions : public odb::dbBlockCallBackObj
8484

8585
void setSinkClustering(bool enable) { sinkClusteringEnable_ = enable; }
8686
bool getSinkClustering() const { return sinkClusteringEnable_; }
87-
void setSinkClusteringUseMaxCap(bool useMaxCap)
88-
{
89-
sinkClusteringUseMaxCap_ = useMaxCap;
90-
}
91-
bool getSinkClusteringUseMaxCap() const { return sinkClusteringUseMaxCap_; }
9287
void setNumMaxLeafSinks(unsigned numSinks) { numMaxLeafSinks_ = numSinks; }
9388
unsigned getNumMaxLeafSinks() const { return numMaxLeafSinks_; }
9489
void setMaxSlew(unsigned slew) { maxSlew_ = slew; }
@@ -211,38 +206,26 @@ class CtsOptions : public odb::dbBlockCallBackObj
211206
void setMaxDiameter(double distance)
212207
{
213208
maxDiameter_ = distance;
214-
sinkClusteringUseMaxCap_ = false;
215209
maxDiameterSet_ = true;
216210
}
217211
void resetMaxDiameter()
218212
{
219213
maxDiameter_ = 50;
220-
sinkClusteringUseMaxCap_ = true;
221214
maxDiameterSet_ = false;
222215
}
223216
bool isMaxDiameterSet() const { return maxDiameterSet_; }
224-
const std::vector<unsigned>& getSinkClusteringDiameters()
225-
{
226-
return sinkClusteringDiameters_;
227-
}
228217
unsigned getSinkClusteringSize() const { return sinkClustersSize_; }
229218
void setSinkClusteringSize(unsigned size)
230219
{
231220
sinkClustersSize_ = size;
232-
sinkClusteringUseMaxCap_ = false;
233221
sinkClustersSizeSet_ = true;
234222
}
235223
void resetSinkClusteringSize()
236224
{
237-
sinkClustersSize_ = 20;
238-
sinkClusteringUseMaxCap_ = true;
225+
sinkClustersSize_ = 30;
239226
sinkClustersSizeSet_ = false;
240227
}
241228
bool isSinkClusteringSizeSet() const { return sinkClustersSizeSet_; }
242-
const std::vector<unsigned>& getSinkClusteringSizes()
243-
{
244-
return sinkClusteringSizes_;
245-
}
246229
void limitSinkClusteringSizes(unsigned limit);
247230
unsigned getSinkClusteringLevels() const { return sinkClusteringLevels_; }
248231
void setSinkClusteringLevels(unsigned levels)
@@ -364,7 +347,6 @@ class CtsOptions : public odb::dbBlockCallBackObj
364347
unsigned wireSegmentUnit_ = 0;
365348
bool plotSolution_ = false;
366349
bool sinkClusteringEnable_ = true;
367-
bool sinkClusteringUseMaxCap_ = true;
368350
bool simpleSegmentsEnable_ = false;
369351
bool vertexBuffersEnable_ = false;
370352
std::unique_ptr<CtsObserver> observer_;
@@ -392,10 +374,8 @@ class CtsOptions : public odb::dbBlockCallBackObj
392374
int sinks_ = 0;
393375
double maxDiameter_ = 50;
394376
bool maxDiameterSet_ = false;
395-
std::vector<unsigned> sinkClusteringDiameters_ = {50, 100, 200};
396-
unsigned sinkClustersSize_ = 20;
377+
unsigned sinkClustersSize_ = 30;
397378
bool sinkClustersSizeSet_ = false;
398-
std::vector<unsigned> sinkClusteringSizes_ = {10, 20, 30};
399379
double macroMaxDiameter_ = 50;
400380
bool macroMaxDiameterSet_ = false;
401381
unsigned macroSinkClustersSize_ = 4;

‎src/cts/src/HTreeBuilder.cpp‎

Lines changed: 47 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -93,70 +93,31 @@ void HTreeBuilder::preSinkClustering(
9393

9494
unsigned bestClusterSize = 0;
9595
float bestDiameter = 0.0;
96-
if (clusterSizeSet && maxDiameterSet) {
97-
// clang-format off
98-
debugPrint(logger_, CTS, "clustering", 1, "**** match.run({}, {}, {}) ****",
99-
clusterSize, maxDiameter, wireSegmentUnit_);
100-
// clang-format on
101-
matching.run(clusterSize,
102-
maxDiameter,
103-
wireSegmentUnit_,
104-
bestClusterSize,
105-
bestDiameter);
106-
} else if (!clusterSizeSet && maxDiameterSet) {
107-
// only diameter is set, try clustering sizes of 10, 20 and 30
108-
for (unsigned clusterSize2 : options_->getSinkClusteringSizes()) {
109-
// clang-format off
110-
debugPrint(logger_, CTS, "clustering", 1, "**** match.run({}, {}, {}) ****",
111-
clusterSize2, maxDiameter, wireSegmentUnit_);
112-
// clang-format on
113-
matching.run(clusterSize2,
114-
maxDiameter,
115-
wireSegmentUnit_,
116-
bestClusterSize,
117-
bestDiameter);
118-
}
119-
} else if (clusterSizeSet && !maxDiameterSet) {
120-
// only clustering size is set, try diameters of 50, 100 and 200 um
121-
for (unsigned clusterDiameter2 : options_->getSinkClusteringDiameters()) {
122-
// clang-format off
123-
debugPrint(logger_, CTS, "clustering", 1, "**** match.run({}, {}, {}) ****",
124-
clusterSize, clusterDiameter2, wireSegmentUnit_);
125-
// clang-format on
126-
float maxDiameter2 = clusterDiameter2 * (float) options_->getDbUnits()
127-
/ wireSegmentUnit_;
128-
matching.run(clusterSize,
129-
maxDiameter2,
130-
wireSegmentUnit_,
131-
bestClusterSize,
132-
bestDiameter);
133-
}
134-
} else { // neighther clustering size nor diameter is set
135-
// try diameters of 50, 100 and 200 um
136-
for (unsigned clusterDiameter2 : clusterDiameters()) {
137-
// try clustering sizes of 10, 20 and 30
138-
for (unsigned clusterSize2 : options_->getSinkClusteringSizes()) {
139-
// clang-format off
140-
debugPrint(logger_, CTS, "clustering", 1, "**** match.run({}, {}, {}) ****",
141-
clusterSize2, clusterDiameter2, wireSegmentUnit_);
142-
// clang-format on
143-
float maxDiameter2 = clusterDiameter2 * (float) options_->getDbUnits()
144-
/ wireSegmentUnit_;
145-
matching.run(clusterSize2,
146-
maxDiameter2,
147-
wireSegmentUnit_,
148-
bestClusterSize,
149-
bestDiameter);
150-
}
151-
}
96+
// clang-format off
97+
debugPrint(logger_, CTS, "clustering", 1, "**** match.run({}, {}, {}) ****",
98+
clusterSize, maxDiameter, wireSegmentUnit_);
99+
// clang-format on
100+
matching.run(clusterSize,
101+
maxDiameter,
102+
wireSegmentUnit_,
103+
bestClusterSize,
104+
bestDiameter);
105+
std::string size_log, diameter_log;
106+
size_log = diameter_log = "";
107+
if (!maxDiameterSet) {
108+
diameter_log = "max ";
109+
bestDiameter = matching.getMaxDiameter();
110+
}
111+
if (!clusterSizeSet) {
112+
size_log = "max ";
113+
bestClusterSize = matching.getMaxSize();
152114
}
153-
154115
if (clusterSizeSet || maxDiameterSet) {
155116
logger_->info(
156117
CTS,
157118
204,
158-
"A clustering solution was found from clustering size of {} "
159-
"and clustering diameter of {:0.0f}.",
119+
"A clustering solution was found from " + size_log + "clustering size of {} "
120+
"and " + diameter_log + "clustering diameter of {:0.0f}.",
160121
bestClusterSize,
161122
std::round(bestDiameter / options_->getDbUnits() * wireSegmentUnit_));
162123
logger_->info(CTS,
@@ -168,8 +129,8 @@ void HTreeBuilder::preSinkClustering(
168129
logger_->info(
169130
CTS,
170131
206,
171-
"Best clustering solution was found from clustering size of {} "
172-
"and clustering diameter of {:0.0f}.",
132+
"Best clustering solution was found from max clustering size of {} "
133+
"and max clustering diameter of {:0.0f}.",
173134
bestClusterSize,
174135
std::round(bestDiameter / options_->getDbUnits() * wireSegmentUnit_));
175136
}
@@ -1237,18 +1198,19 @@ void HTreeBuilder::run()
12371198
unsigned clusterSize = (type_ == TreeType::MacroTree)
12381199
? options_->getMacroSinkClusteringSize()
12391200
: options_->getSinkClusteringSize();
1240-
bool useMaxCap = (type_ == TreeType::MacroTree)
1241-
? false
1242-
: options_->getSinkClusteringUseMaxCap();
1201+
bool use_max_diameter = (type_ == TreeType::MacroTree)
1202+
? options_->isMacroMaxDiameterSet()
1203+
: options_->isMaxDiameterSet();
1204+
bool use_max_size = (type_ == TreeType::MacroTree)
1205+
? options_->isMacroSinkClusteringSizeSet()
1206+
: options_->isSinkClusteringSizeSet();
1207+
bool useMaxCap = !(use_max_size && use_max_diameter);
12431208

12441209
logger_->info(
12451210
CTS, 27, "Generating H-Tree topology for net {}.", clock_.getName());
12461211
logger_->info(CTS, 28, " Total number of sinks: {}.", clock_.getNumSinks());
12471212
if (options_->getSinkClustering()) {
1248-
if (useMaxCap) {
1249-
logger_->info(
1250-
CTS, 90, " Sinks will be clustered based on buffer max cap.");
1251-
} else {
1213+
if (!useMaxCap) {
12521214
logger_->info(
12531215
CTS,
12541216
29,
@@ -1257,6 +1219,23 @@ void HTreeBuilder::run()
12571219
type_ == TreeType::MacroTree ? "Macro " : "Register",
12581220
clusterSize,
12591221
clusterDiameter);
1222+
} else if (use_max_diameter && !use_max_size) {
1223+
logger_->info(CTS,
1224+
59,
1225+
" {} sinks will be clustered with maximum cluster diameter "
1226+
"of {:.1f} um and based on buffer max cap.",
1227+
type_ == TreeType::MacroTree ? "Macro " : "Register",
1228+
clusterDiameter);
1229+
} else if (!use_max_diameter && use_max_size) {
1230+
logger_->info(CTS,
1231+
60,
1232+
" {} sinks will be clustered in groups of up to {} and "
1233+
"based on buffer max cap.",
1234+
type_ == TreeType::MacroTree ? "Macro " : "Register",
1235+
clusterSize);
1236+
} else {
1237+
logger_->info(
1238+
CTS, 90, " Sinks will be clustered based on buffer max cap.");
12601239
}
12611240
}
12621241
logger_->info(

‎src/cts/src/SinkClustering.cpp‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ SinkClustering::SinkClustering(const CtsOptions* options,
3434
techChar_(techChar),
3535
maxInternalDiameter_(10),
3636
capPerUnit_(0.0),
37-
useMaxCapLimit_((HTree->getTreeType() == TreeType::MacroTree)
38-
? false
39-
: options->getSinkClusteringUseMaxCap()),
37+
use_max_diameter_((HTree->getTreeType() == TreeType::MacroTree)
38+
? options->isMacroMaxDiameterSet()
39+
: options->isMaxDiameterSet()),
40+
use_max_size_((HTree->getTreeType() == TreeType::MacroTree)
41+
? options->isMacroSinkClusteringSizeSet()
42+
: options->isSinkClusteringSizeSet()),
43+
useMaxCapLimit_(!(use_max_size_ && use_max_diameter_)),
4044
scaleFactor_(1),
4145
HTree_(HTree)
4246
{
@@ -203,6 +207,10 @@ bool SinkClustering::findBestMatching(const unsigned groupSize)
203207
// Keeps track of the total cost of each solution.
204208
vector<double> costs(groupSize, 0);
205209
vector<double> previousCosts(groupSize, 0);
210+
// Has the max diameter of each solution.
211+
vector<double> max_diameter(groupSize, 0);
212+
// Has the max size of each solution.
213+
vector<unsigned> max_size(groupSize, 0);
206214
// Has the points for each cluster of each solution.
207215
vector<vector<vector<Point<double>>>> solutionPoints;
208216
// Has the points index for each cluster of each solution.
@@ -269,6 +277,9 @@ bool SinkClustering::findBestMatching(const unsigned groupSize)
269277
solutionPoints[j][clusters[j]].size(),
270278
distanceCost,
271279
capCost);
280+
max_diameter[j] = std::max(max_diameter[j], previousCosts[j]);
281+
max_size[j] = std::max(
282+
max_size[j], (unsigned) solutionPoints[j][clusters[j]].size());
272283
// The cost is computed as the highest cost found on the current
273284
// cluster
274285
if (previousCosts[j] == 0) {
@@ -339,6 +350,9 @@ bool SinkClustering::findBestMatching(const unsigned groupSize)
339350
solutionPoints[j][clusters[j]].size(),
340351
distanceCost,
341352
capCost);
353+
max_diameter[j] = std::max(max_diameter[j], previousCosts[j]);
354+
max_size[j] = std::max(
355+
max_size[j], (unsigned) solutionPoints[j][clusters[j]].size());
342356
if (previousCosts[j] == 0) {
343357
previousCosts[j] = maxInternalDiameter_;
344358
}
@@ -385,6 +399,19 @@ bool SinkClustering::findBestMatching(const unsigned groupSize)
385399
// Save the solution for the Tree Builder.
386400
if (bestSolutionFound) {
387401
bestSolution_ = solutions[bestSolution];
402+
// Calculate max diameter to save
403+
double span;
404+
if (xSpan_ == 0 && ySpan_ == 0) {
405+
span = 1; // arbitrary
406+
} else if (xSpan_ == 0) {
407+
span = ySpan_;
408+
} else if (ySpan_ == 0) {
409+
span = xSpan_;
410+
} else {
411+
span = std::min(xSpan_, ySpan_);
412+
}
413+
max_diameter_ = max_diameter[bestSolution] * span;
414+
max_size_ = max_size[bestSolution];
388415
// clang-format off
389416
debugPrint(logger_, CTS, "clustering", 1, "Best solution from group "
390417
"{} has cost of {:0.3f} and size of {}", bestSolution,
@@ -412,11 +439,10 @@ bool SinkClustering::isLimitExceeded(const unsigned size,
412439
const double capCost,
413440
const unsigned sizeLimit)
414441
{
415-
if (useMaxCapLimit_) {
416-
return (capCost > options_->getSinkBufferInputCap() * kMaxCapFactor);
417-
}
418-
419-
return (size >= sizeLimit || cost > maxInternalDiameter_);
442+
return (useMaxCapLimit_
443+
&& (capCost > options_->getSinkBufferInputCap() * kMaxCapFactor))
444+
|| (use_max_size_ && (size >= sizeLimit))
445+
|| (use_max_diameter_ && (cost > maxInternalDiameter_));
420446
}
421447

422448
void SinkClustering::writePlotFile(unsigned groupSize)

‎src/cts/src/SinkClustering.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class SinkClustering
5555

5656
double getWireLength(const std::vector<Point<double>>& points) const;
5757
int getScaleFactor() const { return scaleFactor_; }
58+
double getMaxDiameter() const { return max_diameter_; }
59+
double getMaxSize() const { return max_size_; }
5860

5961
private:
6062
void normalizePoints(float maxDiameter = 10);
@@ -85,13 +87,17 @@ class SinkClustering
8587
std::vector<std::vector<unsigned>> bestSolution_;
8688
float maxInternalDiameter_;
8789
float capPerUnit_;
90+
bool use_max_diameter_;
91+
bool use_max_size_;
8892
bool useMaxCapLimit_;
8993
int scaleFactor_;
9094
static constexpr double kMaxCapFactor = 10;
9195
HTreeBuilder* HTree_;
9296
bool firstRun_ = true;
9397
double xSpan_ = 0.0;
9498
double ySpan_ = 0.0;
99+
double max_diameter_ = 0.0;
100+
double max_size_ = 0.0;
95101
double bestSolutionCost_ = std::numeric_limits<double>::max();
96102
};
97103

0 commit comments

Comments
 (0)