Skip to content

Commit 5e78e00

Browse files
authored
Merge pull request #2714 from macd/pdn-python
Python wrapper for pdn and core set of regression tests
2 parents 7d3be80 + b87bbd3 commit 5e78e00

25 files changed

+1244
-4
lines changed

include/ord/Design.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ namespace psm {
113113
class PDNSim;
114114
}
115115

116+
namespace pdn {
117+
class PdnGen;
118+
}
119+
116120
namespace ord {
117121

118122
class Tech;
@@ -160,6 +164,7 @@ class Design
160164
rmp::Restructure* getRestructure();
161165
stt::SteinerTreeBuilder* getSteinerTreeBuilder();
162166
psm::PDNSim* getPDNSim();
167+
pdn::PdnGen* getPdnGen();
163168

164169
private:
165170
Tech* tech_;

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ if (Python3_FOUND AND BUILD_PYTHON)
399399
rmp_py
400400
stt_py
401401
psm_py
402+
pdn_py
402403
)
403404
else()
404405
message(STATUS "Python3 disabled")

src/Design.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,10 @@ psm::PDNSim* Design::getPDNSim()
240240
return app->getPDNSim();
241241
}
242242

243+
pdn::PdnGen* Design::getPdnGen()
244+
{
245+
auto app = OpenRoad::openRoad();
246+
return app->getPdnGen();
247+
}
248+
243249
} // namespace ord

src/Main.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ using std::string;
9898
X(rmp) \
9999
X(stt) \
100100
X(psm) \
101+
X(pdn) \
101102
X(odb)
102103

103104
#define FOREACH_TOOL(X) \

src/odb/src/swig/python/dbtypes.i

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@
217217

218218
// Handle return by ref.
219219
%apply int &OUTPUT { int & overhang1, int & overhang2 };
220-
%apply int &OUTPUT { int & x, int & y };
221220
%apply int &OUTPUT { int & x_spacing, int & y_spacing };
222221
WRAP_OBJECT_RETURN_REF(odb::Rect, r)
223222
WRAP_OBJECT_RETURN_REF(odb::Rect, rect)

src/pdn/include/pdn/PdnGen.hh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include <array>
3939
#include <map>
4040
#include <memory>
41-
#include <regex>
4241

4342
#include "odb/db.h"
4443
#include "utl/Logger.h"
@@ -57,8 +56,6 @@ using odb::dbRegion;
5756

5857
using utl::Logger;
5958

60-
using std::regex;
61-
6259
enum ExtensionMode
6360
{
6461
CORE,

src/pdn/src/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,29 @@ messages(
8080
TARGET pdn
8181
OUTPUT_DIR ..
8282
)
83+
84+
if (Python3_FOUND AND BUILD_PYTHON)
85+
swig_lib(NAME pdn_py
86+
NAMESPACE pdn
87+
LANGUAGE python
88+
I_FILE PdnGen-py.i
89+
SWIG_INCLUDES ${ODB_HOME}/src/swig/common
90+
${ODB_HOME}/src/swig/python
91+
${ODB_HOME}/include
92+
${PROJECT_SOURCE_DIR}/../include/pdn
93+
SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/pdn_py.py
94+
)
95+
96+
target_include_directories(pdn_py
97+
PUBLIC
98+
.
99+
)
100+
101+
target_link_libraries(pdn_py
102+
PUBLIC
103+
pdn
104+
odb
105+
gui
106+
)
107+
108+
endif()

src/pdn/src/PdnGen-py.i

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2023, The Regents of the University of California
4+
// All rights reserved.
5+
//
6+
// BSD 3-Clause License
7+
//
8+
// Redistribution and use in source and binary forms, with or without
9+
// modification, are permitted provided that the following conditions are met:
10+
//
11+
// * Redistributions of source code must retain the above copyright notice, this
12+
// list of conditions and the following disclaimer.
13+
//
14+
// * Redistributions in binary form must reproduce the above copyright notice,
15+
// this list of conditions and the following disclaimer in the documentation
16+
// and/or other materials provided with the distribution.
17+
//
18+
// * Neither the name of the copyright holder nor the names of its
19+
// contributors may be used to endorse or promote products derived from
20+
// this software without specific prior written permission.
21+
//
22+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
// POSSIBILITY OF SUCH DAMAGE.
33+
//
34+
///////////////////////////////////////////////////////////////////////////////
35+
%module pdngen
36+
%{
37+
38+
// These includes are needed by the SWIG generated CXX files mostly
39+
// for determining the size of Classes that they define. Since that are
40+
// not actually wrapped, the classes defined in these files will appear as
41+
// opaque pointers in Python.
42+
#include "../src/connect.h"
43+
#include "../src/domain.h"
44+
#include "../src/grid.h"
45+
#include "../src/power_cells.h"
46+
#include "../src/renderer.h"
47+
48+
#include "pdn/PdnGen.hh"
49+
#include "odb/db.h"
50+
#include <array>
51+
#include <string>
52+
#include <memory>
53+
#include <vector>
54+
55+
using pdn::ExtensionMode;
56+
using namespace pdn;
57+
58+
%}
59+
60+
%include <std_vector.i>
61+
%include <std_array.i>
62+
%include <std_map.i>
63+
64+
// this maps unsigned long to the enum ExtensionMode
65+
%include typemaps.i
66+
%apply unsigned long { ExtensionMode };
67+
68+
%import "odb.i"
69+
%import "dbtypes.i"
70+
%include <std_string.i>
71+
72+
// These are needed to coax swig into sending or returning Python
73+
// lists, arrays, or sets (as appropriate) of opaque pointers. Note
74+
// that you must %include (not %import) <std_vector.i> and <std_array.i>
75+
// before these definitions
76+
namespace std {
77+
%template(split_cuts_stuff) std::vector<int>;
78+
%template(stuff) std::array<int, 4>;
79+
%template(split_map) std::map<odb::dbTechLayer *, int>;
80+
%template(grid_list) std::vector<pdn::Grid *>;
81+
%template(domain_list) std::vector<pdn::VoltageDomain *>;
82+
%template(net_list) std::vector<odb::dbNet *>;
83+
%template(viagen_list) std::vector<odb::dbTechViaGenerateRule *>;
84+
%template(techvia_list) std::vector<odb::dbTechVia *>;
85+
%template(layer_list) std::vector<odb::dbTechLayer *>;
86+
}
87+
88+
%include "../../Exception-py.i"
89+
%include "pdn/PdnGen.hh"
90+
91+
%inline %{
92+
93+
namespace pdn {
94+
95+
// difficult to pass a set. repair_pdn_via takes a vector and then
96+
// rebuilds the set in C++, so we just borrow that here.
97+
void repair_pdn_vias(const std::vector<odb::dbNet*>& nets);
98+
99+
} // namespace
100+
101+
%} // %inline

src/pdn/test/asap7_taper.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# test for via stacks that require a taper due to min width rules
2+
from openroad import Design, Tech
3+
import pdn_aux
4+
import helpers
5+
6+
tech = Tech()
7+
tech.readLef("asap7_vias/asap7_tech_1x.lef")
8+
tech.readLef("asap7_vias/asap7sc7p5t_27_R_1x.lef")
9+
10+
design = Design(tech)
11+
design.readDef("asap7_vias/floorplan.def")
12+
13+
pdn_aux.add_global_connection(design, net_name="VDD", pin_pattern="^VDD$", power=True)
14+
pdn_aux.add_global_connection(design, net_name="VSS", pin_pattern="^VSS$", ground=True)
15+
16+
pdn_aux.set_voltage_domain(design, power="VDD", ground="VSS")
17+
pdn_aux.define_pdn_grid_real(design, name="top", voltage_domains=["Core"])
18+
19+
pdn_aux.add_pdn_stripe(design, grid="top", layer="M1", width=0.018, pitch=0.54, offset=0, followpins=True)
20+
pdn_aux.add_pdn_stripe(design, grid="top", layer="M2", width=0.018, pitch=0.54, offset=0, followpins=True)
21+
pdn_aux.add_pdn_stripe(design, grid="top", layer="M5", width=0.12, spacing=0.072, pitch=11.88, offset=0.300)
22+
pdn_aux.add_pdn_stripe(design, grid="top", layer="M6", width=0.288, spacing=0.096, pitch=12.0, offset=0.513)
23+
24+
pdn_aux.add_pdn_connect(design, grid="top", layers=["M1", "M2"])
25+
pdn_aux.add_pdn_connect(design, grid="top", layers=["M2", "M5"])
26+
pdn_aux.add_pdn_connect(design, grid="top", layers=["M5", "M6"])
27+
28+
pdn_aux.pdngen_db(design)
29+
30+
def_file = helpers.make_result_file("asap7_taper.def")
31+
design.writeDef(def_file)
32+
helpers.diff_files("asap7_taper.defok", def_file)

src/pdn/test/core_grid.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# test for pdngen -reset
2+
from openroad import Design, Tech
3+
import pdn_aux
4+
import helpers
5+
6+
tech = Tech()
7+
tech.readLef("Nangate45/Nangate45_tech.lef")
8+
tech.readLef("Nangate45/Nangate45_stdcell.lef")
9+
10+
design = Design(tech)
11+
design.readDef("nangate_gcd/floorplan.def")
12+
pdngen = design.getPdnGen()
13+
14+
pdn_aux.add_global_connection(design, net_name="VDD", pin_pattern="VDD", power=True)
15+
pdn_aux.add_global_connection(design, net_name="VSS", pin_pattern="VSS", ground=True)
16+
17+
pdn_aux.set_voltage_domain(design, power='VDD', ground='VSS')
18+
19+
pdn_aux.define_pdn_grid_real(design, name="Core")
20+
pdn_aux.add_pdn_stripe(design, followpins=True, layer="metal1")
21+
22+
pdn_aux.pdngen_db(design)
23+
24+
def_file = helpers.make_result_file("core_grid.def")
25+
design.writeDef(def_file)
26+
helpers.diff_files("core_grid.defok", def_file)

0 commit comments

Comments
 (0)