diff --git a/scripts/aby_tests/c_test_aby.py b/scripts/aby_tests/c_test_aby.py index 473d57bf..3a8d59d4 100755 --- a/scripts/aby_tests/c_test_aby.py +++ b/scripts/aby_tests/c_test_aby.py @@ -31,7 +31,7 @@ if __name__ == "__main__": cryptonets_tests + \ histogram_tests - tests = histogram_tests + tests = biomatch_tests # TODO: add support unsigned + int promotion # unsigned_arithmetic_tests + \ diff --git a/scripts/build_mpc_c_test.zsh b/scripts/build_mpc_c_test.zsh index edab8b8a..c8ab8837 100755 --- a/scripts/build_mpc_c_test.zsh +++ b/scripts/build_mpc_c_test.zsh @@ -36,10 +36,7 @@ function mpc_test_bool { RUST_BACKTRACE=1 measure_time $BIN --parties $parties $cpath mpc --cost-model "hycc" --selection-scheme "b" } - -mpc_test 2 ./examples/C/mpc/benchmarks/histogram/histogram.c - -# mpc_test 2 ./examples/C/mpc/playground.c +mpc_test 2 ./examples/C/mpc/playground.c # # build mpc arithmetic tests # mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_add.c @@ -131,6 +128,10 @@ mpc_test 2 ./examples/C/mpc/benchmarks/histogram/histogram.c # mpc_test 2 ./examples/C/mpc/benchmarks/mnist/mnist.c # mpc_test 2 ./examples/C/mpc/benchmarks/cryptonets/cryptonets.c +# # build OPA benchmarks +# mpc_test 2 ./examples/C/mpc/benchmarks/histogram/histogram.c + + # # build hycc benchmarks bool-only # mpc_test_bool 2 ./examples/C/mpc/benchmarks/biomatch/2pc_biomatch.c diff --git a/src/ir/term/mod.rs b/src/ir/term/mod.rs index 4afef552..f49971fd 100644 --- a/src/ir/term/mod.rs +++ b/src/ir/term/mod.rs @@ -319,6 +319,18 @@ impl Display for Op { } } +impl Ord for Op { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.cmp(&other) + } +} + +impl PartialOrd for Op { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + #[derive(Clone, PartialEq, Eq, Hash, Debug)] /// Boolean n-ary operator pub enum BoolNaryOp { @@ -2001,17 +2013,6 @@ impl Computation { } } -// #[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] -// /// A function definition. -// pub struct FuncDef { -// /// Name of function -// pub name: String, -// /// Type signature of function parameters -// pub params: BTreeMap, -// /// Return type of function -// pub ret_ty: Vec, -// } - #[derive(Clone, Debug, Default, PartialEq)] /// A map of IR computations. pub struct Functions { diff --git a/src/target/aby/call_site_similarity.rs b/src/target/aby/call_site_similarity.rs index c3542bcf..652a7c61 100644 --- a/src/target/aby/call_site_similarity.rs +++ b/src/target/aby/call_site_similarity.rs @@ -5,7 +5,7 @@ use crate::ir::term::*; use std::collections::HashMap; /// Determine if call sites are similar based on input and output arguments to the call site -pub fn call_site_similarity(fs: &Functions) { +pub fn call_site_similarity(fs: &Functions) -> Vec> { // Return a TermMap of (call) --> id for which calls are similar // Maybe return a vector of vector of terms @@ -61,21 +61,24 @@ pub fn call_site_similarity(fs: &Functions) { // Clean input and output terms let mut call_sites: HashMap<(Vec, Vec), Vec> = HashMap::new(); - for (c, (i, o)) in call_term_map { - println!("function: {}", c); - println!( - "inputs: {:?}", - i.iter().map(|x| x.op.clone()).collect::>() - ); - println!( - "outputs: {:?}\n", - o.iter().map(|x| x.op.clone()).collect::>() - ); + let input_ops = i.iter().map(|x| x.op.clone()).collect::>(); + let mut output_ops = o.iter().map(|x| x.op.clone()).collect::>(); + output_ops.sort(); + + let key = (input_ops, output_ops); + + // longest prefix matching? + + // edit distance? + + if call_sites.contains_key(&key) { + call_sites.get_mut(&key).unwrap().push(c); + } else { + call_sites.insert(key, vec![c]); + } } - todo!(); - - // return call_sites values + return call_sites.into_values().collect::>(); } diff --git a/src/target/aby/trans.rs b/src/target/aby/trans.rs index 69455a05..ce8f5c04 100644 --- a/src/target/aby/trans.rs +++ b/src/target/aby/trans.rs @@ -1126,7 +1126,7 @@ impl<'a> ToABY<'a> { /// Convert this (IR) `ir` to ABY. pub fn to_aby(ir: Functions, path: &Path, lang: &str, cm: &str, ss: &str) { // Call site similarity - // call_site_similarity(&ir); + call_site_similarity(&ir); // Protocal Assignments let mut s_map: HashMap = HashMap::new();