Skip to content
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

Deprecate @static #1897

Merged
merged 50 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
1f0a440
replace static w// interval
calebmkim Feb 1, 2024
9efacdb
change primitives to @interval
calebmkim Feb 1, 2024
35b8f75
modified tests
calebmkim Feb 1, 2024
64fc03b
promte_static -> promotable
calebmkim Feb 1, 2024
dd80790
get rid of static
calebmkim Feb 1, 2024
3692bba
remove attribute_promotion
calebmkim Feb 1, 2024
db60b08
py frontend uses promotable
calebmkim Feb 1, 2024
e01afb1
rewrite exp tests
calebmkim Feb 1, 2024
58295fa
corrected some tests
calebmkim Feb 1, 2024
17b360a
overwrite tests
calebmkim Feb 1, 2024
40f79d6
overwrite failing tests
calebmkim Feb 2, 2024
4cf6e2a
change interface
calebmkim Feb 3, 2024
ae4156c
add tests
calebmkim Feb 3, 2024
8d28998
add well formed check
calebmkim Feb 3, 2024
228df7c
change compile_invoke
calebmkim Feb 3, 2024
0738571
add tests
calebmkim Feb 3, 2024
ff8950a
compile invoke test
calebmkim Feb 3, 2024
5e0bb81
change iterface
calebmkim Feb 3, 2024
f076408
adjustments
calebmkim Feb 3, 2024
7bf4aad
fix borrow error
calebmkim Feb 5, 2024
2da54f2
clippy
calebmkim Feb 5, 2024
4bd899c
move files
calebmkim Feb 5, 2024
f28dfd7
fix test
calebmkim Feb 5, 2024
256fe2d
rewrite mlir test
calebmkim Feb 5, 2024
66f9248
always promote @interval
calebmkim Feb 5, 2024
0c494f4
interp tests
calebmkim Feb 5, 2024
a3beb56
documentation
calebmkim Feb 7, 2024
510e124
resolve merge conflicts
calebmkim Feb 7, 2024
67547a0
dummy change
calebmkim Feb 7, 2024
1f42f8e
static->interval
calebmkim Feb 7, 2024
3dbbbda
update tests
calebmkim Feb 7, 2024
77bc3ce
add documentation to compile-static-interface
calebmkim Feb 8, 2024
13764c5
well formed check'
calebmkim Feb 8, 2024
7eed376
small change
calebmkim Feb 8, 2024
3cb17fb
done
calebmkim Feb 8, 2024
0d6c615
tests
calebmkim Feb 8, 2024
c418887
rewrite test
calebmkim Feb 8, 2024
20492cb
dummy change
calebmkim Feb 8, 2024
d706cfe
github workflow
calebmkim Feb 8, 2024
fdbbb28
docker file checks out main
calebmkim Feb 8, 2024
0348ead
checkout master
calebmkim Feb 8, 2024
b3238c0
checkout specific version
calebmkim Feb 8, 2024
70f544c
go back to og dockerfile
calebmkim Feb 8, 2024
4bcabbf
checkout specific commit
calebmkim Feb 9, 2024
9305b44
does this work
calebmkim Feb 9, 2024
0fac42a
still not working
calebmkim Feb 9, 2024
7aa782a
dummy change so non-merge commit
calebmkim Feb 9, 2024
6324ef4
chatgpt no cache
calebmkim Feb 9, 2024
f83d03c
does this change things
calebmkim Feb 9, 2024
9a96808
modify relay tests
calebmkim Feb 9, 2024
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
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
Loading