Skip to content

Commit a2bceac

Browse files
committed
odb: recursive writeDbv and writeDbx
Signed-off-by: osamahammad21 <[email protected]>
1 parent 22759b6 commit a2bceac

File tree

4 files changed

+98
-13
lines changed

4 files changed

+98
-13
lines changed

src/OpenRoad.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ void OpenRoad::read3DBloxBMap(const std::string& filename)
505505
void OpenRoad::write3Dbv(const std::string& filename)
506506
{
507507
odb::ThreeDBlox writer(logger_, db_, sta_);
508-
writer.writeDbv(filename);
508+
writer.writeDbv(filename, db_->getChip());
509509
}
510510
void OpenRoad::readDb(const char* filename, bool hierarchy)
511511
{

src/odb/include/odb/3dblox.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <string>
7+
#include <unordered_set>
78
#include <vector>
89

910
namespace utl {
@@ -26,6 +27,8 @@ class BumpMapEntry;
2627
class dbChipRegion;
2728
class dbBlock;
2829
class dbInst;
30+
class dbTech;
31+
class dbLib;
2932

3033
class ThreeDBlox
3134
{
@@ -36,7 +39,8 @@ class ThreeDBlox
3639
void readDbx(const std::string& dbx_file);
3740
void readBMap(const std::string& bmap_file);
3841
void check();
39-
void writeDbv(const std::string& dbv_file);
42+
void writeDbv(const std::string& dbv_file, odb::dbChip* chip);
43+
void writeDbx(const std::string& dbx_file, odb::dbChip* chip);
4044

4145
private:
4246
void createChiplet(const ChipletDef& chiplet);
@@ -54,5 +58,7 @@ class ThreeDBlox
5458
utl::Logger* logger_ = nullptr;
5559
odb::dbDatabase* db_ = nullptr;
5660
sta::Sta* sta_ = nullptr;
61+
std::unordered_set<odb::dbTech*> written_techs_;
62+
std::unordered_set<odb::dbLib*> written_libs_;
5763
};
5864
} // namespace odb

src/odb/src/3dblox/3dblox.cpp

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
#include "odb/dbTransform.h"
2222
#include "odb/dbTypes.h"
2323
#include "odb/defin.h"
24+
#include "odb/defout.h"
2425
#include "odb/geom.h"
2526
#include "odb/lefin.h"
27+
#include "odb/lefout.h"
2628
#include "sta/Sta.hh"
2729
#include "utl/Logger.h"
28-
30+
#include "utl/ScopedTemporaryFile.h"
2931
namespace odb {
3032

3133
static std::map<std::string, std::string> dup_orient_map
@@ -94,10 +96,91 @@ void ThreeDBlox::check()
9496
checker.check(db_->getChip());
9597
}
9698

97-
void ThreeDBlox::writeDbv(const std::string& dbv_file)
99+
namespace {
100+
std::unordered_set<odb::dbTech*> getUsedTechs(odb::dbChip* chip)
101+
{
102+
std::unordered_set<odb::dbTech*> techs;
103+
for (auto inst : chip->getChipInsts()) {
104+
if (inst->getMasterChip()->getTech() != nullptr) {
105+
techs.insert(inst->getMasterChip()->getTech());
106+
}
107+
}
108+
return techs;
109+
}
110+
std::unordered_set<odb::dbLib*> getUsedLibs(odb::dbChip* chip)
111+
{
112+
std::unordered_set<odb::dbLib*> libs;
113+
for (auto inst : chip->getChipInsts()) {
114+
auto master_chip = inst->getMasterChip();
115+
if (master_chip->getBlock() != nullptr) {
116+
for (auto inst : master_chip->getBlock()->getInsts()) {
117+
libs.insert(inst->getMaster()->getLib());
118+
}
119+
}
120+
}
121+
return libs;
122+
}
123+
std::string getResultsDirectoryPath(const std::string& file_path)
98124
{
125+
std::string current_dir_path;
126+
auto path = std::filesystem::path(file_path);
127+
if (path.has_parent_path()) {
128+
current_dir_path = path.parent_path().string() + "/";
129+
}
130+
return current_dir_path;
131+
}
132+
} // namespace
133+
void ThreeDBlox::writeDbv(const std::string& dbv_file, odb::dbChip* chip)
134+
{
135+
if (chip == nullptr) {
136+
return;
137+
}
138+
///////////Results Directory Path ///////////
139+
std::string current_dir_path = getResultsDirectoryPath(dbv_file);
140+
////////////////////////////////////////////
141+
142+
for (auto inst : chip->getChipInsts()) {
143+
auto master_chip = inst->getMasterChip();
144+
if (master_chip->getChipType() == odb::dbChip::ChipType::HIER) {
145+
writeDbx(current_dir_path + master_chip->getName() + ".3dbx",
146+
master_chip);
147+
}
148+
}
149+
// write used techs
150+
for (auto tech : getUsedTechs(chip)) {
151+
if (written_techs_.find(tech) != written_techs_.end()) {
152+
continue;
153+
}
154+
written_techs_.insert(tech);
155+
std::string tech_file_path = current_dir_path + tech->getName() + ".lef";
156+
utl::OutStreamHandler stream_handler(tech_file_path.c_str());
157+
odb::lefout lef_writer(logger_, stream_handler.getStream());
158+
lef_writer.writeTech(tech);
159+
}
160+
// write used libs
161+
for (auto lib : getUsedLibs(chip)) {
162+
if (written_libs_.find(lib) != written_libs_.end()) {
163+
continue;
164+
}
165+
written_libs_.insert(lib);
166+
std::string lib_file_path = current_dir_path + lib->getName() + "_lib.lef";
167+
utl::OutStreamHandler stream_handler(lib_file_path.c_str());
168+
odb::lefout lef_writer(logger_, stream_handler.getStream());
169+
lef_writer.writeLib(lib);
170+
}
171+
99172
DbvWriter writer(logger_, db_);
100-
writer.writeChiplet(dbv_file, db_->getChip());
173+
writer.writeChiplet(dbv_file, chip);
174+
}
175+
176+
void ThreeDBlox::writeDbx(const std::string& dbx_file, odb::dbChip* chip)
177+
{
178+
if (chip == nullptr) {
179+
return;
180+
}
181+
// TODO: implement
182+
std::string current_dir_path = getResultsDirectoryPath(dbx_file);
183+
writeDbv(current_dir_path + chip->getName() + ".3dbv", chip);
101184
}
102185

103186
void ThreeDBlox::calculateSize(dbChip* chip)
@@ -142,11 +225,13 @@ dbChip::ChipType getChipType(const std::string& type, utl::Logger* logger)
142225
logger->error(
143226
utl::ODB, 527, "3DBV Parser Error: Invalid chip type: {}", type);
144227
}
228+
145229
std::string getFileName(const std::string& tech_file_path)
146230
{
147231
std::filesystem::path tech_file_path_fs(tech_file_path);
148232
return tech_file_path_fs.stem().string();
149233
}
234+
150235
void ThreeDBlox::createChiplet(const ChipletDef& chiplet)
151236
{
152237
dbTech* tech = nullptr;
@@ -239,6 +324,7 @@ void ThreeDBlox::createChiplet(const ChipletDef& chiplet)
239324
createRegion(region, chip);
240325
}
241326
}
327+
242328
dbChipRegion::Side getChipRegionSide(const std::string& side,
243329
utl::Logger* logger)
244330
{
@@ -348,6 +434,7 @@ dbChip* ThreeDBlox::createDesignTopChiplet(const DesignDef& design)
348434
db_->setTopChip(chip);
349435
return chip;
350436
}
437+
351438
void ThreeDBlox::createChipInst(const ChipletInst& chip_inst)
352439
{
353440
auto chip = db_->findChip(chip_inst.reference.c_str());

src/odb/src/3dblox/dbvWriter.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ void DbvWriter::writeLef(YAML::Node& external_node, odb::dbChip* chiplet)
200200
if (chiplet->getTech()) {
201201
auto tech = chiplet->getTech();
202202
std::string tech_file = tech->getName() + ".lef";
203-
std::string tech_file_path = current_dir_path_ + tech_file;
204-
utl::OutStreamHandler stream_handler(tech_file_path.c_str());
205-
odb::lefout lef_writer(logger_, stream_handler.getStream());
206-
lef_writer.writeTech(tech);
207203
YAML::Node list_node;
208204
list_node.SetStyle(YAML::EmitterStyle::Flow);
209205
list_node.push_back(tech_file);
@@ -226,10 +222,6 @@ void DbvWriter::writeLef(YAML::Node& external_node, odb::dbChip* chiplet)
226222
external_node["LEF_file"] = list_node;
227223
for (auto lib : libs) {
228224
std::string lef_file = std::string(lib->getName()) + "_lib.lef";
229-
std::string lef_file_path = current_dir_path_ + lef_file;
230-
utl::OutStreamHandler stream_handler(lef_file_path.c_str());
231-
odb::lefout lef_writer(logger_, stream_handler.getStream());
232-
lef_writer.writeLib(lib);
233225
external_node["LEF_file"].push_back(lef_file);
234226
}
235227
}

0 commit comments

Comments
 (0)