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

[WIP] Vizier integration #1160

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b07d5fb
dependency_support: Add cocotb and cocotb_bus to python requirements
rw1nkler Aug 30, 2023
210b07a
simulation: Add cocotb python library for XLS
rw1nkler Aug 30, 2023
860020c
examples: Add a simple passthrough example that uses cocotb for valid…
rw1nkler Aug 30, 2023
4a3038a
dependency_support: Add packages required for dashboard generation
rw1nkler Sep 28, 2023
568882e
tools/dashboard: Add main dashboard generation scripts
rw1nkler Sep 28, 2023
87552a9
tools/dashboard: Add utilities for dashboard generation by user
rw1nkler Sep 28, 2023
1e5d3b3
build_rules: Add Bazel rule for generating the dashboard
rw1nkler Sep 28, 2023
ded8679
examples: Add a rule to generate dashboard for passthrough example
rw1nkler Sep 28, 2023
fb755bd
modules: Create cocotb test for RLE
rw1nkler Sep 28, 2023
e19b306
modules: Add a rule to generate dashboard for RLE module
rw1nkler Sep 28, 2023
0671eea
xls: modules: rle: Add place_and_route for rle_enc
lpawelcz Jul 25, 2023
30d57f4
xls: tools: dashboard: Add parsers for chip area and power estimate
lpawelcz Sep 1, 2023
39b2e37
tools/dashboard: Add chip area and chip power to RLE dashboard
rw1nkler Sep 29, 2023
da2d5d0
dependency_support: bump pip_requirements_lock.txt
lpawelcz Oct 18, 2023
4e670a4
dependency_support: cocotb: use direct URL to archive
lpawelcz Oct 23, 2023
3bb9d11
[TEMP] use forked bazel_rules_hdl
lpawelcz Oct 9, 2023
eb696de
python: use python 3.10
lpawelcz Oct 23, 2023
b88d78a
dependency_support: python_rules: bump to v0.26.0
lpawelcz Oct 23, 2023
048f869
dependency_support: python: Add google-vizier
lpawelcz Oct 5, 2023
25ff18d
build_rules: codegen_rules: use default_shell_env for verilog write
lpawelcz Oct 9, 2023
8365d31
Add vizier proof of concept integration
lpawelcz Oct 5, 2023
59eeaab
modules: rle: Add cocotb tests for proof of concept rle_enc parameter…
lpawelcz Oct 10, 2023
5361e87
modules: rle: Enable proof of concept rle_enc parameter optimization
lpawelcz Oct 11, 2023
e620ba8
parameter optimization: generic rules compatible with 'has_env_vars' …
lpawelcz Oct 24, 2023
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 WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ load(
py_repositories()

python_register_toolchains(
name = "python39",
python_version = "3.9",
name = "python310",
python_version = "3.10",

# Required for our containerized CI environments; we do not recommend
# building XLS as root normally.
Expand Down
2 changes: 1 addition & 1 deletion dependency_support/initialize_external.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@com_grail_bazel_compdb//:deps.bzl", "bazel_compdb_deps")
load("@io_bazel_rules_closure//closure:repositories.bzl", "rules_closure_dependencies", "rules_closure_toolchains")
load("@python39//:defs.bzl", python_interpreter_target = "interpreter")
load("@python310//:defs.bzl", python_interpreter_target = "interpreter")
load("@rules_hdl//:init.bzl", rules_hdl_init = "init")
load("@rules_hdl//dependency_support:dependency_support.bzl", rules_hdl_dependency_support = "dependency_support")
load("@rules_hdl//toolchains/cpython:cpython_toolchain.bzl", rules_hdl_register_cpython_repository = "register_cpython_repository")
Expand Down
14 changes: 7 additions & 7 deletions dependency_support/load_external.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ def load_external_repositories():
],
)

# Released on 2023-08-22, current as of 2023-09-26
# https://github.com/bazelbuild/rules_python/releases/tag/0.25.0
# Released on 2023-10-06, current as of 2023-10-23
# https://github.com/bazelbuild/rules_python/releases/tag/0.26.0
http_archive(
name = "rules_python",
sha256 = "5868e73107a8e85d8f323806e60cad7283f34b32163ea6ff1020cf27abef6036",
strip_prefix = "rules_python-0.25.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.25.0/rules_python-0.25.0.tar.gz",
sha256 = "9d04041ac92a0985e344235f5d946f71ac543f1b1565f2cdbc9a2aaee8adf55b",
strip_prefix = "rules_python-0.26.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.26.0/rules_python-0.26.0.tar.gz",
)

http_archive(
Expand Down Expand Up @@ -193,8 +193,8 @@ def load_external_repositories():
sha256 = "9c3c0a0ad986ee4fc0a9b58fd71255010068df7d1437c425b525d68c30c85ac7",
strip_prefix = "grpc-1.55.1",
repo_mapping = {
"@local_config_python": "@python39",
"@system_python": "@python39",
"@local_config_python": "@python310",
"@system_python": "@python310",
},
)

Expand Down
7 changes: 7 additions & 0 deletions dependency_support/pip_requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ termcolor==1.1.0
psutil==5.7.0
portpicker==1.3.1
pyyaml==6.0.1
cocotb @ https://github.com/cocotb/cocotb/archive/a853db95b0019db6796a6803aa94304bde743e4e.zip
cocotb_bus==0.2.1
jsonschema==4.18.4
mdutils==1.6.0
mkdocs==1.5.2
mkdocs-material==9.2.8
google-vizier[jax]==0.1.12

# Note: numpy and scipy version availability seems to differ between Ubuntu
# versions that we want to support (e.g. 18.04 vs 20.04), so we accept a
Expand Down
1,085 changes: 1,044 additions & 41 deletions dependency_support/pip_requirements_lock.txt

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dependency_support/rules_hdl/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ def repo():
],
)

# Commit on 2023-10-04 -- Merge pull request #196 from mithro/openroad-upgrade
git_hash = "64688e60b06b5e3bcf277468d9afdc1fa0a7b98c"
archive_sha256 = "2643614fa0625500284937012af7df74579ccd2298559231f7e78328dce15d6d"
# Commit on 2023-10-23 -- temporary link to fork: place_and_route: openroad: append env vars to default_shell_env
git_hash = "66f3155d09e725bdf277b3437bdb94c7330dc08e"
archive_sha256 = "ab83e25ca5466faa686ddc4690cf55a8e7e3894ba75d8ea6d09c9e2d9f670bc1"

maybe(
http_archive,
name = "rules_hdl",
sha256 = archive_sha256,
strip_prefix = "bazel_rules_hdl-%s" % git_hash,
urls = [
"https://github.com/hdl/bazel_rules_hdl/archive/%s.tar.gz" % git_hash,
"https://github.com/antmicro/bazel_rules_hdl/archive/%s.tar.gz" % git_hash,
],
repo_mapping = {
"@rules_hdl_cpython": "@python39",
"@rules_hdl_cpython": "@python310",
},
)
22 changes: 22 additions & 0 deletions xls/build_rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,25 @@ xls_toolchain(
name = "default_xls_toolchain",
visibility = ["//xls:xls_public"],
)

# Workaround for excluding rules for parameter optimization generated by macro
# generate_compression_block_parameter_optimization() from project-wide builds
# like the one in CI: `bazel test //xls/...`
constraint_setting(
name = "are_env_vars_defined",
)

# Exclude rules by specifying `target_compatible_with` attribute with
# constraint_value `//xls/build_rules:has_env_vars`.
constraint_value(
name = "has_env_vars",
constraint_setting = ":are_env_vars_defined",
)

# Define custom platform as a copy of default platform extended with `:has_env_vars`
# and use this platform when parameter optimization rules need to be called.
load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")
platform(
name = "parameter_optimization_platform",
constraint_values = HOST_CONSTRAINTS + [":has_env_vars"],
)
185 changes: 185 additions & 0 deletions xls/build_rules/dashboard.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# Copyright 2023 The XLS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Generates HTML dashboard that aggregates test results.

User has to provide the output directory for the generated website using
the `-o` argument, for example:

`bazel run -- //xls/examples:dashboard -o my_dashboard_directory`
"""

def _prepare_test_related_attrs(tests, files):
"""Reads the tests and files attributes passed to the dashboard macro, and converts
it to the attributes accepted by the underlying bazel rule. Tests and parsers
are provided as a separate list of labels. All the relations between them and
additional information about the output files to parse is passed as a format
string that should be resolved in the underlying bazel rule. Note that
the provided format string depends on the order of test and parser labels.
"""

attr_tests = []
attr_parsers = []
attr_cmd_args = ""
for i, test in enumerate(tests):
test_key = "t{}".format(i)
attr_tests += [test["name"]]

output_parsers = test["output_parsers"] if "output_parsers" in test else []
for parser in output_parsers:
parseattr_key = "p{}".format(len(attr_parsers))
attr_parsers += [parser]
attr_cmd_args += " -p {{{}}},{{{}}}".format(test_key, parseattr_key)

file_parsers = test["file_parsers"] if "file_parsers" in test else {}
for parser, file in file_parsers.items():
parser_key = "p{}".format(len(attr_parsers))
attr_parsers += [parser]
attr_cmd_args += " -f {{{}}},{{{}}},{}".format(test_key, parser_key, file)

attr_data = []
for i, data in enumerate(files):
attr_data += [data["name"]]
file_parsers = data["file_parsers"] if "file_parsers" in data else {}
for parser, file in file_parsers.items():
parser_key = "p{}".format(len(attr_parsers))
attr_parsers += [parser]
attr_cmd_args += " -d {},{{{}}}".format(file, parser_key)


return (attr_tests, attr_parsers, attr_data, attr_cmd_args)

def _resolve_test_related_attrs(ctx, attr_tests, attr_parsers, attr_cmd_args):
"""Resolves the format string passed as an argument to the bazel rule.
It relies on the order of test and parser labels.
"""

keys = {}
for i, test in enumerate(attr_tests):
test_key = "t{}".format(i)
value = str(test.label)
keys.update({test_key: value})

for i, parser in enumerate(attr_parsers):
parser_key = "p{}".format(i)
parser_files = [x for x in parser.files.to_list() if x.is_source]
if len(parser_files) > 1:
fail("Parsers passed as attributes should be a single executable")
[parser_file] = parser_files
keys.update({parser_key: parser_file.short_path})

return attr_cmd_args.format(**keys)

def _create_command(ctx):
"""Creates command for the script executed when invoking bazel run for
a dashboard generation"""

return 'python {dashboard} -r {root_dir} -w {working_dir} -t "{title}" {args} "$@"'.format(
dashboard = ctx.executable._dashboard.short_path,
root_dir = "$BUILD_WORKSPACE_DIRECTORY",
working_dir = "$BUILD_WORKING_DIRECTORY",
title = ctx.attr.title,
args = _resolve_test_related_attrs(
ctx,
ctx.attr.tests,
ctx.attr.parsers,
ctx.attr.cmd_args,
),
)

def _collect_transitive_files(ctx):
"""Collects transitive dependencies that are required for the run executable"""

py_toolchain = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime
return depset(
direct = [py_toolchain.interpreter],
transitive = [
dep[PyInfo].transitive_sources
for dep in ctx.attr.parsers
if PyInfo in dep
] +
[ctx.attr._dashboard[PyInfo].transitive_sources] +
[py_toolchain.files],
)

def _generate_dashboard_impl(ctx):
"""Implementation of the dashboard generation rule"""

executable = ctx.actions.declare_file("{}_run.sh".format(ctx.attr.name))
command = _create_command(ctx)

ctx.actions.write(output = executable, content = command)
py_toolchain = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime

return [
DefaultInfo(
executable = executable,
files = depset(ctx.files.tests),
runfiles = ctx.runfiles(
files = ctx.files.parsers + ctx.files.data,
transitive_files = _collect_transitive_files(ctx),
).merge_all(
[ctx.attr._dashboard.default_runfiles] +
[dep.default_runfiles for dep in ctx.attr.parsers],
),
),
]

_generate_dashboard_attrs = {
"tests": attr.label_list(
doc = "Tests that will be run to generate the dashboard",
),
"parsers": attr.label_list(
doc = "Parsers to run on test output",
),
"data": attr.label_list(
doc = "Data generated by other rules required for dashboard generation",
),
"cmd_args": attr.string(
doc = "Command for the dashboard generation tool",
),
"title": attr.string(
doc = "Title of the dashboard",
),
"_dashboard": attr.label(
cfg = "exec",
executable = True,
doc = "Script for running tests and parsing their outputs",
default = Label("//xls/tools/dashboard:dashboard"),
),
}

generate_dashboard = rule(
implementation = _generate_dashboard_impl,
attrs = _generate_dashboard_attrs,
executable = True,
toolchains = ["@bazel_tools//tools/python:toolchain_type"],
)

def dashboard(name, title, tests, files):
"""Macro used to provide clear interface for the user. It converts the
information provided by the user to the attributes understood by the
underlying dashboard generation rule.
"""

attr_tests, attr_parsers, attr_data, attr_cmd_args = _prepare_test_related_attrs(tests, files)
generate_dashboard(
name = name,
title = title,
tests = attr_tests,
data = attr_data,
parsers = attr_parsers,
cmd_args = attr_cmd_args,
testonly = True,
)
Loading
Loading