Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 97 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,76 @@ single_version_override(
version = "3.8.2.bcr.7",
)


# openroad is normally consumed straight from the tools/OpenROAD
# submodule via local_path_override. While the E12 macro-placement
# experiment carries OpenROAD patches in //patches/openroad
# (local_path_override does not accept patches), it is fetched via
# git_override instead, pinned to the exact commit the submodule
# gitlink records so make (submodule) and bazel (fetched + patched)
# build the same base. Note that bazel builds the fetched source, not
# the live submodule tree, while this override is in place; revert to
# local_path_override when the patches land upstream.
#
# All five patches originate on the public bazel-orfs `macro-selector`
# branch (patches/0040-0043, 0045) and apply cleanly and in order at
# the pinned commit. src/mpl, src/gpl, src/par and src/odb/src are
# byte-identical between the pinned commit and OpenROAD 3ca581e38,
# which is the commit the archived swerv_wrapper measurements in
# flow/test/macro_e12/score_vs_flow_swerv.json were taken at -- that
# is what makes those numbers a valid reference here.
#
# patches/openroad/0001-mpl-fix-rerun-segfault.patch:
# HierRTLMP::run() ends with clear(), which destroys the physical
# hierarchy tree that was only ever built in the constructor, so a
# second rtl_macro_placer in one process handed a null tree to the
# clustering engine and crashed. Recreates the tree lazily. Required
# for generating many candidates in one process.
# OpenROAD issue #11277.
#
# patches/openroad/0002-mpl-add-random_seed.patch:
# adds `rtl_macro_placer -random_seed`, defaulting to the previously
# hard-coded 0 so stock behaviour is unchanged. Same seed reproduces
# the placement; different seeds explore different annealing
# trajectories. This is what turns the macro placer into a
# deterministic candidate generator instead of requiring CORE_AREA or
# cost-weight perturbation to obtain distinct placements.
# No upstream issue: a feature, to be proposed separately.
#
# patches/openroad/0003-mpl-keep-snapped-macros-inside-core.patch:
# the Snapper picked the track position closest to the pin centre,
# rounding up, which pushed top/right-edge macros past the core;
# place_macro then rejected the placer's own -write_macro_placement
# output with MPL-0034, so a selected placement could not be
# re-injected via MACRO_PLACEMENT_TCL. OpenROAD issue #11278.
#
# patches/openroad/0004-mpl-seed-std-cells-when-all-macros-fixed.patch:
# when every macro was fixed, run() skipped the whole pipeline
# including generateTemporaryStdCellsPlacement() and the macro soft
# blockages, so a re-injected placement diverged (~2% achieved
# period) from the run that generated it despite bit-identical macro
# geometry. OpenROAD issue #11279.
#
# patches/openroad/0005-gpl-thread-invariant-parallel-density-scatter.patch:
# BinGrid's density scatter was serial at any -threads. Parallelises
# it while accumulating into the bins' existing int64_t fields via
# std::atomic_ref with relaxed ordering: each addend is truncated to
# int64 before adding, so the sum is over a fixed multiset and is
# bit-identical at any thread count. Ships an mt_invariance
# integration test. OpenROAD PR #11262.
bazel_dep(name = "openroad", dev_dependency = True)
local_path_override(
git_override(
module_name = "openroad",
path = "tools/OpenROAD",
commit = "4b704bb69321203e5bf5db74182bfae9e8721d1e",
init_submodules = True,
patch_strip = 1,
patches = [
"//patches/openroad:0001-mpl-fix-rerun-segfault.patch",
"//patches/openroad:0002-mpl-add-random_seed.patch",
"//patches/openroad:0003-mpl-keep-snapped-macros-inside-core.patch",
"//patches/openroad:0004-mpl-seed-std-cells-when-all-macros-fixed.patch",
"//patches/openroad:0005-gpl-thread-invariant-parallel-density-scatter.patch",
],
remote = "https://github.com/The-OpenROAD-Project/OpenROAD.git",
)

bazel_dep(name = "qt-bazel", dev_dependency = True)
Expand All @@ -90,14 +155,42 @@ bazel_dep(name = "bazel-orfs", version = "0.0.1")

bazel_dep(name = "bazel-orfs-verilog", dev_dependency = True)

BAZEL_ORFS_COMMIT = "6ebadeb4be5c9ada103081c9a5e668c014126616"
# Bumped past bazel-orfs 4254fc9 "synth: support OpenROAD-SYN engine
# (SYNTH_USE_SYN=1)". The previous pin predated that support, so every
# design whose config.mk sets SYNTH_USE_SYN=1 -- gcd and swerv_wrapper
# among them -- failed its bazel synth with `sv_elaborate ... error: no
# input files`. bazel-orfs empties VERILOG_FILES for the synth action
# because the yosys path reads canonicalized RTLIL instead and the
# sources are not among that action's inputs; OpenROAD-SYN elaborates the
# sources directly and has no canonicalize step, so it needs them.
#
# This is the last commit before bazel-orfs 9bc8c74 "migrate from local
# verilog submodule to rules_chisel", which deletes the verilog/ subtree
# that @bazel-orfs-verilog is built from below (strip_prefix = "verilog").
# Going further therefore means migrating ORFS to rules_chisel, which is
# its own change. Note that bazel-orfs's //fork facility lands only after
# that removal, so it is still unavailable here -- flow/test/macro_e12
# detects its absence and runs candidates serially.
BAZEL_ORFS_COMMIT = "ca4e9dd41e0f2e7ab3174535dab4fc7c680b1085"

BAZEL_ORFS_REMOTE = "https://github.com/The-OpenROAD-Project/bazel-orfs.git"

# To bump version, run: bazelisk run @bazel-orfs//:bump
# patches/bazel-orfs/0001-design-count-keep-modules-across-continued-lines.patch:
# orfs_design() sizes SYNTH_NUM_PARTITIONS from SYNTH_KEEP_MODULES using
# Starlark's split() with no separator, which is a Python-ism -- Starlark
# requires one. Any design setting both SYNTH_HIERARCHICAL=1 and
# SYNTH_KEEP_MODULES therefore fails at analysis with "split() missing 1
# required positional argument: sep". Splitting on runs of whitespace is
# what the count actually needs, because a config.mk list is spread over
# backslash-continued lines.
git_override(
module_name = "bazel-orfs",
commit = BAZEL_ORFS_COMMIT,
patch_strip = 1,
patches = [
"//patches/bazel-orfs:0001-design-count-keep-modules-across-continued-lines.patch",
],
remote = BAZEL_ORFS_REMOTE,
)

Expand Down
10 changes: 10 additions & 0 deletions flow/designs/asap7/swerv_wrapper/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
load("//flow/designs:design.bzl", "design")

design(config = "config.mk")

# The E12 macro-placement experiment (//flow/test/macro_e12) drives this
# design's flow from its synthesis output. design() leaves the flow
# targets package-private, so expose just the synth stage to that one
# package rather than widening the whole family.
alias(
name = "swerv_wrapper_synth_for_e12",
actual = ":swerv_wrapper_synth",
visibility = ["//flow/test/macro_e12:__pkg__"],
)
11 changes: 10 additions & 1 deletion flow/designs/asap7/swerv_wrapper/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,18 @@ export SYNTH_KEEP_MODULES ?= \

export LIB_MODEL = CCS

# The sv2v'd RTL instantiates OPENROAD_CLKGATE directly, so the clkgate
# mapping model is a source file rather than a synthesis techmap input.
# Spelled as a resolved path on purpose: bazel-orfs's config.mk parser
# cannot evaluate the make functions behind $(PRIMARY_VT_TAG), so
# $(CLKGATE_MAP_FILE) is dropped when the file list is turned into bazel
# labels, and elaboration then fails with `unknown module
# 'OPENROAD_CLKGATE'`. This path is what $(CLKGATE_MAP_FILE) expands to
# for the platform's default PRIMARY_VT (RVT); it must be kept in step
# with that default, and with ASAP7_USE_VT if this design ever sets it.
export VERILOG_FILES = $(DESIGN_HOME)/src/swerv/swerv_wrapper.sv2v.v \
$(DESIGN_HOME)/$(PLATFORM)/swerv_wrapper/macros.v \
$(CLKGATE_MAP_FILE)
$(PLATFORM_DIR)/yoSys/cells_clkgate_R.v
export SDC_FILE = $(DESIGN_HOME)/$(PLATFORM)/swerv_wrapper/constraint.sdc

export ADDITIONAL_LEFS = $(sort $(wildcard $(DESIGN_HOME)/$(PLATFORM)/swerv_wrapper/lef/*.lef))
Expand Down
68 changes: 68 additions & 0 deletions flow/designs/nangate45/tinyRocket/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,74 @@ export PLATFORM = nangate45
export SYNTH_HIERARCHICAL = 1
export SYNTH_MINIMUM_KEEP_SIZE ?= 5000

# SYNTH_KEEP_MODULES is a captured list of the modules the
# keep-hierarchy discovery step selects at SYNTH_MINIMUM_KEEP_SIZE
# above.
#
# Under make it is redundant: discovery runs and finds the same list.
# Under bazel it is REQUIRED. Parallel synthesis declares one
# per-module re-canonicalization action per kept module, so bazel needs
# the module names at analysis time. When the list is only discovered
# inside a build action, bazel still emits the partition actions but no
# per-module checkpoints exist for them, and every partition fails with
#
# ERROR: per-module checkpoint missing: \
# partition_<Module>_canonical.rtlil
#
# Recapture after changing the RTL or SYNTH_MINIMUM_KEEP_SIZE, then sort:
#
# make DESIGN_CONFIG=./designs/nangate45/tinyRocket/config.mk \
# SYNTH_KEEP_MODULES= clean_synth synth
# jq -r '.modules | sort | join(" ")' \
# results/nangate45/RocketTile/base/kept_modules.json
export SYNTH_KEEP_MODULES ?= \
ALU \
AMOALU \
BreakpointUnit \
CSRFile \
DCache \
DCacheDataArray \
DCacheModuleanon2 \
DCacheModuleanon3 \
Frontend \
HellaCacheArbiter \
IBuf \
ICache \
IntSyncCrossingSink \
IntSyncCrossingSink_1 \
IntSyncCrossingSink_2 \
IntXbar_4 \
MulDiv \
PMPChecker \
PTW \
PlusArgTimeout \
Queue_38 \
Queue_39 \
Queue_40 \
Queue_41 \
RVCExpander \
Repeater_5 \
Rocket \
RocketTile \
ScratchpadSlavePort \
ShiftQueue \
SynchronizerShiftReg_w1_d3 \
TLB \
TLB_1 \
TLBuffer_10 \
TLBuffer_11 \
TLFragmenter_5 \
TLMonitor_35 \
TLMonitor_36 \
TLXbar_8 \
TLXbar_9 \
data_arrays_0 \
data_arrays_0_0 \
data_arrays_0_0_ext \
data_arrays_0_ext \
tag_array \
tag_array_ext

export VERILOG_FILES = $(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/AsyncResetReg.v \
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/ClockDivider2.v \
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/ClockDivider3.v \
Expand Down
123 changes: 123 additions & 0 deletions flow/test/macro_e12/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""E12: does a clustered global placement rank macro-placement candidates?

Every flow-running target here is tags = ["manual"]: the candidate
generation is a ~25 minute job on a 24-core machine and none of it
belongs in an automatic build. The one non-manual target is the gate's
unit test, which runs in about a second on committed fixtures and needs
no OpenROAD at all.

See README.md for the pre-registered configuration and the protocol.
"""

load("@bazel-orfs//:openroad.bzl", "orfs_run_executable")
load("@orfs_designs//:designs.bzl", "DESIGNS")
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")

# The design ladder. Every design here gets the same four executables, so
# an experiment can be flushed on a cheap design and then repeated on an
# expensive one without editing anything.
#
# tinyRocket mechanics. Two macros and a ~6 minute production tail, so
# the whole chain -- generation, scoring, truth, verdict --
# runs in minutes. Its candidate population is too small to
# rank, so a rho from it means nothing; it exists to prove
# the pipeline executes.
# swerv the real population: 28 macros, and the design the
# archived reference numbers were measured on. Hours per
# candidate for the truth stage.
E12_DESIGNS = {
"tinyRocket": "nangate45/tinyRocket",
"swerv": "asap7/swerv_wrapper",
}

# Per-design synth target, exposed to this package by a narrow alias in
# the design's own BUILD (orfs_design leaves flow targets
# package-private and ORFS's design() has no visibility passthrough).
E12_SYNTH = {
"tinyRocket": "//flow/designs/nangate45/tinyRocket:RocketTile_synth_for_e12",
"swerv": "//flow/designs/asap7/swerv_wrapper:swerv_wrapper_synth_for_e12",
}

# The helper Tcl travels as `data`, which orfs_run_executable stages
# alongside `script`, so each driver sources it as a sibling.
# e12_lib.tcl is shared by all drivers; extract_lib.tcl is the vendored
# instrument the archived reference numbers were measured with.
E12_DATA = [
"e12_lib.tcl",
"extract_lib.tcl",
]

# Each stage of the pipeline, as script -> target suffix.
E12_STAGES = {
"macro_e12.tcl": "candidates",
"dump_clusters.tcl": "dump_clusters",
"score_clustered.tcl": "score_clustered",
"evaluate.tcl": "evaluate",
}

# Four `bazelisk run` executables per design, taking KEY=VALUE overrides,
# rather than build-time actions with declared outputs. That matches what
# they are -- a manual campaign whose evidence directory is an input to
# analysis, not a build artifact -- and it is what lets the
# reduction-axis sweeps vary E12_* without a target per value.
#
# candidates regenerate the population and score it flat. Also the
# rig check when grading against the archive.
# dump_clusters RTL-MP's cluster partition, once, from the base
# floorplan.
# score_clustered the clustered rung, one candidate per process.
# evaluate the production tail to grt: the truth.
[
orfs_run_executable(
name = "%s_%s" % (short, suffix),
src = E12_SYNTH[short],
arguments = DESIGNS[full]["arguments"],
cmd = "run",
data = E12_DATA + [
label
for labels in DESIGNS[full]["sources"].values()
for label in labels
],
script = script,
tags = ["manual"],
)
for short, full in E12_DESIGNS.items()
for script, suffix in E12_STAGES.items()
]

py_library(
name = "e12_stats",
srcs = ["e12_stats.py"],
imports = ["."],
)

py_library(
name = "grade_e12_lib",
srcs = ["grade_e12.py"],
imports = ["."],
deps = [":e12_stats"],
)

# Step 3: the gate. Reads the committed archive plus the run's evidence
# directory, prints the rho table and writes the verdict.
py_binary(
name = "grade_e12",
srcs = ["grade_e12.py"],
data = ["score_vs_flow_swerv.json"],
tags = ["manual"],
deps = [":e12_stats"],
)

# The gate's own tests: the pass/fail logic on synthetic fixtures, plus
# five published numbers recomputed from the committed archive. Fast, and
# the only target here that is not manual.
py_test(
name = "grade_e12_test",
size = "small",
srcs = ["grade_e12_test.py"],
data = ["score_vs_flow_swerv.json"],
deps = [
":e12_stats",
":grade_e12_lib",
],
)
Loading
Loading