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
5 changes: 5 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ pub struct RuntimeSchema<A> {
/// Nonblocking assignment sites of the process kernels, ordered like
/// `wait_sites`.
pub nba_sites: Vec<NbaSite<A>>,
/// Canonical event domains whose evaluation commits the results of
/// their blocking assignments, in the active region; their apply units
/// commit only the nonblocking results.
pub active_commits: Vec<A>,
}

impl<A> Default for RuntimeSchema<A> {
Expand All @@ -621,6 +625,7 @@ impl<A> Default for RuntimeSchema<A> {
watches: Vec::new(),
wait_sites: Vec::new(),
nba_sites: Vec::new(),
active_commits: Vec::new(),
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/celox-design/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub struct ScheduleModel<A> {
pub has_pending_nba_sites: bool,
/// The design can execute `$finish`.
pub finish_sites: bool,
/// Canonical event domains whose evaluation commits their blocking
/// results ([`RuntimeSchema::active_commits`]).
pub active_commits: Vec<A>,
}

/// A counted signal and the canonical domains its counters trigger.
Expand Down Expand Up @@ -129,6 +132,7 @@ impl<A: Copy + Eq + std::hash::Hash> ScheduleModel<A> {
.runtime_event_sites
.iter()
.any(|site| matches!(site.kind, RuntimeEventKind::Finish)),
active_commits: schema.active_commits.clone(),
}
}

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 @@ -1905,6 +1905,7 @@ pub fn lower_frontend_artifact(
eval_only_ff_blocks,
apply_ff_blocks,
eval_apply_ff_blocks,
split_commit_ff_blocks: HashMap::default(),
parallel_ff_parts: HashMap::default(),
glue_blocks: HashMap::default(),
indexed_instance_names: HashSet::default(),
Expand Down
14 changes: 14 additions & 0 deletions crates/celox-frontend-core/src/symbolic/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ pub struct SymbolicProcess {
pub slots: ProcessSlots<SourceVarId>,
}

/// The commit of a trigger group's results, split by region.
#[derive(Clone, Debug)]
pub struct SplitCommit<A> {
/// Commits of the results of blocking assignments.
pub active: ExecutionUnit<A>,
/// Commits of the results of nonblocking assignments.
pub nba: ExecutionUnit<A>,
}

#[derive(Clone)]
pub struct SimModule {
/// A frontend's global tick precision; absent for scale-free frontends.
Expand All @@ -67,6 +76,11 @@ pub struct SimModule {
pub eval_only_ff_blocks: HashMap<TriggerSet<SourceVarId>, ExecutionUnit<SymbolicRegionedAddr>>,
pub apply_ff_blocks: HashMap<TriggerSet<SourceVarId>, ExecutionUnit<SymbolicRegionedAddr>>,
pub eval_apply_ff_blocks: HashMap<TriggerSet<SourceVarId>, ExecutionUnit<SymbolicRegionedAddr>>,
/// `apply_ff_blocks` split into the commit of the blocking results (the
/// active region) and that of the nonblocking ones (the NBA region), for
/// a domain whose blocking results another unit observes before the NBA
/// region. Empty when the frontend does not distinguish them.
pub split_commit_ff_blocks: HashMap<TriggerSet<SourceVarId>, SplitCommit<SymbolicRegionedAddr>>,
/// Lane-partitioning alternative of `eval_only_ff_blocks` and
/// `apply_ff_blocks`: a trigger group split into parts which may be
/// evaluated concurrently. Empty unless several lanes were requested.
Expand Down
207 changes: 206 additions & 1 deletion crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::{BTreeMap, BTreeSet};

use crate::symbolic::artifact::{
FfPart, RelocationModule, SimModule, SymbolicGlueAddr as GlueAddr, SymbolicRtl,
FfPart, RelocationModule, SimModule, SplitCommit, SymbolicGlueAddr as GlueAddr, SymbolicRtl,
};
use crate::{
FrontendLookup, FrontendTrace, FrontendTraceOptions, FusedSirOptimizationHints, HashMap,
Expand All @@ -26,6 +26,10 @@ use celox_slt::{

type AbsoluteAddr = SourceAddr;
type RegionedAbsoluteAddr = RegionedAbsoluteAddrBase<SourceVarId>;

/// Per canonical event, the split commit of each of its apply units, in
/// their order; `None` for a unit whose frontend does not split it.
type SplitCommits = HashMap<AbsoluteAddr, Vec<Option<SplitCommit<RegionedAbsoluteAddr>>>>;
type RegionedVarAddr = celox_design::RegionedVarAddrBase<SourceVarId>;

/// Runtime IDs assigned while a module instance is relocated into the global
Expand Down Expand Up @@ -641,6 +645,7 @@ pub fn schedule_symbolic_rtl(
unify_clock_domains(bindings, &expanded, &instance_modules, &modules)
);
let mut parallel_ff_units = HashMap::default();
let mut split_commits = SplitCommits::default();
let (
mut global_arena,
mut eval_apply_ffs,
Expand Down Expand Up @@ -668,6 +673,7 @@ pub fn schedule_symbolic_rtl(
&unpacked_element_widths,
&clock_domains,
parallel.enabled().then_some(&mut parallel_ff_units),
&mut split_commits,
trace_opts,
&mut trace,
)
Expand Down Expand Up @@ -705,6 +711,8 @@ pub fn schedule_symbolic_rtl(
&mut comb_blocks,
)
};
// Combinational values and the variables they are computed from.
let comb_sources = comb_sources(&comb_blocks, &global_arena);
check_package_variable_drivers(
bindings,
&instance_modules,
Expand Down Expand Up @@ -1228,6 +1236,31 @@ pub fn schedule_symbolic_rtl(
eval_apply_ffs,
}
});
// With process kernels, a domain whose blocking results another unit
// observes commits them with its evaluation, in the active region, and
// only its nonblocking results in the NBA region (IEEE 1800-2023 4.5,
// 10.4). Every other domain commits both together, as before.
let mut active_commits = Vec::new();
if !processes.is_empty() {
let events: HashSet<AbsoluteAddr> = eval_apply_ffs
.keys()
.copied()
.chain(clock_domains.keys().copied())
.collect();
active_commits = split_observed_commits(
&mut eval_only_ffs,
&mut apply_ffs,
split_commits,
&comb_sources,
processes.iter().map(|process| &process.kernel),
timing
.wait_sites
.iter()
.flat_map(|site| site.terms.iter().map(|(signal, _)| *signal)),
&events,
&clock_domains,
);
}
let (eval_only_ffs, apply_ffs) = if needs_split_path {
(eval_only_ffs, apply_ffs)
} else {
Expand Down Expand Up @@ -1523,6 +1556,7 @@ pub fn schedule_symbolic_rtl(
wait_sites.iter().map(|site| site.map(project)).collect();
let nba_sites: Vec<NbaSite<StateAddr>> =
nba_sites.iter().map(|site| site.map(project)).collect();
let active_commits: Vec<StateAddr> = active_commits.into_iter().map(project).collect();
// The runtime reads counters, the signals waits watch and staged
// nonblocking values directly; no unit loads a wait's signal.
let timing_read_roots = watches
Expand Down Expand Up @@ -1590,6 +1624,7 @@ pub fn schedule_symbolic_rtl(
watches,
wait_sites,
nba_sites,
active_commits,
},
};

Expand Down Expand Up @@ -2291,6 +2326,7 @@ fn relocate_units(
parallel_ff_units: Option<
&mut HashMap<AbsoluteAddr, Vec<(InstanceId, FfPart<RegionedAbsoluteAddr>)>>,
>,
split_commits: &mut SplitCommits,
trace_opts: &crate::FrontendTraceOptions,
trace: &mut Option<&mut crate::FrontendTrace>,
) -> Result<
Expand Down Expand Up @@ -2640,6 +2676,42 @@ fn relocate_units(
.get(&clock_addr)
.copied()
.unwrap_or(clock_addr);
// The split commit of each apply unit, in the same order.
let split = sim_module
.split_commit_ff_blocks
.get(trigger_set)
.map(|split| SplitCommit {
active: relocate_executation_unit_with_errors(
&split.active,
&|addr| bindings.locate_regioned(addr.region, *id, addr.var_id),
&runtime_error_codes,
&runtime_event_site_map,
&extern_function_map,
),
nba: relocate_executation_unit_with_errors(
&split.nba,
&|addr| bindings.locate_regioned(addr.region, *id, addr.var_id),
&runtime_error_codes,
&runtime_event_site_map,
&extern_function_map,
),
});
// Pushed like the apply units below: the clock, then each reset.
split_commits
.entry(canonical_addr)
.or_default()
.push(split.clone());
for &reset in &trigger_set.resets {
let reset_addr = bindings.locate(*id, reset);
let canonical_addr = clock_domains
.get(&reset_addr)
.copied()
.unwrap_or(reset_addr);
split_commits
.entry(canonical_addr)
.or_default()
.push(split.clone());
}
apply_ffs.entry(canonical_addr).or_default().push(
relocate_executation_unit_with_errors(
eu,
Expand Down Expand Up @@ -2731,6 +2803,139 @@ struct TimingMetadata {
nba_sites: Vec<NbaSite<AbsoluteAddr>>,
}

/// For every combinational value, the variables it is computed from.
fn comb_sources(
comb_blocks: &[celox_slt::LogicPath<AbsoluteAddr>],
arena: &SLTNodeArena<AbsoluteAddr>,
) -> HashMap<AbsoluteAddr, HashSet<AbsoluteAddr>> {
let mut sources: HashMap<AbsoluteAddr, HashSet<AbsoluteAddr>> = HashMap::default();
for path in comb_blocks {
let Some(target) = path.target.var() else {
continue;
};
let mut inputs = HashSet::default();
if matches!(path.target, celox_slt::LogicPathTarget::Process { .. }) {
inputs.extend(path.sources.iter().cloned());
} else {
crate::flattening::collect_inputs(path.expr, arena, &mut inputs);
}
sources
.entry(target.id)
.or_default()
.extend(inputs.into_iter().map(|atom| atom.id));
}
sources
}

/// The variables `unit` loads.
fn unit_loads(unit: &ExecutionUnit<RegionedAbsoluteAddr>, loads: &mut HashSet<AbsoluteAddr>) {
for block in unit.blocks.values() {
for instruction in &block.instructions {
if let SIRInstruction::Load(_, addr, ..) = instruction {
loads.insert(addr.absolute_addr());
}
}
}
}

/// `reads` closed over combinational logic: with a value, the variables it
/// is computed from.
fn through_comb(
mut reads: HashSet<AbsoluteAddr>,
comb_sources: &HashMap<AbsoluteAddr, HashSet<AbsoluteAddr>>,
) -> HashSet<AbsoluteAddr> {
let mut pending: Vec<AbsoluteAddr> = reads.iter().copied().collect();
while let Some(read) = pending.pop() {
for source in comb_sources.get(&read).into_iter().flatten() {
if reads.insert(*source) {
pending.push(*source);
}
}
}
reads
}

/// Move the commits of the blocking results of every observed domain from
/// its apply units to its evaluation: a blocking result is observed when
/// it, or a combinational value computed from it, is read by a process
/// kernel or by another domain's evaluation, is a wait term, or is another
/// domain's event signal. Domains whose apply units the frontend did not
/// split keep them.
#[allow(clippy::too_many_arguments)]
fn split_observed_commits<'k>(
eval_only_ffs: &mut HashMap<AbsoluteAddr, Vec<ExecutionUnit<RegionedAbsoluteAddr>>>,
apply_ffs: &mut HashMap<AbsoluteAddr, Vec<ExecutionUnit<RegionedAbsoluteAddr>>>,
split_commits: SplitCommits,
comb_sources: &HashMap<AbsoluteAddr, HashSet<AbsoluteAddr>>,
kernels: impl Iterator<Item = &'k ExecutionUnit<RegionedAbsoluteAddr>>,
wait_terms: impl Iterator<Item = AbsoluteAddr>,
events: &HashSet<AbsoluteAddr>,
clock_domains: &HashMap<AbsoluteAddr, AbsoluteAddr>,
) -> Vec<AbsoluteAddr> {
let mut split = Vec::new();
let mut shared: HashSet<AbsoluteAddr> = wait_terms.collect();
for kernel in kernels {
unit_loads(kernel, &mut shared);
}
let evaluation_loads: HashMap<AbsoluteAddr, HashSet<AbsoluteAddr>> = eval_only_ffs
.iter()
.map(|(event, units)| {
let mut loads = HashSet::default();
for unit in units {
unit_loads(unit, &mut loads);
}
(*event, loads)
})
.collect();
let canonical = |event: &AbsoluteAddr| clock_domains.get(event).copied().unwrap_or(*event);
for (domain, splits) in split_commits {
let Some(splits) = splits.into_iter().collect::<Option<Vec<_>>>() else {
continue;
};
if apply_ffs.get(&domain).map_or(0, Vec::len) != splits.len() {
continue;
}
let mut blocking = HashSet::default();
for split in &splits {
for block in split.active.blocks.values() {
for instruction in &block.instructions {
if let SIRInstruction::Commit(_, dst, ..) = instruction {
blocking.insert(dst.absolute_addr());
}
}
}
}
if blocking.is_empty() {
continue;
}
let mut reads = shared.clone();
reads.extend(
events
.iter()
.filter(|event| canonical(event) != domain)
.copied(),
);
for (event, loads) in &evaluation_loads {
if *event != domain {
reads.extend(loads.iter().copied());
}
}
let reads = through_comb(reads, comb_sources);
if blocking.is_disjoint(&reads) {
continue;
}
let (active, nba): (Vec<_>, Vec<_>) = splits
.into_iter()
.map(|split| (split.active, split.nba))
.unzip();
eval_only_ffs.entry(domain).or_default().extend(active);
apply_ffs.insert(domain, nba);
split.push(domain);
}
split.sort_unstable();
split
}

/// Place the timing metadata of every instance. Sites name the global index
/// of their process; a kernel numbers its sites in the order they appear
/// here, which is the module's order.
Expand Down
Loading
Loading