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

Single netlist mode #223

Merged
merged 23 commits into from
May 20, 2024
Merged

Single netlist mode #223

merged 23 commits into from
May 20, 2024

Conversation

sgherbst
Copy link
Contributor

@sgherbst sgherbst commented May 15, 2024

This PR adds "single netlist" mode, where an SbNetwork can be simulated in a single Verilator or Icarus simulator instance. This is accomplished by generating Verilog code that implements the network that is specified by .connect() and .external() statements.

Prerequistes

morty

Single netlist mode currently requires morty for Verilog processing, which adds a unique suffix to module definitions used by each unique SbDut. To see why this is necessary, suppose that the network contains two SbDuts, each using an RTL module called memory with different implementations. When a single netlist is constructed, the module definitions for memory will conflict. (This is not a problem outside of single-netlist mode, since the two SbDuts are compiled separately)

To install morty:

  1. Install Rust if you don't have it already:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Install morty (will take a few minutes)
cargo install --git https://github.com/pulp-platform/morty.git
  1. Check if morty is in the path: which morty. If nothing is returned, add $HOME/.cargo/bin to the path.

In the future, we can explore packaging morty with switchboard, or solving this problem another way.

Update packages

The lambdalib version needs to be updated for the example below to work, and this update is included in examples/requirements.txt. Please run

pip install -r examples/requirements.txt

Testing the PR

cd into examples/network and run ./test.py --single-netlist (or ./test.py --tool icarus --single-netlist). If you're curious, you can see the generated Verilog code in build/testbench-*/testbench.sv.

Enabling single netlist mode is just a matter of setting SbNetwork(..., single_netlist=True) or including --single-netlist as a command-line option if cmdline=True has been set. However, there is a caveat, which is that SbDuts used in the network must have autowrap=False and subcomponent=True

To make it easier to define SbDuts that can be used in either single-netlist mode or distributed mode, this PR provides a new method, SbNetwork.make_dut(), that automatically fills in autowrap and subcomponent based on whether single netlist mode is being used. It also passes through command-line arguments automatically. make_dut accepts the same arguments as the SbDut constructor.

If you take a look at examples/network/tests.py, you can see usage examples for make_dut: it just replaces the SbDut constructor where it was being used before.

dut = net.make_dut('umi2axilite', parameters=parameters,
interfaces=interfaces, resets=resets)

Future work

  • Allow SbNetworks with single_netlist=True to be instantiated in an SbNetwork. This will enable hierarchical simulation of large networks.
  • See whether it is possible to avoid the need to have autowrap and subcomponent set to specific values when using SbDuts in single-netlist mode (a bit tricky due to some of the different ways SbDuts are used)

@sgherbst sgherbst marked this pull request as ready for review May 15, 2024 23:13
@sgherbst sgherbst requested a review from azaidy May 15, 2024 23:13
Copy link
Collaborator

@azaidy azaidy left a comment

Choose a reason for hiding this comment

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

LGTM!

@sgherbst sgherbst merged commit 68ccafe into main May 20, 2024
6 checks passed
@sgherbst sgherbst deleted the sgh/single-netlist branch May 20, 2024 18:28
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

2 participants