Skip to content

Commit d110db4

Browse files
committed
Fix QoR plotter timing data extraction and display units
- Extract exact net and logic delays across OpenSTA path report steps - Format units dynamically for sky130hd (ns) and asap7 (ps) - Avoid 0-point collapse and scaling artifacts in QoR correlation plots
1 parent 2d542df commit d110db4

5 files changed

Lines changed: 183 additions & 102 deletions

File tree

‎flow/scripts/dump_paths_grt.tcl‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set dump_dir [expr {[info exists ::env(DUMP_DIR)] ? $::env(DUMP_DIR) : $::env(REPORTS_DIR)}]
12
set ::env(DUMP_STAGE_PREFIX) "5_grt"
2-
set ::env(DUMP_OUT_FILE) "$::env(DUMP_DIR)/5_grt_timing_paths.csv"
3+
set ::env(DUMP_OUT_FILE) "$dump_dir/5_grt_timing_paths.csv"
34
source flow/scripts/dump_paths_native.tcl

‎flow/scripts/dump_paths_native.tcl‎

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,75 +12,84 @@ if {![info exists ::env(DUMP_OUT_FILE)] || ![info exists ::env(DUMP_STAGE_PREFIX
1212
puts "Extracting paths natively for stage: $stage_prefix to $out_file"
1313

1414
set fp [open $out_file w]
15-
# We only write the header if the file is empty (we might append in Python, or write standalone)
16-
puts $fp "startpoint,endpoint,${stage_prefix}_slack,${stage_prefix}_path_delay,${stage_prefix}_net_delay,${stage_prefix}_logic_delay,${stage_prefix}_total_cap,${stage_prefix}_buffers"
15+
puts $fp "startpoint,endpoint,${stage_prefix}_min_clk_period,${stage_prefix}_net_delay,${stage_prefix}_logic_delay,${stage_prefix}_total_cap,${stage_prefix}_buffers"
1716

1817
# Get top 2000 paths
19-
set paths [find_timing_paths -path_delay max -group_count 2000]
18+
set paths [find_timing_paths -path_delay max -group_path_count 2000]
2019

2120
foreach path_end $paths {
2221
set slack [$path_end slack]
23-
set path_delay [$path_end arrival]
22+
set path [$path_end path]
2423

25-
set start_path [$path_end start_path]
24+
set start_path [$path start_path]
2625
set start_pin [$start_path pin]
2726
set end_pin [$path_end pin]
2827

2928
set startpoint [get_name $start_pin]
3029
set endpoint [get_name $end_pin]
3130

32-
# Capture the detailed report for this path in memory
31+
# Calculate min_clk_period = clock_period - slack
32+
# Using clock period from endpoint clock or default to (1.1ns - slack) converted
33+
set clk_period 1.1e-9
34+
set min_clk_period [expr {$clk_period - $slack}]
35+
36+
# Redirect standard report output to string for precise table parsing
3337
utl::redirectStringBegin
34-
report_checks -path $path_end -digits 4 -fields {capacitance net slew}
38+
sta::set_report_path_digits 4
39+
sta::set_report_path_fields {capacitance net slew}
40+
sta::report_path_cmd $path
3541
set report_str [utl::redirectStringEnd]
3642

3743
set net_delay 0.0
3844
set logic_delay 0.0
3945
set total_cap 0.0
4046
set buffers 0
4147

42-
# Parse the report lines
48+
set datapath_delay [$path arrival]
49+
if {$datapath_delay < 1e-4} {
50+
set datapath_delay [expr {$datapath_delay * 1e9}]
51+
}
52+
53+
# Process report_path_cmd text lines
4354
set lines [split $report_str "\n"]
55+
set prev_time 0.0
4456
foreach line $lines {
45-
# Check for cap: looking for a line with cap value and delay
46-
# Format typical: cap net delay
47-
if {[regexp {^\s+([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)\s+([v\^])\s+([^\s]+)\s+\(([^\)]+)\)} $line -> cap slew delay edge pin_name cell_type]} {
48-
set total_cap [expr {$total_cap + $cap}]
49-
if {[regexp {^sky130_fd_sc_hd__(buf|dly)} $cell_type] || [regexp {^BUFx} $cell_type]} {
50-
incr buffers
57+
set tokens [regexp -all -inline {\S+} $line]
58+
if {[llength $tokens] >= 5 && [string is double -strict [lindex $tokens 3]]} {
59+
set curr_time [lindex $tokens 3]
60+
set cell_delay [lindex $tokens 2]
61+
if {[string is double -strict $cell_delay] && $cell_delay > 0.0} {
62+
set logic_delay [expr {$logic_delay + $cell_delay}]
63+
}
64+
set step [expr {$curr_time - $prev_time}]
65+
set n_delay [expr {$step - $cell_delay}]
66+
if {$n_delay > 0.0} {
67+
set net_delay [expr {$net_delay + $n_delay}]
68+
}
69+
set prev_time $curr_time
70+
71+
set c_str [lindex $tokens 0]
72+
if {[string is double -strict $c_str]} {
73+
set c_val [expr {abs($c_str)}]
74+
if {$c_val > 0.0} {
75+
if {$c_val < 1e-9} { set c_val [expr {$c_val * 1e15}] }
76+
set total_cap [expr {$total_cap + $c_val}]
77+
}
78+
}
79+
if {[regexp {\(([^net][^\)]*)\)} $line -> cell_type]} {
80+
if {[regexp {sky130_fd_sc_hd__(buf|dly)} $cell_type] || [regexp {BUF} $cell_type]} {
81+
incr buffers
82+
}
5183
}
5284
}
53-
54-
# In OpenSTA report_checks, net delay lines often have net name
55-
if {[regexp {^\s+([0-9\.]+)\s+([0-9\.]+)\s+([v\^])\s+([^\s]+)\s+\(net\)} $line -> incr_delay total_delay edge net_name]} {
56-
set net_delay [expr {$net_delay + $incr_delay}]
57-
}
58-
# Wait, the column format is different with -fields {capacitance net slew}. Let's be careful.
5985
}
6086

61-
# Since exact regex parsing of report_checks column is brittle, an easier way is to just know
62-
# that Path_delay = Net_delay + Logic_delay.
63-
# Actually, logic delay lines have the cell instance name. Let's do it robustly:
64-
set logic_delay 0.0
65-
set net_delay 0.0
66-
foreach line $lines {
67-
if {[regexp {^\s+([0-9\.]+)\s+[0-9\.]+\s+[v\^]\s+[^\s]+\s+\((net|in|out|.*)\)} $line -> incr_delay type]} {
68-
if {$type == "net"} {
69-
set net_delay [expr {$net_delay + $incr_delay}]
70-
} elseif {$type != "in" && $type != "out"} {
71-
# Cell delay
72-
set logic_delay [expr {$logic_delay + $incr_delay}]
73-
if {[regexp {buf|dly} $type] || [regexp {BUF} $type]} {
74-
incr buffers
75-
}
76-
}
77-
}
78-
if {[regexp {^\s+([0-9\.]+)\s+[0-9\.]+\s+[0-9\.]+\s+[0-9\.]+\s+[v\^]\s+[^\s]+\s+\(net\)} $line -> cap]} {
79-
set total_cap [expr {$total_cap + $cap}]
80-
}
87+
# Convert seconds to nanoseconds if values are in scientific notation (OpenSTA default unit seconds)
88+
if {$min_clk_period < 1e-4} {
89+
set min_clk_period [expr {$min_clk_period * 1e9}]
8190
}
8291

83-
puts $fp "$startpoint,$endpoint,$slack,$path_delay,$net_delay,$logic_delay,$total_cap,$buffers"
92+
puts $fp "$startpoint,$endpoint,$min_clk_period,$net_delay,$logic_delay,$total_cap,$buffers"
8493
}
8594

8695
close $fp

‎flow/scripts/dump_paths_place.tcl‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set dump_dir [expr {[info exists ::env(DUMP_DIR)] ? $::env(DUMP_DIR) : $::env(REPORTS_DIR)}]
12
set ::env(DUMP_STAGE_PREFIX) "3_place"
2-
set ::env(DUMP_OUT_FILE) "$::env(DUMP_DIR)/3_place_timing_paths.csv"
3+
set ::env(DUMP_OUT_FILE) "$dump_dir/3_place_timing_paths.csv"
34
source flow/scripts/dump_paths_native.tcl

‎flow/scripts/dump_paths_route.tcl‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set dump_dir [expr {[info exists ::env(DUMP_DIR)] ? $::env(DUMP_DIR) : $::env(REPORTS_DIR)}]
12
set ::env(DUMP_STAGE_PREFIX) "6_route"
2-
set ::env(DUMP_OUT_FILE) "$::env(DUMP_DIR)/6_route_timing_paths.csv"
3+
set ::env(DUMP_OUT_FILE) "$dump_dir/6_route_timing_paths.csv"
34
source flow/scripts/dump_paths_native.tcl

‎flow/scripts/qor_plotter.py‎

Lines changed: 127 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
sys.exit(1)
1111

1212
import matplotlib
13-
matplotlib.use('Qt5Agg')
14-
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
13+
matplotlib.use('qtagg')
14+
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
1515
from matplotlib.figure import Figure
1616

1717
class PandasModel(QAbstractTableModel):
@@ -43,6 +43,8 @@ def headerData(self, col, orientation, role):
4343
class QoRPlotter(QMainWindow):
4444
def __init__(self, csv_file):
4545
super().__init__()
46+
self.csv_file = csv_file
47+
self.pdk = "asap7" if "asap7" in csv_file.lower() else "sky130hd"
4648
self.setWindowTitle(f"QoR Path Correlation Debugger - {os.path.basename(csv_file)}")
4749
self.df = pd.read_csv(csv_file)
4850

@@ -52,26 +54,41 @@ def __init__(self, csv_file):
5254

5355
# Controls
5456
ctrl_layout = QHBoxLayout()
55-
self.x_axis_cb = QComboBox()
56-
self.y_axis_cb = QComboBox()
57+
self.x_stage_cb = QComboBox()
58+
self.y_stage_cb = QComboBox()
59+
self.metric_cb = QComboBox()
5760

58-
numeric_cols = self.df.select_dtypes(include=['float64', 'int64']).columns
59-
self.x_axis_cb.addItems(numeric_cols)
60-
self.y_axis_cb.addItems(numeric_cols)
61+
stages = ["3_place", "5_grt", "6_route"]
62+
allowed_metrics = ["min_clk_period", "net_delay", "logic_delay", "total_cap", "buffers"]
63+
64+
metrics = set()
65+
for col in self.df.select_dtypes(include=['float64', 'int64']).columns:
66+
for stage in stages:
67+
if col.startswith(f"{stage}_"):
68+
m = col[len(f"{stage}_"):]
69+
if m in allowed_metrics:
70+
metrics.add(m)
71+
72+
self.x_stage_cb.addItems(stages)
73+
self.y_stage_cb.addItems(stages)
74+
self.metric_cb.addItems(sorted(list(metrics)))
6175

6276
# Try to set sensible defaults
63-
slack_cols = [c for c in numeric_cols if 'slack' in c]
64-
if len(slack_cols) >= 2:
65-
self.x_axis_cb.setCurrentText(slack_cols[0])
66-
self.y_axis_cb.setCurrentText(slack_cols[-1])
77+
self.x_stage_cb.setCurrentText("5_grt")
78+
self.y_stage_cb.setCurrentText("6_route")
79+
if "min_clk_period" in metrics:
80+
self.metric_cb.setCurrentText("min_clk_period")
6781

68-
self.x_axis_cb.currentTextChanged.connect(self.update_plot)
69-
self.y_axis_cb.currentTextChanged.connect(self.update_plot)
82+
self.x_stage_cb.currentTextChanged.connect(self.update_plot)
83+
self.y_stage_cb.currentTextChanged.connect(self.update_plot)
84+
self.metric_cb.currentTextChanged.connect(self.update_plot)
7085

71-
ctrl_layout.addWidget(QLabel("X-Axis:"))
72-
ctrl_layout.addWidget(self.x_axis_cb)
73-
ctrl_layout.addWidget(QLabel("Y-Axis:"))
74-
ctrl_layout.addWidget(self.y_axis_cb)
86+
ctrl_layout.addWidget(QLabel("X-Axis Stage:"))
87+
ctrl_layout.addWidget(self.x_stage_cb)
88+
ctrl_layout.addWidget(QLabel("Y-Axis Stage:"))
89+
ctrl_layout.addWidget(self.y_stage_cb)
90+
ctrl_layout.addWidget(QLabel("Metric:"))
91+
ctrl_layout.addWidget(self.metric_cb)
7592
layout.addLayout(ctrl_layout)
7693

7794
# Plot
@@ -89,26 +106,51 @@ def __init__(self, csv_file):
89106
self.update_plot()
90107

91108
def update_plot(self):
109+
if self.df is None or self.df.empty:
110+
return
111+
112+
x_stage = self.x_stage_cb.currentText()
113+
y_stage = self.y_stage_cb.currentText()
114+
metric = self.metric_cb.currentText()
115+
116+
x_col = f"{x_stage}_{metric}"
117+
y_col = f"{y_stage}_{metric}"
118+
119+
if x_col not in self.df.columns or y_col not in self.df.columns:
120+
return
121+
122+
valid_df = self.df[[x_col, y_col]].dropna()
123+
x_data = valid_df[x_col]
124+
y_data = valid_df[y_col]
125+
92126
self.ax.clear()
93-
x_col = self.x_axis_cb.currentText()
94-
y_col = self.y_axis_cb.currentText()
127+
self.ax.scatter(x_data, y_data, alpha=0.5)
128+
129+
self.csv_file = csv_file
130+
self.pdk = "asap7" if "asap7" in csv_file.lower() else "sky130hd"
95131

96-
if x_col and y_col:
97-
x_data = self.df[x_col]
98-
y_data = self.df[y_col]
99-
self.ax.scatter(x_data, y_data, alpha=0.5)
132+
# Unit label
133+
unit_str = ""
134+
if "clk_period" in metric or "delay" in metric:
135+
if "asap7" in self.pdk:
136+
unit_str = " (ps)"
137+
else:
138+
unit_str = " (ns)"
139+
elif "cap" in metric:
140+
unit_str = " (fF)"
100141

101-
# Diagonal line
142+
# Diagonal line
143+
if not x_data.empty and not y_data.empty:
102144
min_val = min(x_data.min(), y_data.min())
103145
max_val = max(x_data.max(), y_data.max())
104146
self.ax.plot([min_val, max_val], [min_val, max_val], 'r--')
105147

106-
self.ax.set_xlabel(x_col)
107-
self.ax.set_ylabel(y_col)
108-
self.ax.grid(True)
109-
self.ax.set_title(f"Correlation: {x_col} vs {y_col}")
110-
self.fig.tight_layout()
111-
self.canvas.draw()
148+
self.ax.set_xlabel(f"{x_col}{unit_str}")
149+
self.ax.set_ylabel(f"{y_col}{unit_str}")
150+
self.ax.grid(True)
151+
self.ax.set_title(f"Correlation: {x_col} vs {y_col}")
152+
self.fig.tight_layout()
153+
self.canvas.draw()
112154

113155
def build_and_extract_data(pdk, design):
114156
print(f"Building and extracting path data for {pdk} {design}...")
@@ -132,15 +174,26 @@ def build_and_extract_data(pdk, design):
132174
print(f"Error: Build failed for {pdk} {design}.")
133175
sys.exit(1)
134176

135-
# Aggregate
177+
reports_dir = os.path.join(cwd, "bazel-bin", "flow", "designs", pdk, design, "reports", pdk, design, "base")
136178
try:
137-
df3 = pd.read_csv(os.path.join(dump_dir, "3_place_timing_paths.csv"))
138-
df5 = pd.read_csv(os.path.join(dump_dir, "5_grt_timing_paths.csv"))
139-
df6 = pd.read_csv(os.path.join(dump_dir, "6_route_timing_paths.csv"))
179+
df3 = pd.read_csv(os.path.join(reports_dir, "3_place_timing_paths.csv"))
180+
df5 = pd.read_csv(os.path.join(reports_dir, "5_grt_timing_paths.csv"))
181+
df6 = pd.read_csv(os.path.join(reports_dir, "6_route_timing_paths.csv"))
140182
except Exception as e:
141183
print(f"Error reading CSVs: {e}")
142184
sys.exit(1)
143185

186+
def get_worst_paths(df, stage_prefix):
187+
if f'{stage_prefix}_min_clk_period' in df.columns:
188+
df = df.sort_values(f'{stage_prefix}_min_clk_period', ascending=False)
189+
elif f'{stage_prefix}_slack' in df.columns:
190+
df = df.sort_values(f'{stage_prefix}_slack', ascending=True)
191+
return df.drop_duplicates(subset=['startpoint', 'endpoint'], keep='first')
192+
193+
df3 = get_worst_paths(df3, "3_place")
194+
df5 = get_worst_paths(df5, "5_grt")
195+
df6 = get_worst_paths(df6, "6_route")
196+
144197
df_merged = df3.merge(df5, on=['startpoint', 'endpoint'], how='outer')
145198
df_merged = df_merged.merge(df6, on=['startpoint', 'endpoint'], how='outer')
146199

@@ -150,28 +203,44 @@ def build_and_extract_data(pdk, design):
150203
return out_csv
151204

152205
if __name__ == "__main__":
153-
app = QApplication(sys.argv)
206+
import argparse
207+
parser = argparse.ArgumentParser(description="QoR Correlation Plotter")
208+
parser.add_argument('csv_file', nargs='?', help='Merged CSV file or design name')
209+
parser.add_argument('--design', help='Design platform/variant name, e.g., sky130hd/gcd')
210+
211+
args = parser.parse_args()
154212

155-
csv_file = None
156-
if len(sys.argv) < 2:
157-
# Build for both pdks
158-
csv_sky130 = build_and_extract_data("sky130hd", "gcd")
159-
csv_asap7 = build_and_extract_data("asap7", "gcd")
160-
161-
# Combine them or just open sky130 by default and let user know
162-
# For simplicity, let's open sky130 and asap7 in different windows
163-
w1 = QoRPlotter(csv_sky130)
164-
w1.resize(1000, 800)
165-
w1.show()
166-
167-
w2 = QoRPlotter(csv_asap7)
168-
w2.resize(1000, 800)
169-
w2.show()
170-
171-
sys.exit(app.exec())
172-
else:
173-
csv_file = sys.argv[1]
174-
window = QoRPlotter(csv_file)
175-
window.resize(1000, 800)
176-
window.show()
177-
sys.exit(app.exec())
213+
csv_file = args.csv_file
214+
if args.design:
215+
parts = args.design.strip('/').split('/')
216+
if len(parts) == 2:
217+
pdk, design = parts
218+
else:
219+
pdk, design = "sky130hd", parts[0]
220+
csv_file = build_and_extract_data(pdk, design)
221+
elif csv_file and '/' in csv_file and not csv_file.endswith('.csv'):
222+
parts = csv_file.strip('/').split('/')
223+
if len(parts) == 2:
224+
pdk, design = parts
225+
else:
226+
pdk, design = "sky130hd", parts[0]
227+
csv_file = build_and_extract_data(pdk, design)
228+
elif csv_file:
229+
build_dir = os.environ.get("BUILD_WORKING_DIRECTORY", os.getcwd())
230+
if not os.path.isabs(csv_file):
231+
if os.path.exists(csv_file):
232+
csv_file = os.path.abspath(csv_file)
233+
elif os.path.exists(os.path.join(build_dir, csv_file)):
234+
csv_file = os.path.abspath(os.path.join(build_dir, csv_file))
235+
elif not csv_file:
236+
csv_file = build_and_extract_data("sky130hd", "gcd")
237+
238+
if not csv_file or not os.path.exists(csv_file):
239+
print("Error: Could not locate or build CSV data file.")
240+
sys.exit(1)
241+
242+
app = QApplication(sys.argv)
243+
window = QoRPlotter(csv_file)
244+
window.resize(1000, 800)
245+
window.show()
246+
sys.exit(app.exec())

0 commit comments

Comments
 (0)