From 6f161d1e06f48be09841d17ce0eddfd6c0f80bc7 Mon Sep 17 00:00:00 2001 From: Xavier Routh <xrouth2@illinois.edu> Date: Fri, 28 Feb 2025 16:40:22 -0600 Subject: [PATCH] canon + forkify fix --- hercules_opt/src/forkify.rs | 21 ++++++++++++++++----- hercules_opt/src/loop_bound_canon.rs | 8 ++++---- juno_samples/rodinia/backprop/src/cpu.sch | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/hercules_opt/src/forkify.rs b/hercules_opt/src/forkify.rs index a6308d66..40fda1ad 100644 --- a/hercules_opt/src/forkify.rs +++ b/hercules_opt/src/forkify.rs @@ -95,6 +95,8 @@ pub fn forkify_loop( ) -> bool { let function = editor.func(); + println!("forkifying {:?}", l.header); + let Some(loop_condition) = get_loop_exit_conditions(function, l, control_subgraph) else { return false; }; @@ -106,12 +108,13 @@ pub fn forkify_loop( else { return false; }; - + // Compute loop variance let loop_variance = compute_loop_variance(editor, l); let ivs = compute_induction_vars(editor.func(), l, &loop_variance); let ivs = compute_iv_ranges(editor, l, ivs, &loop_condition); let Some(canonical_iv) = has_canonical_iv(editor, l, &ivs) else { + println!("no canonical iv"); return false; }; @@ -130,6 +133,7 @@ pub fn forkify_loop( }; let Some(bound_dc_id) = bound else { + println!("no bound iv"); return false; }; @@ -167,6 +171,8 @@ pub fn forkify_loop( return false; } + println!("this one"); + // Get all phis used outside of the loop, they need to be reductionable. // For now just assume all phis will be phis used outside of the loop, except for the canonical iv. // FIXME: We need a different definiton of `loop_nodes` to check for phis used outside hte loop than the one @@ -196,6 +202,9 @@ pub fn forkify_loop( let loop_body_last = editor.get_uses(loop_if).next().unwrap(); + + println!("phis {:?}", reductionable_phis); + if reductionable_phis .iter() .any(|phi| !matches!(phi, LoopPHI::Reductionable { .. })) @@ -403,6 +412,7 @@ pub fn forkify_loop( Ok(edit) }); + println!("result: {:?}", result); return result; } @@ -530,10 +540,11 @@ pub fn analyze_phis<'a>( let intersection: HashSet<_> = set1.intersection(&set2).cloned().collect(); // If this phi uses any other phis the node is loop dependant, - // we use `phis` because this phi can actually contain the loop iv and its fine. - if uses_for_dependance.any(|node| phis.contains(&node) && node != *phi) { - LoopPHI::LoopDependant(*phi) - } else if intersection.clone().iter().next().is_some() { + // // we use `phis` because this phi can actually contain the loop iv and its fine. + // if uses_for_dependance.any(|node| phis.contains(&node) && node != *phi) { + // LoopPHI::LoopDependant(*phi) + // } else + if intersection.clone().iter().next().is_some() { // PHIs on the frontier of the uses by the candidate phi, i.e in uses_for_dependance need // to have headers that postdominate the loop continue latch. The value of the PHI used needs to be defined // by the time the reduce is triggered (at the end of the loop's internal control). diff --git a/hercules_opt/src/loop_bound_canon.rs b/hercules_opt/src/loop_bound_canon.rs index 126f33cf..203e45f8 100644 --- a/hercules_opt/src/loop_bound_canon.rs +++ b/hercules_opt/src/loop_bound_canon.rs @@ -73,7 +73,7 @@ pub fn canonicalize_single_loop_bounds( .into_iter() .partition(|f| loop_bound_iv_phis.contains(&f.phi())); - println!("{:?}", loop_bound_ivs); + // println!("{:?}", loop_bound_ivs); // Assume there is only one loop bound iv. @@ -248,9 +248,9 @@ pub fn canonicalize_single_loop_bounds( } else { None }; - println!("condition node: {:?}", condition_node); + // println!("condition node: {:?}", condition_node); let users = editor.get_users(condition_node).collect_vec(); - println!("{:?}", users); + // println!("{:?}", users); let mut condition_node = condition_node; @@ -280,7 +280,7 @@ pub fn canonicalize_single_loop_bounds( let new_binop_node = edit.add_node(Node::Binary { left, right: blah, op: BinaryOperator::LT }); edit = edit.replace_all_uses_where(binop_node, new_binop_node, |usee| *usee == if_node)?; - Some((init_id, bound_id, new_binop_node, if_node)) + Some((init_id, blah, new_binop_node, if_node)) } else {guard_info}; edit = edit.replace_all_uses_where(dc_bound_node, new_dc_bound_node, |usee| *usee == new_bop)?; diff --git a/juno_samples/rodinia/backprop/src/cpu.sch b/juno_samples/rodinia/backprop/src/cpu.sch index d1fe8953..43294807 100644 --- a/juno_samples/rodinia/backprop/src/cpu.sch +++ b/juno_samples/rodinia/backprop/src/cpu.sch @@ -17,6 +17,7 @@ lift-dc-math(*); loop-bound-canon(*); dce(*); lift-dc-math(*); + fixpoint { forkify(*); fork-guard-elim(*); -- GitLab