# Cosimulation with verilator?

**URL:** <https://discourse.myhdl.org/t/cosimulation-with-verilator/417>\
**Category:** Enhancement Request\
**Created:** [March 13, 2020, 11:14am UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417 "2020-03-13T11:14:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jos.huisken](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/jos.huisken/32/34_2.png) [@jos.huisken](https://discourse.myhdl.org/u/jos.huisken)\
**Post date:** [March 13, 2020, 11:14am UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/1 "2020-03-13T11:14:24Z")

</div>

Hi all,

I would like to perform cosimulation with verilator, due to its systemverilog language support.  
Some 10 years ago, mentioned in the sourceforge myhdl-list, an experiment was done by Terry Chen. Not sure if anyone has been using his method, or maybe another alternative?  
See: [https://sourceforge.net/p/myhdl/mailman/message/26417122/](https://sourceforge.net/p/myhdl/mailman/message/26417122/)

Thanks,  
Jos

---

<div class="post-metadata">

**Author:** ![hgomersall](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/hgomersall/32/10_2.png) [@hgomersall](https://discourse.myhdl.org/u/hgomersall)\
**Post date:** [March 13, 2020, 12:00pm UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/2 "2020-03-13T12:00:07Z")

</div>

Not direct experience of verilator, _but_ we have extensively used an external simulator (Vivado) through a different approach to true cosimulation which might be relevant here.

This work is encapsulated with [Veriutils](https://github.com/hgomersall/Veriutils) and [Ovenbird](https://github.com/hgomersall/Ovenbird). The former is the entry point, and the latter extends Veriutils to target Vivado. The model is that you build python test bench with a bit of (generally helpful) syntactic constraints, and then the tool will automatically wrap the DUT in an equivalent test bench, capturing all the signals and reporting back. It is this wrapped test object which is pure Verilog/VHDL which you can then run in a simulator.

It handles normal signals which have precise timing as well as AXI stream signals in which a convertible BFM is used (for e.g. the case where the DUT uses closed IP which we just model in the python world).

We’ve used this model extensively and with good effect on a large project. The tools are well tested and trusted.

I’m happy to give more assistance if this seems interesting to you…

(I’ve just realised, I haven’t pushed some significant changes to the above repos which don’t change much feature-wise - just filling in a couple of gaps - but were a significant refactoring to make extending easier, so probably relevant to you. I’m just on this now)

---

<div class="post-metadata">

**Author:** ![kranerup](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@kranerup](https://discourse.myhdl.org/u/kranerup)\
**Post date:** [March 13, 2020, 2:22pm UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/3 "2020-03-13T14:22:05Z")

</div>

With the help of Wilson Snyder we have created a cosimulation interface with Verilator. We have been running it extensively for some years. We were planning to provide this to the community but got stuck since our flow, far various reasons, is stuck at MyHDL 0.8.

Kenny

---

<div class="post-metadata">

**Author:** ![jos.huisken](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/jos.huisken/32/34_2.png) [@jos.huisken](https://discourse.myhdl.org/u/jos.huisken)\
**Post date:** [March 18, 2020, 9:36am UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/4 "2020-03-18T09:36:33Z")

</div>

Henry, thanks. I’ll have a look at it. Did not realize vivado sim is an option as well (for working at home). I realized that Verilator, since it is in fact also pure RTL, is a natural match with MyHDL so it still might be interesting.

Jos

---

<div class="post-metadata">

**Author:** ![jos.huisken](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/jos.huisken/32/34_2.png) [@jos.huisken](https://discourse.myhdl.org/u/jos.huisken)\
**Post date:** [March 18, 2020, 9:44am UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/5 "2020-03-18T09:44:06Z")

</div>

Kenny, I’m looking at [https://github.com/wsnyder/myhdl/tree/pull\_verilator2/cosimulation/verilator](https://github.com/wsnyder/myhdl/tree/pull_verilator2/cosimulation/verilator). Is that what you are referring to? I will give it a try. Maybe a pull request for which also is valid fo rthe current myhdl versions.  
Thanks for sharing, I will give it a try.

Jos

---

<div class="post-metadata">

**Author:** ![kranerup](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@kranerup](https://discourse.myhdl.org/u/kranerup)\
**Post date:** [March 18, 2020, 10:01am UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/6 "2020-03-18T10:01:17Z")

</div>

Yes, that is the one. But unfortunately that pull request has a number of bugs. We have done a lot of work to get it working but that is not pushed anywhere. I’ll take a look if there is an easy way to share it with you.

---

<div class="post-metadata">

**Author:** ![hgomersall](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/hgomersall/32/10_2.png) [@hgomersall](https://discourse.myhdl.org/u/hgomersall)\
**Post date:** [March 18, 2020, 11:26am UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/7 "2020-03-18T11:26:44Z")

</div>

Yeah, we use Vivado extensively with MyHDL, and pretty much exclusively with the free version. Ovenbird is the tool we’ve created for verification. Also relevant might be [Kea](https://github.com/SmartAcoustics/Kea) which is useful tools that fit nicely into the Xilinx ecosystem, including a nice register subsystem.

---

<div class="post-metadata">

**Author:** ![jos.huisken](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/jos.huisken/32/34_2.png) [@jos.huisken](https://discourse.myhdl.org/u/jos.huisken)\
**Post date:** [March 27, 2020, 7:20am UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/8 "2020-03-27T07:20:07Z")

</div>

Hi Kenny,

Did you have a look whether you can share? I guess myhdl/\_Cosimulation.py and the cosimulation/verilator/ directory should get me going. Then I’ll prepare a pull request.

Thanks,  
Jos

---

<div class="post-metadata">

**Author:** ![jos.huisken](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/jos.huisken/32/34_2.png) [@jos.huisken](https://discourse.myhdl.org/u/jos.huisken)\
**Post date:** [April 5, 2020, 8:02pm UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/9 "2020-04-05T20:02:27Z")

</div>

I’ve created a pull request to add verilator as a means for cosimulation.  
See [https://github.com/joshuisken/myhdl](https://github.com/joshuisken/myhdl), branch verilator.  
I used ‘pyverilator’ to ease integration. It is a specific version [https://github.com/csail-csg/pyverilator](https://github.com/csail-csg/pyverilator) which allows easy dictionary access to io-ports.  
No interprocess communication is used since the verilated design is imported as a ctypes module.

Not much testing has been done, but few tests have been added.

What I noticed is that both this verilator cosim, but also other cosims like icarus, have some initialization/reset issues which deserve some attention. They behave slightly different than pure myhdl.

Also, I considered to not use pyverilator and rewrite directly for verilator directly, but with this pyverilator version it was more convenient. but anyway, something to reconsider.

I have no performance numbers yet so I’m interested in your experience. Of course there is always room improvement. Also bug reports are welcome, if any.

Thanks,  
Jos

---

<div class="post-metadata">

**Author:** ![hgomersall](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/hgomersall/32/10_2.png) [@hgomersall](https://discourse.myhdl.org/u/hgomersall)\
**Post date:** [April 13, 2020, 9:16am UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/10 "2020-04-13T09:16:02Z")

</div>

@jos.huisken Is this suitable for merging into master? It seems like a good addition. Aren’t the tests provided through the MyHDL tests?

---

<div class="post-metadata">

**Author:** ![jos.huisken](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/jos.huisken/32/34_2.png) [@jos.huisken](https://discourse.myhdl.org/u/jos.huisken)\
**Post date:** [April 13, 2020, 1:37pm UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/11 "2020-04-13T13:37:55Z")

</div>

@hgomersall I think so. Added indeed few tests which should also pass when there is no pyverilator+verilator available. So it should not break anything.

---

<div class="post-metadata">

**Author:** ![hgomersall](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/hgomersall/32/10_2.png) [@hgomersall](https://discourse.myhdl.org/u/hgomersall)\
**Post date:** [April 13, 2020, 1:56pm UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/12 "2020-04-13T13:56:41Z")

</div>

In that case I encourage you to raise a pull request when you’re happy with it.

---

<div class="post-metadata">

**Author:** ![jos.huisken](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/jos.huisken/32/34_2.png) [@jos.huisken](https://discourse.myhdl.org/u/jos.huisken)\
**Post date:** [April 13, 2020, 8:54pm UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/13 "2020-04-13T20:54:39Z")

</div>

@hgomersall Created pull request [#338](https://github.com/myhdl/myhdl/pull/338).  
@kranerup I saw that Wilson Snyder created a pull request some time ago which somehow failed.  
Lets hope this one makes it, despite the dependence on the non-standard pyverilator.

---

<div class="post-metadata">

**Author:** ![hgomersall](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/hgomersall/32/10_2.png) [@hgomersall](https://discourse.myhdl.org/u/hgomersall)\
**Post date:** [April 14, 2020, 7:52am UTC](https://discourse.myhdl.org/t/cosimulation-with-verilator/417/14 "2020-04-14T07:52:07Z")

</div>

How do you mean non-standard? It’s just a python package isn’t it?
