Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions src/odb/include/odb/3dblox.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ class ThreeDBlox
std::unordered_set<odb::dbTech*> written_techs_;
std::unordered_set<odb::dbLib*> written_libs_;
std::unordered_set<std::string> read_files_;
std::unordered_set<odb::dbChip*> insts_with_def_;

int call_depth_ = 0;
std::vector<std::pair<odb::dbChipRegion*, std::string>> pending_bmaps_;
void processPendingBmaps();
};
} // namespace odb
96 changes: 70 additions & 26 deletions src/odb/src/3dblox/3dblox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ThreeDBlox::ThreeDBlox(utl::Logger* logger, odb::dbDatabase* db, sta::Sta* sta)

void ThreeDBlox::readDbv(const std::string& dbv_file)
{
call_depth_++;
read_files_.insert(std::filesystem::absolute(dbv_file).string());
DbvParser parser(logger_);
DbvData data = parser.parseFile(dbv_file);
Expand All @@ -82,6 +83,11 @@ void ThreeDBlox::readDbv(const std::string& dbv_file)
for (const auto& [_, chiplet] : data.chiplet_defs) {
createChiplet(chiplet);
}

call_depth_--;
if (call_depth_ == 0) {
processPendingBmaps();
}
}

void ThreeDBlox::buildChipNetsFromVerilog(dbChip* chip, const DbxData& data)
Expand Down Expand Up @@ -174,6 +180,7 @@ void ThreeDBlox::buildChipNetsFromVerilog(dbChip* chip, const DbxData& data)

void ThreeDBlox::readDbx(const std::string& dbx_file)
{
call_depth_++;
read_files_.insert(std::filesystem::absolute(dbx_file).string());
DbxParser parser(logger_);
DbxData data = parser.parseFile(dbx_file);
Expand All @@ -198,6 +205,35 @@ void ThreeDBlox::readDbx(const std::string& dbx_file)
chip_path->addEntry(path_insts, region_inst, entry.negated);
}
}

call_depth_--;
if (call_depth_ == 0) {
processPendingBmaps();
}
}

void ThreeDBlox::processPendingBmaps()
{
for (const auto& [chip_region, bmap] : pending_bmaps_) {
auto chip = chip_region->getChip();
if (chip->getChipType() != dbChip::ChipType::HIER
&& chip->getBlock() == nullptr) {
// blackbox stage, create block
auto block = odb::dbBlock::create(chip, chip->getName());
const int x_min = chip->getScribeLineWest() + chip->getSealRingWest();
const int y_min = chip->getScribeLineSouth() + chip->getSealRingSouth();
const int x_max = x_min + chip->getWidth();
const int y_max = y_min + chip->getHeight();
block->setDieArea(Rect(x_min, y_min, x_max, y_max));
block->setCoreArea(Rect(x_min, y_min, x_max, y_max));
}
BmapParser parser(logger_);
BumpMapData data = parser.parseFile(bmap);
for (const auto& entry : data.entries) {
createBump(entry, chip_region);
}
}
pending_bmaps_.clear();
}

void ThreeDBlox::check()
Expand Down Expand Up @@ -398,6 +434,18 @@ static std::string getFileName(const std::string& tech_file_path)
return tech_file_path_fs.stem().string();
}

static inline void readDefForChip(odb::dbDatabase* db,
utl::Logger* logger,
odb::dbChip* chip,
const std::string& def_file)
{
odb::defin def_reader(db, logger, odb::defin::DEFAULT);
std::vector<odb::dbLib*> search_libs;
search_libs.assign(db->getLibs().begin(), db->getLibs().end());
// No callbacks here as we are going to give one postRead3Dbx later
def_reader.readChip(search_libs, def_file.c_str(), chip, false);
}

void ThreeDBlox::createChiplet(const ChipletDef& chiplet)
{
dbTech* tech = nullptr;
Expand Down Expand Up @@ -454,16 +502,7 @@ void ThreeDBlox::createChiplet(const ChipletDef& chiplet)

// Read DEF file
if (!chiplet.external.def_file.empty()) {
odb::defin def_reader(db_, logger_, odb::defin::DEFAULT);
std::vector<odb::dbLib*> search_libs;
for (odb::dbLib* lib : db_->getLibs()) {
search_libs.push_back(lib);
}
// No callbacks here as we are going to give one postRead3Dbx later
def_reader.readChip(search_libs,
chiplet.external.def_file.c_str(),
chip,
/*issue_callback*/ false);
readDefForChip(db_, logger_, chip, chiplet.external.def_file);
}
const int dbu_per_micron = db_->getDbuPerMicron();
if (chiplet.design_width != -1.0) {
Expand Down Expand Up @@ -500,17 +539,6 @@ void ThreeDBlox::createChiplet(const ChipletDef& chiplet)

chip->setOffset(Point(std::round(chiplet.offset.x * dbu_per_micron),
std::round(chiplet.offset.y * dbu_per_micron)));
if (chip->getChipType() != dbChip::ChipType::HIER
&& chip->getBlock() == nullptr) {
// blackbox stage, create block
auto block = odb::dbBlock::create(chip, chiplet.name.c_str());
const int x_min = chip->getScribeLineWest() + chip->getSealRingWest();
const int y_min = chip->getScribeLineSouth() + chip->getSealRingSouth();
const int x_max = x_min + chip->getWidth();
const int y_max = y_min + chip->getHeight();
block->setDieArea(Rect(x_min, y_min, x_max, y_max));
block->setCoreArea(Rect(x_min, y_min, x_max, y_max));
}
for (const auto& [_, region] : chiplet.regions) {
createRegion(region, chip);
}
Expand Down Expand Up @@ -556,11 +584,7 @@ void ThreeDBlox::createRegion(const ChipletRegion& region, dbChip* chip)
chip_region->setBox(box);
// Read bump map file
if (!region.bmap.empty()) {
BmapParser parser(logger_);
BumpMapData data = parser.parseFile(region.bmap);
for (const auto& entry : data.entries) {
createBump(entry, chip_region);
}
pending_bmaps_.emplace_back(chip_region, region.bmap);
}
}

Expand Down Expand Up @@ -677,6 +701,26 @@ void ThreeDBlox::createChipInst(const ChipletInst& chip_inst)
chip_inst.reference,
chip_inst.name);
}

if (!chip_inst.external.def_file.empty()) {
if (insts_with_def_.contains(chip)) {
logger_->error(utl::ODB,
546,
"3DBX Parser Error: There can't be 2 instances of the "
"same chiplet {} with a def file each",
chip->getName());
}
insts_with_def_.insert(chip);
if (chip->getBlock() != nullptr) {
logger_->error(utl::ODB,
547,
"3DBX Parser Error: There can't be 2 instances of the "
"same chiplet {} with a def file each",
chip->getName());
}
readDefForChip(db_, logger_, chip, chip_inst.external.def_file);
}
Comment on lines +705 to +722
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.

medium

The logic for reading a DEF file for a chiplet is duplicated between createChiplet and createChipInst. This logic (checking for the property, destroying the existing block, populating search libraries, and reading the chip) should be refactored into a shared free function within a namespace to improve maintainability and ensure consistency.

References
  1. Helper logic should be defined as a free function in a namespace rather than as a local lambda within a function.


dbChipInst* inst = dbChipInst::create(db_->getChip(), chip, chip_inst.name);
auto orient_str = chip_inst.orient;
if (dup_orient_map.contains(orient_str)) {
Expand Down
10 changes: 9 additions & 1 deletion src/odb/src/3dblox/dbxWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DbxWriter::DbxWriter(utl::Logger* logger, odb::dbDatabase* db)

void DbxWriter::writeChiplet(const std::string& filename, odb::dbChip* chiplet)
{
written_def_chips_.clear();
YAML::Node root;
writeYamlContent(root, chiplet);
writeYamlToFile(filename, root);
Expand Down Expand Up @@ -65,8 +66,15 @@ void DbxWriter::writeChipletInsts(YAML::Node& instances_node,
void DbxWriter::writeChipletInst(YAML::Node& instance_node,
odb::dbChipInst* inst)
{
auto master_name = inst->getMasterChip()->getName();
auto chip = inst->getMasterChip();
auto master_name = chip->getName();
instance_node["reference"] = master_name;

if (written_def_chips_.find(chip) == written_def_chips_.end()) {
YAML::Node external_node = instance_node["external"];
external_node["def_file"] = std::string(master_name) + ".def";
written_def_chips_.insert(chip);
}
}

void DbxWriter::writeStack(YAML::Node& stack_node, odb::dbChip* chiplet)
Expand Down
3 changes: 3 additions & 0 deletions src/odb/src/3dblox/dbxWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <string>
#include <unordered_set>
#include <vector>

#include "baseWriter.h"
Expand Down Expand Up @@ -42,6 +43,8 @@ class DbxWriter : public BaseWriter
void writeConnection(YAML::Node& connection_node, odb::dbChipConn* conn);
std::string buildPath(const std::vector<dbChipInst*>& path_insts,
odb::dbChipRegionInst* region);

std::unordered_set<odb::dbChip*> written_def_chips_;
};

} // namespace odb
Loading