From 09fda4a82daa0ea864a5298cc1b0c348c6365b7b Mon Sep 17 00:00:00 2001 From: Russel Arbore <russel.jma@gmail.com> Date: Thu, 30 Jan 2025 10:38:10 -0600 Subject: [PATCH] fix a bunch of warnings --- hercules_opt/src/fork_guard_elim.rs | 8 +-- hercules_opt/src/fork_transforms.rs | 2 +- hercules_opt/src/forkify.rs | 47 ++++-------- hercules_opt/src/gcm.rs | 4 +- hercules_opt/src/ivar.rs | 72 +++++++++---------- hercules_opt/src/unforkify.rs | 11 ++- hercules_opt/src/utils.rs | 3 +- .../hercules_interpreter/src/interpreter.rs | 42 ++--------- hercules_test/hercules_interpreter/src/lib.rs | 11 +-- 9 files changed, 71 insertions(+), 129 deletions(-) diff --git a/hercules_opt/src/fork_guard_elim.rs b/hercules_opt/src/fork_guard_elim.rs index 9384a8c1..a375f809 100644 --- a/hercules_opt/src/fork_guard_elim.rs +++ b/hercules_opt/src/fork_guard_elim.rs @@ -22,14 +22,14 @@ use crate::*; // Simplify factors through max enum Factor { Max(usize, DynamicConstantID), - Normal(usize, DynamicConstantID), + Normal(DynamicConstantID), } impl Factor { fn get_id(&self) -> DynamicConstantID { match self { Factor::Max(_, dynamic_constant_id) => *dynamic_constant_id, - Factor::Normal(_, dynamic_constant_id) => *dynamic_constant_id, + Factor::Normal(dynamic_constant_id) => *dynamic_constant_id, } } } @@ -73,7 +73,7 @@ fn guarded_fork( let mut factors = factors.iter().enumerate().map(|(idx, dc)| { let DynamicConstant::Max(l, r) = *editor.get_dynamic_constant(*dc) else { - return Factor::Normal(idx, *dc); + return Factor::Normal(*dc); }; // There really needs to be a better way to work w/ associativity. @@ -87,7 +87,7 @@ fn guarded_fork( match id { Some(v) => Factor::Max(idx, *v), - None => Factor::Normal(idx, *dc), + None => Factor::Normal(*dc), } }); diff --git a/hercules_opt/src/fork_transforms.rs b/hercules_opt/src/fork_transforms.rs index 5a6d5ff2..b45de643 100644 --- a/hercules_opt/src/fork_transforms.rs +++ b/hercules_opt/src/fork_transforms.rs @@ -225,7 +225,7 @@ pub fn fork_bufferize_fission_helper<'a>( editor.edit(|mut edit| { new_join_id = edit.add_node(Node::Join { control: fork }); - let factors = edit.get_node(fork).try_fork().unwrap().1.clone(); + let factors = edit.get_node(fork).try_fork().unwrap().1; new_fork_id = edit.add_node(Node::Fork { control: new_join_id, factors: factors.into(), diff --git a/hercules_opt/src/forkify.rs b/hercules_opt/src/forkify.rs index fd4fc838..d99c15d7 100644 --- a/hercules_opt/src/forkify.rs +++ b/hercules_opt/src/forkify.rs @@ -101,23 +101,6 @@ pub fn get_node_as_dc( } } -fn all_same_variant<I, T>(mut iter: I) -> bool -where - I: Iterator<Item = T>, -{ - // Empty iterator case - return true - let first = match iter.next() { - None => return true, - Some(val) => val, - }; - - // Get discriminant of first item - let first_discriminant = std::mem::discriminant(&first); - - // Check all remaining items have same discriminant - iter.all(|x| std::mem::discriminant(&x) == first_discriminant) -} - /** Top level function to convert natural loops with simple induction variables into fork-joins. @@ -125,7 +108,7 @@ where pub fn forkify_loop( editor: &mut FunctionEditor, control_subgraph: &Subgraph, - fork_join_map: &HashMap<NodeID, NodeID>, + _fork_join_map: &HashMap<NodeID, NodeID>, l: &Loop, ) -> bool { let function = editor.func(); @@ -155,14 +138,14 @@ pub fn forkify_loop( // Get bound let bound = match canonical_iv { InductionVariable::Basic { - node, - initializer, - update, + node: _, + initializer: _, + update: _, final_value, } => final_value .map(|final_value| get_node_as_dc(editor, final_value)) .and_then(|r| r.ok()), - InductionVariable::SCEV(node_id) => return false, + InductionVariable::SCEV(_) => return false, }; let Some(bound_dc_id) = bound else { @@ -219,8 +202,6 @@ pub fn forkify_loop( .into_iter() .collect(); - let function = editor.func(); - // TODO: Handle multiple loop body lasts. // If there are multiple candidates for loop body last, return false. if editor @@ -245,10 +226,10 @@ pub fn forkify_loop( .iter() .map(|phi| { let LoopPHI::Reductionable { - phi, - data_cycle, + phi: _, + data_cycle: _, continue_latch, - is_associative, + is_associative: _, } = phi else { unreachable!() @@ -362,9 +343,9 @@ pub fn forkify_loop( for reduction_phi in reductionable_phis { let LoopPHI::Reductionable { phi, - data_cycle, + data_cycle: _, continue_latch, - is_associative, + is_associative: _, } = reduction_phi else { panic!(); @@ -398,11 +379,11 @@ pub fn forkify_loop( } // Replace all uses of the loop header with the fork - editor.edit(|mut edit| edit.replace_all_uses(l.header, fork_id)); + editor.edit(|edit| edit.replace_all_uses(l.header, fork_id)); - editor.edit(|mut edit| edit.replace_all_uses(loop_continue_projection, fork_id)); + editor.edit(|edit| edit.replace_all_uses(loop_continue_projection, fork_id)); - editor.edit(|mut edit| edit.replace_all_uses(loop_exit_projection, join_id)); + editor.edit(|edit| edit.replace_all_uses(loop_exit_projection, join_id)); // Get rid of loop condition // DCE should get these, but delete them ourselves because we are nice :) @@ -436,7 +417,7 @@ impl LoopPHI { pub fn get_phi(&self) -> NodeID { match self { LoopPHI::Reductionable { - phi, data_cycle, .. + phi, .. } => *phi, LoopPHI::LoopDependant(node_id) => *node_id, LoopPHI::UsedByDependant(node_id) => *node_id, diff --git a/hercules_opt/src/gcm.rs b/hercules_opt/src/gcm.rs index 0c7665bf..f919acc7 100644 --- a/hercules_opt/src/gcm.rs +++ b/hercules_opt/src/gcm.rs @@ -1022,7 +1022,7 @@ fn liveness_dataflow( * device clones when a single node may potentially be on different devices. */ fn color_nodes( - editor: &mut FunctionEditor, + _editor: &mut FunctionEditor, reverse_postorder: &Vec<NodeID>, objects: &FunctionCollectionObjects, object_device_demands: &FunctionObjectDeviceDemands, @@ -1138,7 +1138,7 @@ fn object_allocation( typing: &Vec<TypeID>, node_colors: &FunctionNodeColors, alignments: &Vec<usize>, - liveness: &Liveness, + _liveness: &Liveness, backing_allocations: &BackingAllocations, ) -> FunctionBackingAllocation { let mut fba = BTreeMap::new(); diff --git a/hercules_opt/src/ivar.rs b/hercules_opt/src/ivar.rs index 15f9416c..929f3a40 100644 --- a/hercules_opt/src/ivar.rs +++ b/hercules_opt/src/ivar.rs @@ -67,9 +67,9 @@ impl InductionVariable { match self { InductionVariable::Basic { node, - initializer, - update, - final_value, + initializer: _, + update: _, + final_value: _, } => *node, InductionVariable::SCEV(_) => todo!(), } @@ -85,7 +85,7 @@ pub fn calculate_loop_nodes(editor: &FunctionEditor, natural_loop: &Loop) -> Has let data = &editor.func().nodes[node.idx()]; // External Phi - if let Node::Phi { control, data } = data { + if let Node::Phi { control, data: _ } = data { if !natural_loop.control[control.idx()] { return true; } @@ -93,8 +93,8 @@ pub fn calculate_loop_nodes(editor: &FunctionEditor, natural_loop: &Loop) -> Has // External Reduce if let Node::Reduce { control, - init, - reduct, + init: _, + reduct: _, } = data { if !natural_loop.control[control.idx()] { @@ -114,7 +114,7 @@ pub fn calculate_loop_nodes(editor: &FunctionEditor, natural_loop: &Loop) -> Has let phis: Vec<_> = editor .node_ids() .filter(|node| { - let Node::Phi { control, ref data } = editor.func().nodes[node.idx()] else { + let Node::Phi { control, data: _ } = editor.func().nodes[node.idx()] else { return false; }; natural_loop.control[control.idx()] @@ -214,7 +214,7 @@ pub fn compute_loop_variance(editor: &FunctionEditor, l: &Loop) -> LoopVarianceI // Two conditions cause something to be loop variant: for node_use in get_uses(&function.nodes[node.idx()]).as_ref() { // 1) The use is a PHI *controlled* by the loop - if let Some((control, data)) = function.nodes[node_use.idx()].try_phi() { + if let Some((control, _)) = function.nodes[node_use.idx()].try_phi() { if *all_loop_nodes.get(control.idx()).unwrap() { node_variance = LoopVariance::Variant; break; @@ -325,7 +325,7 @@ pub fn get_loop_exit_conditions( pub fn has_const_fields(editor: &FunctionEditor, ivar: InductionVariable) -> bool { match ivar { InductionVariable::Basic { - node, + node: _, initializer, update, final_value, @@ -337,7 +337,7 @@ pub fn has_const_fields(editor: &FunctionEditor, ivar: InductionVariable) -> boo .iter() .any(|node| !editor.node(node).is_constant()) } - InductionVariable::SCEV(node_id) => false, + InductionVariable::SCEV(_) => false, } } @@ -345,12 +345,12 @@ pub fn has_const_fields(editor: &FunctionEditor, ivar: InductionVariable) -> boo // IVs need to be bounded... pub fn has_canonical_iv<'a>( editor: &FunctionEditor, - l: &Loop, + _l: &Loop, ivs: &'a [InductionVariable], ) -> Option<&'a InductionVariable> { ivs.iter().find(|iv| match iv { InductionVariable::Basic { - node, + node: _, initializer, update, final_value, @@ -371,7 +371,7 @@ pub fn has_canonical_iv<'a>( }) .is_some()) } - InductionVariable::SCEV(node_id) => false, + InductionVariable::SCEV(_) => false, }) } @@ -379,7 +379,7 @@ pub fn has_canonical_iv<'a>( pub fn compute_induction_vars( function: &Function, l: &Loop, - loop_variance: &LoopVarianceInfo, + _loop_variance: &LoopVarianceInfo, ) -> Vec<InductionVariable> { // 1) Gather PHIs contained in the loop. // FIXME: (@xrouth) Should this just be PHIs controlled by the header? @@ -478,12 +478,12 @@ pub fn compute_iv_ranges( induction_vars: Vec<InductionVariable>, loop_condition: &LoopExit, ) -> Vec<InductionVariable> { - let (if_node, condition_node) = match loop_condition { + let condition_node = match loop_condition { LoopExit::Conditional { - if_node, + if_node: _, condition_node, - } => (if_node, condition_node), - LoopExit::Unconditional(node_id) => todo!(), + } => condition_node, + LoopExit::Unconditional(_) => todo!(), }; // Find IVs used by the loop condition, not across loop iterations. @@ -491,7 +491,7 @@ pub fn compute_iv_ranges( let stop_on: HashSet<_> = editor .node_ids() .filter(|node_id| { - if let Node::Phi { control, data } = editor.node(node_id) { + if let Node::Phi { control, data: _ } = editor.node(node_id) { *control == l.header } else { false @@ -517,20 +517,20 @@ pub fn compute_iv_ranges( // FIXME: DO linear algerbra to solve for loop bounds with multiple variables involved. let final_value = match &editor.func().nodes[condition_node.idx()] { - Node::Phi { control, data } => None, + Node::Phi { control: _, data: _ } => None, Node::Reduce { - control, - init, - reduct, + control: _, + init: _, + reduct: _, } => None, - Node::Parameter { index } => None, - Node::Constant { id } => None, - Node::Unary { input, op } => None, + Node::Parameter { index: _ } => None, + Node::Constant { id: _ } => None, + Node::Unary { input: _, op: _ } => None, Node::Ternary { - first, - second, - third, - op, + first: _, + second: _, + third: _, + op: _, } => None, Node::Binary { left, right, op } => { match op { @@ -547,7 +547,7 @@ pub fn compute_iv_ranges( else if let Node::Binary { left: inner_left, right: inner_right, - op: inner_op, + op: _, } = editor.node(left) { let pattern = [(inner_left, inner_right), (inner_right, inner_left)] @@ -560,12 +560,12 @@ pub fn compute_iv_ranges( // FIXME: pattern_constant can be anything >= loop_update expression, let update = match iv { InductionVariable::Basic { - node, - initializer, + node: _, + initializer: _, update, - final_value, + final_value: _, } => update, - InductionVariable::SCEV(node_id) => todo!(), + InductionVariable::SCEV(_) => todo!(), }; if *pattern_constant == update { Some(*right) @@ -604,7 +604,7 @@ pub fn compute_iv_ranges( update: *update, final_value, }, - InductionVariable::SCEV(node_id) => todo!(), + InductionVariable::SCEV(_) => todo!(), }; // Propagate bounds to other IVs. diff --git a/hercules_opt/src/unforkify.rs b/hercules_opt/src/unforkify.rs index 0efd0b85..85ffd233 100644 --- a/hercules_opt/src/unforkify.rs +++ b/hercules_opt/src/unforkify.rs @@ -11,7 +11,6 @@ pub fn calculate_fork_nodes( editor: &FunctionEditor, inner_control: &NodeVec, fork: NodeID, - join: NodeID, ) -> HashSet<NodeID> { // Stop on PHIs / reduces outside of loop. let stop_on: HashSet<NodeID> = editor @@ -20,7 +19,7 @@ pub fn calculate_fork_nodes( let data = &editor.func().nodes[node.idx()]; // External Phi - if let Node::Phi { control, data } = data { + if let Node::Phi { control, data: _ } = data { if match inner_control.get(control.idx()) { Some(v) => !*v, // None => true, // Doesn't exist, must be external @@ -31,8 +30,8 @@ pub fn calculate_fork_nodes( // External Reduce if let Node::Reduce { control, - init, - reduct, + init: _, + reduct: _, } = data { if match inner_control.get(control.idx()) { @@ -127,7 +126,7 @@ pub fn unforkify( let fork = &l.0; let join = &fork_join_map[&fork]; - let fork_nodes = calculate_fork_nodes(editor, l.1, *fork, *join); + let fork_nodes = calculate_fork_nodes(editor, l.1, *fork); let nodes = &editor.func().nodes; let (fork_control, factors) = nodes[fork.idx()].try_fork().unwrap(); @@ -274,7 +273,7 @@ pub fn unforkify( zip(reduces.iter(), phi_ids).zip(phis).zip(join_phi_ids) { edit.sub_edit(*reduce, phi_id); - let Node::Phi { control, data } = phi else { + let Node::Phi { control: _, data } = phi else { panic!() }; edit = edit.replace_all_uses_where(*reduce, join_phi_id, |usee| { diff --git a/hercules_opt/src/utils.rs b/hercules_opt/src/utils.rs index cc7abc7f..7ad48c1c 100644 --- a/hercules_opt/src/utils.rs +++ b/hercules_opt/src/utils.rs @@ -384,13 +384,12 @@ pub type DenseNodeMap<T> = Vec<T>; pub type SparseNodeMap<T> = HashMap<NodeID, T>; nest! { -// Is this something editor should give... Or is it just for analyses. // #[derive(Clone, Debug)] pub struct NodeIterator<'a> { pub direction: #[derive(Clone, Debug, PartialEq)] - enum Direction { + pub enum Direction { Uses, Users, }, diff --git a/hercules_test/hercules_interpreter/src/interpreter.rs b/hercules_test/hercules_interpreter/src/interpreter.rs index 730f6216..a78330e4 100644 --- a/hercules_test/hercules_interpreter/src/interpreter.rs +++ b/hercules_test/hercules_interpreter/src/interpreter.rs @@ -253,8 +253,6 @@ impl<'a> FunctionExecutionState<'a> { } let thread_values = self.get_thread_factors(&token, join); - // println!("join for: {:?}", token); - // dbg!(thread_values.clone()); // This and_modify doesn't do aynthing?? self.join_counters .entry((thread_values.clone(), join)) @@ -365,8 +363,6 @@ impl<'a> FunctionExecutionState<'a> { } pub fn handle_data(&mut self, token: &ControlToken, node: NodeID) -> InterpreterVal { - // println!("Data Node: {} {:?}", node.idx(), &self.get_function().nodes[node.idx()]); - // Partial borrow complaint. :/ match &self.module.functions[self.function_id.idx()].nodes[node.idx()] { Node::Phi { @@ -386,14 +382,6 @@ impl<'a> FunctionExecutionState<'a> { .expect("PANIC: No nesting information for thread index!") .clone(); - let num_dims_this_level = (self.get_function().nodes - [nested_forks.first().unwrap().idx()] - .try_fork() - .unwrap() - .1 - .len()); - // println!("num forks this level:{:?} ", num_forks_this_level); - // Skip forks until we get to this level. // How many forks are outer? idfk. let outer_forks: Vec<NodeID> = nested_forks @@ -402,8 +390,6 @@ impl<'a> FunctionExecutionState<'a> { .take_while(|fork| *fork != node) .collect(); - // println!("otuer_forkes: {:?}", outer_forks); - let fork_levels: usize = outer_forks .iter() .skip(1) @@ -416,9 +402,7 @@ impl<'a> FunctionExecutionState<'a> { }) .sum(); - // println!("nested forks:{:?} ", nested_forks); - // println!("fork levels: {:?}", fork_levels); - // dimension might need to instead be dimensions - dimension + // Dimension might need to instead be dimensions - dimension let v = token.thread_indicies[fork_levels + dimension]; // Might have to -1? if VERBOSE { println!( @@ -432,12 +416,11 @@ impl<'a> FunctionExecutionState<'a> { // This probably isn't the exact condition, but somethign similar. Anyways, we achieve correctness by iterating control nodes recursively. Node::Reduce { control, - init, + init: _, reduct: _, } => { let thread_values = self.get_thread_factors(token, *control); - // println!("reduction read: {:?}, {:?}", thread_values, node); let entry = self.reduce_values.entry((thread_values.clone(), node)); let val = match entry { @@ -447,7 +430,6 @@ impl<'a> FunctionExecutionState<'a> { token, node, thread_values ), }; - // println!("value: {:?}", val.clone()); val } Node::Parameter { index } => self.args[*index].clone(), @@ -502,12 +484,11 @@ impl<'a> FunctionExecutionState<'a> { } } Node::Call { + control: _, function, dynamic_constants, args, - control, } => { - // todo!("call currently dissabled lol"); let args = args .into_iter() .map(|arg_node| self.handle_data(token, *arg_node)) @@ -536,7 +517,7 @@ impl<'a> FunctionExecutionState<'a> { } Node::Read { collect, indices } => { let collection = self.handle_data(token, *collect); - if let InterpreterVal::Undef(v) = collection { + if let InterpreterVal::Undef(_) = collection { collection } else { let result = self.handle_read(token, collection.clone(), indices); @@ -556,7 +537,7 @@ impl<'a> FunctionExecutionState<'a> { indices, } => { let collection = self.handle_data(token, *collect); - if let InterpreterVal::Undef(v) = collection { + if let InterpreterVal::Undef(_) = collection { collection } else { let data = self.handle_data(token, *data); @@ -610,7 +591,6 @@ impl<'a> FunctionExecutionState<'a> { }) .collect(); let idx = InterpreterVal::array_idx(&extents, &array_indices); - //println!("idx: {:?}", idx); if idx >= vals.len() { InterpreterVal::Undef(type_id) } else { @@ -702,12 +682,6 @@ impl<'a> FunctionExecutionState<'a> { .pop() .expect("PANIC: Interpreter ran out of control tokens without returning."); - // println!( - // "\n\nNew Token at: Control State: {} threads: {:?}, {:?}", - // ctrl_token.curr.idx(), - // ctrl_token.thread_indicies.clone(), - // &self.get_function().nodes[ctrl_token.curr.idx()] - // ); // TODO: (@xrouth): Enable this + PHI latch logging wi/ a simple debug flag. // Tracking PHI vals and control state is very useful for debugging. @@ -747,7 +721,7 @@ impl<'a> FunctionExecutionState<'a> { // Convert condition to usize let cond: usize = match cond { InterpreterVal::Boolean(v) => v.into(), - InterpreterVal::Undef(v) => panic!("PANIC: Undef reached IF"), + InterpreterVal::Undef(_) => panic!("PANIC: Undef reached IF"), _ => panic!("PANIC: Invalid condition for IF, please typecheck."), }; @@ -820,7 +794,7 @@ impl<'a> FunctionExecutionState<'a> { let mut temp = i; let mut new_token = ctrl_token.clone(); // Copy map, curr, prev, etc. - for (j, dim) in factors.clone().enumerate().rev() { + for (_, dim) in factors.clone().enumerate().rev() { new_token.thread_indicies.insert(num_outer_dims, temp % dim); // Stack of thread indicies temp /= dim; } @@ -854,7 +828,6 @@ impl<'a> FunctionExecutionState<'a> { self.initialize_reduction(&ctrl_token, reduction); } - // println!("tokens_to_add: {:?}", tokens_to_add); if VERBOSE { println!( "tf, fork, join, n_tokens: {:?}, {:?}, {:?}, {:?}", @@ -878,7 +851,6 @@ impl<'a> FunctionExecutionState<'a> { } Node::Return { control: _, data } => { let result = self.handle_data(&ctrl_token, *data); - // println!("result = {:?}", result); break 'outer result; } _ => { diff --git a/hercules_test/hercules_interpreter/src/lib.rs b/hercules_test/hercules_interpreter/src/lib.rs index 3f12618c..75a974ec 100644 --- a/hercules_test/hercules_interpreter/src/lib.rs +++ b/hercules_test/hercules_interpreter/src/lib.rs @@ -8,7 +8,6 @@ use hercules_ir::Module; use hercules_ir::TypeID; use hercules_ir::ID; -use juno_scheduler::run_schedule_on_hercules; pub use juno_scheduler::PassManager; pub use crate::interpreter::*; @@ -37,10 +36,9 @@ pub fn into_interp_val( InterpreterWrapper::Array(array) => { let ty = &module.types[target_ty_id.idx()]; - let ele_type = ty + ty .try_element_type() .expect("PANIC: Invalid parameter type"); - // unwrap -> map to rust type, check let mut values = vec![]; @@ -53,13 +51,6 @@ pub fn into_interp_val( } } -pub fn array_from_interp_val<T: Clone>(module: &Module, interp_val: InterpreterVal) -> Vec<T> -where - value::InterpreterVal: Into<T>, -{ - vec![] -} - // Recursively turns rt args into interpreter wrappers. #[macro_export] macro_rules! parse_rt_args { -- GitLab