Skip to content

Commit

Permalink
parameter optimization: generic rules compatible with 'has_env_vars' …
Browse files Browse the repository at this point in the history
…constraint

This is a workaround for excluding generic parameter optimization rules
generated with generate_compression_block_parameter_optimization()
from builds and tests executed with a wildcard expressions like e.g.
in CI: bazel test //xls/...

Internal-tag: [#50339]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
  • Loading branch information
lpawelcz committed Oct 24, 2023
1 parent 5361e87 commit e620ba8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
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"],
)
5 changes: 5 additions & 0 deletions xls/build_rules/vizier.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def generate_compression_block_parameter_optimization(name, optimized_ir, cocotb
},
verilog_file = name + "_compression_block.v",
visibility = ["//visibility:private"],
target_compatible_with = ["//xls/build_rules:has_env_vars"], # Prevent this rule from being called in CI by `bazel test //xls/...`
)

verilog_library(
Expand All @@ -87,6 +88,7 @@ def generate_compression_block_parameter_optimization(name, optimized_ir, cocotb
":" + name + "_compression_block.v",
],
visibility = ["//visibility:private"],
target_compatible_with = ["//xls/build_rules:has_env_vars"], # Prevent this rule from being called in CI by `bazel test //xls/...`
)

synthesize_rtl(
Expand All @@ -97,6 +99,7 @@ def generate_compression_block_parameter_optimization(name, optimized_ir, cocotb
":" + name + "_compression_block_verilog_lib",
],
visibility = ["//visibility:private"],
target_compatible_with = ["//xls/build_rules:has_env_vars"], # Prevent this rule from being called in CI by `bazel test //xls/...`
)

place_and_route(
Expand All @@ -106,6 +109,7 @@ def generate_compression_block_parameter_optimization(name, optimized_ir, cocotb
placement_density = "$env(PLACEMENT_DENSITY)",
synthesized_rtl = ":" + name + "_compression_block_synth",
target_die_utilization_percentage = "$env(TARGET_DIE_UTILIZATION_PERCENTAGE)",
target_compatible_with = ["//xls/build_rules:has_env_vars"], # Prevent this rule from being called in CI by `bazel test //xls/...`
)

py_test(
Expand All @@ -125,6 +129,7 @@ def generate_compression_block_parameter_optimization(name, optimized_ir, cocotb
"//xls/tools/dashboard:utils",
],
imports = ["."],
target_compatible_with = ["//xls/build_rules:has_env_vars"], # Prevent this rule from being called in CI by `bazel test //xls/...`
)

test_label = native.package_name() + ":" + name + "_compression_block_cocotb_test"
Expand Down
9 changes: 7 additions & 2 deletions xls/tools/vizier_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ def construct_bazel_command(test: BazelLabel, test_log: SystemPath, env) -> str:
to bazel build system through `--action-env` argument.
Write test output to the `test_log`.
"""
build_cmd = "bazel build"
test_cmd = "bazel test"
# Force the usage of custom optimization platform with constraint_value
# `has_env_vars` defined which is required for running generic
# implementation and testing rules generated with
# generate_compression_block_parameter_optimization() macro
force_platform = "--platforms //xls/build_rules:parameter_optimization_platform"
build_cmd = f"bazel build {force_platform}"
test_cmd = f"bazel test {force_platform}"
for var, value in env.items():
set_env_var = " --action_env " + var + "=" + str(value)
build_cmd += set_env_var
Expand Down

0 comments on commit e620ba8

Please sign in to comment.