Skip to content

Commit

Permalink
Deprecate @static (#1897)
Browse files Browse the repository at this point in the history
* replace static w// interval

* change primitives to @interval

* modified tests

* promte_static -> promotable

* get rid of static

* remove attribute_promotion

* py frontend uses promotable

* rewrite exp tests

* corrected some tests

* overwrite tests

* overwrite failing tests

* change interface

* add tests

* add well formed check

* change compile_invoke

* add tests

* compile invoke test

* change iterface

* adjustments

* fix borrow error

* clippy

* move files

* fix test

* rewrite mlir test

* always promote @interval

* interp tests

* documentation

* dummy change

* static->interval

* update tests

* add documentation to compile-static-interface

* well formed check'

* small change

* done

* tests

* rewrite test

* dummy change

* github workflow

* docker file checks out main

* checkout master

* checkout specific version

* go back to og dockerfile

* checkout specific commit

* does this work

* still not working

* dummy change so non-merge commit

* chatgpt no cache

* does this change things

* modify relay tests
  • Loading branch information
calebmkim authored Feb 9, 2024
1 parent e7b1fbb commit d94ce93
Show file tree
Hide file tree
Showing 170 changed files with 1,599 additions and 1,094 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ RUN python3 setup.py bdist_wheel && python3 -m pip install --user dist/tvm-*.whl

# Install Dahlia
WORKDIR /home
RUN git clone https://github.com/cucapra/dahlia.git
RUN git clone https://github.com/cucapra/dahlia.git
WORKDIR /home/dahlia
## Checkout specific version
RUN git checkout a352e60
RUN git checkout 51954e7
RUN sbt "; getHeaders; assembly"

# Add the Calyx source code from the build context
Expand Down
24 changes: 16 additions & 8 deletions calyx-frontend/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strum::EnumCount;
use strum_macros::{AsRefStr, EnumCount, EnumString, FromRepr};

/// Attributes that have been deprecated.
pub const DEPRECATED_ATTRIBUTES: &[&str] = &[];
pub const DEPRECATED_ATTRIBUTES: &[&str] = &["static"];

#[derive(
EnumCount,
Expand Down Expand Up @@ -62,7 +62,7 @@ pub enum BoolAttr {
/// Inline this subcomponent
Inline,
#[strum(serialize = "promoted")]
/// denotes a static component promoted from dynamic
/// denotes a static component or control promoted from dynamic
Promoted,
}
impl From<BoolAttr> for Attribute {
Expand Down Expand Up @@ -97,18 +97,23 @@ pub enum NumAttr {
#[strum(serialize = "bound")]
/// The bound of a while loop
Bound,
#[strum(serialize = "static")]
/// Latency information
Static,
#[strum(serialize = "pos")]
/// Source location position for this node
Pos,
#[strum(serialize = "promote_static")]
/// Promote the group or control to static with the annotated latency
PromoteStatic,
#[strum(serialize = "promotable")]
/// Can promote the group, control, or @go port of the component to static
/// with the annotated latency
Promotable,
#[strum(serialize = "compactable")]
/// suggest that the current static seq block is compactable
Compactable,
#[strum(serialize = "interval")]
/// Placed on @go ports of components to denote the II of a component, which
/// is the same as the latency for non pipelined components.
/// This indicates the component can serve ``double-duty'' as both static and
/// dynamic.
/// Therefore, we only place if we can *guarantee* the interval of the component.
Interval,
}
impl From<NumAttr> for Attribute {
fn from(attr: NumAttr) -> Self {
Expand Down Expand Up @@ -173,6 +178,9 @@ impl FromStr for Attribute {
} else if let Ok(n) = NumAttr::from_str(s) {
Ok(Attribute::Num(n))
} else {
if DEPRECATED_ATTRIBUTES.contains(&s) {
log::warn!("The attribute @{s} is deprecated and will be ignored by the compiler.");
}
// Reject attributes that all caps since those are reserved for internal attributes
if s.to_uppercase() == s {
return Err(Error::misc(format!("Invalid attribute: {}. All caps attributes are reserved for internal use.", s)));
Expand Down
5 changes: 5 additions & 0 deletions calyx-ir/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,11 @@ impl Control {
matches!(self, Control::Static(_))
}

pub fn is_empty(&self) -> bool {
matches!(self, Control::Static(StaticControl::Empty(_)))
|| matches!(self, Control::Empty(_))
}

pub fn get_latency(&self) -> Option<StaticLatency> {
match self {
Control::Static(sc) => Some(sc.get_latency()),
Expand Down
73 changes: 67 additions & 6 deletions calyx-ir/src/from_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
RESERVED_NAMES, RRC,
};
use crate::{Nothing, PortComp, StaticTiming};
use calyx_frontend::{ast, BoolAttr, Workspace};
use calyx_frontend::{ast, BoolAttr, NumAttr, Workspace};
use calyx_utils::{CalyxResult, Error, GPosIdx, WithPos};
use itertools::Itertools;

Expand All @@ -24,12 +24,73 @@ struct SigCtx {
lib: LibrarySignatures,
}

// assumes cell has a name (i.e., not a constant/ThisComponent)
// uses sig_ctx to check the latency of comp_name (if not static, then None)
// Assumes cell has a name (i.e., not a constant/ThisComponent)
// uses sig_ctx to check the latency of comp_name, either thru static<n> or
// @interval(n)
fn get_comp_latency(
sig_ctx: &SigCtx,
cell: RRC<Cell>,
attrs: &Attributes,
) -> CalyxResult<Option<NonZeroU64>> {
let comp_name = cell
.borrow()
.type_name()
.unwrap_or_else(|| unreachable!("invoked component without a name"));
if let Some(prim) = sig_ctx.lib.find_primitive(comp_name) {
match prim.latency {
Some(val) => Ok(Some(val)),
None => {
let prim_sig = &prim.signature;
// We can just look at any go port, since if there is an
// @interval(n), it must be the same for all ports.
let interval_value = prim_sig
.iter()
.find(|port_def| port_def.attributes.has(NumAttr::Go))
.and_then(|go_port| {
go_port.attributes.get(NumAttr::Interval)
});
// Annoying thing we have to do bc NonZeroU64.
match interval_value {
Some(lat) => Ok(NonZeroU64::new(lat)),
None => Ok(None),
}
}
}
} else if let Some((comp_sig, latency)) = sig_ctx.comp_sigs.get(&comp_name)
{
match latency {
Some(val) => Ok(Some(*val)),
None => {
// We can just look at any go port, since if there is an
// @interval(n), it must be the same for all ports.
let interval_value = comp_sig
.iter()
.find(|port_def| port_def.attributes.has(NumAttr::Go))
.and_then(|go_port| {
go_port.attributes.get(NumAttr::Interval)
});
// Annoying thing we have to do bc NonZeroU64.
match interval_value {
Some(lat) => Ok(NonZeroU64::new(lat)),
None => Ok(None),
}
}
}
} else {
return Err(Error::undefined(
comp_name,
"primitive or component".to_string(),
)
.with_pos(attrs));
}
}

// Assumes cell has a name (i.e., not a constant/ThisComponent)
// uses sig_ctx to check the latency of comp_name, but only checks static<n> latency
fn get_static_latency(
sig_ctx: &SigCtx,
cell: RRC<Cell>,
attrs: &Attributes,
) -> CalyxResult<Option<NonZeroU64>> {
let comp_name = cell
.borrow()
Expand Down Expand Up @@ -766,7 +827,7 @@ fn build_static_control(
v
} else {
return Err(Error::malformed_control(format!(
"non-static component {} is statically invoked",
"component {} is statically invoked, but is neither static nor does it have @interval attribute its @go port",
comp_name
))
.with_pos(&attributes));
Expand Down Expand Up @@ -951,7 +1012,7 @@ fn build_control(
v
} else {
return Err(Error::malformed_control(format!(
"non-static component {} is statically invoked",
"component {} is statically invoked, but is neither static nor does it have @interval attribute its @go port",
comp_name
))
.with_pos(&attributes));
Expand Down Expand Up @@ -1040,7 +1101,7 @@ fn build_control(
});

// Error to dynamically invoke static component
if get_comp_latency(sig_ctx, Rc::clone(&cell), &attributes)?
if get_static_latency(sig_ctx, Rc::clone(&cell), &attributes)?
.is_some()
{
return Err(Error::malformed_control(format!(
Expand Down
11 changes: 4 additions & 7 deletions calyx-opt/src/analysis/compute_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
fn update_static(&mut self, extra: &Self::Info) -> Option<u64> {
if let Some(time) = self.compute_static(extra) {
self.get_mut_attributes()
.insert(ir::NumAttr::PromoteStatic, time);
.insert(ir::NumAttr::Promotable, time);
Some(time)
} else {
None
Expand Down Expand Up @@ -62,19 +62,16 @@ impl WithStatic for ir::Enable {
fn compute_static(&mut self, _: &Self::Info) -> Option<u64> {
// Attempt to get the latency from the attribute on the enable first, or
// failing that, from the group.
self.attributes.get(ir::NumAttr::PromoteStatic).or_else(|| {
self.group
.borrow()
.attributes
.get(ir::NumAttr::PromoteStatic)
self.attributes.get(ir::NumAttr::Promotable).or_else(|| {
self.group.borrow().attributes.get(ir::NumAttr::Promotable)
})
}
}

impl WithStatic for ir::Invoke {
type Info = CompTime;
fn compute_static(&mut self, extra: &Self::Info) -> Option<u64> {
self.attributes.get(ir::NumAttr::PromoteStatic).or_else(|| {
self.attributes.get(ir::NumAttr::Promotable).or_else(|| {
let comp = self.comp.borrow().type_name()?;
extra.get(&comp).cloned()
})
Expand Down
46 changes: 32 additions & 14 deletions calyx-opt/src/analysis/inference_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ impl From<&ir::Primitive> for GoDone {
let go_ports = prim
.find_all_with_attr(ir::NumAttr::Go)
.filter_map(|pd| {
pd.attributes.get(ir::NumAttr::Static).and_then(|st| {
// Primitives only have @interval.
pd.attributes.get(ir::NumAttr::Interval).and_then(|st| {
done_ports
.get(&pd.attributes.get(ir::NumAttr::Go))
.map(|done_port| (pd.name(), *done_port, st))
Expand All @@ -96,11 +97,19 @@ impl From<&ir::Cell> for GoDone {
.find_all_with_attr(ir::NumAttr::Go)
.filter_map(|pr| {
let port = pr.borrow();
port.attributes.get(ir::NumAttr::Static).and_then(|st| {
done_ports
// Get static interval thru either @interval or @promotable.
let st = match port.attributes.get(ir::NumAttr::Interval) {
Some(st) => Some(st),
None => port.attributes.get(ir::NumAttr::Promotable),
};
if let Some(static_latency) = st {
return done_ports
.get(&port.attributes.get(ir::NumAttr::Go))
.map(|done_port| (port.name, *done_port, st))
})
.map(|done_port| {
(port.name, *done_port, static_latency)
});
}
None
})
.collect_vec();
GoDone::new(go_ports)
Expand Down Expand Up @@ -151,11 +160,20 @@ impl InferenceAnalysis {
.find_all_with_attr(ir::NumAttr::Go)
.filter_map(|pd| {
let pd_ref = pd.borrow();
pd_ref.attributes.get(ir::NumAttr::Static).and_then(|st| {
done_ports
// Get static interval thru either @interval or @promotable.
let st = match pd_ref.attributes.get(ir::NumAttr::Interval)
{
Some(st) => Some(st),
None => pd_ref.attributes.get(ir::NumAttr::Promotable),
};
if let Some(static_latency) = st {
return done_ports
.get(&pd_ref.attributes.get(ir::NumAttr::Go))
.map(|done_port| (pd_ref.name, *done_port, st))
})
.map(|done_port| {
(pd_ref.name, *done_port, static_latency)
});
}
None
})
.collect_vec();

Expand Down Expand Up @@ -442,21 +460,21 @@ impl InferenceAnalysis {
pub fn get_possible_latency(c: &ir::Control) -> Option<u64> {
match c {
ir::Control::Static(sc) => Some(sc.get_latency()),
_ => c.get_attribute(ir::NumAttr::PromoteStatic),
_ => c.get_attribute(ir::NumAttr::Promotable),
}
}

pub fn remove_promotable_from_seq(seq: &mut ir::Seq) {
for stmt in &mut seq.stmts {
Self::remove_promotable_attribute(stmt);
}
seq.get_mut_attributes().remove(ir::NumAttr::PromoteStatic);
seq.get_mut_attributes().remove(ir::NumAttr::Promotable);
}

/// Removes the @promotable attribute from the control program.
/// Recursively visits the children of the control.
pub fn remove_promotable_attribute(c: &mut ir::Control) {
c.get_mut_attributes().remove(ir::NumAttr::PromoteStatic);
c.get_mut_attributes().remove(ir::NumAttr::Promotable);
match c {
ir::Control::Empty(_)
| ir::Control::Invoke(_)
Expand Down Expand Up @@ -512,7 +530,7 @@ impl InferenceAnalysis {
group
.borrow_mut()
.attributes
.remove(ir::NumAttr::PromoteStatic);
.remove(ir::NumAttr::Promotable);
}
}

Expand All @@ -523,7 +541,7 @@ impl InferenceAnalysis {
group
.borrow_mut()
.attributes
.insert(ir::NumAttr::PromoteStatic, latency);
.insert(ir::NumAttr::Promotable, latency);
}
}

Expand Down
Loading

0 comments on commit d94ce93

Please sign in to comment.