Skip to content

feat(vpi): run SV processes in cocotb images - #1938

Merged
mergify[bot] merged 7 commits into
masterfrom
feat/vpi-sv-processes
Oct 26, 2026
Merged

mergify[bot] merged 7 commits into
masterfrom
feat/vpi-sv-processes

Conversation

@tignear

@tignear tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1730. PR 3 of 3, on top of #1926 (PR 1) and #1934 (PR 2), which have both merged.

Change

celox vpi build

VPI host (crates/celox-vpi)

  • state.rs: a VpiState trait gives the entry points one view of the state.
    • NativeProgramInstance implements it as before. The host still schedules its edge batches itself.
    • TimedRuntime (a Simulation<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 the SlotIo of PR 2's slot observer.
  • callbacks::run_timed merges the two time axes. Each step goes to T = min(next cbAfterDelay, next_event_time()):
    1. advance_to(T) (PR 1), then cbNextSimTime, then the due cbAfterDelay callbacks;
    2. run_until(T), with the slot observer:
      • before_domains dispatches every changed cbValueChange at 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_slot runs the remaining value changes, then cbReadWriteSynch until the callbacks write nothing (writes settle again at T), then cbReadOnlySynch, 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.
      • One bound covers every round at T (re-runs, ReadWrite passes, timers): after a million, the run fails with "simulation does not advance at time T".
    3. When no slot ran at T (only callbacks wrote), the same regions run outside a step. Signals with value-change callbacks are the observed signals, so only the kernels that drive them leave compiled slots (PR 2).
  • Writes are blocking host writes at the current time (Simulation::modify, or SlotIo inside 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 $finish ends 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_image picks the host from image.has_processes().

celox (small, for the host)

  • NativeProgramImage::signal_identity, signal_aliases, force_slots and has_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:

Tests

  • New cocotb fixture processes.sv + test_processes.py:
    • a design-generated clock seen by RisingEdge before its always_ff update;
    • a DUT @(posedge go) #3 process woken by a cocotb write;
    • a cocotb Clock driving a DUT always @(posedge tick) #1 … process;
    • $display with %0t from an initial #12;
    • data_changes_are_seen_settled: the end-of-slot order, asserted on Celox and logged elsewhere.
  • cocotb_runs_dut_processes_in_step runs 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 every TRACE line. They are identical. Locally, settled at value change is True on Celox and False on Icarus, the documented difference. CI runs it in the external-suite job (sv, icarus; schedule, manual and release runs) through nix develop with the locked cocotb and Icarus versions. I verified that exact command locally.
  • changes_are_seen_before_their_waiters_run (in test_processes, part of the Icarus comparison): Edge(count) sees mirror one behind, ReadOnly sees it caught up, on both simulators.
  • cocotb_forces_and_releases_a_register_of_a_timed_design (--force-signal Top.x): a forced always_ff register 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 $finish at 30 ends the cocotb run (expect_error=SimFailure). Its $display is asserted and a later $display never appears.
  • cocotb_runs_dut_processes_in_step now asserts the %0t output (at 12000 count=1).
  • basic_vpi:
    • a_finish_inside_a_time_step_ends_a_timed_run: vpiFinish from a value-change callback at 5 ends the run there, and end-of-simulation callbacks run. This isn't a cocotb fixture because cocotb's stop_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's always #5 clock sees count before each update ((5, 0), (15, 1)), and the DUT's $finish at 23 ends the run.
  • The fix(sim)!: reject designs with processes in untimed Simulator builds #1720 workarounds ("A VPI image runs no process") in diagnostics.rs and project_cli.rs are reverted to the real sources. The image checks there now load the attached image as a Simulation.

Validation

  • cargo nextest run -p celox-vpi --features systemverilog --run-ignored all with CELOX_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-codegen with -D warnings (the cross-codegen case): clean.
  • cargo clippy -p celox -p celox-vpi -p celox-napi --all-targets -- -D warnings and cargo fmt --check: clean.

@tignear
tignear force-pushed the feat/vpi-sv-processes branch from 3607eb1 to 7302c93 Compare October 25, 2026 04:28
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
@tignear
tignear force-pushed the feat/vpi-sv-processes branch from 7302c93 to 30a5fe9 Compare October 25, 2026 09:47
@tignear
tignear marked this pull request as ready for review October 25, 2026 09:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T05:53:51.102302Z 5627729 New commits
ℹ️ 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" or "@codex security review".

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread crates/celox-vpi/src/callbacks.rs Resolved
Comment thread crates/celox-vpi/src/callbacks.rs Resolved
… 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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread crates/celox-vpi/src/callbacks.rs Outdated
&& with_host(|host| borrow_cell(&host.callbacks, |state| state.read_only_at))
!= Some(time)
{
with_simulation(|simulation| simulation.eval_comb());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +557 to +560
fn before_domains(&mut self, io: &mut celox::SlotIo<'_, celox::NativeBackend>, time: u64) {
in_slot(io, time, || {
dispatch_value_changes();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 26, 2026
…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
@mergify mergify Bot added the queued Mergify queue entry label Oct 26, 2026
@mergify

mergify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

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
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify
mergify Bot merged commit 2a76ded into master Oct 26, 2026
23 checks passed
@mergify
mergify Bot deleted the feat/vpi-sv-processes branch October 26, 2026 07:03
@mergify mergify Bot removed the queued Mergify queue entry label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(vpi): run SV processes in cocotb images

1 participant