Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
schedule:
- cron: "17 2 * * *"
workflow_dispatch:
inputs:
runner_probe:
description: Check Macro Runner availability without building or benchmarking
type: boolean
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -16,9 +21,20 @@ env:
permissions: {}

jobs:
runner-probe:
name: Probe CodSpeed runner
if: github.event_name == 'workflow_dispatch' && inputs.runner_probe
runs-on: codspeed-macro-arm64-graviton-ubuntu-22-04
timeout-minutes: 2
steps:
- name: Verify the ARM64 runner is available
run: test "$(uname -m)" = aarch64

codspeed:
name: CodSpeed
runs-on: ubuntu-latest
if: inputs.runner_probe != true
timeout-minutes: 60
runs-on: codspeed-macro-arm64-graviton-ubuntu-22-04
outputs:
run-id: ${{ steps.benchmarks.outputs.run-id }}
permissions:
Expand All @@ -39,19 +55,20 @@ jobs:
tool: cargo-codspeed@5.0.1

- name: Build compile-time benchmarks
run: cargo codspeed build --locked -p celox --bench compilation
run: cargo codspeed build --locked --measurement-mode walltime -p celox --bench compilation

- name: Run compile-time benchmarks
id: benchmarks
timeout-minutes: 15
uses: CodSpeedHQ/action@v5
with:
mode: simulation
run: cargo codspeed run -p celox
mode: walltime
run: cargo codspeed run --measurement-mode walltime -p celox --bench compilation

report:
name: Report CodSpeed
needs: codspeed
if: always() && (github.ref_name == 'master' || github.ref_name == 'develop')
if: always() && inputs.runner_probe != true && (github.ref_name == 'master' || github.ref_name == 'develop')
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
Expand Down
10 changes: 8 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ interpreter, native and Cranelift backends in both two-state and four-state mode
wide-value latch checks, and a small sorter compilation smoke test.
The 257/512-bit per-bit graph cases and sorter sizes 4/8/16/32 are measured by
`benches/compilation.rs` in the existing daily/manual CodSpeed workflow.
Compilation benchmarks use CodSpeed walltime measurement on its ARM64 Graviton
Macro Runner: CPU simulation made
a single 512-bit case take tens of minutes. The benchmark step has a 15-minute
timeout and the complete job a 60-minute limit; a timeout is reported as failure.
The organization runner group must allow this public repository to use CodSpeed
Macro Runners. Simulation and walltime measurements have separate baselines.
Nested-write benchmarks reuse the same semantic assertions as the small tests.
Scaling cases use one iteration without per-case warmups or adaptive sampling;
a small counter warms process-global analyzer state before measurement.
Expand All @@ -130,8 +136,8 @@ CodSpeed reporting workflow.
Build and run them with the same CodSpeed harness as CI:

```sh
cargo codspeed build --locked -p celox --bench compilation
cargo codspeed run -p celox
cargo codspeed build --locked --measurement-mode walltime -p celox --bench compilation
cargo codspeed run --measurement-mode walltime -p celox --bench compilation
```

## Finish validation
Expand Down
17 changes: 17 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ pub enum ProcessStatus {
/// A synchronous host operation. The delay slot holds its family and
/// local site index; the same process resumes after the host responds.
HostRequest,
/// A program kernel called `$exit` (IEEE 1800-2023 24.7): it and every
/// other kernel of its program instance ([`ProcessSlots::program`]) end.
Exit,
}

impl ProcessStatus {
Expand All @@ -308,6 +311,7 @@ impl ProcessStatus {
Self::Yield => 8,
Self::Stop => 9,
Self::HostRequest => 10,
Self::Exit => 11,
}
}

Expand All @@ -323,6 +327,7 @@ impl ProcessStatus {
8 => Some(Self::Yield),
9 => Some(Self::Stop),
10 => Some(Self::HostRequest),
11 => Some(Self::Exit),
_ => None,
}
}
Expand Down Expand Up @@ -465,6 +470,12 @@ pub struct ProcessSlots<A> {
/// Every delay the kernel suspends for is a constant of at least one
/// time unit.
pub const_delays: bool,
/// For an `initial` procedure of a program instance (IEEE 1800-2023
/// 24.3), the status slot of that instance's first such kernel, which
/// every kernel of the instance names: the kernel runs in the reactive
/// region set (24.3.1), and `$exit` and the end of the instance's
/// kernels act on them together (24.7). `None` for design code.
pub program: Option<A>,
pub resume: A,
pub status: A,
pub delay: A,
Expand All @@ -476,6 +487,7 @@ impl<A> ProcessSlots<A> {
is_initializer: self.is_initializer,
requires_timed_simulation: self.requires_timed_simulation,
const_delays: self.const_delays,
program: self.program.map(&mut map),
resume: map(self.resume),
status: map(self.status),
delay: map(self.delay),
Expand Down Expand Up @@ -1058,6 +1070,9 @@ pub struct SchedulerSchema<A> {
/// The event signals a host periodic clock may drive inside the
/// scheduler's slots, in the order of its clock slots.
pub clocks: Vec<A>,
/// Per process kernel, the event signals it writes, as indices into
/// [`Self::events`]; empty for a kernel the scheduler does not run.
pub kernel_events: Vec<Vec<usize>>,
}

impl<A> SchedulerSchema<A> {
Expand All @@ -1069,6 +1084,7 @@ impl<A> SchedulerSchema<A> {
fallback: self.fallback,
events: self.events.into_iter().map(&mut map).collect(),
clocks: self.clocks.into_iter().map(map).collect(),
kernel_events: self.kernel_events,
}
}
}
Expand Down Expand Up @@ -1791,6 +1807,7 @@ mod tests {
ProcessStatus::from_code(10),
Some(ProcessStatus::HostRequest)
);
assert_eq!(ProcessStatus::from_code(11), Some(ProcessStatus::Exit));
}

#[test]
Expand Down
7 changes: 7 additions & 0 deletions crates/celox-frontend-core/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ impl ProcessKernelBuilder {
self.end(ProcessStatus::Finish);
}

/// End the kernel and the other kernels of its program instance
/// (`$exit`, IEEE 1800-2023 24.7). No block is open afterwards.
pub fn exit(&mut self) {
self.wait_site = None;
self.end(ProcessStatus::Exit);
}

/// Complete the kernel. If a block is still open, the process ends there.
pub fn build(mut self) -> ExecutionUnit<RegionedSourceAddr> {
if self.builder.has_open_block() {
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,7 @@ fn lower_processes(
is_initializer: false,
requires_timed_simulation: false,
const_delays: false,
program: None,
resume: lowering
.hidden
.declare(name("resume"), PROCESS_RESUME_WIDTH, false),
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
fallback: Vec::new(),
events: Vec::new(),
clocks: Vec::new(),
kernel_events: Vec::new(),
});
// The runtime reads counters, the signals waits watch and staged
// nonblocking values directly; no unit loads a wait's signal.
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4537,6 +4537,7 @@ fn lower_initial_processes(
is_initializer: process.is_initializer(),
requires_timed_simulation: process.is_scheduled_edge(),
const_delays: false,
program: None,
resume: declare("resume", PROCESS_RESUME_WIDTH),
status: declare("status", PROCESS_STATUS_WIDTH),
delay: declare("delay", PROCESS_DELAY_WIDTH),
Expand Down
31 changes: 31 additions & 0 deletions crates/celox-runtime/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct ResolvedSchedule<B: SimBackend> {
pub(crate) signal_to_id: FxHashMap<SignalRef, usize>,
pub(crate) signal_index_by_id: Vec<usize>,
pub(crate) processes: Vec<ProcessRefs>,
/// The kernels of program instances, in declaration order.
pub(crate) program_processes: Vec<usize>,
/// Counted signals and the domains their counters trigger.
pub(crate) counted: Vec<CountedDomainRefs>,
pub(crate) counted_by_offset: FxHashMap<usize, usize>,
Expand Down Expand Up @@ -77,6 +79,10 @@ pub(crate) struct SchedulerRefs {
/// The event id and signal of each host clock the scheduler may run,
/// in the order of its clock slots.
pub(crate) clocks: Vec<(usize, SignalRef)>,
/// Per process kernel, the bits of `levels` of the events it writes.
pub(crate) kernel_events: Vec<u64>,
/// Per clock slot, the bit of `levels` of its event.
pub(crate) clock_events: Vec<u64>,
pub(crate) clock_next: SignalRef,
pub(crate) clock_period: SignalRef,
pub(crate) clock_value: SignalRef,
Expand Down Expand Up @@ -190,6 +196,7 @@ impl<B: SimBackend> ResolvedSchedule<B> {
.iter()
.map(|process| ProcessRefs {
is_initializer: process.slots.is_initializer,
program: process.slots.program.as_ref().map(resolve),
resume: resolve(&process.slots.resume),
starts_with_event_wait: process.slots.requires_timed_simulation,
status: resolve(&process.slots.status),
Expand Down Expand Up @@ -299,6 +306,12 @@ impl<B: SimBackend> ResolvedSchedule<B> {
event_info,
signal_to_id,
signal_index_by_id,
program_processes: processes
.iter()
.enumerate()
.filter(|(_, process)| process.program.is_some())
.map(|(index, _)| index)
.collect(),
processes,
counted,
counted_by_offset,
Expand Down Expand Up @@ -365,6 +378,24 @@ impl<B: SimBackend> ResolvedSchedule<B> {
.iter()
.map(|event| backend.resolve_event_opt(event).map(|event| event.id()))
.collect::<Option<_>>()?,
kernel_events: (0..scheduler.fallback.len())
.map(|index| {
scheduler
.kernel_events
.get(index)
.into_iter()
.flatten()
.fold(0, |mask, &bit| mask | 1 << bit)
})
.collect(),
clock_events: scheduler
.clocks
.iter()
.map(|clock| {
let bit = scheduler.events.iter().position(|event| event == clock)?;
Some(1 << bit)
})
.collect::<Option<_>>()?,
clocks: scheduler
.clocks
.iter()
Expand Down
31 changes: 24 additions & 7 deletions crates/celox-runtime/src/simulation/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,19 @@ impl<B: SimBackend> SimulationState<B> {
|| !pending.ready.is_empty()
|| !pending.inactive.is_empty()
|| !pending.nba_queue.is_empty()
|| pending
.waiters
.iter()
.any(|(process, _)| scheduler.waits.get(process).is_none_or(Option::is_none))
|| pending.waiters.iter().any(|(process, _)| {
scheduler.waits.get(process).is_none_or(Option::is_none)
|| self.writes_observed(scheduler, process)
})
{
return None;
}
let mut first = u64::MAX;
let mut other = u64::MAX;
for &Reverse((time, process)) in self.process_wakeups.iter() {
if scheduler.wake.get(process).is_some_and(Option::is_some) {
if scheduler.wake.get(process).is_some_and(Option::is_some)
&& !self.writes_observed(scheduler, process)
{
first = first.min(time);
} else {
other = other.min(time);
Expand All @@ -100,8 +102,10 @@ impl<B: SimBackend> SimulationState<B> {
let clocks = &self.scheduler.clocks;
let compiled = compiled_clocks(scheduler, queue, clocks);
for event in queue {
if clock_slot(scheduler, event, clocks).is_some_and(|bit| compiled >> bit & 1 != 0)
{
if clock_slot(scheduler, event, clocks).is_some_and(|bit| {
compiled >> bit & 1 != 0
&& scheduler.clock_events[bit] & self.observed_events == 0
}) {
first = first.min(event.time);
} else {
other = other.min(event.time);
Expand All @@ -126,6 +130,15 @@ impl<B: SimBackend> SimulationState<B> {
})
}

/// Whether `process` may change an event the host observes, so that
/// its slots run in the reference loop.
fn writes_observed(&self, scheduler: &SchedulerRefs, process: usize) -> bool {
scheduler
.kernel_events
.get(process)
.is_some_and(|&events| events & self.observed_events != 0)
}

/// Run the compiled scheduler for the slots up to `limit`. Returns, like
/// [`Self::step_until`], the time of the last slot run.
pub(super) fn run_compiled<E>(
Expand Down Expand Up @@ -393,6 +406,10 @@ impl<B: SimBackend> SimulationState<B> {
}
}
executor.try_finish_timed_step(now)?;
// What the host writes after the slot is an update of its time.
if executor.take_slot_writes() {
self.host_pending = true;
}
Ok(now)
}
}
17 changes: 17 additions & 0 deletions crates/celox-runtime/src/simulation/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ pub trait HostBoundary: UnitExecutor {
output
}

/// Called in every round when its processes and scheduled values have
/// run and its flip-flop domains are about to evaluate: the round's
/// edges are in state, and no domain has committed. Returns whether the
/// host wrote state; the round then settles it before the domains read
/// it. Writes to signals a wait watches are logged as in
/// [`Self::take_host_writes`].
fn before_domains(&mut self, _timestamp: u64) -> Result<bool, Halt> {
Ok(false)
}

/// Whether the host wrote state in [`Self::try_finish_timed_step`]
/// since the last call. The writes are updates of that slot's time: the
/// next step settles them there.
fn take_slot_writes(&mut self) -> bool {
false
}

/// Snapshot external-component inputs immediately before an event domain
/// evaluates its sequential logic.
fn stage_external_event(
Expand Down
Loading
Loading