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

sim: Add Observer #628

Closed
wants to merge 2 commits into from
Closed

sim: Add Observer #628

wants to merge 2 commits into from

Conversation

alanvgreen
Copy link
Contributor

Adds an Observer interface to the simulator, allowing arbitrary code
to receive values from the simulation.

The implementation is based on the implementation of write_vcd. An
obvious next step would be to make _VCDWriter a subclass of Observer,
then

  • rewrite Simulator.write_vcd() as a call to Simulator.oberve()
  • remove PySimEngine._vcd_writers and associated code.

This commit is an RFC for #327.
It is not intended to be submitted as-is.

Adds an Observer interface to the simulator, allowing arbitrary code
to receive values from the simulation.

The implementation is based on the implementation of write_vcd. An
obvious next step would be to make _VCDWriter a subclass of Observer,
then
- rewrite Simulator.write_vcd() as a call to Simulator.oberve()
- remove PySimEngine._vcd_writers and associated code.

This commit is an RFC for amaranth-lang#327.
It is not intended to be submitted as-is.
@codecov
Copy link

codecov bot commented Aug 20, 2021

Codecov Report

Merging #628 (f668853) into master (e974a31) will decrease coverage by 0.21%.
The diff coverage is 40.62%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #628      +/-   ##
==========================================
- Coverage   81.46%   81.25%   -0.22%     
==========================================
  Files          49       49              
  Lines        6446     6475      +29     
  Branches     1287     1291       +4     
==========================================
+ Hits         5251     5261      +10     
- Misses       1008     1025      +17     
- Partials      187      189       +2     
Impacted Files Coverage Δ
nmigen/sim/pysim.py 86.46% <23.52%> (-4.34%) ⬇️
nmigen/sim/core.py 78.50% <57.14%> (-3.42%) ⬇️
nmigen/sim/__init__.py 100.00% <100.00%> (ø)
nmigen/build/run.py 22.05% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e974a31...f668853. Read the comment docs.

Adds an 'observe' action to cli.py, to go along with generate and
simulate.

This is not intended to be merged. Its purpose is to illustrate the
Observer proposed in the previous change,

Example use:

$ python examples/basic/ctr.py observe -c 3
Simluation begins at 0.0
   0.0
             o:          1
   0.5
             o:          0
             v:          0
           clk:          1
   1.0
           clk:          0
   1.5
             v:          1
           clk:          1
   2.0
           clk:          0
   2.5
             v:          2
           clk:          1
Simluation ends at 3.0
@whitequark
Copy link
Member

I think this interface isn't appropriate for larger designs (especially ones too large to simulate with the Python simulator and which require CXXRTL). Since a Python function is called for every single value change, it is inevitable that (in cases other than full design waveform capture) most of the calls will be for naught, and a new, more efficient interface would be added later. Even in the case of waveform capture, it's pretty common for full design VCD files to end up being too large, with only a subset being captured.

As such I'm closing this PR. Any implementation improving on it needs to be able to observe only a subset of value changes.

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

Successfully merging this pull request may close these issues.

None yet

2 participants