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

Add cocotb verilator flow_tool option #409

Closed
wants to merge 7 commits into from
Closed

Conversation

isomoye
Copy link
Contributor

@isomoye isomoye commented Jan 9, 2024

This PR adds verilator as a cocotb flow_tool simulation option by adding the cocotb "extend an existing build flow" options in sim.py. It also adds a switch to the verilator makefile call to use "Vtop.mk" instead of "V 'cocotb-module'.mk".

A cocotb simulation running on verilator can then be run using just the following fusesoc simulation configuration

  flow: sim
  flow_options:
    tool : verilator
    cocotb_module : test_file
    timescale: 1ns/1ns
  filesets : [rtl,cocotb]
  toplevel : [toplevel]```

@isomoye isomoye changed the title Add verilator flow option Add cocotb verilator flow_tool option Jan 9, 2024
@@ -23,6 +24,8 @@ class Sim(Generic):
def configure_tools(self, flow):
if self.flow_options.get("cocotb_module"):
tool = self.flow_options.get("tool")
share_dir = os.popen("cocotb-config --share").read().rstrip() \
Copy link
Owner

Choose a reason for hiding this comment

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

I wouild prefer evaluating cocotb-config --share directly like we do with cocotb-config --libdir. That makes the script more portable if we want to run it on a different machine than it was created on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed by changing the share directory evaluation to a direct call in tools/verilator.py rather than a system call. see commit aa7d8c3.

@olofk
Copy link
Owner

olofk commented Jan 11, 2024

Many thanks. A very welcome addition and I'm hoping to find some time to try it myself. I just had a smaller comment above. Happy to merge if you could fix that.

isomoye and others added 4 commits January 11, 2024 10:23
update cocotb specific verilator.cpp command to use local cocotb-config call rather than system call
update cocotb specific verilator.cpp command to use local cocotb-config call rather than system call
remove unused import call
@olofk
Copy link
Owner

olofk commented Jan 12, 2024

Thanks. Code looks fine now, but regression tests are failing and there seems to be two reasons for that.

  1. Formatting needs to be redone. This is typically done with a pre-commit hook automatically, so just run pre-commit install from the repo root and any changed files will be reformatted correctly when you make a commit
  2. The verilator regression tests fail because there is no flow_options key in the EDAM. The easiest way to get around this is probably to replace if self.edam["flow_options"].get("cocotb_module"): with something like if self.edam.get("flow_options", {}).get("cocotb_module"):, but I'm also thinking more philosophically if the tools are supposed to be looking at flow options at all. The other way to do this would be to add a cocotb_module tool option for Verilator and then define let the sim flow define the value of that option. Long-term we probably want to do something like that, but we can keep it simple for now and just make sure not to crash if flow_options is missing

@isomoye
Copy link
Contributor Author

isomoye commented Jan 17, 2024

I fixed the format issue by following your suggestions. I agree with your assessment of using flow_options in the tool specific flow and I'm open to working on a permanent fix soon. I tested the verilator.py changes without flow_options and it looks like your suggested change fixed the crashing issue.

@olofk
Copy link
Owner

olofk commented Jan 21, 2024

There was still some formatting issues in sim.py, but I took the liberty to fix that locally. Squashed and pushed! Thank you for your contributions!

@olofk olofk closed this Jan 21, 2024
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.

2 participants