Skip to content
Merged
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
1 change: 1 addition & 0 deletions crates/celox-bench/src/bin/layout-spike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ mod tests {
eval_apply_ffs: FxHashMap::default(),
eval_comb_apply_ffs: FxHashMap::default(),
merge_comb_apply: true,
eval_comb_stateful: None,
eval_only_ffs: FxHashMap::default(),
apply_ffs: FxHashMap::default(),
parallel: None,
Expand Down
7 changes: 7 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,11 @@ pub struct SchedulerSlots<A> {
/// last settle. The caller initializes this before every scheduler run;
/// timed runs set it even after a checkpoint restore or partial-slot exit.
pub dirty: A,
/// Set by a caller that observes the design itself (the compiled
/// testbench) while it runs the scheduler: a run that reaches its limit
/// then leaves a deferred settle pending instead of settling for the
/// host.
pub defer_limit_settle: A,
/// The number of time slots the run ran.
pub count: A,
/// The kernel running when the run returned, `u64::MAX` for none.
Expand Down Expand Up @@ -1399,6 +1404,7 @@ impl<A> SchedulerSlots<A> {
finish: map(self.finish),
cont: map(self.cont),
dirty: map(self.dirty),
defer_limit_settle: map(self.defer_limit_settle),
count: map(self.count),
current: map(self.current),
levels: map(self.levels),
Expand All @@ -1423,6 +1429,7 @@ impl<A> SchedulerSlots<A> {
&self.finish,
&self.cont,
&self.dirty,
&self.defer_limit_settle,
&self.count,
&self.current,
&self.levels,
Expand Down
12 changes: 12 additions & 0 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,16 @@ pub fn schedule_symbolic_rtl_reporting_loops(
tracing::debug!("[flatten] scheduler::sort: {:?}", s.elapsed());
}
runtime_errors.extend(schedule.runtime_errors);
let eval_comb_stateful = schedule.stateful_targets.as_ref().map(|targets| {
targets
.iter()
.map(|target| RegionedAbsoluteAddr {
region: STABLE_REGION,
instance_id: target.id.instance_id,
var_id: target.id.var_id,
})
.collect::<Vec<_>>()
});
let stable_unit = |eu: ExecutionUnit<AbsoluteAddr>| ExecutionUnit {
entry_block_id: eu.entry_block_id,
blocks: eu
Expand Down Expand Up @@ -2188,6 +2198,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
eval_apply_ffs,
eval_comb_apply_ffs,
merge_comb_apply,
eval_comb_stateful,
eval_only_ffs,
apply_ffs,
eval_comb,
Expand Down Expand Up @@ -2767,6 +2778,7 @@ fn declare_scheduler_slots(
finish: declare("finish".into(), FLAG),
cont: declare("cont".into(), FLAG),
dirty: declare("dirty".into(), FLAG),
defer_limit_settle: declare("defer_limit_settle".into(), FLAG),
count: declare("count".into(), TIME),
current: declare("current".into(), TIME),
levels: declare("levels".into(), TIME),
Expand Down
9 changes: 7 additions & 2 deletions crates/celox-runtime/src/testbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,13 @@ pub fn bind_testbench_program<B: SimBackend>(
celox_testbench::KernelRequest::Statement(site) => {
celox_testbench::KernelRequest::Statement(*site)
}
celox_testbench::KernelRequest::Settle => {
celox_testbench::KernelRequest::Settle
celox_testbench::KernelRequest::Settle { reads } => {
celox_testbench::KernelRequest::Settle {
reads: reads
.iter()
.map(|address| backend.resolve_signal(address))
.collect(),
}
}
celox_testbench::KernelRequest::Written { address, width } => {
celox_testbench::KernelRequest::Written {
Expand Down
1 change: 1 addition & 0 deletions crates/celox-sir-opt/src/optimizer/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ mod tests {
.collect(),
eval_comb_apply_ffs: crate::HashMap::default(),
merge_comb_apply: true,
eval_comb_stateful: None,
eval_only_ffs: crate::HashMap::default(),
apply_ffs: crate::HashMap::default(),
parallel: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ fn optimize_process(
eval_apply_ffs: crate::HashMap::default(),
eval_comb_apply_ffs: crate::HashMap::default(),
merge_comb_apply: true,
eval_comb_stateful: None,
eval_only_ffs: crate::HashMap::default(),
apply_ffs: crate::HashMap::default(),
parallel: None,
Expand Down
9 changes: 9 additions & 0 deletions crates/celox-sir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ pub struct SirProgram<EventAddr, StateAddr> {
/// FF program, so the combinational program exists once however many
/// events there are. See [`SirProgram::comb_apply`].
pub merge_comb_apply: bool,
/// The storage of the `eval_comb` paths that keep state from one settle
/// to the next, as its scheduler found them: latches and other
/// previous-value reads, loops, guarded processes. Every other path is a
/// function of its inputs. `None` when unknown.
pub eval_comb_stateful: Option<Vec<StateAddr>>,
pub eval_only_ffs: HashMap<EventAddr, Vec<ExecutionUnit<StateAddr>>>,
pub apply_ffs: HashMap<EventAddr, Vec<ExecutionUnit<StateAddr>>>,
/// Lane-partitioned alternatives of the hot phases, present only when
Expand Down Expand Up @@ -252,6 +257,9 @@ impl<EventAddr, StateAddr> SirProgram<EventAddr, StateAddr> {
&mut map_state,
),
merge_comb_apply: self.merge_comb_apply,
eval_comb_stateful: self
.eval_comb_stateful
.map(|stateful| stateful.into_iter().map(&mut map_state).collect()),
eval_only_ffs: map_groups(self.eval_only_ffs, &mut map_event, &mut map_state),
apply_ffs: map_groups(self.apply_ffs, &mut map_event, &mut map_state),
processes: self
Expand Down Expand Up @@ -1142,6 +1150,7 @@ mod program_mapping_tests {
eval_apply_ffs: [(1u32, vec![unit])].into_iter().collect(),
eval_comb_apply_ffs: HashMap::default(),
merge_comb_apply: true,
eval_comb_stateful: None,
eval_only_ffs: HashMap::default(),
apply_ffs: HashMap::default(),
parallel: None,
Expand Down
1 change: 1 addition & 0 deletions crates/celox-sir/src/two_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn canonicalize_program<EventAddr, StateAddr>(program: &mut SirProgram<Event
eval_apply_ffs,
eval_comb_apply_ffs,
merge_comb_apply: _,
eval_comb_stateful: _,
eval_only_ffs,
apply_ffs,
parallel,
Expand Down
38 changes: 38 additions & 0 deletions crates/celox-slt/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,14 @@ pub struct ScheduleResult<Addr> {
/// The partitions of a partitioned settle, in schedule order; empty when
/// the schedule runs as one pass.
pub partitions: Vec<SettlePartition<Addr>>,
/// The targets of the paths that keep state from one settle to the next:
/// paths that read a previous value or loop, and guarded processes.
/// Every other path computes what it stores from its inputs alone (a
/// bit-level order may still load a range before the bits it needs are
/// stored, and then discards the stale bits). `None` when that is not
/// known per path: capture events, and partitioned settles, whose flags
/// keep what changed since the last one.
pub stateful_targets: Option<Vec<VarAtomBase<Addr>>>,
}

/// Request to split a combinational schedule into partitions that run only
Expand Down Expand Up @@ -4661,6 +4669,33 @@ fn sort_impl<Addr: Clone + Eq + Ord + Hash + Debug + Copy + Display, E>(
ff.as_deref().map(|lowering| lowering.summaries()),
)
.map_err(ClockSortError::Scheduler)?;
let component = &prepared.component_by_path;
let looping: HashSet<usize> = prepared
.adj
.iter()
.enumerate()
.flat_map(|(v, successors)| {
successors
.iter()
.filter(move |&&u| component[u] == component[v])
.flat_map(move |&u| [u, v])
})
.collect();
let stateful_targets = prepared
.input
.iter()
.enumerate()
.filter_map(|(index, path)| match &path.target {
LogicPathTarget::CombCaptureEvent { .. } => Some(None),
LogicPathTarget::Process { target, .. } => Some(Some(*target)),
LogicPathTarget::Var(target)
if !path.previous_sources.is_empty() || looping.contains(&index) =>
{
Some(Some(*target))
}
LogicPathTarget::Var(_) => None,
})
.collect::<Option<Vec<_>>>();
let direct_ff_writes = prepared
.direct_ff_writes_by_action
.iter()
Expand Down Expand Up @@ -4741,6 +4776,8 @@ fn sort_impl<Addr: Clone + Eq + Ord + Hash + Debug + Copy + Display, E>(
.finish(&mut lowering.builder, &prepared.direct_ff_writes_by_action)
.map_err(ClockSortError::Lowering)?;
}
// Partition flags carry what changed from one settle to the next.
let stateful_targets = stateful_targets.filter(|_| plan.is_none());
Ok(ScheduleResult {
execution_units: lowering.finish(),
runtime_errors,
Expand All @@ -4757,6 +4794,7 @@ fn sort_impl<Addr: Clone + Eq + Ord + Hash + Debug + Copy + Display, E>(
.collect()
})
.unwrap_or_default(),
stateful_targets,
})
}

Expand Down
11 changes: 9 additions & 2 deletions crates/celox-testbench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,15 @@ pub struct TestbenchClock<Event> {
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum KernelRequest<A> {
Statement(usize),
Settle,
Written { address: A, width: usize },
/// Settle the DUT before the TB reads `reads`, the storage of DUT
/// signals its next expression loads.
Settle {
reads: Vec<A>,
},
Written {
address: A,
width: usize,
},
Error(String),
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions crates/celox/src/backend/native/image_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::{
use super::backend::NativeProgramImage;

const TRAILER_MAGIC: &[u8; 8] = b"CELOXNPI";
// Images retain generated TB scheduler continuations and clock state.
const CONTAINER_VERSION: u16 = 55;
// Images retain the scheduler's slots and the reads of TB settle requests.
const CONTAINER_VERSION: u16 = 56;
const TRAILER_SIZE: usize = 32;
// This optional prefix descriptor does not change the Postcard payload. Older
// readers ignore framing flags and continue to locate the payload at EOF.
Expand Down
1 change: 1 addition & 0 deletions crates/celox/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ mod fused_hint_tests {
.into_iter()
.collect(),
merge_comb_apply: true,
eval_comb_stateful: None,
eval_only_ffs: Default::default(),
apply_ffs: Default::default(),
parallel: None,
Expand Down
Loading
Loading