Skip to content

Commit e41302d

Browse files
committed
odb: read chipConn
Signed-off-by: Osama <[email protected]>
1 parent 5b78c6e commit e41302d

File tree

5 files changed

+132
-17
lines changed

5 files changed

+132
-17
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#pragma once
55
#include <string>
6+
#include <vector>
67

78
namespace utl {
89
class Logger;
@@ -16,6 +17,8 @@ class dbChip;
1617
class ChipletInst;
1718
class Connection;
1819
class DesignDef;
20+
class dbChipRegionInst;
21+
class dbChipInst;
1922
class ThreeDBlox
2023
{
2124
public:
@@ -33,6 +36,8 @@ class ThreeDBlox
3336
void createDesignTopChiplet(const DesignDef& design);
3437
void createChipInst(const ChipletInst& chip_inst);
3538
void createConnection(const Connection& connection);
39+
dbChipRegionInst* resolvePath(const std::string& path,
40+
std::vector<dbChipInst*>& path_insts);
3641

3742
std::string resolveIncludePath(const std::string& include_path,
3843
const std::string& current_file_path);

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

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,93 @@ void ThreeDBlox::createChipInst(const ChipletInst& chip_inst)
183183
chip_inst.name);
184184
}
185185
dbChipInst* inst = dbChipInst::create(db_->getChip(), chip, chip_inst.name);
186+
inst->setLoc(Point3D(chip_inst.loc.x * db_->getDbuPerMicron(),
187+
chip_inst.loc.y * db_->getDbuPerMicron(),
188+
chip_inst.z * db_->getDbuPerMicron()));
189+
// TODO: set orient
190+
}
191+
std::vector<std::string> splitPath(const std::string& path)
192+
{
193+
std::vector<std::string> parts;
194+
std::istringstream stream(path);
195+
std::string part;
196+
197+
while (std::getline(stream, part, '/')) {
198+
if (!part.empty()) {
199+
parts.push_back(part);
200+
}
201+
}
202+
203+
return parts;
204+
}
205+
206+
dbChipRegionInst* ThreeDBlox::resolvePath(const std::string& path,
207+
std::vector<dbChipInst*>& path_insts)
208+
{
209+
if (path == "~") {
210+
return nullptr;
211+
}
212+
// Split the path by '/'
213+
std::vector<std::string> path_parts = splitPath(path);
214+
215+
if (path_parts.empty()) {
216+
logger_->error(utl::ODB, 524, "3DBX Parser Error: Invalid path {}", path);
217+
}
218+
219+
// The last part should contain ".regions.regionName"
220+
std::string last_part = path_parts.back();
221+
size_t regions_pos = last_part.find(".regions.");
222+
if (regions_pos == std::string::npos) {
223+
return nullptr; // Invalid format
224+
}
225+
226+
// Extract chip instance name and region name from last part
227+
std::string last_chip_inst = last_part.substr(0, regions_pos);
228+
std::string region_name = last_part.substr(regions_pos + 9);
229+
230+
// Replace the last part with just the chip instance name
231+
path_parts.back() = last_chip_inst;
232+
233+
// TODO: Traverse hierarchy and find region
234+
path_insts.reserve(path_parts.size());
235+
dbChip* curr_chip = db_->getChip();
236+
dbChipInst* curr_chip_inst = nullptr;
237+
for (auto inst_name : path_parts) {
238+
curr_chip_inst = curr_chip->findChipInst(inst_name);
239+
if (curr_chip_inst == nullptr) {
240+
logger_->error(utl::ODB,
241+
522,
242+
"3DBX Parser Error: Chip instance {} not found in path {}",
243+
inst_name,
244+
path);
245+
}
246+
path_insts.push_back(curr_chip_inst);
247+
curr_chip = curr_chip_inst->getMasterChip();
248+
}
249+
auto region = curr_chip_inst->findChipRegionInst(region_name);
250+
if (region == nullptr) {
251+
logger_->error(utl::ODB,
252+
523,
253+
"3DBX Parser Error: Chip region {} not found in path {}",
254+
region_name,
255+
path);
256+
}
257+
return region;
186258
}
187259
void ThreeDBlox::createConnection(const Connection& connection)
188260
{
189-
// dbChip* top_chip = db_->findChip(connection.top.c_str());
190-
// dbChip* bottom_chip = db_->findChip(connection.bot.c_str());
191-
// if (top_chip == nullptr || bottom_chip == nullptr) {
192-
// logger_->error(utl::ODB,
193-
// 520,
194-
// "3DBX Parser Error: Connection top or bottom chip not
195-
// found " "for connection {}", connection.name);
196-
// }
261+
auto top_path = connection.top;
262+
auto bottom_path = connection.bot;
263+
std::vector<dbChipInst*> top_region_path;
264+
std::vector<dbChipInst*> bottom_region_path;
265+
auto top_region = resolvePath(top_path, top_region_path);
266+
auto bottom_region = resolvePath(bottom_path, bottom_region_path);
267+
auto conn = odb::dbChipConn::create(connection.name,
268+
db_->getChip(),
269+
top_region_path,
270+
top_region,
271+
bottom_region_path,
272+
bottom_region);
273+
conn->setThickness(connection.thickness * db_->getDbuPerMicron());
197274
}
198275
} // namespace odb

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void BaseParser::parseIncludes(std::vector<std::string>& includes,
9090

9191
void BaseParser::logError(const std::string& message)
9292
{
93-
logger_->error(utl::ODB, 520, "Parser Error: {}", message);
93+
logger_->error(utl::ODB, 521, "Parser Error: {}", message);
9494
}
9595

9696
std::string BaseParser::trim(const std::string& str)

src/odb/test/cpp/Test3DBVParser.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,34 @@ BOOST_FIXTURE_TEST_CASE(test_3dbv, F_DBV_PARSER)
7979
BOOST_FIXTURE_TEST_CASE(test_3dbx, F_DBV_PARSER)
8080
{
8181
auto chip_insts = db->getChipInsts();
82-
BOOST_CHECK_EQUAL(chip_insts.size(), 1);
83-
auto chip_inst = *chip_insts.begin();
84-
BOOST_CHECK_EQUAL(chip_inst->getName(), "soc_inst");
85-
BOOST_CHECK_EQUAL(chip_inst->getMasterChip()->getName(), "SoC");
86-
BOOST_CHECK_EQUAL(chip_inst->getParentChip()->getName(), "TopDesign");
82+
BOOST_CHECK_EQUAL(chip_insts.size(), 2);
83+
auto soc_inst = db->getChip()->findChipInst("soc_inst");
84+
auto soc_inst_duplicate = db->getChip()->findChipInst("soc_inst_duplicate");
85+
BOOST_CHECK_EQUAL(soc_inst->getName(), "soc_inst");
86+
BOOST_CHECK_EQUAL(soc_inst->getMasterChip()->getName(), "SoC");
87+
BOOST_CHECK_EQUAL(soc_inst->getParentChip()->getName(), "TopDesign");
88+
BOOST_CHECK_EQUAL(soc_inst_duplicate->getName(), "soc_inst_duplicate");
89+
BOOST_CHECK_EQUAL(soc_inst_duplicate->getMasterChip()->getName(), "SoC");
90+
BOOST_CHECK_EQUAL(soc_inst_duplicate->getParentChip()->getName(),
91+
"TopDesign");
92+
BOOST_CHECK_EQUAL(soc_inst->getLoc().x(), 100.0 * db->getDbuPerMicron());
93+
BOOST_CHECK_EQUAL(soc_inst->getLoc().y(), 200.0 * db->getDbuPerMicron());
94+
BOOST_CHECK_EQUAL(soc_inst->getLoc().z(), 0.0);
95+
BOOST_CHECK_EQUAL(soc_inst_duplicate->getLoc().x(),
96+
100.0 * db->getDbuPerMicron());
97+
BOOST_CHECK_EQUAL(soc_inst_duplicate->getLoc().y(),
98+
200.0 * db->getDbuPerMicron());
99+
BOOST_CHECK_EQUAL(soc_inst_duplicate->getLoc().z(),
100+
300.0 * db->getDbuPerMicron());
101+
auto connections = db->getChipConns();
102+
BOOST_CHECK_EQUAL(connections.size(), 1);
103+
auto connection = *connections.begin();
104+
BOOST_CHECK_EQUAL(connection->getName(), "soc_to_soc");
105+
BOOST_CHECK_EQUAL(connection->getTopRegion()->getChipInst()->getName(),
106+
"soc_inst_duplicate");
107+
BOOST_CHECK_EQUAL(connection->getBottomRegion()->getChipInst()->getName(),
108+
"soc_inst");
109+
BOOST_CHECK_EQUAL(connection->getThickness(), 2.0 * db->getDbuPerMicron());
87110
}
88111

89112
BOOST_AUTO_TEST_SUITE_END()

src/odb/test/data/example.3dbx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,25 @@ ChipletInst:
1717
verilog_file: "/path/to/soc.v"
1818
sdc_file: "/path/to/soc.sdc"
1919
def_file: "/path/to/soc.def"
20+
soc_inst_duplicate:
21+
reference: SoC
22+
external:
23+
verilog_file: "/path/to/soc.v"
24+
sdc_file: "/path/to/soc.sdc"
25+
def_file: "/path/to/soc.def"
2026

2127
Stack:
2228
soc_inst:
2329
loc: [100.0, 200.0]
2430
z: 0.0
2531
orient: R0
32+
soc_inst_duplicate:
33+
loc: [100.0, 200.0]
34+
z: 300.0
35+
orient: MZ
2636

2737
Connection:
28-
soc_to_substrate:
29-
top: r1
30-
bot: ~
38+
soc_to_soc:
39+
top: soc_inst_duplicate.regions.r1
40+
bot: soc_inst.regions.r1
3141
thickness: 2.0

0 commit comments

Comments
 (0)