Skip to content

Commit 155dabc

Browse files
oharboeclaude
andcommitted
Split defs.bzl: extract gallery macros to gallery.bzl
Move demo_gallery_image, demo_stage_images, and _STAGE_SCRIPTS to gallery.bzl. defs.bzl keeps flow macros (demo_flow, demo_sram, demo_hierarchical). No behavior change. Update load statements in 14 BUILD.bazel files and 2 docs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cc784fc commit 155dabc

File tree

17 files changed

+305
-129
lines changed

17 files changed

+305
-129
lines changed

.claude/commands/demo-add.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ After synthesis passes, run through placement and generate a gallery screenshot.
334334

335335
```starlark
336336
# Add to <project>/BUILD.bazel:
337-
load("//:defs.bzl", "demo_gallery_image")
337+
load("//:gallery.bzl", "demo_gallery_image")
338338

339339
demo_gallery_image(
340340
name = "<top_module>_gallery",

coralnpu/BUILD.bazel

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
load("//:defs.bzl", "demo_flow", "demo_sram")
2+
load("//:gallery.bzl", "demo_gallery_image", "demo_stage_images", "orfs_run")
13
load("@bazel-orfs-verilog//:generate.bzl", "fir_library")
2-
load("@bazel-orfs//:openroad.bzl", "orfs_synth")
34
load("@bazel-orfs-verilog//:verilog.bzl", "verilog_directory")
5+
load("@bazel-orfs//:openroad.bzl", "orfs_synth")
46
load("@rules_chisel//chisel:defs.bzl", "chisel_binary")
5-
load("//:defs.bzl", "demo_flow", "demo_gallery_image", "demo_sram", "demo_stage_images", "orfs_run")
67

78
# Step 1: Compile the Chisel generator binary
89
chisel_binary(
@@ -43,7 +44,6 @@ filegroup(
4344
"@cvfpu//:all_srcs",
4445
"@fpu_div_sqrt_mvp//:all_srcs",
4546
],
46-
4747
)
4848

4949
# Step 5: Parallel per-module synthesis (megaboom pattern)
@@ -54,30 +54,37 @@ filegroup(
5454
# from ~6 min to ~30s.
5555

5656
KEPT_MODULES = [
57-
"Regfile", # 26,775 cells — register file (24% of design)
57+
"Regfile", # 26,775 cells — register file (24% of design)
5858
"RetirementBuffer", # 7,508 cells — reorder buffer
59-
"fpnew_fma", # 7,072 cells — FPU multiply-add
59+
"fpnew_fma", # 7,072 cells — FPU multiply-add
6060
"CircularBufferMulti", # 6,911 cells — instruction buffer
61-
"Csr", # 5,225 cells — CSR unit
62-
"Mlu", # 4,819 cells — multiply unit
63-
"DispatchV2", # 4,743 cells — dispatch
61+
"Csr", # 5,225 cells — CSR unit
62+
"Mlu", # 4,819 cells — multiply unit
63+
"DispatchV2", # 4,743 cells — dispatch
6464
"fpnew_cast_multi", # 2,605 cells — FPU cast
65-
"ram_3x145", # 2,437 cells — small RAM
66-
"DebugModule", # 2,366 cells — debug
67-
"Aligner", # 2,334 cells — memory alignment
68-
"ram_3x137", # 2,304 cells — small RAM
69-
"Alu", # 2,285 cells — ALU
70-
"FetchControl", # 2,122 cells — fetch control
65+
"ram_3x145", # 2,437 cells — small RAM
66+
"DebugModule", # 2,366 cells — debug
67+
"Aligner", # 2,334 cells — memory alignment
68+
"ram_3x137", # 2,304 cells — small RAM
69+
"Alu", # 2,285 cells — ALU
70+
"FetchControl", # 2,122 cells — fetch control
7171
"pa_fdsu_srt_single", # 2,052 cells — FPU divsqrt
7272
]
7373

7474
# Mocked SRAMs — always blackboxed
75-
MOCKED_SRAMS = ["Sram_2048x128", "Sram_512x128"]
75+
MOCKED_SRAMS = [
76+
"Sram_2048x128",
77+
"Sram_512x128",
78+
]
7679

7780
# Modules with SystemVerilog type parameters — slang can't blackbox these.
7881
# They are still individually synthesized but must NOT appear in SYNTH_BLACKBOXES
7982
# for the CoreMiniAxi top-level target.
80-
TYPE_PARAM_MODULES = ["fpnew_fma", "fpnew_cast_multi", "Aligner"]
83+
TYPE_PARAM_MODULES = [
84+
"fpnew_fma",
85+
"fpnew_cast_multi",
86+
"Aligner",
87+
]
8188

8289
# Modules safe to blackbox (no type parameters)
8390
BLACKBOXABLE_MODULES = [m for m in KEPT_MODULES if m not in TYPE_PARAM_MODULES]
@@ -102,14 +109,12 @@ ALL_SYNTH_MODULES = KEPT_MODULES + ["CoreMiniAxi"]
102109
# CoreMiniAxi can only blackbox modules without type parameters;
103110
# submodule targets blackbox all other kept modules.
104111
"SYNTH_BLACKBOXES": " ".join(
105-
([b for b in BLACKBOXABLE_MODULES if b != name] if name == "CoreMiniAxi"
106-
else [b for b in KEPT_MODULES if b != name]) + MOCKED_SRAMS,
112+
([b for b in BLACKBOXABLE_MODULES if b != name] if name == "CoreMiniAxi" else [b for b in KEPT_MODULES if b != name]) + MOCKED_SRAMS,
107113
),
108114
},
109115
module_top = name,
110116
save_odb = False,
111117
sources = {"SDC_FILE": [":constraints.sdc"]},
112-
113118
variant = "netlist",
114119
verilog_files = [":coralnpu_all_sv"],
115120
) for name in ALL_SYNTH_MODULES]
@@ -118,21 +123,18 @@ ALL_SYNTH_MODULES = KEPT_MODULES + ["CoreMiniAxi"]
118123
name = "{}_netlist".format(name),
119124
srcs = ["{}_netlist_synth".format(name)],
120125
output_group = "1_2_yosys.v",
121-
122126
) for name in ALL_SYNTH_MODULES]
123127

124128
filegroup(
125129
name = "netlists",
126130
srcs = [":{}_netlist".format(name) for name in ALL_SYNTH_MODULES],
127-
128131
)
129132

130133
genrule(
131134
name = "CoreMiniAxi_combined_netlist",
132135
srcs = [":netlists"],
133136
outs = ["CoreMiniAxi_combined_netlist.v"],
134137
cmd = "cat $(SRCS) > $@",
135-
136138
)
137139

138140
# Step 6: SRAM macro targets (provide LEF/LIB for mocked memories)
@@ -143,41 +145,35 @@ genrule(
143145

144146
demo_sram(
145147
name = "Sram_2048x128",
146-
verilog_files = [":coralnpu_all_sv"],
147-
mock_area = 1.0,
148148
abstract_stage = "cts",
149149
arguments = {
150150
"CORE_UTILIZATION": "40",
151151
"PLACE_DENSITY": "0.65",
152152
"PDN_TCL": "$(PLATFORM_DIR)/openRoad/pdn/BLOCK_grid_strategy.tcl",
153153
"SYNTH_SLANG_ARGS": "--disable-instance-caching=false -DUSE_GENERIC -Iexternal/+_repo_rules+common_cells/include",
154154
},
155+
mock_area = 1.0,
155156
sources = {"SDC_FILE": [":constraints-sram.sdc"]},
157+
verilog_files = [":coralnpu_all_sv"],
156158
)
157159

158160
demo_sram(
159161
name = "Sram_512x128",
160-
verilog_files = [":coralnpu_all_sv"],
161-
mock_area = 1.0,
162162
abstract_stage = "cts",
163163
arguments = {
164164
"CORE_UTILIZATION": "40",
165165
"PLACE_DENSITY": "0.65",
166166
"PDN_TCL": "$(PLATFORM_DIR)/openRoad/pdn/BLOCK_grid_strategy.tcl",
167167
"SYNTH_SLANG_ARGS": "--disable-instance-caching=false -DUSE_GENERIC -Iexternal/+_repo_rules+common_cells/include",
168168
},
169+
mock_area = 1.0,
169170
sources = {"SDC_FILE": [":constraints-sram.sdc"]},
171+
verilog_files = [":coralnpu_all_sv"],
170172
)
171173

172174
# Step 7: ORFS physical design flow (uses pre-synthesized netlists + SRAM macros)
173175
demo_flow(
174176
name = "CoreMiniAxi",
175-
substeps = True,
176-
verilog_files = [":coralnpu_all_sv"],
177-
macros = [
178-
":Sram_2048x128_generate_abstract",
179-
":Sram_512x128_generate_abstract",
180-
],
181177
arguments = {
182178
# Synthesis is skipped (SYNTH_NETLIST_FILES provides pre-synthesized netlists).
183179
# SYNTH_HIERARCHICAL=0 because KEEP_VARS is not generated when synthesis
@@ -211,11 +207,17 @@ demo_flow(
211207
"FILL_CELLS": "",
212208
"TAPCELL_TCL": "",
213209
},
210+
macros = [
211+
":Sram_2048x128_generate_abstract",
212+
":Sram_512x128_generate_abstract",
213+
],
214214
sources = {
215215
"SDC_FILE": [":constraints.sdc"],
216216
"SYNTH_NETLIST_FILES": [":CoreMiniAxi_combined_netlist"],
217217
"PRE_GLOBAL_PLACE_TCL": [":CoreMiniAxi_probe_placement"],
218218
},
219+
substeps = True,
220+
verilog_files = [":coralnpu_all_sv"],
219221
)
220222

221223
# Probe placement: run fast routability-driven placement on floorplan,
@@ -230,7 +232,6 @@ orfs_run(
230232
"PLACEMENT_TIPS_OUT": "$(location :placement-tips.tcl)",
231233
},
232234
script = "//scripts:probe_placement.tcl",
233-
234235
)
235236

236237
demo_gallery_image(
@@ -241,5 +242,9 @@ demo_gallery_image(
241242
demo_stage_images(
242243
name = "CoreMiniAxi_images",
243244
module = "CoreMiniAxi",
244-
stages = ["floorplan", "place", "cts"],
245+
stages = [
246+
"floorplan",
247+
"place",
248+
"cts",
249+
],
245250
)

cva6/BUILD.bazel

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
load("//:defs.bzl", "demo_flow", "demo_gallery_image")
1+
load("//:defs.bzl", "demo_flow")
2+
load("//:gallery.bzl", "demo_gallery_image")
23

34
# CVA6 cv32a60x — 32-bit RISC-V CPU with HPDcache
45
#
@@ -17,13 +18,6 @@ load("//:defs.bzl", "demo_flow", "demo_gallery_image")
1718

1819
demo_flow(
1920
name = "cva6",
20-
substeps = True,
21-
verilog_files = [
22-
"@cva6//:rtl",
23-
"@cv_hpdcache//:rtl",
24-
"@cvfpu//:all_srcs",
25-
"@fpu_div_sqrt_mvp//:all_srcs",
26-
],
2721
arguments = {
2822
# Synthesis — survey mode: keep all modules for size analysis
2923
"SYNTH_HIERARCHICAL": "1",
@@ -55,6 +49,13 @@ demo_flow(
5549
"TNS_END_PERCENT": "0",
5650
},
5751
sources = {"SDC_FILE": [":constraints.sdc"]},
52+
substeps = True,
53+
verilog_files = [
54+
"@cva6//:rtl",
55+
"@cv_hpdcache//:rtl",
56+
"@cvfpu//:all_srcs",
57+
"@fpu_div_sqrt_mvp//:all_srcs",
58+
],
5859
)
5960

6061
demo_gallery_image(

docs/adding-projects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ All three apply GLOBAL_SETTINGS + FAST_SETTINGS by default.
337337
Use `demo_gallery_image()` to generate `.webp` screenshots:
338338

339339
```starlark
340-
load("//:defs.bzl", "demo_gallery_image")
340+
load("//:gallery.bzl", "demo_gallery_image")
341341

342342
# Start with placement (fast)
343343
demo_gallery_image(

gallery.bzl

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""Gallery image macros for the OpenROAD Demo Gallery.
2+
3+
Generate screenshots and thumbnails from ORFS stage outputs.
4+
"""
5+
6+
load("@bazel-orfs//:openroad.bzl", _orfs_run = "orfs_run")
7+
8+
orfs_run = _orfs_run
9+
10+
# Per-stage gallery scripts — each stage has different interesting features.
11+
_STAGE_SCRIPTS = {
12+
"floorplan": "//scripts:floorplan_image.tcl",
13+
"place": "//scripts:place_image.tcl",
14+
"cts": "//scripts:cts_image.tcl",
15+
"grt": "//scripts:grt_image.tcl",
16+
"route": "//scripts:route_image.tcl",
17+
"final": "//scripts:route_image.tcl",
18+
}
19+
20+
def demo_gallery_image(
21+
name,
22+
src,
23+
stage = None,
24+
thumbnail_size = 400):
25+
"""Generate a gallery screenshot and thumbnail from an ORFS stage.
26+
27+
Uses a per-stage Tcl script for optimal display settings (e.g. CTS
28+
hides power/ground, route shows signal nets). Falls back to the
29+
generic gallery_image.tcl for unknown stages.
30+
31+
Creates two targets:
32+
:<name> — full-resolution screenshot (.webp)
33+
:<name>_thumb — resized thumbnail (.webp)
34+
35+
Args:
36+
name: Target name (e.g., "multiplier_gallery")
37+
src: The orfs stage target to screenshot (e.g., ":multiplier_route")
38+
stage: Stage name for script selection (e.g., "cts"). Auto-detected from src if None.
39+
thumbnail_size: Max dimension in pixels for thumbnail (default: 400)
40+
"""
41+
script = _STAGE_SCRIPTS.get(stage, "//scripts:gallery_image.tcl")
42+
orfs_run(
43+
name = name,
44+
src = src,
45+
outs = [name + ".webp"],
46+
arguments = {
47+
"GALLERY_IMAGE": "$(location :" + name + ".webp)",
48+
"OR_ARGS": "-gui",
49+
},
50+
extra_args = "OPENROAD_CMD='xvfb-run -a $(OPENROAD_EXE) -exit $(OPENROAD_ARGS)'",
51+
script = script,
52+
)
53+
54+
native.genrule(
55+
name = name + "_thumb",
56+
srcs = [":" + name],
57+
outs = [name + "_thumb.webp"],
58+
cmd = "$(execpath //scripts:resize_image) $(SRCS) $@ --size " + str(thumbnail_size),
59+
tools = ["//scripts:resize_image"],
60+
)
61+
62+
def demo_stage_images(
63+
name,
64+
module,
65+
stages = None):
66+
"""Generate gallery images at multiple ORFS stages.
67+
68+
Creates `<name>_<stage>` and `<name>_<stage>_thumb` targets for each
69+
specified stage. Images show how the design evolves through the flow —
70+
from empty die at floorplan to final routed design.
71+
72+
Args:
73+
name: Target name prefix (e.g. "MeshWithDelays_images")
74+
module: The orfs_flow target name (e.g. "MeshWithDelays")
75+
stages: List of stages to image (default: ["floorplan", "place", "cts", "route"])
76+
"""
77+
if stages == None:
78+
stages = ["floorplan", "place", "cts", "grt", "route"]
79+
for stage in stages:
80+
demo_gallery_image(
81+
name = name + "_" + stage,
82+
src = ":" + module + "_" + stage,
83+
stage = stage,
84+
)

gemmini/BUILD.bazel

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
load("@rules_chisel//chisel:defs.bzl", "chisel_binary")
1+
load("//:defs.bzl", "demo_flow")
2+
load("//:gallery.bzl", "demo_gallery_image", "demo_stage_images")
23
load("@bazel-orfs-verilog//:generate.bzl", "fir_library")
3-
load("@bazel-orfs-verilog//:verilog.bzl", "verilog_single_file_library", "verilog_directory")
4-
load("//:defs.bzl", "demo_flow", "demo_gallery_image", "demo_stage_images")
4+
load("@bazel-orfs-verilog//:verilog.bzl", "verilog_directory", "verilog_single_file_library")
5+
load("@rules_chisel//chisel:defs.bzl", "chisel_binary")
56

67
# Step 1: Compile the Chisel generator binary
78
chisel_binary(
@@ -39,13 +40,11 @@ genrule(
3940
srcs = [":gemmini_concat_sv"],
4041
outs = ["MeshWithDelays.sv"],
4142
cmd = "cp $< $@",
42-
4343
)
4444

4545
# Step 5: ORFS physical design flow
4646
demo_flow(
4747
name = "MeshWithDelays",
48-
verilog_files = [":gemmini_sv"],
4948
arguments = {
5049
# --- Synthesis ---
5150
# Keep all modules for hierarchy analysis (run //scripts:module_sizes after synth)
@@ -70,6 +69,7 @@ demo_flow(
7069
sources = {
7170
"SDC_FILE": [":constraints.sdc"],
7271
},
72+
verilog_files = [":gemmini_sv"],
7373
)
7474

7575
demo_gallery_image(
@@ -80,5 +80,11 @@ demo_gallery_image(
8080
demo_stage_images(
8181
name = "MeshWithDelays_images",
8282
module = "MeshWithDelays",
83-
stages = ["floorplan", "place", "cts", "grt", "route"],
83+
stages = [
84+
"floorplan",
85+
"place",
86+
"cts",
87+
"grt",
88+
"route",
89+
],
8490
)

0 commit comments

Comments
 (0)