Repository navigation
refactor(runtime)!: run timed slots from SimulationState with a differential scheduler harness - #1756
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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
17af9f5 to
2ba0d0a
Compare
|
Queued — the merge queue status continues in this comment ↓. |
… times ProcessKernelBuilder takes the delay amount's value when the frontend knows it and records in ProcessSlots::const_delays whether every delay of the kernel is a constant of at least one time unit. The SV frontend records integral constants; the SIR it emits is unchanged. The slots are part of the native image, so its container version moves to 28. BREAKING CHANGE: ProcessSlots has a new field, `const_delays`, and ProcessKernelBuilder::delay and inactive_delay take the amount's known value as a second argument. Native images use container format 28; images written by earlier versions must be rebuilt. Change-Id: I0cf80b28fd983be51686322c0562d9b664d919e1
…uler mode SimulationState::run_until now holds the loop Simulation::run_until ran, and run_until_observed/step_until_observed show every step to a StepObserver; the plain versions pass (). A hidden builder option selects the SchedulerMode, and a hidden Simulation::scheduler_stats reports the mode, the steps checked against a shadow and how each kernel is scheduled. Every mode runs the reference loop until a compiled scheduler exists. SchedulerMode::Differential compiles the design twice and runs the same loop with a shadow check as its observer: before a step the shadow takes the design state, scheduling state (remapped to its own event handles) and undrained runtime events, or in a slot suspended at $stop the design state and host changes; after it the step result, scheduling state, state bytes, string heap and runtime events must match. Designs without a shadow record why. The SV suite harness selects the mode from CELOX_SCHEDULER and reports every case it could not check. BREAKING CHANGE: SimulatorOptions has a new field, `scheduler`. Change-Id: I34d2fda76a4ed59ab4a2d0efc84ca033774c9bac
Merge Queue Status
This pull request spent 47 minutes 24 seconds in the queue, with no time running CI. ReasonPull request #1756 has been dequeued Queue conditions are not satisfied:
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Waiting for
All conditions
Requeued — the merge queue status continues in this comment ↓. |
|
@Mergifyio dequeue |
2ba0d0a to
c90b37d
Compare
Merge Queue Status
This pull request spent 1 hour 1 minute 23 seconds in the queue, including 59 minutes 40 seconds running CI. Required conditions to merge
|
Part of #1123, step 3b-1 (compiled scheduler), PR 2 of 7. This prepares the runtime for a compiled time-slot loop. Behaviour is unchanged: every mode still runs the reference loop.
BREAKING CHANGE
SimulatorOptions(public, exhaustive) has a new field,scheduler(#[doc(hidden)]).celox_design::ProcessSlotshas a new field,const_delays.celox_frontend_core::process::ProcessKernelBuilder::delayandinactive_delaytake a second argument, the amount's value when the frontend knows it (Option<u64>).Run loop in
SimulationStateSimulationState::run_untilnow holds the loopSimulation::run_untilran (step every time with work up to the target, stop at$stopor$finish, then advance to the target).Simulation::run_untildelegates to it and keeps the VCD dump at the target.step_untilstays the one-step API. Both have_observedvariants that show every step to aStepObserver; the plain versions pass(), whose empty hooks cost nothing. In PR 3 the free-running loop is where a compiled scheduler takes over runs of slots, and Differential mode checks exactly that loop through the observer.Scheduler mode and stats (hidden)
SchedulerMode::{Reference, Compiled, Differential}, selected with the#[doc(hidden)]builder optionSimulation::builder(..).scheduler_mode(..). Library code reads no environment variable. The default isReference; PR 3 makesCompiledthe default with the compiled loop.Simulation::scheduler_stats()(#[doc(hidden)]) reports the mode, the compiled slots (always 0 here), the steps checked against a shadow, and how each kernel is scheduled. Today every kernel reports "the design has no compiled scheduler".Differential harness
SchedulerMode::Differentialcompiles the design a second time into a shadowSimulationthat runsReference. The primary runs the sameSimulationState::run_until/step_untilas every other mode, with the shadow check as itsStepObserver; there is no separate checked loop.add_clock,schedule,load_state, raw memory writes) therefore need no mirroring. Pending events are remapped by id to the shadow's own handles, so the shadow runs its own compiled code (a native test checks the handles' function pointers).SimulationState::schedule_key: events by id, wakeups and waiters in order, ready/inactive sets, NBA queue, counters, flags), the state bytes, the string heap (Heap::same_contents) and the pending runtime events must match. A mismatch fails the step with the step's start time and the first difference, e.g.state byte 1234 (top.count).$stopthe scheduling state cannot be copied: the shadow takes the design state, host flags and the pending host-write flag, and continues the slot in lockstep. A test runs$stop, a host write, thenrun_untilin Differential mode.scheduler_stats().uncheckedgives the reason, and the SV suite harness reports each such case (differential: unchecked: ...); every other timed case must havechecked_steps > 0or fails.The SV suite harness maps
CELOX_SCHEDULER=reference|compiled|differentialto the builder option (the scopedclippy::disallowed_methodsallow followscelox-vpi/tests/cocotb_e2e.rs). Unit tests show that the harness passes a run with a host write betweenrun_untilcalls, and reports a shadow that diverges (one that sees other plusargs).Constant delays as kernel metadata
ProcessKernelBuilder::delay/inactive_delaytake the amount's value when the frontend knows it, and the builder records inProcessSlots::const_delayswhether every delay of the kernel is a constant of at least one time unit. The SV frontend records integral constants (literals, parameters, after time-unit scaling, without overflow); real and negative delays count as variable. The SDK lowering records two-state constant expressions. The emitted SIR is unchanged.ProcessSlotsis part of the native image, so the image container version moves from 27 to 28 (one above master; #1720 also changed the image schema at 27).Moved to PR 3:
SchedulerSchemaand the handoff functions. They land with their first user instead of as dead code here.Perf
Callgrind, whole program, Ir per cycle = (Ir at 200,000 cycles − Ir at 20,000) / 180,000, median of 5. Base and branch built from the same base (8af0a41, #1720).
Simulator::tickSimulation+add_clock(a) and (ac) are equal (the run-to-run spread of one variant is ~0.5–1.2 Ir/cycle; (a) runs none of the changed code). No new work runs per step: with no observer the loop calls
()'s empty hooks, andscheduler_statscounts nothing in the reference loop (a first version counted every step and cost (ac) +7 Ir/cycle; it was removed). The (b1)/(b5) difference is about 4 Ir per step inside the unchangedstep_untilcode, from code layout; the frontend commit alone measures (b1) 10,281.6.Compile-dominated totals at 20,000 cycles, base → branch: (a) 310.21M → 310.21M, (ac) 419.71M → 419.14M, (b1) 566.05M → 566.11M, (b5) 585.22M → 585.45M Ir. Differential mode compiles the design twice; it is a test option.
Validation
CELOX_SCHEDULER=differential cargo test -p celox --features systemverilog --test systemverilog timing::(native, cranelift, native/cranelift parallel, wasm): 504 passed, 0 failed, every step checked against the shadow. Unchecked runs reported by the harness: 10, all "the case took no scheduler step" (time_calls_in_child_port_actualsandtime_calls_in_child_port_subroutineson the 5 backends: no processes, waits or scheduled events, so host writes settle on read andrun_untilonly moves time). No timed case lacks a shadow.--test shared_jit_cache(image version tests): 34 passed;-p celox-heap: 10 passed.cargo test -p celox --features systemverilog --lib simulation: 67 passed (runtime core tests on every backend including the interpreter and a native image round trip, the differential harness tests, the const-delay tests).--test checkpoint30,processes17,simulation_limits10,simulation_step7,simulation_stop9,state_file20: all passed.cargo fmt --check; clippy-D warningswith tests on celox, celox-runtime, celox-design, celox-frontend-core, celox-frontend-sv, celox-heap: clean.