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

Conversation

lpawelcz
Copy link
Contributor

@lpawelcz lpawelcz commented Oct 23, 2023

Depends on #1137

This PR integrates Vizier Black-Box Optimization tool with XLS workspace.
It allows running parameter optimization tasks on designs written in DSLX.

The optimization task relies on:

  • performance metrics which define the objective of the optimization
  • set of parameters to optimize in order to fulfill the objective
  • evaluation function used for obtaining performance metrics values based on given parameters values

The optimization engine explores the parameter search space in iterative fashion composing suggestions of parameter values which are then used in evaluation function to obtain performance metrics. The evaluation function evaluates the sets of parameter values in the process of implementing and testing DSLX designs.

The implementation consists of 3 components:

  • vizier_runner.py - python script utilizing vizier library, which is responsible for:

    • Defining:
      • Parameters for the optimization process
      • Performance Metrics used for search space exploration
      • Evaluation Function used for testing suggested parameter values and obtaining performance metrics by implementing and testing DSLX designs (by calling generic bazel rules instatiated by generate_compression_block_parameter_optimization())
    • Setting up the search space exploration engine
    • Performing the optimization of defined parameters
  • vizier_optimize - top-level bazel rule used for starting vizier_runner

  • generate_compression_block_parameter_optimization() - helper bazel macro which purpose is to instantiate a set of generic bazel rules necessary for using suggestions for implementing and testing DSLX design in order to get performance metrics. Generic rules instantiated by this macro are used in the evaluation function or serve as the entry point for starting the optimization task (vizier_optimize rule). Parameter values from the suggestions are passed to those rules by environment variables and bazel argument --action_env.

This PR purpose is to showcase possible way of adding support for parameter optimization and handling of the suggestions in the evaluation function. For the purpose of the showcase, the parameters and performance metrics available for the optimization tasks are limited to:

  • parameters:
  • performance metrics:
    • delay (latency)
    • throughput
    • chip_area (added as performance metric but not used in optimization task)

Additionally, PR provides an example which showcases the usage of integration components. The example is based on rle_enc module. It optimizes delay and throughput metrics based on single pipeline_stages parameter. The example can be launched with:

bazel run //xls/modules/rle:rle_enc_compression_block_parameter_optimization

This PR requires a number of additional changes which include:

  • passing ctx.configuration.default_shell_env to bazel action in codegen rule in order to facilitate passing environment variables through bazel into scripts or binaries lying under called bazel rules.
  • passing ctx.configuration.default_shell_env to bazel action in place_and_route rule in bazel_rules_hdl (temporarily use forked bazel_rules_hdl repository)
  • bumping python to version 3.10 because google-vizier modules requires kw_only parameter of dataclass which was introduced in python 3.10
  • bumping rules_python to version 0.26.0 to allow correct installation of modules which depend on modules like setuptools

@proppy please take a look
Please note that since this work is based on #1137, it has commits from that PR in commit list and the changes from those are visible in Files changed. The commits relevant to this PR are top 8 commits, starting from [TEMP] use forked bazel_rules_hdl

rw1nkler and others added 24 commits October 24, 2023 12:43
Internal-tag: [#46586]
Signed-off-by: Robert Winkler's avatarRobert Winkler <rwinkler@antmicro.com>
The library contains XLSChannel, XLSChannelDriver and XLSChannelMonitor classes.

* XLSChannel - provides a mechanism for wrapping all signals related to XLS channels into one object.
* XLSChannelDriver - may be used to send data to XLS channel
* XLSChannelMonitor - may be used to monitor transaction taking place in XLS Channel

Internal-tag: [#46586]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
…ation

This commit adds a simple DSLX module that sends back the information
received on the input channel. The example contains tests written in
DSLX to verify the IR, as well as tests that use Cocotb framework to validate
behavior of the generated Verilog sources.

Internal-tag: [#46586]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
- `jsonschema` is used for validating in data provided for the dashboard
  generation script in for of a dedicated Dashboard JSON is valid

- `mdutils` is used to generate markdown from the obtained Dashboard JSON data

- `mkdocs`, `mkdocs-material` are used to generate HTML website out of the
  markdown files generated previously from Dashboard JSON

Internal-tag: #[46111]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
- `dashboard.py` is the main script responsible for generating the
  dashboard. It uses the rest of the scripts as utilities.

- `run_and_parse.py` contains functions for running tests and parsing
  their output to a Dashboard JSON format

- `validate_dashboard_json.py` contains function for validating if the
  provided JSON is in the Dashboard JSON format

- `json_to_markdown.py` converts the Dashboard JSON to a markdown document

- `mkdocs_creator.py` converts the markdown to HTML using mkdocs

Internal-tag: #[46111]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
This commit adds three parsers that can be used by the user
to extract the data for creating a dashboard:

- `cocotb_results_xml_parser.py` can extract the information about
  successful and failed cocotb tests using result.xml saved by the test

- `dslx_test_parser.py` can be used to extract the information about
  successful and failed DSLX tests using the log from the test

- `generic_parser.py` can be used to get the Dashboard JSON data dumped
  directly to the log within special delimiters. To dump data in this format,
  one can use a dedicated function contained in `utils.py`

Internal-tag: #[46111]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
Internal-tag: #[46111]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
Internal-tag: #[46111]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
The test check correctness of the encoding and measures both delay
and performance of the core

Internal-tag: #[46111]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
The dashboard contains results of DSLX and cocotb tests as well as
delay and performance measurements obtained in the cocotb test.

Internal-tag: #[46111]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
Add rules for implementing physical design for rle_enc module
for SKY130 process technology.

Internal-tag: [#46111]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
Internal Tag: [#47739]

Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
Internal-tag: [#47739]
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
Bump lock file for python dependencies.
This change is required after rebase between XLS with
python_rules v0.8 and v0.25.

Internal-tag: [#46111]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
Replace git URL with link to direct archive
This is workaround for possible bug in bazel python_rules
which causes faulty builds of python extension modules built from C/C++ sources.

Internal-tag: [#46111]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
This is a temporary change required to pass environment variables to
place_and_route roule defined in bazel_rules_hdl. This commit will
be removed and replaced with bumping bazel_rules_hdl dependency once
necessary changes will be merged in bazel_rules_hdl upstream repository.

Internal-tag: [#49957]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
google-vizier python module requires `kw_only` parameter of `dataclass`
which was introduced in python 3.10

Internal-tag: [#50339]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
Newer version passes by default argument `--allow-unsafe` to pip-compile.
It is required for correct installation of python modules which depend on
modules like:
* setuptools
* pip-tools

Internal-tag: [#50339]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
Internal-tag: [#49957]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
Allows passing environment variables to codegen through bazel
`--action-env` argument.

Internal-tag: [#49957]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
Internal-tag: [#50339]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
… optimization

Internal-tag: [#49957]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
Internal-tag: [#50339]
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
…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>
@proppy
Copy link
Member

proppy commented Oct 26, 2023

Some initial feedback

parameters

It would be nice to also have design based parameters, you can parameters DSLX based design by generating a dslx from from a textproto file using

int main(int argc, char* argv[]) {

generate_compression_block_parameter_optimization() - helper bazel macro which purpose is to instantiate a set of generic bazel rules

I think it would easier to decouple the flow from bazel (currently it does bazel -> python -> shell(bazel)), at least initially until we converge on the design discussion :

Another alternative is to rely on the python bindings for yosys and openroad and drive the tools directly as library rather than launching them as commands with a tcl script.

@QuantamHD and @grotival are also interested into a finding a more sustainable to do without an hard dependencies on shelling out to bazel, so it'd be good to get their perspective as well.

performance metrics:

  • throughput

do you currently extract throughput data from simulation data using realistic payload? if not, it @grebe could provide an example he put together for https://github.com/google/xls/tree/main/xls/examples/protobuf

@lpawelcz
Copy link
Contributor Author

@proppy parameterization through DSLX files generated with proto_to_dslx_main indeed looks like a good solution for passing DSLX design parameters, thank you for that suggestion, I will look into this.

My biggest concern is to figure out a solution that would not require reimplementing flows that are already defined in bazel rules. This is because I want to prevent a situation where there is a need to maintain 2 separate flows that perform the same task. For example, in synthesis rule we gather the files required for the synthesis, construct args and environment variables and only after that the rule calls the synthesis tool.
This creates a problem if we would like to reuse only the synth.tcl script. In such case we would have to reimplement the whole environment preparation part and make sure it is always the same as the original implementation in bazel rule. That is why I think it is worth to take a closer look at rule synthesis_binary which takes our bazel synthesize_rtl rule as input and generates a shell script which should perform the same steps as synthesise_rtl would. I think we could benefit from this approach in synthesis and place_and_route. We could make vizier_optimize depend on shell script generation rules and this way we could modify the flow to look more like: bazel -> python -> shell(yosys, openroad, etc.).

Your idea with python bindings for yosys and openroad is also very interesting and I will surely investigate more on that but I believe that apart from the bindings for the tools we should also have a way of generating the preparation steps before those tools are called based on the implementation of bazel rules.

do you currently extract throughput data from simulation data using realistic payload?

No, current example simulates RLE encoder with some trivial payload which does not represent realistic data

@proppy
Copy link
Member

proppy commented Oct 27, 2023

My biggest concern is to figure out a solution that would not require reimplementing flows that are already defined in bazel rules. This is because I want to prevent a situation where there is a need to maintain 2 separate flows that perform the same task.

While I agree it would be best to have maintain only one flow, I think that's orthogonal to what we are trying to achieve here (the Vizier driven parameter exploration). I think we should tackle that as a separate effort.

In such case we would have to reimplement the whole environment preparation part and make sure it is always the same as the original implementation in bazel rule.

Another way to look at this, is that if we come with a good way to tackle the flow preparation outside of bazel (in C++, Python) we might be able to integrate it as a tool back into the bazel rules and drop a bunch of non-reusable skylark logic.

@proppy
Copy link
Member

proppy commented Apr 3, 2024

what do you think of moving this (along side #1137) in separate repo similar to https://github.com/antmicro/xls-cosimulation-demonstrator ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants