Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cts: add recording of masters used to report_cts #6799

Merged
merged 4 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions src/cts/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ add_library(cts_lib
TritonCTS.cpp
Clustering.cpp
LevelBalancer.cpp
CtsOptions.cpp
)

swig_lib(NAME cts
Expand Down
72 changes: 72 additions & 0 deletions src/cts/src/CtsOptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/////////////////////////////////////////////////////////////////////////////
//
// BSD 3-Clause License
//
// Copyright (c) 2025, The Regents of the University of California
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////

#include "CtsOptions.h"

namespace cts {

CtsOptions::MasterType CtsOptions::getType(odb::dbInst* inst) const
{
if (inst->getName().substr(0, dummyload_prefix_.size())
== dummyload_prefix_) {
return MasterType::DUMMY;
}

return MasterType::TREE;
}

void CtsOptions::inDbInstCreate(odb::dbInst* inst)
{
recordBuffer(inst->getMaster(), getType(inst));
}

void CtsOptions::inDbInstCreate(odb::dbInst* inst, odb::dbRegion* region)
{
recordBuffer(inst->getMaster(), getType(inst));
}

void CtsOptions::recordBuffer(odb::dbMaster* master, MasterType type)
{
switch (type) {
case MasterType::DUMMY:
dummy_count_[master]++;
break;
case MasterType::TREE:
buffer_count_[master]++;
break;
}
}

} // namespace cts
26 changes: 22 additions & 4 deletions src/cts/src/CtsOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,24 @@
#include "CtsObserver.h"
#include "Util.h"
#include "odb/db.h"
#include "odb/dbBlockCallBackObj.h"
#include "utl/Logger.h"

namespace stt {
class SteinerTreeBuilder;
}
namespace cts {

class CtsOptions
class CtsOptions : public odb::dbBlockCallBackObj
{
public:
enum class MasterType
{
DUMMY,
TREE
};
using MasterCount = std::map<odb::dbMaster*, int>;

CtsOptions(utl::Logger* logger, stt::SteinerTreeBuilder* sttBuildder)
: logger_(logger), sttBuilder_(sttBuildder)
{
Expand Down Expand Up @@ -250,12 +258,20 @@ class CtsOptions
float getDelayBufferDerate() const { return delayBufferDerate_; }
void enableDummyLoad(bool dummyLoad) { dummyLoad_ = dummyLoad; }
bool dummyLoadEnabled() const { return dummyLoad_; }
std::string getDummyLoadPrefix() const { return dummyload_prefix_; }
void setCtsLibrary(const char* name) { ctsLibrary_ = name; }
const char* getCtsLibrary() { return ctsLibrary_.c_str(); }
bool isCtsLibrarySet() { return !ctsLibrary_.empty(); }

void recordBuffer(odb::dbMaster* master) { buffer_count_[master]++; }
std::map<odb::dbMaster*, int> getBufferCount() const { return buffer_count_; }
void recordBuffer(odb::dbMaster* master, MasterType type);
const MasterCount& getBufferCount() const { return buffer_count_; }
const MasterCount& getDummyCount() const { return dummy_count_; }

MasterType getType(odb::dbInst* inst) const;

// Callbacks
void inDbInstCreate(odb::dbInst* inst) override;
void inDbInstCreate(odb::dbInst* inst, odb::dbRegion* region) override;

private:
std::string clockNets_ = "";
Expand Down Expand Up @@ -315,7 +331,9 @@ class CtsOptions
bool dummyLoad_ = true;
float delayBufferDerate_ = 1.0; // no derate
std::string ctsLibrary_;
std::map<odb::dbMaster*, int> buffer_count_;
MasterCount buffer_count_;
std::string dummyload_prefix_ = "clkload";
MasterCount dummy_count_;
};

} // namespace cts
21 changes: 15 additions & 6 deletions src/cts/src/TritonCTS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ TritonCTS::~TritonCTS()

void TritonCTS::runTritonCts()
{
odb::dbChip* chip = db_->getChip();
odb::dbBlock* block = chip->getBlock();
options_->addOwner(block);

setupCharacterization();
findClockRoots();
populateTritonCTS();
Expand Down Expand Up @@ -122,6 +126,7 @@ void TritonCTS::runTritonCts()
sinkBuffers_.clear();
regTreeRootBufIndex_ = 0;
delayBufIndex_ = 0;
options_->removeOwner();
}

TreeBuilder* TritonCTS::addBuilder(CtsOptions* options,
Expand Down Expand Up @@ -568,10 +573,14 @@ void TritonCTS::reportCtsMetrics()
<< ".\n";
file << "Total number of Sinks: " << options_->getNumSinks() << ".\n";

file << "Cells used:\n";
file << "Buffers used:\n";
for (const auto& [master, count] : options_->getBufferCount()) {
file << " " << master->getName() << ": " << count << "\n";
}
file << "Dummys used:\n";
for (const auto& [master, count] : options_->getDummyCount()) {
file << " " << master->getName() << ": " << count << "\n";
}
file.close();

} else {
Expand All @@ -587,6 +596,10 @@ void TritonCTS::reportCtsMetrics()
for (const auto& [master, count] : options_->getBufferCount()) {
logger_->report(" {}: {}", master->getName(), count);
}
logger_->report("Dummys used:");
for (const auto& [master, count] : options_->getDummyCount()) {
logger_->report(" {}: {}", master->getName(), count);
}
}
}

Expand Down Expand Up @@ -1265,7 +1278,6 @@ Clock TritonCTS::forkRegisterClockNetwork(
odb::dbMaster* master = db_->findMaster(options_->getRootBuffer().c_str());
topBufferName = "clkbuf_regs_" + std::to_string(regTreeRootBufIndex_++) + "_"
+ clockNet.getSdcName();
options_->recordBuffer(master);
odb::dbInst* clockBuf = odb::dbInst::create(
block_, master, topBufferName.c_str(), false, target_module);
odb::dbITerm* inputTerm = getFirstInput(clockBuf);
Expand Down Expand Up @@ -1615,7 +1627,6 @@ void TritonCTS::createClockBuffers(Clock& clockNet, odb::dbModule* parent)
unsigned numBuffers = 0;
clockNet.forEachClockBuffer([&](ClockInst& inst) {
odb::dbMaster* master = db_->findMaster(inst.getMaster().c_str());
options_->recordBuffer(master);
odb::dbInst* newInst = odb::dbInst::create(
block_, master, inst.getName().c_str(), false, parent);
newInst->setSourceType(odb::dbSourceType::TIMING);
Expand Down Expand Up @@ -2048,8 +2059,7 @@ ClockInst& TritonCTS::placeDummyCell(Clock& clockNet,
dummyCell->name());
}
std::string cellName
= std::string("clkload") + std::to_string(dummyLoadIndex_++);
options_->recordBuffer(master);
= options_->getDummyLoadPrefix() + std::to_string(dummyLoadIndex_++);
dummyInst = odb::dbInst::create(block_, master, cellName.c_str());
dummyInst->setSourceType(odb::dbSourceType::TIMING);
dummyInst->setLocation(inst->getX(), inst->getY());
Expand Down Expand Up @@ -2389,7 +2399,6 @@ odb::dbInst* TritonCTS::insertDelayBuffer(odb::dbInst* driver,
std::string newBufName
= "delaybuf_" + std::to_string(delayBufIndex_++) + "_" + clockName;
odb::dbMaster* master = db_->findMaster(options_->getRootBuffer().c_str());
options_->recordBuffer(master);
odb::dbInst* newBuf = odb::dbInst::create(block_, master, newBufName.c_str());

newBuf->setSourceType(odb::dbSourceType::TIMING);
Expand Down
6 changes: 4 additions & 2 deletions src/cts/test/array.ok
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ Total number of Clock Roots: 1.
Total number of Buffers Inserted: 231.
Total number of Clock Subnets: 231.
Total number of Sinks: 2475.
Buffers used:
BUF_X4: 233
Cells used:
BUF_X4: 231
Dummys used:
BUF_X4: 2
INV_X1: 6
INV_X16: 6
INV_X4: 23
Expand Down
3 changes: 2 additions & 1 deletion src/cts/test/simple_test.ok
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Total number of Clock Roots: 1.
Total number of Buffers Inserted: 3.
Total number of Clock Subnets: 3.
Total number of Sinks: 16.
Buffers used:
Cells used:
CLKBUF_X3: 3
Dummys used:
No differences found.
6 changes: 4 additions & 2 deletions src/cts/test/simple_test_clustered.ok
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ Total number of Clock Roots: 1.
Total number of Buffers Inserted: 35.
Total number of Clock Subnets: 35.
Total number of Sinks: 300.
Buffers used:
CLKBUF_X3: 37
Cells used:
CLKBUF_X3: 35
Dummys used:
CLKBUF_X3: 2