Skip to content

Commit f46913d

Browse files
authored
Merge pull request #8900 from The-OpenROAD-Project-staging/options-parsing
gpl: Improved options parsing (example template)
2 parents c064501 + ed4484b commit f46913d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2659
-1343
lines changed

BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ exports_files([
2222
"LICENSE",
2323
"src/Design.i",
2424
"src/Exception.i",
25+
"src/options.i",
2526
])
2627

2728
string_flag(
@@ -298,6 +299,7 @@ py_library(
298299
imports = ["."],
299300
visibility = ["//visibility:public"],
300301
deps = [
302+
"//src/gpl:gpl_py",
301303
"//src/odb:odb_py",
302304
"//src/utl:utl_py",
303305
],
@@ -362,3 +364,11 @@ filegroup(
362364
"src/Design.i",
363365
],
364366
)
367+
368+
filegroup(
369+
name = "options_swig",
370+
srcs = [
371+
"src/options.i",
372+
],
373+
visibility = ["@//:__subpackages__"],
374+
)

src/Exception-py.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// This catches std::runtime_error (utl::error) and sta::Exception.
3232
catch (std::exception &excp) {
3333
#ifdef BAZEL
34-
Logger* logger = Logger::defaultLogger();
34+
utl::Logger* logger = utl::Logger::defaultLogger();
3535
if (logger->debugCheck(utl::ORD, "trace", 1)) {
3636
std::stringstream trace;
3737
trace << boost::stacktrace::stacktrace();
@@ -56,7 +56,7 @@
5656
}
5757
catch (...) {
5858
#ifdef BAZEL
59-
Logger* logger = Logger::defaultLogger();
59+
utl::Logger* logger = utl::Logger::defaultLogger();
6060
if (logger->debugCheck(utl::ORD, "trace", 1)) {
6161
std::stringstream trace;
6262
trace << boost::stacktrace::stacktrace();

src/OpenRoad.i

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,20 +493,10 @@ microns_to_dbu(double microns)
493493

494494
// Common check for placement tools.
495495
bool
496-
db_has_rows()
496+
db_has_core_rows()
497497
{
498498
dbDatabase *db = OpenRoad::openRoad()->getDb();
499-
if (!db->getChip() || !db->getChip()->getBlock()) {
500-
return false;
501-
}
502-
503-
for (odb::dbRow* row : db->getChip()->getBlock()->getRows()) {
504-
if (row->getSite()->getClass() != odb::dbSiteClass::PAD) {
505-
return true;
506-
}
507-
}
508-
509-
return false;
499+
return dbHasCoreRows(db);
510500
}
511501

512502
bool

src/dpl/src/Opendp.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ proc detailed_placement { args } {
3939
utl::warn DPL 3 "-disallow_one_site_gaps is deprecated"
4040
}
4141

42-
if { [ord::db_has_rows] } {
42+
if { [ord::db_has_core_rows] } {
4343
set site [dpl::get_row_site]
4444
# Convert displacement from microns to sites.
4545
set max_displacement_x [expr [ord::microns_to_dbu $max_displacement_x] \

src/gpl/BUILD

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2025, The OpenROAD Authors
33

4+
load("@openroad_rules_python//python:defs.bzl", "py_library")
5+
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
46
load("@rules_cc//cc:cc_library.bzl", "cc_library")
5-
load("//bazel:python_wrap_cc.bzl", "python_wrap_cc")
7+
load("//bazel:python_wrap_cc.bzl", "PYTHON_STABLE_API_DEFINE", "python_wrap_cc")
68
load("//bazel:tcl_encode_or.bzl", "tcl_encode")
79
load("//bazel:tcl_wrap_cc.bzl", "tcl_wrap_cc")
810

@@ -83,27 +85,61 @@ cc_library(
8385
],
8486
)
8587

88+
# This target compiles the SWIG C++ wrapper into a shared library (.so)
89+
# that Python can load dynamically.
90+
cc_binary(
91+
name = "_gpl.so",
92+
srcs = [
93+
":swig-py",
94+
],
95+
defines = [PYTHON_STABLE_API_DEFINE],
96+
includes = ["src"],
97+
linkshared = True,
98+
deps = [
99+
"//src/gpl",
100+
"//src/odb",
101+
"//src/utl",
102+
"@boost.stacktrace",
103+
"@openroad_rules_python//python/cc:current_py_cc_headers",
104+
],
105+
)
106+
107+
# This packages the SWIG-generated Python wrapper (gpl.py) and the
108+
# compiled C++ extension (_gpl.so) together.
109+
py_library(
110+
name = "gpl_py",
111+
srcs = [":swig-py"], # Use the .py output from the swig-py rule
112+
# The data attribute makes the .so file available at runtime.
113+
data = [":_gpl.so"],
114+
# This allows imports relative to the workspace root.
115+
imports = ["."],
116+
visibility = ["//visibility:public"],
117+
)
118+
86119
tcl_encode(
87120
name = "tcl",
88121
srcs = [
89122
"src/replace.tcl",
90123
],
91124
char_array_name = "gpl_tcl_inits",
92125
namespace = "gpl",
126+
visibility = ["//visibility:public"],
93127
)
94128

95129
tcl_wrap_cc(
96130
name = "swig",
97131
srcs = [
98132
"src/replace.i",
99133
"//:error_swig",
134+
"//:options_swig",
100135
],
101136
module = "gpl",
102137
namespace_prefix = "gpl",
103138
root_swig_src = "src/replace.i",
104139
swig_includes = [
105140
"src/gpl/src",
106141
],
142+
visibility = ["//visibility:public"],
107143
deps = [
108144
"//src/odb:swig",
109145
],

src/gpl/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ Timing-driven arguments
6767
global_placement
6868
[-timing_driven]
6969
[-routability_driven]
70-
[-disable_timing_driven]
71-
[-disable_routability_driven]
7270
[-skip_initial_place]
7371
[-incremental]
7472
[-bin_grid_count grid_count]

src/gpl/include/gpl/Replace.h

Lines changed: 62 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,57 @@ class NesterovPlace;
4444
using Cluster = std::vector<odb::dbInst*>;
4545
using Clusters = std::vector<Cluster>;
4646

47+
struct PlaceOptions
48+
{
49+
int initialPlaceMaxIter = 20;
50+
int initialPlaceMinDiffLength = 1500;
51+
int initialPlaceMaxSolverIter = 100;
52+
int initialPlaceMaxFanout = 200;
53+
float initialPlaceNetWeightScale = 800;
54+
55+
bool skipIoMode = false;
56+
bool timingDrivenMode = false;
57+
bool routabilityDrivenMode = false;
58+
bool uniformTargetDensityMode = false;
59+
std::vector<int> timingNetWeightOverflows{64, 20};
60+
float timingNetWeightMax = 5;
61+
float overflow = 0.1;
62+
int nesterovPlaceMaxIter = 5000;
63+
// timing driven check overflow to keep resizer changes (non-virtual resizer)
64+
float keepResizeBelowOverflow = 1.0;
65+
bool routabilityUseRudy = true;
66+
bool disableRevertIfDiverge = false;
67+
bool enable_routing_congestion = false;
68+
float minPhiCoef = 0.95;
69+
float maxPhiCoef = 1.05;
70+
float initDensityPenaltyFactor = 0.00008;
71+
float initWireLengthCoef = 0.25;
72+
float referenceHpwl = 446000000;
73+
int binGridCntX = 0;
74+
int binGridCntY = 0;
75+
float density = 0.7;
76+
77+
float routabilityCheckOverflow = 0.3;
78+
float routabilityMaxDensity = 0.99;
79+
float routabilityTargetRcMetric = 1.01;
80+
float routabilityInflationRatioCoef = 2;
81+
float routabilityMaxInflationRatio = 3;
82+
int routabilityMaxInflationIter = 4;
83+
84+
// routability RC metric coefficients
85+
float routabilityRcK1 = 1.0;
86+
float routabilityRcK2 = 1.0;
87+
float routabilityRcK3 = 0.0;
88+
float routabilityRcK4 = 0.0;
89+
90+
// OpenDB should have these values.
91+
int padLeft = 0;
92+
int padRight = 0;
93+
94+
void skipIo();
95+
void validate(utl::Logger* log);
96+
};
97+
4798
class Replace
4899
{
49100
public:
@@ -64,62 +115,19 @@ class Replace
64115

65116
void reset();
66117

67-
void doIncrementalPlace(int threads);
68-
void doInitialPlace(int threads);
118+
void doIncrementalPlace(int threads, const PlaceOptions& options = {});
119+
void doPlace(int threads, const PlaceOptions& options = {});
120+
void doInitialPlace(int threads, const PlaceOptions& options = {});
121+
int doNesterovPlace(int threads,
122+
const PlaceOptions& options = {},
123+
int start_iter = 0);
124+
69125
void runMBFF(int max_sz, float alpha, float beta, int threads, int num_paths);
70126

71127
void addPlacementCluster(const Cluster& cluster);
72-
int doNesterovPlace(int threads, int start_iter = 0);
73-
74-
// Initial Place param settings
75-
void setInitialPlaceMaxIter(int iter);
76-
void setInitialPlaceMinDiffLength(int length);
77-
void setInitialPlaceMaxSolverIter(int iter);
78-
void setInitialPlaceMaxFanout(int fanout);
79-
void setInitialPlaceNetWeightScale(float scale);
80-
81-
void setNesterovPlaceMaxIter(int iter);
82-
83-
void setBinGridCnt(int binGridCntX, int binGridCntY);
84-
85-
void setTargetDensity(float density);
86-
// Execute gpl with uniform density as target density
87-
void setUniformTargetDensityMode(bool mode);
88-
void setTargetOverflow(float overflow);
89-
void setInitDensityPenalityFactor(float penaltyFactor);
90-
void setInitWireLengthCoef(float coef);
91-
void setMinPhiCoef(float minPhiCoef);
92-
void setMaxPhiCoef(float maxPhiCoef);
93128

94129
// Query for uniform density value
95-
float getUniformTargetDensity(int threads);
96-
97-
// HPWL: half-parameter wire length.
98-
void setReferenceHpwl(float refHpwl);
99-
100-
// temp funcs; OpenDB should have these values.
101-
void setPadLeft(int padding);
102-
void setPadRight(int padding);
103-
104-
void setTimingDrivenMode(bool mode);
105-
106-
void setSkipIoMode(bool mode);
107-
void setDisableRevertIfDiverge(bool mode);
108-
109-
void setRoutabilityDrivenMode(bool mode);
110-
void setRoutabilityUseGrt(bool mode);
111-
void setRoutabilityCheckOverflow(float overflow);
112-
void setRoutabilityMaxDensity(float density);
113-
void setRoutabilityMaxInflationIter(int iter);
114-
void setRoutabilityTargetRcMetric(float rc);
115-
void setRoutabilityInflationRatioCoef(float coef);
116-
void setRoutabilityMaxInflationRatio(float ratio);
117-
void setRoutabilityRcCoefficients(float k1, float k2, float k3, float k4);
118-
void setEnableRoutingCongestion(bool mode);
119-
120-
void addTimingNetWeightOverflow(int overflow);
121-
void setTimingNetWeightMax(float max);
122-
void setKeepResizeBelowOverflow(float overflow);
130+
float getUniformTargetDensity(const PlaceOptions& options, int threads);
123131

124132
void setDebug(int pause_iterations,
125133
int update_iterations,
@@ -128,10 +136,11 @@ class Replace
128136
odb::dbInst* inst,
129137
int start_iter,
130138
bool generate_images,
131-
std::string images_path);
139+
const std::string& images_path);
132140

133141
private:
134-
bool initNesterovPlace(int threads);
142+
bool initNesterovPlace(const PlaceOptions& options, int threads);
143+
void checkHasCoreRows();
135144

136145
odb::dbDatabase* db_ = nullptr;
137146
sta::dbSta* sta_ = nullptr;
@@ -151,55 +160,10 @@ class Replace
151160
std::unique_ptr<InitialPlace> ip_;
152161
std::unique_ptr<NesterovPlace> np_;
153162

154-
int initialPlaceMaxIter_ = 20;
155-
int initialPlaceMinDiffLength_ = 1500;
156-
int initialPlaceMaxSolverIter_ = 100;
157-
int initialPlaceMaxFanout_ = 200;
158-
float initialPlaceNetWeightScale_ = 800;
159-
160163
int total_placeable_insts_ = 0;
161164

162-
int nesterovPlaceMaxIter_ = 5000;
163-
int binGridCntX_ = 0;
164-
int binGridCntY_ = 0;
165-
float overflow_ = 0.1;
166-
float density_ = 1.0;
167-
float initDensityPenalityFactor_ = 0.00008;
168-
float initWireLengthCoef_ = 0.25;
169-
float minPhiCoef_ = 0.95;
170-
float maxPhiCoef_ = 1.05;
171-
float referenceHpwl_ = 446000000;
172-
173-
float routabilityCheckOverflow_ = 0.3;
174-
float routabilityMaxDensity_ = 0.99;
175-
float routabilityTargetRcMetric_ = 1.01;
176-
float routabilityInflationRatioCoef_ = 2;
177-
float routabilityMaxInflationRatio_ = 3;
178-
int routabilityMaxInflationIter_ = 4;
179-
180-
// routability RC metric coefficients
181-
float routabilityRcK1_ = 1.0;
182-
float routabilityRcK2_ = 1.0;
183-
float routabilityRcK3_ = 0.0;
184-
float routabilityRcK4_ = 0.0;
185-
186-
float timingNetWeightMax_ = 5;
187-
float keepResizeBelowOverflow_ = 1.0;
188-
189-
bool timingDrivenMode_ = true;
190-
bool routabilityDrivenMode_ = true;
191-
bool routabilityUseRudy_ = true;
192-
bool uniformTargetDensityMode_ = false;
193-
bool skipIoMode_ = false;
194-
bool disableRevertIfDiverge_ = false;
195-
bool enable_routing_congestion_ = false;
196-
197-
std::vector<int> timingNetWeightOverflows_;
198165
Clusters clusters_;
199166

200-
// temp variable; OpenDB should have these values.
201-
int padLeft_ = 0;
202-
int padRight_ = 0;
203167
bool gui_debug_ = false;
204168
int gui_debug_pause_iterations_ = 10;
205169
int gui_debug_update_iterations_ = 10;

src/gpl/src/initialPlace.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,15 @@ namespace gpl {
2121

2222
using T = Eigen::Triplet<float>;
2323

24-
InitialPlaceVars::InitialPlaceVars()
24+
InitialPlaceVars::InitialPlaceVars(const PlaceOptions& options,
25+
const bool debug)
26+
: maxIter(options.initialPlaceMaxIter),
27+
minDiffLength(options.initialPlaceMinDiffLength),
28+
maxSolverIter(options.initialPlaceMaxSolverIter),
29+
maxFanout(options.initialPlaceMaxFanout),
30+
netWeightScale(options.initialPlaceNetWeightScale),
31+
debug(debug)
2532
{
26-
reset();
27-
}
28-
29-
void InitialPlaceVars::reset()
30-
{
31-
maxIter = 20;
32-
minDiffLength = 1500;
33-
maxSolverIter = 100;
34-
maxFanout = 200;
35-
netWeightScale = 800.0;
36-
debug = false;
3733
}
3834

3935
InitialPlace::InitialPlace(InitialPlaceVars ipVars,

0 commit comments

Comments
 (0)