From 3347bca5ceb07cc7c6896a93997914d037e19ece Mon Sep 17 00:00:00 2001 From: Edward Chen Date: Tue, 26 Jul 2022 18:19:30 -0400 Subject: [PATCH] minor --- .../C/mpc/benchmarks/cryptonets/cryptonets.c | 8 ++-- examples/C/mpc/playground.c | 37 ++----------------- scripts/aby_tests/c_test_aby.py | 2 + scripts/aby_tests/test_suite.py | 6 +-- scripts/build_mpc_c_test.zsh | 4 +- src/target/aby/trans.rs | 9 ++--- 6 files changed, 18 insertions(+), 48 deletions(-) diff --git a/examples/C/mpc/benchmarks/cryptonets/cryptonets.c b/examples/C/mpc/benchmarks/cryptonets/cryptonets.c index 70977969..a5b32d9c 100644 --- a/examples/C/mpc/benchmarks/cryptonets/cryptonets.c +++ b/examples/C/mpc/benchmarks/cryptonets/cryptonets.c @@ -161,7 +161,6 @@ typedef struct DT final_layer[FINAL_OUTPUT_CHANNELS]; } Output; - DT mmulT_unrolled_inner_2(DT* a, DT* b) { DT sum = 0; // int i = 0; @@ -176,7 +175,6 @@ DT mmulT_unrolled_inner_2(DT* a, DT* b) { // for(i=0; i < OUTPUT_CHANNELS * SIZE_CONVOLUTION; i++) { // sum += a[i] * b[i]; // } - for(int k = 0; k < FULLY_CONNECTED_WIDTH; k++) { sum += a[k] * b[k]; } @@ -318,8 +316,7 @@ Output main( // Convolution (1) DT convolution_layer[OUTPUT_CHANNELS * SIZE_CONVOLUTION]; convolution_naive_outputs_1(convolution_input, INPUT_B.kernelsL1, convolution_layer); - - + // Activation Function (2) for(int i = 0; i < OUTPUT_CHANNELS * SIZE_CONVOLUTION; i++) { convolution_layer[i] = activate_sqr(convolution_layer[i]); @@ -330,7 +327,6 @@ Output main( // mmulT_unrolled(INPUT_B.pool_layer, convolution_layer, im_layer, FULLY_CONNECTED_WIDTH, 1, OUTPUT_CHANNELS * SIZE_CONVOLUTION); mmulT_unrolled_1(INPUT_B.pool_layer, convolution_layer, im_layer); - // Activation Function (4) for(int i = 0; i < FULLY_CONNECTED_WIDTH; i++) { im_layer[i] = activate_sqr(im_layer[i]); @@ -348,3 +344,5 @@ Output main( return OUTPUT_classify; } + + diff --git a/examples/C/mpc/playground.c b/examples/C/mpc/playground.c index caa91676..91aca50a 100644 --- a/examples/C/mpc/playground.c +++ b/examples/C/mpc/playground.c @@ -1,37 +1,6 @@ -#define LEN 32 -#define NUM_REVIEWERS 1 -#define NUM_RATINGS 1 -#define INTERVALS 2 -#define NUM_BUCKETS (INTERVALS * 5) - 1 -#define TOTAL_REV (NUM_REVIEWERS * NUM_RATINGS) - - -int main(__attribute__((private(0))) int reviews[TOTAL_REV], __attribute__((private(1))) int offset) -{ - int result[NUM_BUCKETS]; - - for (int i = 0; i < NUM_REVIEWERS; i++) { - int sum = 0; - for (int j = 0; j < NUM_RATINGS; j++) { - sum = sum + reviews[i*NUM_RATINGS + j]; - } - int bucket = sum; - for (int j = 0; j < NUM_BUCKETS; j++) { - int temp; - if (j == bucket) { - temp = result[j] + 1; - } - else { - temp = result[j]; - } - result[j] = temp; - } - } - int sum_all = offset; - for(int i = 0; i < NUM_BUCKETS; i++){ - sum_all += result[i]; - } - return sum_all; +int main(__attribute__((private(0))) int a, __attribute__((private(1))) int b) { + int c = a * b; + return c + a; } diff --git a/scripts/aby_tests/c_test_aby.py b/scripts/aby_tests/c_test_aby.py index e2c6c6fb..7f8f04b3 100755 --- a/scripts/aby_tests/c_test_aby.py +++ b/scripts/aby_tests/c_test_aby.py @@ -31,6 +31,8 @@ if __name__ == "__main__": cryptonets_tests + \ histogram_tests + tests = ts + # TODO: add support unsigned + int promotion # unsigned_arithmetic_tests + \ diff --git a/scripts/aby_tests/test_suite.py b/scripts/aby_tests/test_suite.py index 1ab84347..e86669e9 100644 --- a/scripts/aby_tests/test_suite.py +++ b/scripts/aby_tests/test_suite.py @@ -1,8 +1,8 @@ ts = [ [ - "Array index test", - "2pc_array_index", - "./scripts/aby_tests/test_inputs/add.txt", + "Multiply two numbers - 1", + "2pc_mult", + "./scripts/aby_tests/test_inputs/mult_1.txt", ], ] diff --git a/scripts/build_mpc_c_test.zsh b/scripts/build_mpc_c_test.zsh index 178e51fa..d1e85e35 100755 --- a/scripts/build_mpc_c_test.zsh +++ b/scripts/build_mpc_c_test.zsh @@ -37,6 +37,8 @@ function mpc_test_bool { } # mpc_test 2 ./examples/C/mpc/playground.c +# mpc_test 2 ./examples/C/mpc/benchmarks/cryptonets/cryptonets.c +mpc_test_2 2 ./examples/C/mpc/benchmarks/histogram/histogram.c # # build mpc arithmetic tests # mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_add.c @@ -126,7 +128,7 @@ function mpc_test_bool { # mpc_test 2 ./examples/C/mpc/benchmarks/db/db_join2.c # mpc_test 2 ./examples/C/mpc/benchmarks/db/db_merge.c # mpc_test 2 ./examples/C/mpc/benchmarks/mnist/mnist.c -mpc_test 2 ./examples/C/mpc/benchmarks/cryptonets/cryptonets.c +# mpc_test 2 ./examples/C/mpc/benchmarks/cryptonets/cryptonets.c # # build OPA benchmarks # mpc_test_2 2 ./examples/C/mpc/benchmarks/histogram/histogram.c diff --git a/src/target/aby/trans.rs b/src/target/aby/trans.rs index 5cadfe44..8379ccc5 100644 --- a/src/target/aby/trans.rs +++ b/src/target/aby/trans.rs @@ -555,7 +555,7 @@ impl<'a> ToABY<'a> { } } - fn embed_nonscalar(&mut self, t: Term) { + fn embed_vector(&mut self, t: Term) { match &t.op { Op::Const(Value::Array(arr)) => { let mut shares: Vec = Vec::new(); @@ -667,6 +667,7 @@ impl<'a> ToABY<'a> { Op::Field(i) => { assert!(t.cs.len() == 1); let shares = self.get_shares(&t.cs[0]); + let tuple_sort = check(&t.cs[0]); let (offset, len) = match tuple_sort { Sort::Tuple(t) => { @@ -717,8 +718,6 @@ impl<'a> ToABY<'a> { let op = format!("CALL({})", name); let num_args: usize = arg_sorts.iter().map(|ret| self.get_sort_len(ret)).sum(); let num_rets: usize = ret_sorts.iter().map(|ret| self.get_sort_len(ret)).sum(); - // map argument shares - // define rewireable shares with "r" let mut arg_shares: Vec = Vec::new(); for c in t.cs.iter() { let sort = check(c); @@ -753,7 +752,7 @@ impl<'a> ToABY<'a> { self.bytecode_output.push(line); } _ => { - panic!("Non-field in embed_nonscalar: {}", t.op) + panic!("Non-field in embed_vector: {}", t.op) } } } @@ -772,7 +771,7 @@ impl<'a> ToABY<'a> { self.embed_bv(c); } Sort::Array(..) | Sort::Tuple(_) => { - self.embed_nonscalar(c); + self.embed_vector(c); } e => panic!("Unsupported sort in embed: {:?}", e), }