Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yosys: avoid resynthesis on ORFS upgrade when yosys doesn't change #237

Closed
wants to merge 3 commits into from
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
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ orfs = use_extension("//:extension.bzl", "orfs_repositories")
orfs.default(
# a local only or remote docker image. Local docker images do not
# have a sha256.
image = "docker.io/openroad/orfs:v3.0-1679-g980de246",
image = "docker.io/openroad/orfs:v3.0-1694-g0a5008b6",
# Comment out line below for local only docker images
sha256 = "e3c30971e63d4748fde1ddbec63f9680bda53be5a50319d67db9279dd51d2945",
sha256 = "4ef9b95551629ff00217188eb68198873ed709c09671e3c40a184ad14e88df19",
)
use_repo(orfs, "com_github_nixos_patchelf_download")
use_repo(orfs, "docker_orfs")
Expand Down
6 changes: 3 additions & 3 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 24 additions & 6 deletions docker.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,37 @@ filegroup(
visibility = ["//visibility:public"],
)

MAKEFILE_SHARED = [
"OpenROAD-flow-scripts/flow/util/utils.mk",
"OpenROAD-flow-scripts/flow/scripts/*.py",
"OpenROAD-flow-scripts/flow/scripts/*.sh",
"OpenROAD-flow-scripts/flow/scripts/*.yaml",

]

# Narrowly define yosys dependencies to avoid hours of resynthesis
# upon upgrading ORFS since yosys hardly ever changes
filegroup(
name = "makefile_yosys",
srcs = ["OpenROAD-flow-scripts/flow/Makefile"],
data = glob(MAKEFILE_SHARED + [
"OpenROAD-flow-scripts/flow/scripts/*.script",
"OpenROAD-flow-scripts/flow/scripts/util.tcl",
"OpenROAD-flow-scripts/flow/scripts/synth*.tcl",
"OpenROAD-flow-scripts/flow/util/preprocessLib.py",
"OpenROAD-flow-scripts/flow/util/mergeLib.pl",
]),
visibility = ["//visibility:public"],
)

filegroup(
name = "makefile",
srcs = ["OpenROAD-flow-scripts/flow/Makefile"],
data = glob([
"OpenROAD-flow-scripts/flow/util/utils.mk",
data = glob(MAKEFILE_SHARED + [
"OpenROAD-flow-scripts/flow/util/*.pl",
"OpenROAD-flow-scripts/flow/util/*.py",
"OpenROAD-flow-scripts/flow/util/*.sh",
"OpenROAD-flow-scripts/flow/scripts/*.py",
"OpenROAD-flow-scripts/flow/scripts/*.script",
"OpenROAD-flow-scripts/flow/scripts/*.sh",
"OpenROAD-flow-scripts/flow/scripts/*.tcl",
"OpenROAD-flow-scripts/flow/scripts/*.yaml",
]),
visibility = ["//visibility:public"],
)
Expand Down
102 changes: 69 additions & 33 deletions openroad.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,31 @@ def odb_environment(ctx):
return {"ODB_FILE": ctx.attr.src[OrfsInfo].odb.path}
return {}

def orfs_environment(ctx):
return {
"HOME": _work_home(ctx),
"STDBUF_CMD": "",
"TCL_LIBRARY": commonpath(ctx.files._tcl),
"WORK_HOME": _work_home(ctx),
}

def flow_environment(ctx):
return {
"DLN_LIBRARY_PATH": commonpath(ctx.files._ruby_dynamic),
"FLOW_HOME": ctx.file._makefile.dirname,
"HOME": _work_home(ctx),
"KLAYOUT_CMD": ctx.executable._klayout.path,
"OPENROAD_EXE": ctx.executable._openroad.path,
"QT_PLUGIN_PATH": commonpath(ctx.files._qt_plugins),
"QT_QPA_PLATFORM_PLUGIN_PATH": commonpath(ctx.files._qt_plugins),
"RUBYLIB": ":".join([commonpath(ctx.files._ruby), commonpath(ctx.files._ruby_dynamic)]),
"STDBUF_CMD": "",
"TCL_LIBRARY": commonpath(ctx.files._tcl),
"WORK_HOME": _work_home(ctx),
}
} | orfs_environment(ctx)

def yosys_environment(ctx):
return {
"ABC": ctx.executable._abc.path,
"YOSYS_EXE": ctx.executable._yosys.path,
}
"FLOW_HOME": ctx.file._makefile_yosys.dirname,
} | orfs_environment(ctx)

def config_environment(config):
return {"DESIGN_CONFIG": config.path}
Expand Down Expand Up @@ -182,13 +187,22 @@ def flow_inputs(ctx):

def yosys_inputs(ctx):
return depset(
[ctx.executable._abc, ctx.executable._yosys] +
[
ctx.executable._abc,
ctx.executable._yosys,
ctx.executable._make,
ctx.file._makefile_yosys,
] +
ctx.files._tcl,
transitive = [
ctx.attr._abc[DefaultInfo].default_runfiles.files,
ctx.attr._abc[DefaultInfo].default_runfiles.symlinks,
ctx.attr._yosys[DefaultInfo].default_runfiles.files,
ctx.attr._yosys[DefaultInfo].default_runfiles.symlinks,
ctx.attr._makefile_yosys[DefaultInfo].default_runfiles.files,
ctx.attr._makefile_yosys[DefaultInfo].default_runfiles.symlinks,
ctx.attr._make[DefaultInfo].default_runfiles.files,
ctx.attr._make[DefaultInfo].default_runfiles.symlinks,
],
)

Expand Down Expand Up @@ -310,7 +324,7 @@ def _deps_impl(ctx):
def flow_provides():
return [DefaultInfo, OutputGroupInfo, OrfsDepInfo, OrfsInfo, LoggingInfo, PdkInfo, TopInfo]

def flow_attrs():
def orfs_attrs():
return {
"arguments": attr.string_dict(
doc = "Dictionary of additional flow arguments.",
Expand All @@ -330,25 +344,34 @@ def flow_attrs():
doc = "Variant of the used flow.",
default = "base",
),
"_deploy_template": attr.label(
default = ":deploy.tpl",
allow_single_file = True,
"_make": attr.label(
doc = "make binary.",
executable = True,
allow_files = True,
cfg = "exec",
default = Label("@docker_orfs//:make"),
),
"_make_template": attr.label(
default = ":make.tpl",
allow_single_file = True,
"_tcl": attr.label(
doc = "Tcl library.",
allow_files = True,
default = Label("@docker_orfs//:tcl8.6"),
),
"_makefile": attr.label(
doc = "Top level makefile.",
allow_single_file = ["Makefile"],
default = Label("@docker_orfs//:makefile"),
),
"_make": attr.label(
doc = "make binary.",
executable = True,
allow_files = True,
cfg = "exec",
default = Label("@docker_orfs//:make"),
}

def flow_attrs():
return {
"_deploy_template": attr.label(
default = ":deploy.tpl",
allow_single_file = True,
),
"_make_template": attr.label(
default = ":make.tpl",
allow_single_file = True,
),
"_openroad": attr.label(
doc = "OpenROAD binary.",
Expand All @@ -374,11 +397,6 @@ def flow_attrs():
allow_files = True,
default = Label("@docker_orfs//:ruby_dynamic3.0.0"),
),
"_tcl": attr.label(
doc = "Tcl library.",
allow_files = True,
default = Label("@docker_orfs//:tcl8.6"),
),
"_opengl": attr.label(
doc = "OpenGL drivers.",
allow_files = True,
Expand All @@ -394,7 +412,7 @@ def flow_attrs():
allow_files = True,
default = Label("@docker_orfs//:gio_modules"),
),
}
} | orfs_attrs()

def yosys_only_attrs():
return {
Expand All @@ -412,6 +430,11 @@ def yosys_only_attrs():
cfg = "exec",
default = Label("@docker_orfs//:yosys"),
),
"_makefile_yosys": attr.label(
doc = "Top level makefile yosys.",
allow_single_file = ["Makefile"],
default = Label("@docker_orfs//:makefile_yosys"),
),
}

def renamed_inputs_attr():
Expand Down Expand Up @@ -452,6 +475,8 @@ def openroad_only_attrs():
}

def yosys_attrs():
# flow_attrs() is not used by synthesis, but by bazel run foo_synth to
# open synthesis results in OpenROAD
return flow_attrs() | yosys_only_attrs()

def openroad_attrs():
Expand Down Expand Up @@ -626,18 +651,16 @@ def _yosys_impl(ctx):
commands = _generation_commands(canon_logs) + [ctx.executable._make.path + " $@"]

ctx.actions.run_shell(
arguments = ["--file", ctx.file._makefile.path, canon_output.path],
arguments = ["--file", ctx.file._makefile_yosys.path, canon_output.path],
command = " && ".join(commands),
env = _verilog_arguments(ctx.files.verilog_files) |
flow_environment(ctx) |
yosys_environment(ctx) |
config_environment(config),
inputs = depset(
[config] +
ctx.files.verilog_files +
ctx.files.extra_configs,
transitive = [
flow_inputs(ctx),
yosys_inputs(ctx),
data_inputs(ctx),
pdk_inputs(ctx),
Expand All @@ -661,7 +684,7 @@ def _yosys_impl(ctx):
ctx.actions.run_shell(
arguments = [
"--file",
ctx.file._makefile.path,
ctx.file._makefile_yosys.path,
"--old-file",
canon_output.path,
"yosys-dependencies",
Expand All @@ -671,14 +694,12 @@ def _yosys_impl(ctx):
],
command = " && ".join(commands),
env = _verilog_arguments([]) |
flow_environment(ctx) |
yosys_environment(ctx) |
config_environment(config),
inputs = depset(
[canon_output, config] +
ctx.files.extra_configs,
transitive = [
flow_inputs(ctx),
yosys_inputs(ctx),
data_inputs(ctx),
pdk_inputs(ctx),
Expand All @@ -688,7 +709,22 @@ def _yosys_impl(ctx):
outputs = synth_outputs + synth_logs,
)

outputs = [canon_output] + synth_outputs
# Dummy action to make sure that the flow environment is available to
# bazel run foo_synth without causing resynthesis when upgrading
# ORFS where yosys did not change, saves many hours of synthesis
dummy_output = _declare_artifact(ctx, "results", "dummy.txt")
ctx.actions.run_shell(
command = "touch " + dummy_output.path,
env = flow_environment(ctx),
inputs = depset(
transitive = [
flow_inputs(ctx),
],
),
outputs = [dummy_output],
)

outputs = [canon_output] + synth_outputs + [dummy_output]

config_short = _declare_artifact(ctx, "results", "1_synth.short.mk")
ctx.actions.write(
Expand Down