Skip to content

Commit

Permalink
Export circuit as ISPD benchmark for debug purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloquinte committed Nov 2, 2023
1 parent 3182872 commit 4d52e8e
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ INCLUDE_DIRECTORIES(
SET(SOURCES
src/coloquinte.cpp
src/parameters.cpp
src/export.cpp
src/place_global/net_model.cpp
src/place_global/density_legalizer.cpp
src/place_global/density_grid.cpp
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ lemon_dep = lemon.dependency('lemon')
sources = [
'src/coloquinte.cpp',
'src/parameters.cpp',
'src/export.cpp',
'src/place_global/net_model.cpp',
'src/place_global/density_legalizer.cpp',
'src/place_global/density_grid.cpp',
Expand Down
7 changes: 7 additions & 0 deletions pycoloquinte/coloquinte.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,10 @@ def main():
parser.add_argument(
"--image-extension", help=argparse.SUPPRESS, type=str, default="webp"
)
# Export the ISPD benchmark files after reading
parser.add_argument(
"--export-ispd", help=argparse.SUPPRESS, type=str
)

tuning_options = parser.add_argument_group("tuning options")
_add_arguments(tuning_options, ColoquinteParameters(), [])
Expand Down Expand Up @@ -864,6 +868,9 @@ def main():
print(circuit.report())

sys.stdout.flush()
if args.export_ispd is not None:
print("Exporting as ISPD benchmark")
circuit.export_ispd(args.export_ispd)
callback = None
if args.save_images is not None:
circuit.write_image(
Expand Down
2 changes: 2 additions & 0 deletions pycoloquinte/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ Construct a circuit.
"Expand the standard cells by an individual factor")
.def("check", &Circuit::check, "Check the datastructure")
.def("report", &Circuit::report)
.def("export_ispd", &Circuit::exportIspd,
"Export the circuit to ISPD benchmark files")
.def("__str__", &Circuit::toString)
.def("__repr__", &Circuit::toString);
}
5 changes: 5 additions & 0 deletions src/coloquinte.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,11 @@ class Circuit {
*/
std::string toString() const;

/**
* @brief Export as an ISPD benchmark
*/
void exportIspd(const std::string &filename) const;

/**
* @brief Obtain a detailed report
*/
Expand Down
91 changes: 91 additions & 0 deletions src/export.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

#include <fstream>

#include "coloquinte.hpp"

namespace coloquinte {

void exportIspdAux(const std::string &filename) {
std::ofstream f(filename + ".aux");
f << "RowBasedPlacement : " << filename << ".nodes " << filename << ".nets "
<< filename << ".pl " << filename << ".scl" << std::endl;
}

void exportIspdNodes(const Circuit &circuit, const std::string &filename) {
std::ofstream f(filename + ".nodes");
f << "UCLA nodes 1.0\n\n";
f << "NumNodes : " << circuit.nbCells() << "\n";
int numTerminals = 0;
for (int i = 0; i < circuit.nbCells(); ++i) {
if (circuit.isFixed(i)) {
++numTerminals;
}
}
f << "NumTerminals : " << numTerminals << "\n";

for (int i = 0; i < circuit.nbCells(); ++i) {
f << "\to" << i << "\t" << circuit.cellWidth_[i] << "\t"
<< circuit.cellHeight_[i];
if (circuit.isFixed(i)) {
f << "\tterminal";
}
f << "\n";
}
}

void exportIspdPlace(const Circuit &circuit, const std::string &filename) {
std::ofstream f(filename + ".pl");
f << "UCLA pl 1.0\n\n";

for (int i = 0; i < circuit.nbCells(); ++i) {
f << "o" << i << "\t" << circuit.x(i) << "\t" << circuit.y(i)
<< "\t: " << toString(circuit.orientation(i)) << "\n";
}
}

void exportIspdNets(const Circuit &circuit, const std::string &filename) {
std::ofstream f(filename + ".nets");
f << "UCLA nets 1.0\n\n";

f << "NumNets : " << circuit.nbNets() << "\n";
f << "NumPins : " << circuit.nbPins() << "\n\n";

for (int i = 0; i < circuit.nbNets(); ++i) {
f << "NetDegree : " << circuit.nbPinsNet(i) << " n" << i << "\n";
for (int j = 0; j < circuit.nbPinsNet(i); ++j) {
int c = circuit.pinCell(i, j);
f << "\to" << c << " I : ";
double x = circuit.pinXOffset(i, j) - 0.5 * circuit.cellWidth_[c];
double y = circuit.pinYOffset(i, j) - 0.5 * circuit.cellHeight_[c];
f << x << " " << y << "\n";
}
}
}

void exportIspdRows(const Circuit &circuit, const std::string &filename) {
std::ofstream f(filename + ".scl");
f << "UCLA scl 1.0\n\n";

f << "NumRows : " << circuit.nbRows() << "\n\n";
for (int i = 0; i < circuit.nbRows(); ++i) {
f << "CoreRow Horizontal\n";
f << " Coordinate : " << circuit.rows()[i].minY << "\n";
f << " Height : " << circuit.rows()[i].height() << "\n";
f << " Sitewidth : 1\n";
f << " Sitespacing : 1\n";
f << " Siteorient : 1\n";
f << " Sitesymmetry : 1\n";
f << " SubrowOrigin : " << circuit.rows()[i].minX
<< " NumSites : " << circuit.rows()[i].width() << "\n";
f << "End\n";
}
}

void Circuit::exportIspd(const std::string &filename) const {
exportIspdAux(filename);
exportIspdNodes(*this, filename);
exportIspdPlace(*this, filename);
exportIspdNets(*this, filename);
exportIspdRows(*this, filename);
}
} // namespace coloquinte

0 comments on commit 4d52e8e

Please sign in to comment.