From 3fc941eae90e262db01b1994da4fcc1fb804c532 Mon Sep 17 00:00:00 2001 From: UnsignedByte Date: Thu, 17 Oct 2024 19:55:35 +0000 Subject: [PATCH] fix bugs and get working scheduling --- crates/filament/src/ir_passes/lower/utils.rs | 1 - .../filament/src/ir_passes/schedule/retime.rs | 11 ++++- .../filament/src/ir_passes/schedule/solve.rs | 19 +++++--- tests/run/schedule.expect | 1 + tests/run/schedule.fil | 44 +++++++++++++++++++ tests/run/schedule.fil.data | 12 +++++ 6 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 tests/run/schedule.expect create mode 100644 tests/run/schedule.fil create mode 100644 tests/run/schedule.fil.data diff --git a/crates/filament/src/ir_passes/lower/utils.rs b/crates/filament/src/ir_passes/lower/utils.rs index 2bd0a9b6..75b01b48 100644 --- a/crates/filament/src/ir_passes/lower/utils.rs +++ b/crates/filament/src/ir_passes/lower/utils.rs @@ -70,7 +70,6 @@ impl NameGenerator { /// Returns the name of an [ir::Param]. pub fn param_name(&self, idx: ParamIdx, comp: &Component) -> String { - println!("Getting param name for {}", comp.display(idx)); comp.src_info .as_ref() .map(|src| src.params.get(idx).to_string()) diff --git a/crates/filament/src/ir_passes/schedule/retime.rs b/crates/filament/src/ir_passes/schedule/retime.rs index 52042c7e..fa20c9f8 100644 --- a/crates/filament/src/ir_passes/schedule/retime.rs +++ b/crates/filament/src/ir_passes/schedule/retime.rs @@ -77,9 +77,15 @@ impl Retime { rhs: live, }); // Set up ports to the component + + // clk and reset ports are unannotated + comp.unannotated_ports = + Box::new(vec![("clk".into(), 1), ("reset".into(), 1)]); + + // input port let input = ir::Port { owner: ir::PortOwner::Sig { - dir: ir::Direction::In, + dir: ir::Direction::Out, }, width, live: ir::Liveness { @@ -110,9 +116,10 @@ impl Retime { comp.get_mut(input).live.idxs.push(input_param); src_info.ports.push(input, "in".into()); + // output port let output = ir::Port { owner: ir::PortOwner::Sig { - dir: ir::Direction::Out, + dir: ir::Direction::In, }, width, live: ir::Liveness { diff --git a/crates/filament/src/ir_passes/schedule/solve.rs b/crates/filament/src/ir_passes/schedule/solve.rs index c522a7e2..4c9c2b28 100644 --- a/crates/filament/src/ir_passes/schedule/solve.rs +++ b/crates/filament/src/ir_passes/schedule/solve.rs @@ -264,7 +264,7 @@ impl Visitor for Solve { } let model = self.sol.get_model().unwrap(); - println!("Model: {}", self.sol.display(model)); + log::trace!("Model solution: {}", self.sol.display(model)); let SExprData::List(bindings) = self.sol.get(model) else { unreachable!( @@ -332,8 +332,6 @@ impl Visitor for Solve { let time = *bindings.get(s).unwrap(); - println!("Invocation {} is scheduled at time {}", inv_idx, time); - let time = data.comp.add(ir::Expr::Concrete(time)); let time = data.comp.add(ir::Time { @@ -341,6 +339,12 @@ impl Visitor for Solve { offset: time, }); + log::debug!( + "Invocation {} scheduled at cycle {}", + data.comp.display(inv_idx), + data.comp.display(time) + ); + // Set the time of the invocation let inv = data.comp.get_mut(inv_idx); @@ -378,8 +382,6 @@ impl Visitor for Solve { let end = *bindings.get(s).unwrap(); - println!("Port {} is live from {} to {}", pidx, start, end); - let start = data.comp.add(ir::Expr::Concrete(start)); let end = data.comp.add(ir::Expr::Concrete(end)); @@ -390,6 +392,13 @@ impl Visitor for Solve { let end = data.comp.add(ir::Time { event, offset: end }); + log::debug!( + "Port {} scheduled to be live from [{}, {}]", + data.comp.display(pidx), + data.comp.display(start), + data.comp.display(end) + ); + let port = data.comp.get_mut(pidx); port.live.range = ir::Range { start, end }; diff --git a/tests/run/schedule.expect b/tests/run/schedule.expect new file mode 100644 index 00000000..e26d8af8 --- /dev/null +++ b/tests/run/schedule.expect @@ -0,0 +1 @@ +{"out0": {"0": [25], "1": [5], "2": [11]}, "out1": {"0": [25], "1": [5], "2": [11]}, "cycles": 13} \ No newline at end of file diff --git a/tests/run/schedule.fil b/tests/run/schedule.fil new file mode 100644 index 00000000..4a1ef492 --- /dev/null +++ b/tests/run/schedule.fil @@ -0,0 +1,44 @@ +import "primitives/core.fil"; + +comp DelayedAdd[W, D]<'G: 1>( + in0: ['G, 'G+1] W, + in1: ['G, 'G+1] W, +) -> ( + out: ['G+D, 'G+D+1] W +) where W > 0 +{ + sum := new Add[W]<'G>(in0, in1); + + delayed := new Shift[W, D]<'G>(sum.out); + + out = delayed.out; +} + +comp DelayedDup[W, D]<'G: 1>( + in: ['G, 'G+1] W, +) -> ( + out0: ['G+D, 'G+D+1] W, + out1: ['G+D, 'G+D+1] W +) where W > 0 +{ + delayed := new Shift[W, D]<'G>(in); + + out0 = delayed.out; + out1 = delayed.out; +} + +#[toplevel, schedule] +comp main<'G: 1>( + go: interface['G], + in0: ['G, 'G+1] 32, + in1: ['G, 'G+1] 32, +) -> ( + out0: ['G+10, 'G+11] 32, + out1: ['G+10, 'G+11] 32 +) + { + sum := new DelayedAdd[32, 1]<'G>(in0, in1); + dup := new DelayedDup[32, 1]<'G>(sum.out); + out0 = dup.out0; + out1 = dup.out1; +} \ No newline at end of file diff --git a/tests/run/schedule.fil.data b/tests/run/schedule.fil.data new file mode 100644 index 00000000..30f430f5 --- /dev/null +++ b/tests/run/schedule.fil.data @@ -0,0 +1,12 @@ +{ + "in0": [ + 10, + 2, + 5 + ], + "in1": [ + 15, + 3, + 6 + ] +} \ No newline at end of file