Repository navigation
feat(runtime)!: compiled time-slot loop for delay-only kernels - #1777
Conversation
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. |
bfc3576 to
d6926f3
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d6926f3016
ℹ️ 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".
| let reference = shadow.state.step_until(&mut shadow.simulator, limit); | ||
| let mut reference = shadow.state.step_until(&mut shadow.simulator, limit); | ||
| // A compiled run of several slots: the shadow runs them one by one. | ||
| if let Ok(Some(time)) = result { |
There was a problem hiding this comment.
Catch the shadow up when a compiled run errors
In DifferentialRuns, catch-up only occurs when the compiled result is Ok(Some(_)). If a multi-slot run succeeds for several slots and then encounters an error—such as a delay-only kernel reaching $fatal on a later wake—the primary is left at that later timestamp, while the shadow executes only its first slot. difference then reports an artificial scheduler divergence and masks the actual matching runtime error. Error results need to catch the shadow up to state.time() (or until it returns an error) as well.
Useful? React with 👍 / 👎.
Merge Queue Status
This pull request spent 1 hour 19 seconds in the queue, including 58 minutes 45 seconds running CI. ReasonThe merge conditions cannot be satisfied due to failing checks
Failing checks: HintYou may have to fix your CI before adding the pull request to the queue again. Waiting for
All conditions
Requeued — the merge queue status continues in this comment ↓. |
d6926f3 to
d564a16
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d564a16ca2
ℹ️ 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".
| let finish = matches!(&inst, SIRInstruction::RuntimeEvent { site_id, .. } | ||
| if self.finish_sites.contains(site_id)); | ||
| instructions.push(inst); |
There was a problem hiding this comment.
Keep finish detection consistent when the event ring wraps
When an inlined FF or combinational unit emits $finish and then produces more than the 1,024-record runtime-event capacity before returning (for example, $finish; repeat (1025) $display(...)), this instrumentation stores a durable finish flag, so compiled execution stops. The reference path calls take_runtime_finish() only after the whole unit and scans the bounded ring, where the finish record has already been overwritten, so it continues and differential mode reports a divergence. Make finish detection equally durable in the reference path, or otherwise preserve identical behavior across scheduler modes.
Useful? React with 👍 / 👎.
| let Ok(sim) = builder.build_interpreter() else { | ||
| continue; | ||
| }; |
There was a problem hiding this comment.
Fail coverage when a timed case cannot be built
If an interpreter build fails, the case is silently omitted from both the required-case check and the coverage denominator. In particular, a case listed in COMPILED_CASES can stop compiling and this test still leaves incomplete empty, so the assertion intended to guarantee that every kernel in those cases compiles can pass without examining the case at all. Treat build failures as test failures, or at least record required cases as incomplete.
Useful? React with 👍 / 👎.
Timed designs get hidden `$scheduler.*` variables on the top module: the limit, current time, exit code and argument, current kernel, start-of-slot levels, finish flag, settle continuation and slot count of a run, and a wake time and waiting flag per process kernel. RuntimeSchema::scheduler (and ScheduleModel::scheduler) carries them with the index of a generated scheduler unit and why each kernel falls back. State files leave the slots out; the native image carries the schema, accepts the extra process unit, and moves to format 29. BREAKING CHANGE: RuntimeSchema and ScheduleModel have a new field, `scheduler`. Native images use container format 29; images written by earlier versions must be rebuilt. Change-Id: Ia8fd6db4be840280b8e1b964521f291af2419c8e
A timed simulation now generates one SIR process unit that runs the time slots of kernels that only delay by constants: it takes the earliest wake time, publishes the time, runs the due kernels in kernel order, settles, runs the domain whose edge they gave (eval_apply) or several domains (eval_only each, then apply each) and settles again, exactly as the reference loop does for such a slot. It inlines the units the reference loop calls; nothing in the backends changes. SimulationState::run_until hands a stretch of slots to the unit when nothing else is pending (no waiting or ready process, no queued NBA, no host change, no scheduled event or other kernel's wakeup before it) and takes the wake times back. Any other slot, and every design or kernel that does not qualify, runs in the reference loop as before; the reasons are in scheduler_stats. A run that ends in the middle of a slot (a finish, a delay overflow, an error) leaves the reference's state: the kernel that ended it is filed nowhere, kernels due then that did not run are ready, and the slot's edge baseline is restored. Backends that run the unit slower than the loop (the interpreter, the tiered backend before it adopts generated code) keep the reference loop. SchedulerMode::Compiled is the default; SchedulerMode::DifferentialRuns checks multi-slot runs against the shadow. BREAKING CHANGE: SchedulerMode defaults to Compiled and has a new variant, DifferentialRuns; KernelSchedule::Reference holds a String. Change-Id: I33705e908c95b460326c670c2ab9c74a90c68449
In differential modes the suite harness reports, per case, whether it ran compiled slots and why none was checked. A test prints how the compiled scheduler runs the kernels of every timed case, requires the cases of generated clocks it targets to compile entirely and a floor on the compiled share. run_to_finish runs run_until stretches, so compiled slots also reach a finish. Change-Id: I6a7cd1e638c23aca36a5489606133b792aa66543
Variant d clocks the registers from always #5 clk = ~clk alone. A third argument selects the scheduler, a fourth the backend, and the run prints its stats. Change-Id: I62dc870c9cfec474addfd69220d5e04b27e49e99
d564a16 to
3885415
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3885415846
ℹ️ 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".
| }); | ||
| g.b.switch_to_block(unit); | ||
| for unit in &event.eval_apply { | ||
| g.inline(unit, finish_exit); |
There was a problem hiding this comment.
Defer finish exit until the entire domain has run
When an event domain contains multiple execution units, such as a parallel-partitioned clock domain, g.inline checks the finish flag after each unit and branches out immediately, so a $finish emitted by an earlier unit prevents the remaining units in that domain from executing. The reference path calls eval_apply_ff_at for the whole domain and checks runtime_finish() only after that call, so all units execute before termination; consequently, state written by later units can be missing only in compiled mode. Apply the finish check after the complete unit list for each domain invocation.
Useful? React with 👍 / 👎.
| self.sim.run_until(next.saturating_add(FINISH_STRETCH))?; | ||
| self.capture_events()?; |
There was a problem hiding this comment.
Drain runtime events before a finish stretch wraps the ring
When a timed case emits more than the 1,024-record runtime-event capacity during one FINISH_STRETCH window, this single run_until call overwrites the earliest records before capture_events() runs. The previous step-by-step loop drained after every event time, so cases that print or write frequently before $finish now fail with Missed or lose expected output solely because the harness batches up to 1,048,576 simulation units. Bound each batch by the event-buffer capacity or drain events at intermediate slot boundaries.
Useful? React with 👍 / 👎.
Merge Queue Status
This pull request spent 1 hour 17 minutes 37 seconds in the queue, including 1 hour 16 minutes 2 seconds running CI. Required conditions to merge
|
Part of #1123, step 3b-1 (compiled scheduler), PR 3 of 7. Builds on #1756.
A timed simulation now generates one SIR process unit, the compiled scheduler, that runs the time slots of kernels that only delay by constants (
always #5 clk = ~clk,initial begin #10 rst = 0; ... end). For a design whose slots it can take, the per-cycle cost drops from the Rust loop's bookkeeping to about the JIT work: the new bench case (d) goes from 7,443 to 883 Ir per cycle.A slot that touches a fallback kernel runs entirely in the Rust reference loop, exactly as before, so nothing is slower than today. The fallback is per kernel and per slot, never per design: a kernel that does not qualify only keeps its own slots (and, while it waits for an event, the slots in between) in the reference loop.
BREAKING CHANGE
RuntimeSchemaandScheduleModel(exhaustive public structs) have a new field,scheduler.SchedulerMode(#[doc(hidden)]) defaults toCompiledand has a new variant,DifferentialRuns;KernelSchedule::Referenceholds aString.What a compiled slot does
For a slot at time t > 0, in a qualified design, the reference loop (
run_time→step_round→continue_round) does exactly this, and so does the unit:BTreeSet::pop_firstorder); a kernel'sFinishends the slot at once, a delay sets its next wake time (overflow is the reference's error),Doneends it. An event signal the kernel moves to its active level is an edge (round.previousis the level before that run);settle_passruns once even without edges);eval_applyunit; several:eval_onlyof each, thenapplyof each, in event-id order; then settle again. No edge: nothing more (no extra settle).publish_nbais a no-op in these slots (compiled kernels have no nonblocking sites, and no other kernel ran). A$finishrecord emitted by any inlined unit ends the run after that unit, asruntime_finishdoes after each unit call.A run that ends in the middle of a slot (a kernel's or a unit's
$finish, a delay overflow, a unit error) leaves exactly the reference's state: the unit records the kernel it is running and the levels the slot started from, and the hand-back files the kernel that ended the slot nowhere, puts the kernels due then that had not run intoready, and restores the slot's edge baseline. Tests runrun_untilacross a compiled$finishin every mode and compare the state file with the reference's. Wake times carry a separatewaitingflag, so a kernel may wake atu64::MAX.Runtime events do not end a run. The reference loop does not drain the 1,024-record ring buffer between slots either; a long run overwrites old records and reports
Missedalike in both loops. The one boundary that reads the buffer, the heap safepoint, collects only in designs with handle slots, and those run one slot per run.The unit loops over slots up to a limit: the earliest wake time is a min-scan over the compiled kernels' wake slots. It inlines the same
SirProgramunits the reference loop calls (each kernel, each written event's domain units, and comb once, shared by both settles through a continuation slot), so FF, comb and kernel codegen are untouched. Only events a compiled kernel writes get dispatch code; the several-domain path exists only with two or more such events.Carrier and state
SirProgram::processesafter the kernels and referenced byRuntimeSchema::scheduler.unit; every backend compiles and enters it throughrun_process. It is generated after layout and dead-store elimination, from the final units, and only for timed (Simulation) builds whose mode is notReference. The optimizer's and layout's FF-address scans never see it.$scheduler.*variables on the top module (limit, now, exit code, current kernel, start-of-slot levels, finish flag, settle continuation, slot count, a wake time and waiting flag per kernel), declared at assembly like the kernels'$process[i]control slots. Between runs they hold nothing; state files leave them out.Qualification (structural only)
Design (else no unit): two-state; no counted signals; no cascaded, state-derived or combinationally derived clocks; no combinational observers or fatal assertions in comb; at most 64 events, each a clock or reset edge with its own canonical domain and its own
eval_apply/eval_only/applyunits; no comb or FF unit stores to an event signal's storage.Kernel (else it falls back): not a declaration initializer or edge procedure;
ProcessSlots::const_delays(from #1756); no wait, nonblocking or host-request sites; every status it stores is a constantDelay,InactiveDelay,DoneorFinish. It also falls back if it drives a clock whose domain commits its blocking results in the active region (RuntimeSchema::active_commits): since #1783 the reference evaluates such a domain before the NBA region whenever it triggers, a path the compiled slot does not take.At run time (
SimulationState::compiled_limit) a run starts only when no process waits or is ready, no NBA is queued, no host change awaits a settle, nothing is suspended or finished, and the next compiled wakeup comes before every scheduled event and every other kernel's wakeup. The limit is the end of therun_untilor the next such Rust-owned work. The executor decides the run length (HostBoundary::compiled_slots): any number of slots, one per run when VCD records or the heap collects at slot boundaries, none with external components or on a backend that runs the unit slower than the loop (SimBackend::runs_compiled_scheduler: the interpreter, and the tiered backend until it adopts generated code; see Perf).Handoff: wake times move from
process_wakeupsinto the wake slots and back; after a normal end the edge baselines are resampled (the reference resamples at every slot end) and the slot boundary hook runs. Finish, delay overflow and unit errors take the same paths asstep_until.Coverage and fallback stats
compiled_scheduler_coverageprints, for every timed SV suite case, how many kernels compile and why the others fall back. It asserts only invariants, so new suite cases do not touch it: six named cases (delay-generated clocks with their domains, an asynchronous reset, two clocks sharing an edge, host writes between runs, two finishes) must compile entirely, and at least 30% of all kernels must compile. In differential modes the suite harness also requires every timed case to check its steps against the shadow or to report why not. At the time of writing, 126 of 296 kernels compile across the timed cases. Fallback reasons, by kernel:#0, variable, real)In the differential SV suite, 194 case-backend runs execute compiled slots (the suite's
run_to_finishrunsrun_untilstretches, so compiled slots also reach$finish); the others keep a waiting kernel or fall back. The bench's (b1)/(b5) show the same: the clock kernel compiles, thestimkernel waits forposedge clk, so every slot stays in the reference loop until PR 4.Perf
Callgrind, whole program, Ir per cycle = (Ir at 200,000 cycles − Ir at 20,000) / 180,000, median of 5. Base: master 3766461 (with #1783 and #1776, whose one-period tick raises (a) on both sides); base and branch both built with this PR's
sched_bench.rs.Simulator::tickSimulation+add_clockalways #5 clk = ~clk+ RTL, reference → compiledwaiters.is_empty()test per step before the compiled-run check, which their waitingstimkernel fails; a first version called the full check every step and cost +87.stimkernel waits; PR 4 (clock-waiting kernels) is what makes it run.host-runtime(the wasm32 NAPI package) generate no scheduler unit and run every slot in the reference loop. The wasm backend of native builds runs the unit, and the SV suite's wasm variants check it in both differential modes.SimBackend::runs_compiled_scheduler).Validation
cargo test -p celox --features systemverilog --test systemverilog, all groups, native/cranelift/parallel/wasm): 4,222 passed, 20 ignored, on master 3766461 (with fix(sv): run waiters of blocking edge writes before the NBA region #1783 and feat(sim)!: make a tick one clock period and run every clock generator #1776), in each ofCELOX_SCHEDULER=differential(every compiled slot checked against the reference shadow) and the default (compiled). Unchecked runs reported: 25 "keeps host state outside its memory image" (file I/O), 10 "took no scheduler step".CELOX_SCHEDULER=differential-runs ... timing::: 560 passed (multi-slot compiled runs, the shadow catching up slot by slot).--lib: 188 passed, including the compiled-scheduler tests: delay-only kernels in every mode, a kernel without event writes, free-running runs being multi-slot, a domain with two$finishsites,run_untilacross a kernel's$finishin both kernel orders with the state file compared to the reference, and a wake atu64::MAX.celox-runtime,celox-design,celox-frontend-core,celox-sir,celox-heap,celox-vpi: all passed;celox-napibuilds, natively and forwasm32-wasip1-threads(napi build --platform --target wasm32-wasip1-threads, WASI SDK 25, as the NAPI WASM job).-D warnings(tests, examples) andcargo fmt --check: clean.Follow-ups (not in this PR)
add_clockdesigns (PR 7).DomainKind::Otherevents; constant real delays; nonblocking assignments in delay-only kernels; whether the interpreter and the tiered backend's interpreted tier should run the unit (not measured here).