-
Notifications
You must be signed in to change notification settings - Fork 740
odb: add 3dbxWriter #8775
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
Draft
rafaelmoresco
wants to merge
1
commit into
The-OpenROAD-Project:master
Choose a base branch
from
rafaelmoresco:dbxwriter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
odb: add 3dbxWriter #8775
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright (c) 2019-2025, The OpenROAD Authors | ||
|
|
||
| #include "baseWriter.h" | ||
|
|
||
| #include <yaml-cpp/emitterstyle.h> | ||
| #include <yaml-cpp/node/node.h> | ||
| #include <yaml-cpp/yaml.h> | ||
|
|
||
| #include <cstddef> | ||
| #include <fstream> | ||
| #include <string> | ||
|
|
||
| #include "odb/db.h" | ||
| #include "odb/defout.h" | ||
| #include "odb/lefout.h" | ||
| #include "utl/Logger.h" | ||
| #include "utl/ScopedTemporaryFile.h" | ||
|
|
||
| namespace odb { | ||
|
|
||
| BaseWriter::BaseWriter(utl::Logger* logger) : logger_(logger) | ||
| { | ||
| } | ||
|
|
||
| void BaseWriter::writeHeader(YAML::Node& header_node, odb::dbDatabase* db) | ||
| { | ||
| header_node["version"] = "2.5"; // TODO: add version to DB | ||
| header_node["unit"] = "micron"; | ||
| header_node["precision"] = db->getDbuPerMicron(); | ||
| } | ||
|
|
||
| void BaseWriter::writeYamlToFile(const std::string& filename, | ||
| const YAML::Node& root) | ||
| { | ||
| std::ofstream out(filename); | ||
| if (!out) { | ||
| if (logger_ != nullptr) { | ||
| logError("cannot open " + filename); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| out << root; | ||
| } | ||
|
|
||
| void BaseWriter::writeLef(YAML::Node& external_node, | ||
| odb::dbDatabase* db, | ||
| odb::dbChip* chiplet) | ||
| { | ||
| auto libs = db->getLibs(); | ||
| int num_libs = libs.size(); | ||
| if (num_libs > 0) { | ||
| if (num_libs > 1) { | ||
| logger_->info( | ||
| utl::ODB, | ||
| 539, | ||
| "More than one lib exists, multiple files will be written."); | ||
| } | ||
| int cnt = 0; | ||
| for (auto lib : libs) { | ||
| std::string name(std::string(lib->getName()) + ".lef"); | ||
| if (cnt > 0) { | ||
| auto pos = name.rfind('.'); | ||
| if (pos != std::string::npos) { | ||
| name.insert(pos, "_" + std::to_string(cnt)); | ||
| } else { | ||
| name += "_" + std::to_string(cnt); | ||
| } | ||
| utl::OutStreamHandler stream_handler(name.c_str()); | ||
| odb::lefout lef_writer(logger_, stream_handler.getStream()); | ||
| lef_writer.writeLib(lib); | ||
| } else { | ||
| utl::OutStreamHandler stream_handler(name.c_str()); | ||
| odb::lefout lef_writer(logger_, stream_handler.getStream()); | ||
| lef_writer.writeTechAndLib(lib); | ||
| } | ||
| YAML::Node list_node; | ||
| list_node.SetStyle(YAML::EmitterStyle::Flow); | ||
| list_node.push_back(name.c_str()); | ||
| if ((name.find("_tech") != std::string::npos) || (libs.size() == 1)) { | ||
| external_node["APR_tech_file"] = list_node; | ||
| } else { | ||
| external_node["LEF_file"] = list_node; | ||
| } | ||
| ++cnt; | ||
| } | ||
| } else if (db->getTech()) { | ||
| utl::OutStreamHandler stream_handler( | ||
| (std::string(chiplet->getName()) + ".lef").c_str()); | ||
| odb::lefout lef_writer(logger_, stream_handler.getStream()); | ||
| lef_writer.writeTech(db->getTech()); | ||
| external_node["APR_tech_file"] = (std::string(chiplet->getName()) + ".lef"); | ||
| } | ||
| } | ||
|
|
||
| void BaseWriter::writeDef(YAML::Node& external_node, | ||
| odb::dbDatabase* db, | ||
| odb::dbChip* chiplet) | ||
| { | ||
| odb::DefOut def_writer(logger_); | ||
| auto block = chiplet->getBlock(); | ||
| def_writer.writeBlock(block, | ||
| (std::string(chiplet->getName()) + ".def").c_str()); | ||
| external_node["DEF_file"] = std::string(chiplet->getName()) + ".def"; | ||
| } | ||
|
|
||
| void BaseWriter::logError(const std::string& message) | ||
| { | ||
| if (logger_ != nullptr) { | ||
| logger_->error(utl::ODB, 538, "Writer Error: {}", message); | ||
| } | ||
| } | ||
|
|
||
| std::string BaseWriter::trim(const std::string& str) | ||
| { | ||
| std::size_t first = str.find_first_not_of(' '); | ||
| if (first == std::string::npos) { | ||
| return ""; | ||
| } | ||
| std::size_t last = str.find_last_not_of(' '); | ||
| return str.substr(first, (last - first + 1)); | ||
| } | ||
|
|
||
| } // namespace odb | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright (c) 2019-2025, The OpenROAD Authors | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <yaml-cpp/node/node.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "odb/db.h" | ||
| #include "odb/dbObject.h" | ||
| #include "odb/dbShape.h" | ||
| namespace utl { | ||
| class Logger; | ||
| } | ||
|
|
||
| namespace odb { | ||
|
|
||
| class BaseWriter | ||
| { | ||
| public: | ||
| BaseWriter(utl::Logger* logger); | ||
| virtual ~BaseWriter() = default; | ||
| virtual void writeFile(const std::string& filename, odb::dbDatabase* db) = 0; | ||
|
|
||
| protected: | ||
| // Common YAML content writing | ||
| void writeHeader(YAML::Node& header_node, odb::dbDatabase* db); | ||
| void writeLef(YAML::Node& external_node, | ||
| odb::dbDatabase* db, | ||
| odb::dbChip* chiplet); | ||
| void writeDef(YAML::Node& external_node, | ||
| odb::dbDatabase* db, | ||
| odb::dbChip* chiplet); | ||
| void logError(const std::string& message); | ||
| std::string trim(const std::string& str); | ||
| void writeYamlToFile(const std::string& filename, const YAML::Node& root); | ||
|
|
||
| // Member variables | ||
| utl::Logger* logger_ = nullptr; | ||
| std::string current_file_path_; | ||
| }; | ||
|
|
||
| } // namespace odb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,150 @@ | ||||
| // SPDX-License-Identifier: BSD-3-Clause | ||||
| // Copyright (c) 2019-2025, The OpenROAD Authors | ||||
|
|
||||
| #include "dbxWriter.h" | ||||
|
|
||||
| #include <yaml-cpp/emitterstyle.h> | ||||
| #include <yaml-cpp/node/node.h> | ||||
| #include <yaml-cpp/yaml.h> | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: included header yaml.h is not used directly [misc-include-cleaner]
Suggested change
|
||||
| #include <string> | ||||
| #include <vector> | ||||
|
|
||||
| #include "baseWriter.h" | ||||
| #include "odb/db.h" | ||||
| #include "utl/Logger.h" | ||||
|
|
||||
| namespace odb { | ||||
|
|
||||
| DbxWriter::DbxWriter(utl::Logger* logger) : BaseWriter(logger) | ||||
| { | ||||
| } | ||||
|
|
||||
| void DbxWriter::writeFile(const std::string& filename, odb::dbDatabase* db) | ||||
| { | ||||
| // TODO: Connect the following | ||||
| // DbvWriter dbvwriter(logger_); | ||||
| // dbvwriter.writeChiplet( | ||||
| // std::string(db->getChip()->getName()) + ".3dbv", db, db->getChip()); | ||||
| YAML::Node root; | ||||
| writeYamlContent(root, db->getChip()); | ||||
| writeYamlToFile(filename, root); | ||||
| } | ||||
|
|
||||
| void DbxWriter::writeChiplet(odb::dbChip* chiplet) | ||||
| { | ||||
| YAML::Node root; | ||||
| // TODO: Connect the following | ||||
| // DbvWriter dbvwriter(logger_); | ||||
| // dbvwriter.writeChiplet( | ||||
| // std::string(chiplet->getName()) + ".3dbv", chiplet->getDb(), chiplet); | ||||
| writeYamlContent(root, chiplet); | ||||
| writeYamlToFile(std::string(chiplet->getName()), root); | ||||
| } | ||||
|
|
||||
| void DbxWriter::writeYamlContent(YAML::Node& root, odb::dbChip* chiplet) | ||||
| { | ||||
| YAML::Node header_node = root["Header"]; | ||||
| writeHeader(header_node, chiplet->getDb()); | ||||
| YAML::Node includes_node = header_node["include"]; | ||||
| includes_node.push_back(std::string(chiplet->getName()) + ".3dbv"); | ||||
|
|
||||
| YAML::Node design_node = root["Design"]; | ||||
| writeDesign(design_node, chiplet); | ||||
|
|
||||
| YAML::Node instances_node = root["ChipletInst"]; | ||||
| writeChipletInsts(instances_node, chiplet); | ||||
|
|
||||
| YAML::Node stack_node = root["Stack"]; | ||||
| writeStack(stack_node, chiplet); | ||||
|
|
||||
| YAML::Node connections_node = root["Connection"]; | ||||
| writeConnections(connections_node, chiplet); | ||||
| } | ||||
|
|
||||
| void DbxWriter::writeDesign(YAML::Node& design_node, odb::dbChip* chiplet) | ||||
| { | ||||
| design_node["name"] = chiplet->getName(); | ||||
| } | ||||
|
|
||||
| void DbxWriter::writeChipletInsts(YAML::Node& instances_node, | ||||
| odb::dbChip* chiplet) | ||||
| { | ||||
| for (auto inst : chiplet->getChipInsts()) { | ||||
| YAML::Node instance_node = instances_node[std::string(inst->getName())]; | ||||
| writeChipletInst(instance_node, inst); | ||||
| } | ||||
| } | ||||
|
|
||||
| void DbxWriter::writeChipletInst(YAML::Node& instance_node, | ||||
| odb::dbChipInst* inst) | ||||
| { | ||||
| auto master_name = inst->getMasterChip()->getName(); | ||||
| instance_node["reference"] = master_name; | ||||
| } | ||||
|
|
||||
| void DbxWriter::writeStack(YAML::Node& stack_node, odb::dbChip* chiplet) | ||||
| { | ||||
| for (auto inst : chiplet->getChipInsts()) { | ||||
| YAML::Node stack_instance_node = stack_node[std::string(inst->getName())]; | ||||
| writeStackInstance(stack_instance_node, inst); | ||||
| } | ||||
| } | ||||
|
|
||||
| void DbxWriter::writeStackInstance(YAML::Node& stack_instance_node, | ||||
| odb::dbChipInst* inst) | ||||
| { | ||||
| const double u = inst->getDb()->getDbuPerMicron(); | ||||
| const double loc_x = inst->getLoc().x() / u; | ||||
| const double loc_y = inst->getLoc().y() / u; | ||||
| YAML::Node loc_out; | ||||
| loc_out.SetStyle(YAML::EmitterStyle::Flow); | ||||
| loc_out.push_back(loc_x); | ||||
| loc_out.push_back(loc_y); | ||||
| stack_instance_node["loc"] = loc_out; | ||||
| stack_instance_node["z"] = inst->getLoc().z() / u; | ||||
| stack_instance_node["orient"] = inst->getOrient().getString(); | ||||
| } | ||||
|
|
||||
| void DbxWriter::writeConnections(YAML::Node& connections_node, | ||||
| odb::dbChip* chiplet) | ||||
| { | ||||
| for (auto conn : chiplet->getChipConns()) { | ||||
| YAML::Node connection_node = connections_node[std::string(conn->getName())]; | ||||
| writeConnection(connection_node, conn); | ||||
| } | ||||
| } | ||||
|
|
||||
| void DbxWriter::writeConnection(YAML::Node& connection_node, | ||||
| odb::dbChipConn* conn) | ||||
| { | ||||
| const double u = conn->getDb()->getDbuPerMicron(); | ||||
| connection_node["top"] | ||||
| = buildPath(conn->getTopRegionPath(), conn->getTopRegion()); | ||||
| connection_node["bot"] | ||||
| = buildPath(conn->getBottomRegionPath(), conn->getBottomRegion()); | ||||
| connection_node["thicness"] = conn->getThickness() / u; | ||||
| } | ||||
|
|
||||
| std::string DbxWriter::buildPath(const std::vector<dbChipInst*>& path_insts, | ||||
| odb::dbChipRegionInst* region) | ||||
| { | ||||
| if (region == nullptr) { | ||||
| return "~"; | ||||
| } | ||||
|
|
||||
| std::string path; | ||||
| for (auto inst : path_insts) { | ||||
| if (!path.empty()) { | ||||
| path += "/"; | ||||
| } | ||||
| path += inst->getName(); | ||||
| } | ||||
|
|
||||
| if (!path.empty()) { | ||||
| path += ".regions." + region->getChipRegion()->getName(); | ||||
| } | ||||
| return path; | ||||
| } | ||||
|
|
||||
| } // namespace odb | ||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: included header yaml.h is not used directly [misc-include-cleaner]