Skip to content

Commit

Permalink
sweep: add sweep macro
Browse files Browse the repository at this point in the history
make sweep in megaboom reusable

Signed-off-by: Øyvind Harboe <[email protected]>
  • Loading branch information
oharboe committed Dec 2, 2024
1 parent ce857d0 commit 3fff266
Show file tree
Hide file tree
Showing 7 changed files with 479 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/smoketests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bazel query //:* | grep -q -v lb_32x128_3_place
echo This target should exist
bazel query //:* | grep -q -v lb_32x128_4_synth

bazel build check_mock_area cell_count lb_32x128_shared_synth_floorplan wns_report //sram:sdq_17x64_mock-naja_floorplan_deps //sram:mock-naja
bazel build check_mock_area cell_count lb_32x128_shared_synth_floorplan lb_32x128_wns_report //sram:sdq_17x64_mock-naja_floorplan_deps //sram:mock-naja
grep naja bazel-bin/sram/mock-naja.v
grep -q naja bazel-bin/sram/results/asap7/sdq_17x64/mock-naja/1_synth.v && false || true
(bazel build //sram:sdq_17x64_naja-error_floorplan 2>&1 || true) | grep "syntax error"
Expand Down
107 changes: 41 additions & 66 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("//:eqy.bzl", "eqy_test")
load("//:openroad.bzl", "get_stage_args", "orfs_floorplan", "orfs_flow", "orfs_run")
load("//:sweep.bzl", "sweep")

exports_files(["mock_area.tcl"])

Expand Down Expand Up @@ -146,60 +147,6 @@ orfs_flow(
verilog_files = LB_VERILOG_FILES,
)

SWEEP = {
"1": {
"variables": {
"PLACE_DENSITY": "0.65",
},
"previous_stage": {"floorplan": "lb_32x128_synth"},
},
"2": {
"variables": {
"PLACE_DENSITY": "0.70",
},
"previous_stage": {"place": "lb_32x128_floorplan"},
},
"3": {
"variables": {
"PLACE_DENSITY": "0.75",
},
"previous_stage": {"cts": "lb_32x128_place"},
},
"4": {
"variables": {
"PLACE_DENSITY": "0.80",
},
},
}

# buildifier: disable=duplicated-name
[
orfs_flow(
name = "lb_32x128",
abstract_stage = "cts",
arguments = LB_ARGS | SWEEP[variant]["variables"],
# Share synthesis across all variants, the sweep
# differs from floorplan and onwards
previous_stage = SWEEP[variant].get("previous_stage", {}),
stage_sources = LB_STAGE_SOURCES,
variant = variant,
verilog_files = LB_VERILOG_FILES,
)
for variant in SWEEP
]

[orfs_run(
name = "lb_32x128_" + variant + "_report",
src = ":lb_32x128_" + ("" if variant == "base" else variant + "_cts"),
outs = [
"lb_32x128_" + variant + ".yaml",
],
arguments = {
"OUTFILE": "$(location :lb_32x128_" + variant + ".yaml)",
},
script = ":report-wns.tcl",
) for variant in SWEEP]

orfs_run(
name = "cell_count",
src = ":lb_32x128_floorplan",
Expand All @@ -210,18 +157,6 @@ orfs_run(
script = ":cell_count.tcl",
)

genrule(
name = "wns_report",
srcs = ["wns-report.py"] +
[":lb_32x128_" + variant + ".yaml" for variant in SWEEP],
outs = ["lb_32x128_wns_report.md"],
cmd = (
"$(location :wns-report.py) > $@ " +
" ".join(["$(location :lb_32x128_" + variant + ".yaml)" for variant in SWEEP])
),
visibility = ["//visibility:public"],
)

orfs_flow(
name = "L1MetadataArray",
abstract_stage = "cts",
Expand Down Expand Up @@ -356,3 +291,43 @@ orfs_flow(
"test/rtl/regfile_128x65.sv",
],
)

# buildifier: disable=duplicated-name
sweep(
name = "lb_32x128",
stage = "cts",
stage_sources = {
"synth": [":constraints-sram"],
"floorplan": [":io-sram"],
"place": [":io-sram"],
},
sweep = {
"1": {
"variables": {
"PLACE_DENSITY": "0.65",
},
"previous_stage": {"floorplan": "lb_32x128_synth"},
},
"2": {
"variables": {
"PLACE_DENSITY": "0.70",
},
"previous_stage": {"place": "lb_32x128_floorplan"},
},
"3": {
"variables": {
"PLACE_DENSITY": "0.75",
},
"previous_stage": {"cts": "lb_32x128_place"},
},
"4": {
"variables": {
"PLACE_DENSITY": "0.80",
},
},
},
variables = LB_ARGS,
verilog_files = ["test/mock/lb_32x128.sv"],
)

exports_files(["sweep-wns.tcl"])
12 changes: 12 additions & 0 deletions sweep-wns.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Test this on some simple design in ORFS:
# make floorplan
# ODB_FILE=results/nangate45/gcd/base/2_floorplan.odb make run RUN_SCRIPT=~/megaboom/report-wns.tcl
source $::env(SCRIPTS_DIR)/open.tcl

set paths [find_timing_paths -path_group reg2reg -sort_by_slack -group_count 1]
set path [lindex $paths 0]
set slack [get_property $path slack]

puts "slack: $slack"
report_tns
report_cell_usage
141 changes: 141 additions & 0 deletions sweep.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
"""Sweep OpenROAD stages"""

load("@bazel-orfs//:openroad.bzl", "orfs_flow", "orfs_run", "set")
load(":write_binary.bzl", "write_binary")

all_stages = [
"floorplan",
"place",
"cts",
"grt",
"route",
"final",
]

def sweep(
name,
variables,
sweep,
verilog_files,
stage_sources,
other_variants = {},
stage = "floorplan",
macros = []):
"""Run a sweep of OpenROAD stages
Args:
name: Verilog module name
variables: dictionary of the base variables for the flow
sweep: The dictionary describing the variables to sweep
other_variants: Dictionary with other variants to generate, but not as part of the sweep
stage: The stage to do the sweep on
macros: name of modules to use as macros
verilog_files: The Verilog files to build
stage_sources: dictionary with list of sources to use for the stage
"""
sweep_json = {
"name": name,
"base": variables,
"sweep": sweep,
"stage": stage,
"stages": all_stages[0:all_stages.index(stage) + 1],
}
write_binary(
name = name + "_sweep.json",
data = str(sweep_json),
)

all_variants = sweep | other_variants

for variant in all_variants:
orfs_flow(
name = name,
arguments = variables | all_variants[variant].get("variables", {}),
macros = [
m
for m in macros
if m not in all_variants[variant].get("dissolve", [])
] + all_variants[variant].get("macros", []),
previous_stage = all_variants[variant].get("previous_stage", {}),
renamed_inputs = all_variants[variant].get("renamed_inputs", {}),
stage_arguments = all_variants[variant].get("stage_arguments", {}),
stage_sources = {
stage: set(stage_sources.get(stage, []) + all_variants[variant].get("stage_sources", {}).get(stage, []))
for stage in set(stage_sources.keys() + all_variants[variant].get("stage_sources", {}).keys())
},
variant = variant,
verilog_files = verilog_files,
)

native.filegroup(
name = name + "_" + variant + "_odb",
srcs = [":" + name + "_" + ("" if variant == "base" else variant + "_") + sweep_json["stage"]],
output_group = ("5_1_grt" if sweep_json["stage"] == "grt" else str(sweep_json["stages"].index(sweep_json["stage"]) + 2) + "_" + sweep_json["stage"]) +
".odb",
visibility = [":__subpackages__"],
)

orfs_run(
name = name + "_" + variant + "_report",
src = ":" + name + "_" + ("" if variant == "base" else variant + "_") + sweep_json["stage"],
outs = [
name + "_" + variant + ".txt",
],
arguments = {
"ODB_FILE": "$(location :" + name + "_" + variant + "_odb)",
},
data = [":" + name + "_" + variant + "_odb"],
extra_args = "> $WORK_HOME/" + name + "_" + variant + ".txt",
script = Label(":sweep-wns.tcl"),
)

native.filegroup(
name = name + "_" + variant + "_logs",
srcs = [":" + name + "_" + ("" if variant == "base" else variant + "_") + stage for stage in sweep_json["stages"]],
output_group = "logs",
visibility = [":__subpackages__"],
)

# This can be built in parallel, but grt needs to be build in serial, or
# we will run out of memory
native.filegroup(
name = name + "_sweep_parallel",
srcs = [name + "_" + ("" if variant == "base" else variant + "_") + "cts" for variant in sweep],
visibility = ["//visibility:public"],
)

native.genrule(
name = name + "_wns_report",
srcs = [
"wns_report.py",
name + "_sweep.json",
] + [":" + name + "_" + variant + ".txt" for variant in sweep] +
[":" + name + "_" + variant + "_logs" for variant in sweep],
outs = [name + "_wns_report.md"],
cmd = (
"$(location :wns_report.py) > $@" +
" $(location :" + name + "_sweep.json)"
),
visibility = ["//visibility:public"],
)

native.filegroup(
name = name + "_repair_logs",
srcs = [
":" + name + "_" + ("" if variant == "base" else variant + "_") + stage
for stage in sweep_json["stages"]
for variant in sweep
],
output_group = "logs",
)

native.genrule(
name = name + "_plot_repair",
srcs = [
"plot-retiming.py",
name + "_repair_logs",
],
outs = [name + "_retiming.pdf"],
cmd = "$(location plot-retiming.py) $(location " + name + "_retiming.pdf) $(locations " + name + "_repair_logs)",
visibility = ["//visibility:public"],
)
Loading

0 comments on commit 3fff266

Please sign in to comment.