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

Universal Yosys module #581

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

kboronski-ant
Copy link
Collaborator

@kboronski-ant kboronski-ant commented Jul 5, 2022

The synth module is quite troublesome, because its outputs are dependent on the contents of a Tcl script used by Yosys. This PR is an attempt to solve this issue by replacing this module with an universal Yosys module.

Content description

The approach is to create a binding mechanism for variables used in Tcl script that allows f4pga to inspect the I/O of the script. This is achieved by replacing direct references to environmental variables with calls to f4pga command in Tcl script. f4pga provides its implementation of Tcl f4pga command that gathers metadata from the arguments and creates dummy bindings for those variables. The Tcl script is then executed by a Tcl interpreter within f4pga using that implementation when instantiating the module. This allows the module to inspect I/O of the script and present stage dependencies and values. Then when the script gets passed to yosys, it gets prefixed with an alternative implementation of f4pga command, one that reads environmental variables. Those variables are provided by the yosys module during execution stage, or by legacy wrappers*.

* Legacy wrappers require changes in names of environmental variables in order to work with this.

Features

  • Inspect Tcl scripts for I/O
  • Can be used with legacy scripts (after modifying them a little bit)
  • Manage temporary files used by Tcl scripts (creates bindings to unique file names in a temporary directory and performs cleanup after script execution)
  • Run yosys in unpolluted environment
  • I/O can be determined by logic within Tcl script
  • Supports optional takes and product descriptions
  • Produce Yosys log on demand

Caveats

  • Yosys scripts (non-tcl) are not supported
  • Running the modified Tcl scripts in yosys requires running the f4pga_exec.tcl script first. If anybody is using those scripts in a standalone manner, this could be a confusing change.
  • Scripts need to behave in a deterministic manner and flow control should be independent from file paths.

Work being done

  • Yosys module for f4pga
  • Updated XC7 platform flow definitions
  • Updated XC7 Tcl scripts
  • Updated XC7 legacy wrappers
  • Updated EOS-S3 platform flow definitions
  • Updated EOS-S3 Tcl scripts
  • Updated EOS-S3 legacy wrappers
  • Updated docs

@kboronski-ant kboronski-ant force-pushed the yosys_module branch 3 times, most recently from 9c2c779 to 978589c Compare August 4, 2022 12:37
@umarcor
Copy link
Contributor

umarcor commented Aug 4, 2022

Changing this to a draft, to be rebased after #604 is merged.

@umarcor umarcor marked this pull request as draft August 4, 2022 19:06
@umarcor
Copy link
Contributor

umarcor commented Aug 6, 2022

To be complemented with f4pga/f4pga-arch-defs#2851.

@kboronski-ant kboronski-ant force-pushed the yosys_module branch 2 times, most recently from 45da1d9 to 0cb8079 Compare August 26, 2022 13:53
@umarcor umarcor force-pushed the yosys_module branch 4 times, most recently from c533d72 to 94b8b09 Compare September 2, 2022 13:21
@kboronski-ant kboronski-ant marked this pull request as ready for review September 6, 2022 17:37
@kboronski-ant
Copy link
Collaborator Author

Marking as ready for review, as for now the most effective approach is probably to keep a separate copy of Tcl scripts to use with legacy tooling (arch-defs), until we figure out how to fully transition to using f4pga build.

f4pga/flows/platforms.yml Outdated Show resolved Hide resolved
yosys_plugins:
- ql-iob
- ql-qlf
split_inouts:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above.

@@ -30,6 +30,7 @@

bin_dir_path = str(Path(sys_argv[0]).resolve().parent.parent)
share_dir_path = str(F4PGA_SHARE_DIR)
aux_dir_path = str(Path(__file__).resolve().parent.parent / "aux")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aux is a reserved keyword on some systems. Please, use a different name/location for the aux_dir_path. I would suggest to put the TCL scripts added in this PR into f4pga/flows/tcl.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aux stands for "auxilary". The directory is mean to hold all sorts of auxilary scripts/data. I think it's more convinient to havve one, well-structured directory for such things callend "aux", rather than having one for tcl, one for python, etc and creating a separate variable for each such directory.

Could you give me an example of how this "aux" would interfere with some systems?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give me an example of how this "aux" would interfere with some systems?

Cloning this branch on an NTFS drive on Fedora produces the following error:

$ git clone https://github.com/antmicro/f4pga
Cloning into 'f4pga'...
remote: Enumerating objects: 5008, done.
remote: Counting objects: 100% (5008/5008), done.
remote: Compressing objects: 100% (1855/1855), done.
remote: Total 5008 (delta 3007), reused 4971 (delta 2995), pack-reused 0
Receiving objects: 100% (5008/5008), 241.55 MiB | 16.21 MiB/s, done.
Resolving deltas: 100% (3007/3007), done.
$ cd f4pga/
$ git checkout -b test-branch origin/yosys_module 
fatal: cannot create directory at 'f4pga/aux': Invalid argument

See also https://www.google.com/search?q=aux+reserved+filename.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more convinient to havve one, well-structured directory for such things callend "aux", rather than having one for tcl, one for python, etc and creating a separate variable for each such directory.

So far, we only have TCL assets (which will very probably be removed soon) and a single YAML file. Python code is installed as part of the package and it does not need any separated variable.

Let's not overengineer the implementations. Better wait until the need arises. Please, focus on the core functionality that this PR is trying to bring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you going to remove Tcl scripts? The old ones might be removed at some point, but I don't think that the new ones are going to be purged as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed aux to auxiliary. That should fix the problem with nonsensical filesystems.

I'm not entirely sure what data is going to be used in the future. Whether it's auxiliary directory or tcl doesn't really change the complexity of my current solution.

kboronski-ant and others added 10 commits September 7, 2022 18:44
Signed-off-by: Krzysztof Boronski <kboronski@antmicro.com>
Signed-off-by: Krzysztof Boronski <kboronski@antmicro.com>
Extracted common Tcl utility commands into another Tcl sctipt

Signed-off-by: Krzysztof Boronski <kboronski@antmicro.com>
Signed-off-by: Krzysztof Boronski <kboronski@antmicro.com>
* use ttop value instead of eblif path for bitstream file name
* io_rename fixes, eos-s3 flow: sdc-in -> sdc

Signed-off-by: Krzysztof Boronski <kboronski@antmicro.com>
Signed-off-by: Krzysztof Boronski <kboronski@antmicro.com>
Signed-off-by: Unai Martinez-Corral <umartinezcorral@antmicro.com>
Signed-off-by: Krzysztof Boronski <kboronski@antmicro.com>
… comments about optional outputs

Signed-off-by: Krzysztof Boronski <kboronski@antmicro.com>
Signed-off-by: Krzysztof Boronski <kboronski@antmicro.com>
@@ -0,0 +1,61 @@
# Copyright (C) 2022 F4PGA Authors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be sourced in synth.tcl only. Is there any reason not to copy the content there? See https://github.com/chipsalliance/f4pga/blob/main/f4pga/wrappers/tcl/xc7.f4pga.tcl#L14-L58.

@@ -18,7 +18,16 @@

set -e

SYNTH_TCL_PATH="$(python3 -m f4pga.wrappers.tcl synth)"
MYPATH=`realpath $0`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the current proposal is to duplicate the TCL pipelines, please keep f4pga.wrappers.sh untouched in this PR. Move these changes to a follow-up PR.

@@ -58,8 +58,8 @@ def execute(self, ctx: ModuleContext):
if ctx.outputs.util_rpt:
(build_dir / DEFAULT_UTIL_RPT).rename(ctx.outputs.util_rpt)

def __init__(self, _):
self.name = "pack"
def __init__(self, params, r_env, instance_name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation for this change? Can it be handled as an standalone PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation is to grab be able to access stage's name. When yosys module gets called twice in a flow, it should output different log targets. Names of these targets are based on the name of a stage.

I think this change could be handled in a separate PR.

This change can also be used to remove stage_name field from generic_script_wrapper.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, split it to a separate PR, so we can analyse that feature on its own. If most of the stages receive params, r_env and instance_name, it might be worth wrapping those in an object/class and use it as the payload from stage to stage.

What about r_env?


# Write output JSON, fixup cell names using an external Python script
write_json $f4pga_json_org
exec $f4pga_python3 ${f4pga_shareDir}/scripts/yosys_fixup_cell_names.py $f4pga_json_org $f4pga_json_presplit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After rebasing, use -m f4pga.utils.quicklogic.yosys_fixup_cell_names and -m f4pga.utils.yosys_split_inouts as in https://github.com/chipsalliance/f4pga/blob/main/f4pga/wrappers/tcl/eos-s3.f4pga.tcl#L176-L194.

Signed-off-by: Krzysztof Boronski <kboronski@antmicro.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backlog Discussion Enhancement New feature or request f4pga (python) Python package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants