Repository navigation
feat(vpi): run SV processes in cocotb images - #1938
Conversation
3607eb1 to
7302c93
Compare
NativeProgramImage::signal_identity, signal_aliases, force_slots and has_processes answer from the image what NativeProgramInstance kept to itself, so that a host of a timed Simulation of the image can address and force its signals the same way. Simulation::peek_four_state reads stored state without a settle, and set_observed_signals replaces the signals a slot observer watches. Change-Id: Ice5f5f4d43c2630b20c59540f41548a631556212
celox vpi build compiles a SystemVerilog design with processes into a timed Simulation image instead of rejecting it, and the executable runs the processes in step with cocotb. Its VPI host drives the simulation through a slot observer: timers and NextTimeStep open a time step, value changes of clocks run before the domains commit, value changes of other signals, ReadWrite and ReadOnly run when the step has settled. A cocotb write is a blocking host write at the current time; the simulation schedules its edges. Designs without processes keep the untimed program instance. Closes #1730 Change-Id: If5f8d9ac914c6dd5b83a1ddd86990dadff1e5f8c
The external-suite job (sv, icarus) runs icarus_and_celox_agree_on_dut_processes, which compares a cocotb test module's traces on Celox and on Icarus, with the locked tool versions of nix develop. Change-Id: I026ef342f35c2dd778aea6e85778642db92bdd21
7302c93 to
30a5fe9
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
A timed run counts the rounds it spends at one time, the settles of callback writes, ReadWrite passes and due timers alike, and fails with "simulation does not advance at time T" after a million. VPI writes during ReadOnly callbacks are rejected (IEEE 1800-2023 38.36.2), and a zero-delay timer registered there runs read-only without opening the time step's regions again. The cocotb guide describes the value-change timing the host has: at each boundary of a time step, after the settle of the wave that made the change and before the processes it wakes. It notes that pulses within one wave are not reported, that reads outside a step see stored values, and that only celox vpi build supports designs with processes (#1983). Change-Id: Ib964d9258f4e3844cff344d5f2c88f5c716e758b
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b0f16d7810
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… before its slot Timers due at the current time, including the zero-delay ones a timer or ReadWrite callback registers, now run in a loop until none is due, both before the step's slot and before its ReadOnly region; the same-time bound covers the loop. A vpiFinish from a due timer ends the run before the design's slot at that time runs, as in the untimed host. Change-Id: I8b52b5e212d440fe19398a4458d256fdb7fc6ceb
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5303cbaa21
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| && with_host(|host| borrow_cell(&host.callbacks, |state| state.read_only_at)) | ||
| != Some(time) | ||
| { | ||
| with_simulation(|simulation| simulation.eval_comb()); |
There was a problem hiding this comment.
Run the fallback settle outside the runtime borrow
When a timer changes a plain data input while the DUT's remaining processes are waiting on delays, run_until(time) can run no slot, reaching this fallback. with_simulation holds a mutable borrow of host.runtime throughout eval_comb(). If that evaluation executes $finish or encounters a runtime error, Simulation::sync_finish_checked or flush_error_output invokes the slot observer, whose in_slot() tries to borrow the same runtime again. This causes a RefCell panic instead of clean termination or a reported simulation error. Execute this settle through timed_step, which removes the simulation from the borrowed runtime and handles its result and runtime events.
Useful? React with 👍 / 👎.
| fn before_domains(&mut self, io: &mut celox::SlotIo<'_, celox::NativeBackend>, time: u64) { | ||
| in_slot(io, time, || { | ||
| dispatch_value_changes(); | ||
| }); |
There was a problem hiding this comment.
Propagate observer finish requests into the running simulation
If a clock value-change callback calls vpi_control(VPI_FINISH), this observer returns normally after setting only the VPI host's finish flag. The running scheduler does not inspect that flag: continue_round in crates/celox-runtime/src/simulation/round.rs proceeds from before_domains() to evaluating and committing the triggered domains. Consequently, an always_ff assertion on that edge can still execute $fatal, turning a requested successful finish into an error. This is a separate path from the corrected timer-finish guard: the simulation is already running when the callback requests termination. Propagate a termination signal from the observer so the current step stops before executing the remaining DUT work.
Useful? React with 👍 / 👎.
Propagate vpiFinish from slot observers through SlotIo::request_finish and Halt::Finish, stopping the running scheduler before its pending domains execute. IEEE 1800-2023 38.4 executes $finish on return from the application routine; 20.2 ends the simulation. Preserve writes already made by the observer. Run the fallback combinational settle through timed_step so the Simulation is out of the runtime borrow during observer dispatch, and its result and events are handled through the same path as scheduled steps. Use VERIFY_SHELL for the CI Icarus comparison, matching the external job's explicit development shell selection and its workflow regression contract. Validation: - Strengthened finish regression fails before the fix (count 1 instead of 0). - VPI suite with all ignored tests enabled: 158 passed, including cocotb and Icarus process-region comparisons. - Host library, native image and slot observer regressions: 236 passed; observer finish covered Native, Interpreter, Cranelift and Wasm. - Repository script suite: 296 passed. - Celox and celox-vpi all-target clippy, formatting and diff checks passed. Change-Id: Iac1ad02c9fa9f3f543f47663f23080e4b1204716
…ackends Retain Native and Interpreter coverage for compiled and reference execution without requiring the optional Cranelift and Wasm builder methods introduced on current master. All four backends were verified during local validation; both retained observer finish regressions pass. Change-Id: Ifefe2684679445782a2f28d1b4d38f596caaca91
Merge Queue Status
This pull request spent 31 minutes 41 seconds in the queue, including 26 minutes 23 seconds running CI. Required conditions to merge
|
Closes #1730. PR 3 of 3, on top of #1926 (PR 1) and #1934 (PR 2), which have both merged.
Change
celox vpi buildinitialwith delays or system tasks,alwayswith delays or event controls,always #5 clk = ~clk, …) now compiles into a timedSimulationimage. Before, fix(sim)!: reject designs with processes in untimed Simulator builds #1720 rejected it withProcessRequiresSimulation.Simulation::from_sv_sources(..).compile_native()(PR 1), using the same options.NativeProgramInstancehost. Moving them to the Simulation host is perf(vpi): run process-free images on the Simulation host #1922.VPI host (
crates/celox-vpi)state.rs: aVpiStatetrait gives the entry points one view of the state.NativeProgramInstanceimplements it as before. The host still schedules its edge batches itself.TimedRuntime(aSimulation<NativeBackend>plus its image) implements it too. While a step runs, the simulation is out of the session, and VPI calls from callbacks reach the state through theSlotIoof PR 2's slot observer.callbacks::run_timedmerges the two time axes. Each step goes to T = min(nextcbAfterDelay,next_event_time()):advance_to(T)(PR 1), thencbNextSimTime, then the duecbAfterDelaycallbacks;run_until(T), with the slot observer:before_domainsdispatches every changedcbValueChangeat each wave boundary: after a round's processes (before its flip-flops commit), and after each wave's nonblocking updates and settle. So the edge of a clock (cocotb's or the design's) is seen before its flip-flops commit, and a change is seen before the processes it wakes run;end_of_slotruns the remaining value changes, thencbReadWriteSynchuntil the callbacks write nothing (writes settle again at T), thencbReadOnlySynch, during which writes are rejected (IEEE 1800-2023 38.36.2). A zero-delay timer registered in ReadOnly runs read-only without opening T's regions again.Simulation::modify, orSlotIoinside a slot); the simulation schedules their edges. Force and release use the image's compiler-inserted force slots (NativeProgramImage::force_slots). The untimed instance's legacy force support isn't available in a timed image.$display/$write/assertions go out after each step. The design's$finishends the run, and so does$stop(no interactive mode; pausing is Host writes during a $stop-suspended time step are lost at the edge process's NBA commit #1886, linked in the docs).driver::run_cocotb_imagepicks the host fromimage.has_processes().celox (small, for the host)
NativeProgramImage::signal_identity,signal_aliases,force_slotsandhas_processes; the instance now delegates to them.NativeProgramInstance::program_image.Simulation::peek_four_state(a read without a settle).Simulation::set_observed_signals.Docs:
docs/guide/cocotb.md(en/ja) replace the "runs no HDL process" paragraph with a "Designs with processes" section:celox vpi buildsupports these designs;celox-vpi-compile/celox-vpi-runtimestill reject them (feat(vpi): run SV processes with celox-vpi-compile and celox-vpi-runtime #1983);$stopends the run (Host writes during a $stop-suspended time step are lost at the edge process's NBA commit #1886).Tests
processes.sv+test_processes.py:RisingEdgebefore itsalways_ffupdate;@(posedge go) #3process woken by a cocotb write;Clockdriving a DUTalways @(posedge tick) #1 …process;$displaywith%0tfrom aninitial #12;data_changes_are_seen_settled: the end-of-slot order, asserted on Celox and logged elsewhere.cocotb_runs_dut_processes_in_stepruns the fixture in CI's cocotb job (cocotb_ -- --ignored).icarus_and_celox_agree_on_dut_processes(ignored in normal runs, needs cocotb and Icarus Verilog): runs the same test module through cocotb's Icarus runner (run_icarus.py) and on Celox, and compares everyTRACEline. They are identical. Locally,settled at value changeisTrueon Celox andFalseon Icarus, the documented difference. CI runs it in the external-suite job (sv,icarus; schedule, manual and release runs) throughnix developwith the locked cocotb and Icarus versions. I verified that exact command locally.changes_are_seen_before_their_waiters_run(intest_processes, part of the Icarus comparison):Edge(count)seesmirrorone behind,ReadOnlysees it caught up, on both simulators.cocotb_forces_and_releases_a_register_of_a_timed_design(--force-signal Top.x): a forcedalways_ffregister holds across edges, and is released between edges keeping its value until the next edge. It also passes unchanged on Icarus.cocotb_ends_at_the_designs_finish: the design's$finishat 30 ends the cocotb run (expect_error=SimFailure). Its$displayis asserted and a later$displaynever appears.cocotb_runs_dut_processes_in_stepnow asserts the%0toutput (at 12000 count=1).basic_vpi:a_finish_inside_a_time_step_ends_a_timed_run:vpiFinishfrom a value-change callback at 5 ends the run there, and end-of-simulation callbacks run. This isn't a cocotb fixture because cocotb'sstop_simulator()writes no results, on Icarus as well;a_timed_time_step_that_never_ends_fails_the_run: a ReadWrite callback re-registering itself forever, with and without a write, hits the bound at time 0;a_timed_read_only_region_rejects_writes_and_stays_closed.basic_vpi::a_timed_runtime_runs_the_dut_processes_between_callbacks: in-process, a value-change callback on the DUT'salways #5clock seescountbefore each update ((5, 0), (15, 1)), and the DUT's$finishat 23 ends the run.diagnostics.rsandproject_cli.rsare reverted to the real sources. The image checks there now load the attached image as aSimulation.Validation
cargo nextest run -p celox-vpi --features systemverilog --run-ignored allwithCELOX_COCOTB_PYTHON(cocotb 2.0.1, Icarus 13.0): 153 passed on master feba1a5, including all cocotb e2e tests and the Icarus comparison.cargo nextest run -p celox --features celox/systemverilog,celox-test-suite/runtime-cases --lib --test native_simulation_image --test slot_observer: 234 passed.node scripts/run-vtest.mjs --test systemverilog: 4974 passed.cargo check -p celox -p celox-bench --no-default-features --features arm64-codegenwith-D warnings(the cross-codegen case): clean.cargo clippy -p celox -p celox-vpi -p celox-napi --all-targets -- -D warningsandcargo fmt --check: clean.