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

Previous work and future ideas #1

Open
7 of 15 tasks
umarcor opened this issue Apr 12, 2020 · 12 comments
Open
7 of 15 tasks

Previous work and future ideas #1

umarcor opened this issue Apr 12, 2020 · 12 comments
Labels

Comments

@umarcor
Copy link
Member

umarcor commented Apr 12, 2020

This repository was created by merging the following resources:

In fact, #1 in the commit history corresponds to umarcor#1 or ghdl/ghdl-systemc-fosdem16#1.

This issue is just a placeholder for consistency and to acknowledge the references.

Refs:

Ideas:

Examples:

@umarcor umarcor closed this as completed Apr 12, 2020
@umarcor umarcor changed the title Previous work Previous work and future ideas Apr 13, 2020
@umarcor umarcor reopened this Apr 13, 2020
@bellaz89
Copy link

bellaz89 commented Apr 15, 2020

Hi! I am the co-writer of the (still unreleased) GHDL backend for SpinalHDL (SpinalHDL/SpinalHDL#146)

To write the support, one of the most useful reference I found is a master thesis about Clash co-simulation integration . The SpinalHDL GHDL integration is mostly based on it. I think it is a very well written work.

@umarcor
Copy link
Member Author

umarcor commented Apr 16, 2020

Hi @bellaz89! As you see, this repository was created a few days ago, and we've been busy uploading all the initial content/examples. I wanted to let it settle down a bit before pinging you explicitly. Anyway, since you already came by (thanks!), let's go ahead:

Although @RocketRoss and myself are currently focused on uploading content related to VHPIDIRECT and the C interface, I acknowledge that most (if not all) non-trivial existing projects do use VPI instead. To name a few: the Clash integration you refed, your own VPIInteropREPL (for SpinalHDL), cocotb (for Python), MyHDL, ACMIX (for SystemC), etc. In fact, that's why section https://ghdl.github.io/ghdl-cosim/vpi/examples/index.html exists. That's where we'd like to add resources related to VPI. As far as I am aware, there is little to none VPI-specific content in the main docs. Link, compile and load options are explained, but there are no further explanations or examples. Furthermore, to be honest, I am not sure about sections "Wrapping a simulation", "Linking objects files" and "Dynamic loading" being exclusive to VHPIDIRECT/Cinterface. Those might be common to any co-simulation approach with GHDL.

Hence, it would be awesome if you wanted to contribute a PR with an initial version of section VPI, where you added a brief description of VPIInteropREPL, along with any other reference that you might consider relevant. I think that the point now is to have info gathered, rather than having very detailed explanations. In the long term, it'd be interesting to know whether VPIInteropREPL can be used with cocotb or MyHDL too, or if execution models are too different.

Refs:

@bellaz89
Copy link

Hi! :)
Sure, right now I don't have so much time to work on this (I have the SpinalHDL-GHDL cosim to finish and document and I also my 'real' work XD), however, I think it is a nice idea to share this kind of information.

Right now VPIInteropREPL is a bit out of date because I am continuing the development on SpinalHDL's ghdl branch. Once It is finished, that code can be used to update VPIInteropREPL. Since the wrapper interface is created using SWIG, it could be possible to add the support of several languages (Python/Octave/Ruby/Tcl.. etc for example).

@radonnachie
Copy link
Contributor

Very interested in expanding my knowledge to cover VPI, will be looking to make some time for an investigation once the current VHPI PRs are completed

@bellaz89
Copy link

Recent bugfixes/enhancements in the GHDL-VPI interface resulted in the addition of several VPI usage examples in GHDL testbenches directory:

  • gna/issue1226 shows how to simulate an arbitrary number of steps.
  • gna/issue1233 shows how to iterate through top entity nets.
  • gna/issue1256 shows how to read/write enums (but the approach can be used for others unstructured type signals)

These tests and in particular the last one, are a good starting point to develop VPI based co-simulation code and can be added to documentation as examples since they are quite simple to understand.

@umarcor
Copy link
Member Author

umarcor commented Apr 27, 2020

@bellaz89, actually, there are other several examples in the testsuite:

# grep -l -r ./testsuite/ -e "vpi-compile"
./testsuite/gna/issue1226/testsuite.sh
./testsuite/gna/issue1228/testsuite.sh
./testsuite/gna/issue1233/testsuite.sh
./testsuite/gna/issue1256/testsuite.sh
./testsuite/gna/issue450/testsuite.sh
./testsuite/gna/issue531/testsuite.sh
./testsuite/gna/issue98/testsuite.sh

By the same token:

# grep -l -r ./testsuite/ -e "VHPIDIRECT"
./testsuite/gna/bug021/sim_pkg.vhd
./testsuite/gna/bug026/xb.vhd
./testsuite/gna/bug092/t.vhdl
./testsuite/gna/bug092/t2.vhdl
./testsuite/gna/bug097/tb.vhdl
./testsuite/gna/issue1229/pkg.vhdl
./testsuite/gna/issue1252/pkg.vhdl
./testsuite/gna/issue152/ax_wb_pli_pkg.vhdl
./testsuite/gna/issue797/pkg_c.vhdl

@bellaz89
Copy link

bellaz89 commented Apr 28, 2020

Hi,

I know the existence of these examples and I used them as a reference to write the SpinalHDL-GHDL bindings. However, until now, there were no examples of how to ask GHDL to advance the simulation time through VPI. Believe me, it is very difficult to find a simple example on how to do that on the internet, and understand it from cocotb is quite a challenge. Therefore, since I wrote these three reproducers (1226,1233, 1256), and given that from what I understand the ghdl-cosim aim is to document/give example on GHDL foreign programming interface, I thought that It would be very helpful to point you to these three testbenches. I think that including them in the documentation could help many people to avoid wasting their time trying to understand how to advance the GHDL simulation time with VPI like I did :P.

BTW I think I will write some PR :)

Edit:
See pull request #19

@umarcor
Copy link
Member Author

umarcor commented Apr 30, 2020

@bellaz89, the point is that there are dozens of undocumented and independent examples about VHPIDIRECT and/or VPI. All the references in this issue contain one or multiple examples of different complexity. Some are simpler, others are frameworks, but almost each of them has features which are very difficult to find on the internet. Each of them is likely to be very useful for a subset of users.

The purpose of this repo is not only to gather references (to make them easier to find), but also to explain them (to make them easier to understand), and to have a fine-grained test suite (to find issues in different platforms/backends). For gathering only, this issue exists. On top of that, explaining implies thinking about a coherent and easy-going path that takes any new user from zero to the most complex examples. With "zero" I mean "no knowledge about co-simulation with GHDL". Users are expected to be familiar with, VHDL, GHDL, C and GCC.

how to ask GHDL to advance the simulation time through VPI.

I believe this is a very interesting example. Precisely, this is currently not possible/documented with VHPIDIRECT/Cinterface. Hence, it is one of the motivations to recommend using VPI instead.

However, ATM there is absolutely no documentation about VPI. Not a single line. Before introducing any of the examples you propose, I believe that at least one should exist about how to do nothing other than building and running a simulation with an VPI module. For instance, a very relevant difference compared to VHPIDIRECT is that VPI needs vpi_user.h. At the same time, according to your examples, VPI modules need to be built as a shared library; which is just one of the multiple possibilities with VHPIDIRECT. Since I want to learn about VPI too, I'm ok with helping/co-authoring the example(s) that are missing until yours fit. Nonetheless, I'd like to know if you are ok with looking at the VPI section as a whole, and not just adding independent examples.

See pull request #19

I will have a look!

@bellaz89
Copy link

bellaz89 commented Apr 30, 2020

@umarcor

@bellaz89, the point is that there are dozens of undocumented and independent examples about VHPIDIRECT and/or VPI. All the references in this issue contain one or multiple examples of different complexity. Some are simpler, others are frameworks, but almost each of them has features that are very difficult to find on the internet. Each of them is likely to be very useful for a subset of users.

Hi! Yes, sorry, I realize I was a bit unclear in my first message about why I think these references are valuable for me. That's why after thinking about that I opened a PR to explicitly give a set of examples that can be understood with basic programming/VHDL skills and that covers the most basic use of VPI one can do.

The purpose of this repo is not only to gather references (to make them easier to find), but also to explain them (to make them easier to understand), and to have a fine-grained test suite (to find issues in different platforms/backends). For gathering only, this issue exists. On top of that, explaining implies thinking about a coherent and easy-going path that takes any new user from zero to the most complex examples. With "zero" I mean "no knowledge about co-simulation with GHDL". Users are expected to be familiar with, VHDL, GHDL, C and GCC.

how to ask GHDL to advance the simulation time through VPI.

I believe this is a very interesting example. Precisely, this is currently not possible/documented with VHPIDIRECT/Cinterface. Hence, it is one of the motivations to recommend using VPI instead.

However, ATM there is absolutely no documentation about VPI. Not a single line. Before introducing any of the examples you propose, I believe that at least one should exist about how to do nothing other than building and running a simulation with an VPI module. For instance, a very relevant difference compared to VHPIDIRECT is that VPI needs vpi_user.h. At the same time, according to your examples, VPI modules need to be built as a shared library; which is just one of the multiple possibilities with VHPIDIRECT. Since I want to learn about VPI too, I'm ok with helping/co-authoring the example(s) that are missing until yours fit. Nonetheless, I'd like to know if you are ok with looking at the VPI section as a whole, and not just adding independent examples.

See pull request #19

I will have a look!

I fully agree that giving full and free documentation that covers many aspects/usage of VPI is something that would be very nice to have. However, this is going to take much more effort than giving a basic set of examples because VPI is a complex API with many details I am not aware of. So I think that this can be taken as a long term task that can be updated from time to time (also because my job doesn't allow me to spend a lot of time on hobby projects... so I can't give a 100% assurance that I will be able to follow it). Even if just giving an organized basic set of VPI examples couldn't be enough for complete newcomers, they may be still valuable for people that have knowledge above basic skills but find it hard to understand how to make VPI work in practice.

Thank you for reviewing my PR!

@umarcor
Copy link
Member Author

umarcor commented Apr 30, 2020

That's why after thinking about that I opened a PR to explicitly give a set of examples that can be understood with basic programming/VHDL skills and that covers the most basic use of VPI one can do.

In fact, as you saw after I reviewed your PR, I believe that the set of examples that you proposed is nice and more than enough. I'm not expecting/requesting any more than that. Let's just make a little effort for the "story" to be easier to understand/follow.

I fully agree that giving full and free documentation that covers many aspects/usage of VPI is something that would be very nice to have. However, this is going to take much more effort than giving a basic set of examples

This repo is not "a tutorial about VPI", but "a tutorial about using VPI with GHDL". Anything which is related to GHDL or VPI only does not belong in here. However, we need to acknowledge/reference it. For example:

VPI (and VHPI) are complex APIs. Compared to VHPIDIRECT, these provide advanced features, at the cost of having to learn/understand many more details. Since this is the user and reference manual for GHDL, it does not contain an introduction to VPI/VHPI. Thus, the reader should have at least a basic knowledge of them. A good knowledge of the reference manuals (usually called LRM) is a plus. Please read X, Y and Z if you are not familiar with VPI/VHPI yet.

The one-liner introduction to VPI is that C header vpi_user.h provides dozens of functions to scan/navigate the hierarchy of the elaborated hardware design, and it allows to set callbacks for specific events/signals. Hence, unlike VHPIDIRECT, when using VPI/VHPI, VHDL sources are agnostic to the existence of C sources.

VPI is a complex API with many details I am not aware of.

Writing the docs is an exercise for us to learn too. We need to point which details we are not sure about. We will either find the answer or add some note/warning acknowledging that we don't know it. Nonetheless, if questions arise while we write the examples, new users are likely to ask the same questions in the future.

So I think that this can be taken as a long term task that can be updated from time to time

I believe it is a mid-term task. If we open the door to adding examples with sources that are partially inconsistent, and we allow to contribute them without proper documentation, there is a serious risk that those will never be completed. It is ok to keep PRs open and to enhance them as spare time allows to. When they are merged, we need to assume that the content might not be updated in weeks, months or years.

Even if just giving an organized basic set of VPI examples couldn't be enough for complete newcomers, they may be still valuable for people that have knowledge above basic skills but find it hard to understand how to make VPI work in practice.

I think that people with skills slightly above the basic will have no issues with finding either this thread or the open PRs. They don't really need the docs. We can make it more explicit by adding some note either to the site or to the README:

This repository was created recently and multiple existing examples are not published yet. See issue #1 and the list of open Pull Requests for on-going work.

By the same token, we can add "Contributing guidelines", to suggest potential contributors different levels of commitment:

  • Add a reference to this issue.
  • Propose a PR with working or non-working examples, and with/without complete docs.
  • Propose a PR with working examples and complete docs matching the overall learning path.

@miree
Copy link

miree commented Aug 16, 2023

Hi,

I just found this repository and I would like to advertise my solution to VHDL/Verilog cosimulation using GHDL and Verilator.
It uses a code generator that generates glue-code to integrate Verilog modules (processed with Verialtor) with a GHDL simulation using VHPIDIRECT.

https://github.com/miree/gvi

I find it very convenient and it might be useful to others as well. Perhaps a link to this code generator (or even the code generator itself) could be integrated into this repository to make people aware of it.

@tgingold
Copy link
Member

tgingold commented Aug 16, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants