-
Notifications
You must be signed in to change notification settings - Fork 6
Beginning of timing aware optimization using comb-depth and node count #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
61df3a5
8a040ba
7335358
e24be57
4bf46aa
a7a100f
1c4a4fd
4d062ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /*! | ||
|
|
||
| Timing analysis helpers for timing-aware optimization flows. | ||
|
|
||
| */ | ||
|
|
||
| use safety_net::Instantiable; | ||
| use safety_net::NetRef; | ||
| use safety_net::graph::CombDepthInfo; | ||
| use std::collections::HashSet; | ||
|
|
||
| #[derive(Debug)] | ||
| /// A representative critical path ending at a timing endpoint. | ||
| pub struct DelayPath<I: Instantiable> { | ||
| /// The path from endpoint backward through critical fan-in. | ||
| path: Vec<NetRef<I>>, | ||
|
danielpenas42 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| impl<I: Instantiable> DelayPath<I> { | ||
| /// Returns the depth/length of the delay path. | ||
| pub fn depth(&self) -> usize { | ||
| self.path.len() | ||
| } | ||
|
|
||
| /// The signal being driven by this path | ||
| pub fn endpoint(&self) -> NetRef<I> { | ||
| self.path[0].clone() | ||
| } | ||
|
|
||
| /// The nodes along the delay path as a slice | ||
| pub fn path(&self) -> &[NetRef<I>] { | ||
| &self.path | ||
| } | ||
| } | ||
|
|
||
| impl<I: Instantiable> IntoIterator for DelayPath<I> { | ||
| type Item = NetRef<I>; | ||
| type IntoIter = std::vec::IntoIter<NetRef<I>>; | ||
|
|
||
| fn into_iter(self) -> Self::IntoIter { | ||
| self.path.into_iter() | ||
| } | ||
| } | ||
|
|
||
| fn build_path_from_endpoint<I: Instantiable>( | ||
| analysis: &CombDepthInfo<'_, I>, | ||
| endpoint: NetRef<I>, | ||
|
danielpenas42 marked this conversation as resolved.
Outdated
|
||
| ) -> Option<DelayPath<I>> { | ||
| let mut path = Vec::new(); | ||
| let mut current = endpoint; | ||
|
|
||
| while let Some(crit) = analysis.get_crit_input(¤t) { | ||
| path.push(current.clone()); | ||
| if let Some(c) = crit.get_driver() { | ||
| current = c.unwrap(); | ||
| } else { | ||
| return None; | ||
| } | ||
| } | ||
|
|
||
| path.push(current); | ||
| Some(DelayPath { path }) | ||
| } | ||
|
|
||
| /// Gets up to `n` most critical paths. | ||
| pub fn get_critical_paths<I: Instantiable>( | ||
| analysis: &CombDepthInfo<'_, I>, | ||
| n: usize, | ||
| ) -> Vec<DelayPath<I>> { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this function lazy? Return a Something like pub fn get_critical_paths<I: Instantiable>(
analysis: &CombDepthInfo<'_, I>,
n: usize,
) -> impl Iterator<Item =DelayPath<I>> {
if analysis.get_max_depth().is_none() {
return std::iter::empty();
}
analysis.get_critical_points().into_iter().take(n).flat_map(|p| build_path_from_endpoint(analysis, p))
}
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big deal if it doesn't work. Let me know. |
||
| if analysis.get_max_depth().is_none() { | ||
| return Vec::new(); | ||
| } | ||
|
|
||
| let mut vec = Vec::new(); | ||
|
|
||
| for p in analysis.get_critical_points().into_iter().take(n) { | ||
| if let Some(path) = build_path_from_endpoint(analysis, p.clone()) { | ||
| vec.push(path); | ||
| } | ||
| } | ||
|
|
||
| vec | ||
| } | ||
|
|
||
| /// Expands a critical path backward through fan-in for `n` frontier steps. | ||
|
danielpenas42 marked this conversation as resolved.
Outdated
|
||
| pub fn expand_n_nodes<I: Instantiable>(path: DelayPath<I>, n: usize) -> HashSet<NetRef<I>> { | ||
|
danielpenas42 marked this conversation as resolved.
Outdated
|
||
| let mut frontier: Vec<NetRef<I>> = path.into_iter().collect(); | ||
| let mut expanded_nodes: HashSet<NetRef<I>> = frontier.iter().cloned().collect(); | ||
|
|
||
| for _ in 0..n { | ||
| let mut next_frontier = Vec::new(); | ||
|
|
||
| for node in frontier { | ||
| for driver in node.drivers().flatten() { | ||
| if expanded_nodes.insert(driver.clone()) { | ||
| next_frontier.push(driver); | ||
| } | ||
|
matth2k marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| frontier = next_frontier; | ||
| } | ||
|
|
||
| expanded_nodes | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.