amaranth icon indicating copy to clipboard operation
amaranth copied to clipboard

sim: Add Observer

Open alanvgreen opened this issue 4 years ago • 1 comments

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 https://github.com/nmigen/nmigen/issues/327. It is not intended to be submitted as-is.

alanvgreen avatar Aug 20 '21 22:08 alanvgreen

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%) :arrow_down:
nmigen/sim/core.py 78.50% <57.14%> (-3.42%) :arrow_down:
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.

codecov[bot] avatar Aug 20 '21 22:08 codecov[bot]

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.

whitequark avatar Feb 03 '23 03:02 whitequark