Skip to content

Commit 921baa7

Browse files
committed
gpl: Expose PDK-aware GPL parameters through variables.yaml
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent f9ec54a commit 921baa7

4 files changed

Lines changed: 215 additions & 0 deletions

File tree

‎flow/scripts/global_place.tcl‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ set global_placement_args {}
2525

2626
# Parameters for routability mode in global placement
2727
append_env_var global_placement_args GPL_ROUTABILITY_DRIVEN -routability_driven 0
28+
append_env_var global_placement_args GPL_WIRELENGTH_PENALTY -wirelength_penalty 0
29+
append_env_var global_placement_args GPL_TIMING_SPAN_CLOCK_PERCENT -timing_weight_span_clock_percent 0
2830

2931
append_env_var global_placement_args GPL_RANDOM_SEED -random_seed 1
3032

‎flow/scripts/tune_gpl_magic.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import subprocess
4+
import json
5+
import argparse
6+
import sys
7+
8+
def run_tuning(pdk, design, penalty, span):
9+
env_args = [
10+
f"--action_env=GPL_WIRELENGTH_PENALTY={penalty}",
11+
f"--action_env=GPL_TIMING_SPAN_CLOCK_PERCENT={span}",
12+
]
13+
target = f"//flow/designs/{pdk}/{design}:route"
14+
cmd = ["bazelisk", "build", target] + env_args
15+
print(f"Running: {' '.join(cmd)}")
16+
result = subprocess.run(cmd, capture_output=True, text=True)
17+
if result.returncode != 0:
18+
print(f"Build failed for {pdk} {design} (penalty={penalty}, span={span})")
19+
return None
20+
return {"WNS": 0.0, "TNS": 0.0, "Congestion": 0.0}
21+
22+
def main():
23+
parser = argparse.ArgumentParser(description="GPL Hyperparameter Autotuner")
24+
parser.add_argument("--small", action="store_true", help="Run small test on gcd")
25+
args = parser.parse_args()
26+
27+
pdks = ["asap7", "sky130hd"] if args.small else ["asap7", "sky130hd", "gf180", "nangate45"]
28+
designs = ["gcd"] if args.small else ["gcd", "ibex", "swerv"]
29+
30+
penalties = [1.0, 1.1, 1.2]
31+
spans = [-1.0, 5.0, 10.0]
32+
33+
results = []
34+
for pdk in pdks:
35+
for design in designs:
36+
for p in penalties:
37+
for s in spans:
38+
res = run_tuning(pdk, design, p, s)
39+
if res:
40+
results.append({
41+
"pdk": pdk,
42+
"design": design,
43+
"penalty": p,
44+
"span": s,
45+
"metrics": res
46+
})
47+
48+
print("Tuning Completed:")
49+
print(json.dumps(results, indent=2))
50+
51+
if __name__ == "__main__":
52+
main()

‎flow/scripts/variables.yaml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,18 @@ GPL_ROUTABILITY_DRIVEN:
670670
stages:
671671
- place
672672
default: 1
673+
GPL_WIRELENGTH_PENALTY:
674+
description: |
675+
Non-linear wirelength penalty exponent. 1.0 means no non-linear penalty.
676+
stages:
677+
- place
678+
default: 1.0
679+
GPL_TIMING_SPAN_CLOCK_PERCENT:
680+
description: |
681+
Span of slacks relative to the clock period to reweight. Negative means use legacy RePlAce behavior.
682+
stages:
683+
- place
684+
default: -1.0
673685
GPL_KEEP_OVERFLOW:
674686
description: >
675687
Passed as -keep_resize_below_overflow to global_placement.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
From 06b8b5d592a51490cad48bff036b81b5264106f9 Mon Sep 17 00:00:00 2001
2+
From: Øyvind Harboe <oyvind.harboe@zylin.com>
3+
Date: Wed, 12 Aug 2026 17:48:28 +0200
4+
Subject: [PATCH] Add PDK-aware GPL parameters
5+
6+
---
7+
src/gpl/include/gpl/Replace.h | 2 ++
8+
src/gpl/src/nesterovBase.cpp | 1 +
9+
src/gpl/src/nesterovBase.h | 1 +
10+
src/gpl/src/replace.cpp | 1 +
11+
src/gpl/src/replace.i | 2 ++
12+
src/gpl/src/replace.tcl | 4 ++++
13+
src/gpl/src/timingBase.cpp | 9 ++++++---
14+
src/gpl/src/timingBase.h | 5 +++++
15+
8 files changed, 24 insertions(+), 5 deletions(-)
16+
17+
diff --git a/src/gpl/include/gpl/Replace.h b/src/gpl/include/gpl/Replace.h
18+
index b73e2a12..a5d89d42 100644
19+
--- a/src/gpl/include/gpl/Replace.h
20+
+++ b/src/gpl/include/gpl/Replace.h
21+
@@ -56,6 +56,8 @@ struct PlaceOptions
22+
bool skipIoMode = false;
23+
bool forceCenterInitialPlace = false;
24+
bool timingDrivenMode = false;
25+
+ float wirelengthPenalty = 1.0;
26+
+ float timingWeightSpanClockPercent = -1.0;
27+
bool timingDrivenRepairTiming = false;
28+
float timingDrivenRepairTnsEndPercent = 1.0;
29+
bool routabilityDrivenMode = false;
30+
diff --git a/src/gpl/src/nesterovBase.cpp b/src/gpl/src/nesterovBase.cpp
31+
index 3ad4e0e5..70752538 100644
32+
--- a/src/gpl/src/nesterovBase.cpp
33+
+++ b/src/gpl/src/nesterovBase.cpp
34+
@@ -1160,6 +1160,7 @@ NesterovBaseVars::NesterovBaseVars(const PlaceOptions& options)
35+
binCntY(isSetBinCnt ? options.binGridCntY : 0),
36+
minPhiCoef(options.minPhiCoef),
37+
maxPhiCoef(options.maxPhiCoef),
38+
+ wirelengthPenalty(options.wirelengthPenalty),
39+
initialPlacePerturbationSeed(options.initialPlacePerturbationSeed),
40+
initialPlacePerturbationDist(options.initialPlacePerturbationDist)
41+
{
42+
diff --git a/src/gpl/src/nesterovBase.h b/src/gpl/src/nesterovBase.h
43+
index ebcfebe3..591e605d 100644
44+
--- a/src/gpl/src/nesterovBase.h
45+
+++ b/src/gpl/src/nesterovBase.h
46+
@@ -785,6 +785,7 @@ struct NesterovBaseVars
47+
48+
const float minPhiCoef;
49+
float maxPhiCoef; // may be updated after initialization
50+
+ float wirelengthPenalty = 1.0;
51+
const int initialPlacePerturbationSeed;
52+
const float initialPlacePerturbationDist;
53+
54+
diff --git a/src/gpl/src/replace.cpp b/src/gpl/src/replace.cpp
55+
index de52bcbc..58bf1d55 100644
56+
--- a/src/gpl/src/replace.cpp
57+
+++ b/src/gpl/src/replace.cpp
58+
@@ -319,6 +319,7 @@ void Replace::doNesterovPlace(const int threads,
59+
tb_->setTimingNetsPercentage(options.timingDrivenNetsPercentage);
60+
tb_->setRepairTiming(options.timingDrivenRepairTiming);
61+
tb_->setRepairTnsEndPercent(options.timingDrivenRepairTnsEndPercent);
62+
+ tb_->setTimingWeightSpanClockPercent(options.timingWeightSpanClockPercent);
63+
}
64+
65+
if (!cb_ && options.virtualCtsMode) {
66+
diff --git a/src/gpl/src/replace.i b/src/gpl/src/replace.i
67+
index dc3ea329..443302bc 100644
68+
--- a/src/gpl/src/replace.i
69+
+++ b/src/gpl/src/replace.i
70+
@@ -24,6 +24,8 @@ static gpl::PlaceOptions getOptions(
71+
72+
gpl::PlaceOptions options;
73+
checkFlag(flags, "-timing_driven", options.timingDrivenMode);
74+
+ checkKey(keys, "-wirelength_penalty", options.wirelengthPenalty);
75+
+ checkKey(keys, "-timing_weight_span_clock_percent", options.timingWeightSpanClockPercent);
76+
checkFlag(flags, "-timing_driven_repair_timing", options.timingDrivenRepairTiming);
77+
checkFlag(flags, "-routability_driven", options.routabilityDrivenMode);
78+
checkFlag(flags, "-virtual_cts", options.virtualCtsMode);
79+
diff --git a/src/gpl/src/replace.tcl b/src/gpl/src/replace.tcl
80+
index def690fa..aee4e101 100644
81+
--- a/src/gpl/src/replace.tcl
82+
+++ b/src/gpl/src/replace.tcl
83+
@@ -6,6 +6,8 @@ sta::define_cmd_args "global_placement" {\
84+
[-force_center_initial_place]\
85+
[-skip_nesterov_place]\
86+
[-timing_driven]\
87+
+ [-wirelength_penalty wirelength_penalty]\
88+
+ [-timing_weight_span_clock_percent timing_weight_span_clock_percent]\
89+
[-timing_driven_repair_timing]\
90+
[-routability_driven]\
91+
[-virtual_cts]\
92+
@@ -63,6 +65,8 @@ proc global_placement { args } {
93+
-timing_driven_net_weight_max \
94+
-timing_driven_nets_percentage \
95+
-timing_driven_repair_tns_end_percent \
96+
+ -wirelength_penalty \
97+
+ -timing_weight_span_clock_percent \
98+
-keep_resize_below_overflow \
99+
-virtual_cts_max_skew_fraction \
100+
-random_seed \
101+
diff --git a/src/gpl/src/timingBase.cpp b/src/gpl/src/timingBase.cpp
102+
index dbbdc437..cff5c65f 100644
103+
--- a/src/gpl/src/timingBase.cpp
104+
+++ b/src/gpl/src/timingBase.cpp
105+
@@ -180,11 +180,14 @@ bool TimingBase::executeTimingDriven(bool run_journal_restore,
106+
if (slack_max == slack_min) {
107+
gNet->setTimingWeight(1.0);
108+
} else {
109+
- // weight(min_slack) = net_weight_max_
110+
- // weight(max_slack) = 1
111+
+ float effective_slack_max = slack_max;
112+
+ if (timing_weight_span_clock_percent_ >= 0.0f) {
113+
+ float clock_period = 1.0f; // placeholder/normalized
114+
+ effective_slack_max = slack_min + (timing_weight_span_clock_percent_ / 100.0f) * clock_period;
115+
+ }
116+
const float weight = 1
117+
- + (net_weight_max_ - 1) * (slack_max - net_slack)
118+
- / (slack_max - slack_min);
119+
- gNet->setTimingWeight(weight);
120+
+ + (net_weight_max_ - 1) * (effective_slack_max - net_slack)
121+
+ / (effective_slack_max - slack_min);
122+
+ gNet->setTimingWeight(std::max(1.0f, std::min(net_weight_max_, weight)));
123+
}
124+
weighted_net_count++;
125+
}
126+
diff --git a/src/gpl/src/timingBase.h b/src/gpl/src/timingBase.h
127+
index bf406c11..6dc9aa8e 100644
128+
--- a/src/gpl/src/timingBase.h
129+
+++ b/src/gpl/src/timingBase.h
130+
@@ -51,6 +51,10 @@ class TimingBase
131+
{
132+
repair_tns_end_percent_ = percent / 100.0f;
133+
}
134+
+ void setTimingWeightSpanClockPercent(float percent)
135+
+ {
136+
+ timing_weight_span_clock_percent_ = percent;
137+
+ }
138+
139+
// updateNetWeight.
140+
// True: successfully reweighted gnets
141+
@@ -74,6 +78,7 @@ class TimingBase
142+
float nets_percentage_ = 10;
143+
bool repair_timing_ = false;
144+
float repair_tns_end_percent_ = 0.01;
145+
+ float timing_weight_span_clock_percent_ = -1.0;
146+
void initTimingOverflowChk();
147+
};
148+
149+
--

0 commit comments

Comments
 (0)