Giter VIP home page Giter VIP logo

intel / rohd-cosim Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 3.0 666 KB

Cosimulation for the Rapid Open Hardware Development (ROHD) framework with other simulators

Home Page: https://pub.dev/packages/rohd_cosim

License: BSD 3-Clause "New" or "Revised" License

Dart 69.93% Python 14.87% SystemVerilog 4.71% Shell 10.44% Forth 0.05%
co-simulation cocotb cosim cosimulation dart framework hardware hardware-design hardware-verification python

rohd-cosim's Introduction

Open in GitHub Codespaces

Tests API Docs Chat License Contributor Covenant

ROHD Cosim

ROHD Framework Co-simulation (ROHD Cosim) is a Dart package built upon the Rapid Open Hardware Development (ROHD) framework for cosimulation between the ROHD Simulator and a SystemVerilog simulator.

Common use cases include:

  • Instantiating a SystemVerilog module within a ROHD Module and running a simulation.
  • Using ROHD and the ROHD Verification Framework (ROHD-VF) to build a testbench for a SystemVerilog module.
  • Connecting and simulating a ROHD and ROHD-VF developed functional model to a empty shell located within a SystemVerilog hierarchy.
  • Developing a mixed-simulation model where portions of design and/or testbench are in ROHD/ROHD-VF and other are in SystemVerilog or other languages which can run in or interact with a SystemVerilog simulator.

When you instantiate a SystemVerilog module within the ROHD simulator with ROHD Cosim, from the perspective of the rest of the ROHD environment it looks just like any other ROHD module. You can run simulations, set breakpoints and debug, etc. even with the SystemVerilog simulator running in cosimulation.

Prerequisites

ROHD Cosim relies on a python package called cocotb and its GPI library for communicating to SystemVerilog simulators. The cocotb libraries have good support for a variety of simulators and have been used by many silicon and FPGA projects.

Detailed instructions for installing cocotb are available here: https://docs.cocotb.org/en/stable/install.html. The instructions generally boil down to:

pip install cocotb

You will also need your favorite SystemVerilog simulator to do cosimulation between ROHD and SystemVerilog modules. ROHD Cosim does not do any SystemVerilog parsing or SystemVerilog simulation itself.

Using ROHD Cosim

There are two steps to using ROHD Cosim:

1. Wrap your SystemVerilog module

Wrap your SystemVerilog module with ROHD's ExternalSystemVerilogModule and apply the Cosim mixin.

For example, here are corresponding SystemVerilog module definitions and a wrapper for it with Cosim.

// example_cosim_module.v
module my_cosim_test_module(
    input logic a,
    input logic b,
    output logic a_bar,
    output logic b_same,
    output logic c_none
);

assign a_bar = ~a;
assign b_same = b;
assign c_none = 0;

endmodule
// example_cosim_module.dart
class ExampleCosimModule extends ExternalSystemVerilogModule with Cosim {
  Logic get aBar => output('a_bar');
  Logic get bSame => output('b_same');

  @override
  List<String> get verilogSources => ['./example_cosim_module.v'];

  ExampleCosimModule(Logic a, Logic b, {String name = 'ecm'})
      : super(definitionName: 'my_cosim_test_module', name: name) {
    addInput('a', a);
    addInput('b', b);
    addOutput('a_bar');
    addOutput('b_same');
    addOutput('c_none');
  }
}

You can add inputs and output using any mechanism, including ROHD Interfaces.

2. Generate a connector and start the cosimulation

Call the Cosim.connectToSimulation function with an appropriate configuration after Module.build to connect to the SystemVerilog simulator.

Additional information

  • Note that for cosimulation to execute, the ROHD Simulator must be running.
  • Note that with the cosimulation process running in a unit test suite, you have an additional thing to reset each tearDown: Cosim.reset().
  • The example/ directory has a counter example similar to what's available in the ROHD and ROHD-VF examples.
  • The ROHD Cosim test suite in test/ is a good reference for some examples of how to set things up.

Cosimulation Configurations

There are three different types of configuration that can be used when connecting to the SystemVerilog simulation: "wrap", "custom", and "port".

Wrap Configuration

The wrap configuration is the simplest way to get started with cosimulation if you don't already have an existing build and simulation system set up for the SystemVerilog module.

Pass a CosimWrapConfig object into the Cosim.connectToSimulation call with information about which simulator you want to use and let ROHD Cosim take care of the rest! It will automatically create a wrapper with all SystemVerilog submodules for each that needs to be cosimulated.

The below diagram shows how the wrap configuration connects to your simulation. ROHD will generate a Makefile and connector for your design, and then connect to it by listening to some port information coming through stdout from the simulation process.

Wrap Config Diagram

The example in example/main.dart uses the wrap configuration and is a good reference to get started.

Custom Configuration

A custom configuration is a good approach if you already have a build system set up for your design and want to make the minimum changes possible.

Pass a CosimCustomConfig object into the Cosim.connectToSimulation call with information about how to launch the simulation and it will handle the rest.

ROHD Cosim will generate a cocotb-based python connector which is launched by the simulation process.

ROHD Cosim communicates with the python connector through a local socket. ROHD watches for a special string with port information that comes from stdout via the python connector for how to connect. If you mask stdout (e.g. to some other file), you need to find another way to pass that information through.

Your SystemVerilog build will need to be configured to properly integrate the cocotb libraries. You can follow these instructions for your choice of simulator: https://docs.cocotb.org/en/stable/custom_flows.html

You will need to set some environment variables during simulation so that cocotb can determine what to run:

# Modules to search for test functions (should match python file name and module path generated by ROHD Cosim)
export MODULE=cosim_test_module
 
export TOPLEVEL_LANG=verilog
 
# TOPLEVEL is the name of the toplevel module in your Verilog build
export TOPLEVEL=top_tb

You will also need to ensure the following plusarg is passed to your simulation:

+define+COCOTB_SIM=1

The diagram below shows how the custom configuration connects to your simulation. Your custom build flow generates the simulation executable, and then ROHD cosim takes care of the rest similar to the wrap configuration.

Custom Config Diagram

Port Configuration

A port configuration is an even more specialized config in case you have not only your own custom build system, but a custom simulation run system as well. With the port configuration, you create a PortConfig object to the Cosim.connectToSimulation call with information about what unix socket port it should connect to. In this way, it is no longer necessary for ROHD Cosim to be the launcher of the SystemVerilog simulation: another process can launch the simulation and then ROHD Cosim can attach at the specified port.

To build this system may require some custom python code to manually pass the port information where it needs to go. The file python/rohd_port_connector.py can help with a lot of this.

Check out test/port_test.dart for a good example of how to make this work.

The diagram below shows how the port configuration connects to your simulation. Your custom build flow generates the simulation executable, and your custom run flow starts the simulation. You must create some mechanism, such as through a custom cocotb test, to pass port information back to ROHD cosim. In this diagram, the custom test is launching the actual ROHD process with a port argument on the command line.

Port Config Diagram


2022 September 9
Author: Max Korbel <[email protected]>

Copyright (C) 2022-2023 Intel Corporation
SPDX-License-Identifier: BSD-3-Clause

rohd-cosim's People

Contributors

mkorbel1 avatar rdower avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rohd-cosim's Issues

Add an example to the repo

Motivation

It's good to have an example/ directory with example(s) of using the package. This is also used by pub.dev for points and included as a tab.

Desired solution

Add an example directory, with maybe one example per type of configuration?

Don't forget to add it to devcontainer.json so it opens by default

Alternatives considered

No response

Additional details

No response

Add testing for clock-divider logic with cosimulation

A bug exists in ROHD related to clock dividers:
intel/rohd#191

The logic in cosimulation is similar to the logic of sequential logic in a plain ROHD simulation. We should review that a similar bug does not exist in ROHD Cosim, and add tests that clock dividers behave as expected in cosimulation. This may require waiting for the ROHD issue to be resolved first.

Enable cosim access to hierarchically reference signals in SystemVerilog modules and submodules

There's already support for accessing registered ports of ExternalSystemVerilogModules, but it would be cool to be able to access other non-port signals in modules or submodules in the SystemVerilog.

This opens the question of "listening" to other signals in addition to just driving them. Also, this could overlap with inputs, should we be able to listen to those as well? What about handling of infinite loops of listening?

What if you have a ROHD module, within a SystemVerilog module, within a ROHD module? To access relative signals from ROHD to ROHD would require context of their relative hierarchies.

Listeners linger after simulations end

Some listeners and subscriptions from Cosim.connectCosimulation do not cancel when a simulation ends. This means if the simulation is reset and started again, at least there's a performance penalty and at worst duplicate actions can break functionality. Listeners and subscriptions should be closed and cancelled once a simulation ends so that the next one is not affected by prior simulations.

Build an annotation-based cosim-wrapper code generator

It can be tedious to build a cosim wrapper for a SystemVerilog module for cosimulation. Since enough information is provided anyways to build and simulate the module, it would be nice to have an annotation-based code generator which could build the wrapper with all ports already added.

Add testing that SV `#` delays are properly handled

A # delay in the SystemVerilog simulator can result in signals changing at intermediate times between ticks and not edge triggered by any signal driven by ROHD Cosim. We should add better testing that these scenarios still function correctly.

Resolve race condition in RohdConnector during interactive debug and SV timeout

There is a block of code in rohd_connector.py which is designed to detect whether there was a timeout waiting for the SystemVerilog simulator to complete a tick:

            if not ready_to_read and self.mid_tick:
                # not necessarily an error, since maybe SV simulator called $finish
                print('Timeout waiting for tick to complete in Simulator!', flush=True)
                self.shutdown()
                break

This code is only necessary because sometimes simulators appear to not properly indicate to cocotb that the simulation has ended, so a graceful shutdown cannot be achieved (cocotb/cocotb#3121).

The race condition appears if ROHD is being interactively debugged and fails to send the entirety of a tick's information (i.e. not ready_to_read) even though a tick is ongoing (i.e. self.mid_tick).

For most users, unless actively debugging ROHD Cosim itself, this will not be often hit.

Don't send more ticks than necessary

There are some scenarios where ROHD Cosim will send multiple ticks to the SV simulator back-to-back without any additional value added (e.g. I think if there are no events in a given time). This is a waste of processing, socket communication, and overall simulation time. If it happens frequently it could potentially impact overall simulation duration.

We should avoid sending ticks that aren't necessary.

Add ability to configure build and sim arguments at connection time

Motivation

Cosim modules currently have the ability to specify things like simulation and compile time arguments. Sometimes, it might be useful to provide compile, simulation, or other arguments at a "top" level when the cosimulation is launched rather than within a specific module.

Desired solution

Arguments at the connection time for the wrap config with instructions for how to compile, simulate, etc. in addition to the arguments available in Cosim already.

Alternatives considered

No response

Additional details

No response

Support `LogicArray` ports

Motivation

intel/rohd#375 introduced LogicArrays, including on Module ports. For compatibility, the ROHD Cosim package should also support them.

Desired solution

Upgrade utilities in ROHD Cosim and add testing for LogicArray ports on Modules being cosimulated.

Alternatives considered

No response

Additional details

No response

Use typing for cosim messages

There is some limited typing of cosim messages in both the Dart and Python sides of the package. Creating some better types for different types of messages could make the package more robust and easier to change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.