Skip to content

feat(sim): build a timed Simulation from a native image - #1926

Merged
mergify[bot] merged 4 commits into
masterfrom
feat/sim-native-simulation-image
Oct 25, 2026
Merged

mergify[bot] merged 4 commits into
masterfrom
feat/sim-native-simulation-image

Conversation

@tignear

@tignear tignear commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Part of #1730 (PR 1 of 3; the plan is in the issue thread with the coordinator). This PR changes no VPI behaviour. It adds what the cocotb host will build on: a timed Simulation that runs from a native image.

Change

  • SimulatorBuilder<Simulation>::compile_native() returns a NativeCompilation<Simulation>. NativeCompilation now has a target parameter that defaults to Simulator, so existing code is unchanged. The image is compiled with the trigger stores and the compiled scheduler unit, and carries the process kernels. NativeCompilation<Simulation>::initialize() starts a timed simulation of it in-process.
  • SimulatorBuilder<Simulation>::build_native_from_image(image) starts a timed simulation of an image without code generation. It mirrors Simulator's method of the same name: the runtime metadata comes from the image, and the builder supplies only runtime options (scheduler mode, DPI symbols, plusargs, VCD).
    • In Differential mode it loads a second copy of the image as the reference-loop shadow. The scheduler unit is simply unused there.
    • The shadow set-up is factored out of build_with_backend into start_shadow, which both paths use.
  • Simulation::advance_to(time) runs every slot before time, then moves time to time without running that slot. Host writes made next join the slot, ahead of the processes that resume in it. The VPI host needs this to fire cbAfterDelay/cbNextSimTime at the start of a slot: run_until(T) would already have run slot T.
  • NativeProgramInstance::from_image now fails to attach an image with process kernels. It reports the existing Attach error with ProcessRequiresSimulation, the same check every Simulator loader already makes (Simulator silently ignores process kernels #1712).

Image format

No change. The container stays at v34, so this is not a breaking change:

  • A Simulation build differs from a Simulator build only by the compiled scheduler unit (scheduler::attach), which the image already serializes (process_offsets, runtime_schema.scheduler).
  • The native codegen emits trigger stores whenever the SIR has them.
  • An image with process kernels can only come from a Simulation build, and every untimed loader rejects it.

A process-free image from Simulator::compile_native also loads as a Simulation. It runs every time slot in the reference loop, never in compiled slots, because it has no scheduler unit. The test checks that its state file after add_clock and run_until(97) equals a fresh Simulation build's (compiled_slots == 0).

Tests

  • New crates/celox/tests/native_simulation_image.rs:
    • a design with always #5, always_ff, delays, @(posedge) and $display. It runs from container bytes, matching the in-process build_native events and outputs, with compiled slots taken; initialize() gives the same result;
    • differential mode loaded from an image, with checked steps;
    • a Simulator image as a Simulation (state file equality, reference loop);
    • process images rejected by Simulator::build_native_from_image and NativeProgramInstance::from_image;
    • advance_to: stops before the slot, a host write at that time is seen by the process resuming there, and an earlier target is a no-op.
  • The timing suite gets a native_image backend: compile, encode, decode, load and run every timed case. All 124 pass, with the default scheduler and with CELOX_SCHEDULER=differential.

Validation

  • node scripts/run-vtest.mjs --test systemverilog: 4666 passed.
  • cargo nextest run -p celox --lib --features celox/systemverilog,...: 214 passed.
  • cargo nextest run -p celox-vpi --features systemverilog: 140 passed.
  • cargo nextest run -p celox --test native_simulation_image: 5 passed.
  • cargo clippy -p celox -p celox-vpi --all-targets -- -D warnings and cargo fmt --check: clean.
  • Not run: the #[ignore] cocotb e2e tests. The VPI host is unchanged for every image vpi build can produce today.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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 ⚠️ Failed 2026-10-25T04:19:30.167446Z
We couldn’t complete this review. Comment @codex review to try again.
5835d61 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.

@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: f22d0d6706

ℹ️ 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/src/simulator/builder.rs Resolved
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 24, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 24, 2026
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 2 hours 15 minutes 56 seconds in the queue, including 1 hour 29 minutes 6 seconds running CI.

Reason

The merge conditions cannot be satisfied due to failing checks

  • Queue validation
  • Rust Test & NAPI Build

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for
  • check-success = Queue validation
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
    • check-success = @github-actions/Rust Test & NAPI Build
All conditions
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
    • check-success = @github-actions/Rust Test & NAPI Build
  • check-success = Conventional Commit title
  • 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/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

Requeued — the merge queue status continues in this comment ↓.

Simulation's builder gets compile_native, which returns a
NativeCompilation<Simulation> whose image carries the process kernels
and the compiled scheduler, and build_native_from_image, which starts a
timed simulation of such an image without code generation. A
differential simulation loads a second copy of the image for its
reference-loop shadow. Simulation::advance_to runs the slots before a
time and stops there, so a host can act at the start of that slot.

NativeProgramInstance now fails to attach an image with process kernels,
as every Simulator loader already does.

Part of #1730

Change-Id: I94db5d6a6ee51fd7059303f78a0c7b8cadd9312c
build_native_from_image and NativeCompilation<Simulation>::initialize
now make the packed-array check of the untimed native loader, through
one shared validate_native_vcd_layout: an image compiled without VCD
cannot record element-strided unpacked arrays.

Change-Id: I4d968bb5136d9fe772ec0afedb8f648161900f3a
A cross-compiling build, such as x86-64 code generation on AArch64,
cannot execute an image: start_native_image is now a separate stub
there instead of an early return, so no binding of the real loader is
left unused.

Change-Id: Ief37d80cf28c9ee09417a864934ff01b9e6617df
Program-rejection cases of the timing group are untimed designs: their
native-image backend round-trips a Simulator image, with the same
language-rejection classification as the other untimed backends.

Change-Id: Ie295e8c565eba3dc382ba8b5624f7ebb75aa513f
@tignear
tignear force-pushed the feat/sim-native-simulation-image branch from 7e97e2e to 5835d61 Compare October 25, 2026 04:19
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@mergify mergify Bot removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 25, 2026
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 25, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 52 minutes 16 seconds in the queue, including 25 minutes 45 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 17dedea into master Oct 25, 2026
23 checks passed
@mergify
mergify Bot deleted the feat/sim-native-simulation-image branch October 25, 2026 05:54
@mergify mergify Bot removed the queued Mergify queue entry label Oct 25, 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.

1 participant