Skip to content

Commit b57cfc6

Browse files
Merge pull request #8775 from rafaelmoresco/dbxwriter
odb: add 3dbxWriter
2 parents 1177304 + 75c90d9 commit b57cfc6

File tree

13 files changed

+265
-1
lines changed

13 files changed

+265
-1
lines changed

include/ord/OpenRoad.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ class OpenRoad
225225
void read3Dbv(const std::string& filename);
226226
void read3Dbx(const std::string& filename);
227227
void write3Dbv(const std::string& filename);
228+
void write3Dbx(const std::string& filename);
228229
void read3DBloxBMap(const std::string& filename);
229230

230231
void readDb(std::istream& stream);

src/OpenRoad.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ void OpenRoad::write3Dbv(const std::string& filename)
507507
odb::ThreeDBlox writer(logger_, db_, sta_);
508508
writer.writeDbv(filename, db_->getChip());
509509
}
510+
void OpenRoad::write3Dbx(const std::string& filename)
511+
{
512+
odb::ThreeDBlox writer(logger_, db_, sta_);
513+
writer.writeDbx(filename, db_->getChip());
514+
}
510515
void OpenRoad::readDb(const char* filename, bool hierarchy)
511516
{
512517
try {

src/OpenRoad.i

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ write_3dbv_cmd(const char *filename)
383383
ord->write3Dbv(filename);
384384
}
385385

386+
void
387+
write_3dbx_cmd(const char *filename)
388+
{
389+
OpenRoad *ord = getOpenRoad();
390+
ord->write3Dbx(filename);
391+
}
392+
386393
void
387394
read_db_cmd(const char *filename, bool hierarchy)
388395
{

src/OpenRoad.tcl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ proc write_3dbv { args } {
191191
ord::write_3dbv_cmd $filename
192192
}
193193

194+
proc write_3dbx { args } {
195+
sta::parse_key_args "write_3dbx" args keys {} flags {}
196+
sta::check_argc_eq1 "write_3dbx" $args
197+
set filename [file nativename [lindex $args 0]]
198+
ord::write_3dbx_cmd $filename
199+
}
200+
194201
sta::define_cmd_args "read_3dbx" {filename}
195202

196203
proc read_3dbx { args } {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "dbvParser.h"
1818
#include "dbvWriter.h"
1919
#include "dbxParser.h"
20+
#include "dbxWriter.h"
2021
#include "objects.h"
2122
#include "odb/db.h"
2223
#include "odb/dbTransform.h"
@@ -179,9 +180,14 @@ void ThreeDBlox::writeDbx(const std::string& dbx_file, odb::dbChip* chip)
179180
if (chip == nullptr) {
180181
return;
181182
}
182-
// TODO: implement
183+
///////////Results Directory Path ///////////
183184
std::string current_dir_path = getResultsDirectoryPath(dbx_file);
185+
////////////////////////////////////////////
186+
184187
writeDbv(current_dir_path + chip->getName() + ".3dbv", chip);
188+
189+
DbxWriter writer(logger_, db_);
190+
writer.writeChiplet(dbx_file, chip);
185191
}
186192

187193
void ThreeDBlox::calculateSize(dbChip* chip)

src/odb/src/3dblox/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_library(3dblox
1010
dbxParser.cpp
1111
baseWriter.cpp
1212
dbvWriter.cpp
13+
dbxWriter.cpp
1314
3dblox.cpp
1415
checker.cpp
1516
)

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

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2019-2025, The OpenROAD Authors
3+
4+
#include "dbxWriter.h"
5+
6+
#include <yaml-cpp/yaml.h>
7+
8+
#include <string>
9+
#include <vector>
10+
11+
#include "baseWriter.h"
12+
#include "odb/db.h"
13+
#include "utl/Logger.h"
14+
15+
namespace odb {
16+
17+
DbxWriter::DbxWriter(utl::Logger* logger, odb::dbDatabase* db)
18+
: BaseWriter(logger, db)
19+
{
20+
}
21+
22+
void DbxWriter::writeChiplet(const std::string& filename, odb::dbChip* chiplet)
23+
{
24+
YAML::Node root;
25+
writeYamlContent(root, chiplet);
26+
writeYamlToFile(filename, root);
27+
}
28+
29+
void DbxWriter::writeYamlContent(YAML::Node& root, odb::dbChip* chiplet)
30+
{
31+
YAML::Node header_node = root["Header"];
32+
writeHeader(header_node);
33+
YAML::Node includes_node = header_node["include"];
34+
includes_node.push_back(std::string(chiplet->getName()) + ".3dbv");
35+
36+
YAML::Node design_node = root["Design"];
37+
writeDesign(design_node, chiplet);
38+
39+
YAML::Node instances_node = root["ChipletInst"];
40+
writeChipletInsts(instances_node, chiplet);
41+
42+
YAML::Node stack_node = root["Stack"];
43+
writeStack(stack_node, chiplet);
44+
45+
YAML::Node connections_node = root["Connection"];
46+
writeConnections(connections_node, chiplet);
47+
}
48+
49+
void DbxWriter::writeDesign(YAML::Node& design_node, odb::dbChip* chiplet)
50+
{
51+
design_node["name"] = chiplet->getName();
52+
}
53+
54+
void DbxWriter::writeChipletInsts(YAML::Node& instances_node,
55+
odb::dbChip* chiplet)
56+
{
57+
for (auto inst : chiplet->getChipInsts()) {
58+
YAML::Node instance_node = instances_node[std::string(inst->getName())];
59+
writeChipletInst(instance_node, inst);
60+
}
61+
}
62+
63+
void DbxWriter::writeChipletInst(YAML::Node& instance_node,
64+
odb::dbChipInst* inst)
65+
{
66+
auto master_name = inst->getMasterChip()->getName();
67+
instance_node["reference"] = master_name;
68+
}
69+
70+
void DbxWriter::writeStack(YAML::Node& stack_node, odb::dbChip* chiplet)
71+
{
72+
for (auto inst : chiplet->getChipInsts()) {
73+
YAML::Node stack_instance_node = stack_node[std::string(inst->getName())];
74+
writeStackInstance(stack_instance_node, inst);
75+
}
76+
}
77+
78+
void DbxWriter::writeStackInstance(YAML::Node& stack_instance_node,
79+
odb::dbChipInst* inst)
80+
{
81+
const double u = inst->getDb()->getDbuPerMicron();
82+
const double loc_x = inst->getLoc().x() / u;
83+
const double loc_y = inst->getLoc().y() / u;
84+
YAML::Node loc_out;
85+
loc_out.SetStyle(YAML::EmitterStyle::Flow);
86+
loc_out.push_back(loc_x);
87+
loc_out.push_back(loc_y);
88+
stack_instance_node["loc"] = loc_out;
89+
stack_instance_node["z"] = inst->getLoc().z() / u;
90+
stack_instance_node["orient"] = inst->getOrient().getString();
91+
}
92+
93+
void DbxWriter::writeConnections(YAML::Node& connections_node,
94+
odb::dbChip* chiplet)
95+
{
96+
for (auto conn : chiplet->getChipConns()) {
97+
YAML::Node connection_node = connections_node[std::string(conn->getName())];
98+
writeConnection(connection_node, conn);
99+
}
100+
}
101+
102+
void DbxWriter::writeConnection(YAML::Node& connection_node,
103+
odb::dbChipConn* conn)
104+
{
105+
const double u = conn->getDb()->getDbuPerMicron();
106+
connection_node["top"]
107+
= buildPath(conn->getTopRegionPath(), conn->getTopRegion());
108+
connection_node["bot"]
109+
= buildPath(conn->getBottomRegionPath(), conn->getBottomRegion());
110+
connection_node["thicness"] = conn->getThickness() / u;
111+
}
112+
113+
std::string DbxWriter::buildPath(const std::vector<dbChipInst*>& path_insts,
114+
odb::dbChipRegionInst* region)
115+
{
116+
if (region == nullptr) {
117+
return "~";
118+
}
119+
120+
std::string path;
121+
for (auto inst : path_insts) {
122+
if (!path.empty()) {
123+
path += "/";
124+
}
125+
path += inst->getName();
126+
}
127+
128+
if (!path.empty()) {
129+
path += ".regions." + region->getChipRegion()->getName();
130+
}
131+
return path;
132+
}
133+
134+
} // namespace odb

src/odb/src/3dblox/dbxWriter.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2019-2025, The OpenROAD Authors
3+
4+
#pragma once
5+
6+
#include <string>
7+
#include <vector>
8+
9+
#include "baseWriter.h"
10+
11+
namespace utl {
12+
class Logger;
13+
}
14+
namespace YAML {
15+
class Node;
16+
}
17+
18+
namespace odb {
19+
class dbDatabase;
20+
class dbChip;
21+
class dbChipInst;
22+
class dbChipConn;
23+
class dbChipRegionInst;
24+
25+
class DbxWriter : public BaseWriter
26+
{
27+
public:
28+
DbxWriter(utl::Logger* logger, odb::dbDatabase* db);
29+
30+
void writeChiplet(const std::string& filename, odb::dbChip* chiplet);
31+
32+
private:
33+
void writeYamlContent(YAML::Node& root, odb::dbChip* chiplet);
34+
void writeDesign(YAML::Node& design_node, odb::dbChip* chiplet);
35+
void writeDesignExternal(YAML::Node& external_node, odb::dbChip* chiplet);
36+
void writeChipletInsts(YAML::Node& instances_node, odb::dbChip* chiplet);
37+
void writeChipletInst(YAML::Node& instance_node, odb::dbChipInst* inst);
38+
void writeStack(YAML::Node& stack_node, odb::dbChip* chiplet);
39+
void writeStackInstance(YAML::Node& stack_instance_node,
40+
odb::dbChipInst* inst);
41+
void writeConnections(YAML::Node& connections_node, odb::dbChip* chiplet);
42+
void writeConnection(YAML::Node& connection_node, odb::dbChipConn* conn);
43+
std::string buildPath(const std::vector<dbChipInst*>& path_insts,
44+
odb::dbChipRegionInst* region);
45+
};
46+
47+
} // namespace odb

src/odb/test/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ COMPULSORY_TESTS = [
200200
"wire_encoder",
201201
"write_cdl",
202202
"write_3dbv",
203+
"write_3dbx",
203204
"write_def58",
204205
"write_def58_gzip",
205206
"write_lef_and_def",

src/odb/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ or_integration_tests(
5858
wire_encoder
5959
write_cdl
6060
write_3dbv
61+
write_3dbx
6162
write_def58
6263
write_def58_gzip
6364
write_lef_and_def

0 commit comments

Comments
 (0)