diff --git a/benchmark/test_benchmark_comparisons.py b/benchmark/test_benchmark_comparisons.py new file mode 100644 index 00000000..0f911303 --- /dev/null +++ b/benchmark/test_benchmark_comparisons.py @@ -0,0 +1,64 @@ +from pytest import mark + +from honeybadgermpc.progs.fixedpoint import FixedPoint +from honeybadgermpc.progs.mixins.share_arithmetic import ( + BeaverMultiply, + BeaverMultiplyArrays, + DivideShareArrays, + DivideShares, + InvertShare, + InvertShareArray, +) +from honeybadgermpc.progs.mixins.share_comparison import Equality + +MIXINS = [ + BeaverMultiply(), + BeaverMultiplyArrays(), + InvertShare(), + InvertShareArray(), + DivideShares(), + DivideShareArrays(), + Equality(), +] + +TEST_PREPROCESSING = ["rands", "triples", "zeros", "cubes", "bits"] + +ALL_BIT_NUMBERS = [int(f"0b{'1' * i}", 2) for i in [1, 64, 128, 256]] + +n, t = 4, 1 +k = 50000 +COUNT_MAX = 2 + + +def run_benchmark( + runner, prog, n=n, t=t, preprocessing=TEST_PREPROCESSING, k=k, mixins=MIXINS +): + runner(prog, n, t, preprocessing, k, mixins) + + +@mark.parametrize("comparator", ALL_BIT_NUMBERS) +def test_benchmark_fixedpoint_lt(benchmark_runner, comparator): + async def _prog(context): + base = FixedPoint( + context, + 6846412461894745224441235558443359243034138132682534265960483512729196124138, + ) + result = await base.lt(FixedPoint(context, comparator)) + await result.open() + + run_benchmark(benchmark_runner, _prog) + + +@mark.parametrize("comparator", ALL_BIT_NUMBERS) +def test_benchmark_share_eq(benchmark_runner, comparator): + equality = Equality() + + async def _prog(context): + base = context.Share( + 6846412461894745224441235558443359243034138132682534265960483512729196124138 + ) + comp = context.Share(comparator) + result = await equality(context, base, comp) + await result.open() + + run_benchmark(benchmark_runner, _prog) diff --git a/benchmark/test_benchmark_jubjub.py b/benchmark/test_benchmark_jubjub.py index 2194a356..0c7058a0 100644 --- a/benchmark/test_benchmark_jubjub.py +++ b/benchmark/test_benchmark_jubjub.py @@ -7,11 +7,10 @@ BeaverMultiplyArrays, DivideShareArrays, DivideShares, - Equality, InvertShare, InvertShareArray, ) - +from honeybadgermpc.progs.mixins.share_comparison import Equality MIXINS = [ BeaverMultiply(), diff --git a/benchmark/test_benchmark_mimc.py b/benchmark/test_benchmark_mimc.py index 8de72960..2010e7ec 100644 --- a/benchmark/test_benchmark_mimc.py +++ b/benchmark/test_benchmark_mimc.py @@ -9,10 +9,10 @@ BeaverMultiplyArrays, DivideShareArrays, DivideShares, - Equality, InvertShare, InvertShareArray, ) +from honeybadgermpc.progs.mixins.share_comparison import Equality CONFIG = { BeaverMultiply.name: BeaverMultiply(), diff --git a/benchmark/test_benchmark_polynomial.py b/benchmark/test_benchmark_polynomial.py index 2294ab24..b73d5771 100644 --- a/benchmark/test_benchmark_polynomial.py +++ b/benchmark/test_benchmark_polynomial.py @@ -2,7 +2,7 @@ from pytest import mark -from honeybadgermpc.ntl.helpers import fft_interpolate, lagrange_interpolate +from honeybadgermpc.ntl import fft_interpolate, lagrange_interpolate from honeybadgermpc.polynomial import get_omega cache = {} diff --git a/benchmark/test_benchmark_share_mult.py b/benchmark/test_benchmark_share_mult.py new file mode 100644 index 00000000..23100770 --- /dev/null +++ b/benchmark/test_benchmark_share_mult.py @@ -0,0 +1,50 @@ +from pytest import mark + +from honeybadgermpc.progs.mixins.share_arithmetic import ( + BeaverMultiply, + BeaverMultiplyArrays, + DivideShareArrays, + DivideShares, + InvertShare, + InvertShareArray, +) +from honeybadgermpc.progs.mixins.share_comparison import Equality + +MIXINS = [ + BeaverMultiply(), + BeaverMultiplyArrays(), + InvertShare(), + InvertShareArray(), + DivideShares(), + DivideShareArrays(), + Equality(), +] + +TEST_PREPROCESSING = ["rands", "triples", "zeros", "cubes", "bits"] + +ALL_BIT_NUMBERS = [int(f"0b{'1' * i}", 2) for i in [1, 64, 128, 256]] + +n, t = 4, 1 +k = 50000 +COUNT_MAX = 2 + + +def run_benchmark( + runner, prog, n=n, t=t, preprocessing=TEST_PREPROCESSING, k=k, mixins=MIXINS +): + runner(prog, n, t, preprocessing, k, mixins) + + +@mark.parametrize("multiplier", ALL_BIT_NUMBERS) +def test_benchmark_beaver_mul_shares(benchmark_runner, multiplier): + multiply = BeaverMultiply() + + async def _prog(context): + base = context.Share( + 6846412461894745224441235558443359243034138132682534265960483512729196124138 + ) + mult = context.Share(multiplier) + result = await multiply(context, base, mult) + await result.open() + + run_benchmark(benchmark_runner, _prog) diff --git a/docker-compose.yml b/docker-compose.yml index 3852d0eb..20c5afac 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,5 +27,5 @@ services: - ./pairing/benches:/usr/src/HoneyBadgerMPC/pairing/benches - ./pairing/Cargo.toml:/usr/src/HoneyBadgerMPC/pairing/Cargo.toml - ./pairing/setup.py:/usr/src/HoneyBadgerMPC/pairing/setup.py - - /usr/src/HoneyBadgerMPC/honeybadgermpc/ntl # Directory _not_ mounted from host + # - /usr/src/HoneyBadgerMPC/honeybadgermpc/ntl # Directory _not_ mounted from host command: pytest -v --cov=honeybadgermpc diff --git a/honeybadgermpc/ntl/hbmpc_ntl_helpers.cpp b/honeybadgermpc/ntl/hbmpc_ntl_helpers.cpp index dbe2e0a0..0b21811d 100644 --- a/honeybadgermpc/ntl/hbmpc_ntl_helpers.cpp +++ b/honeybadgermpc/ntl/hbmpc_ntl_helpers.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.29.13 */ +/* Generated by Cython 0.29.17 */ /* BEGIN: Cython Metadata { @@ -45,8 +45,8 @@ END: Cython Metadata */ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_29_13" -#define CYTHON_HEX_VERSION 0x001D0DF0 +#define CYTHON_ABI "0_29_17" +#define CYTHON_HEX_VERSION 0x001D11F0 #define CYTHON_FUTURE_DIVISION 0 #include #ifndef offsetof @@ -536,8 +536,10 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #define PyString_Type PyUnicode_Type #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact +#ifndef PyObject_Unicode #define PyObject_Unicode PyObject_Str #endif +#endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) @@ -4897,7 +4899,7 @@ static PyObject *__pyx_f_14honeybadgermpc_3ntl_18_hbmpc_ntl_helpers_fft_batch_ev * */ __pyx_t_1 = __pyx_v_batch_size; - if (1 == 0) abort(); + if ((1 == 0)) abort(); { __pyx_t_9 = (__pyx_t_1 - 0 + 1 - 1/abs(1)) / 1; if (__pyx_t_9 > 0) @@ -5824,7 +5826,7 @@ static PyObject *__pyx_pf_14honeybadgermpc_3ntl_18_hbmpc_ntl_helpers_18fft_batch * zz_omega, n) */ __pyx_t_2 = __pyx_v_n_chunks; - if (1 == 0) abort(); + if ((1 == 0)) abort(); { __pyx_t_4 = (__pyx_t_2 - 0 + 1 - 1/abs(1)) / 1; if (__pyx_t_4 > 0) @@ -8795,7 +8797,7 @@ static int __Pyx_ParseOptionalKeywords( } name = first_kw_arg; #if PY_MAJOR_VERSION < 3 - if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { + if (likely(PyString_Check(key))) { while (*name) { if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) && _PyString_Eq(**name, key)) { @@ -8822,7 +8824,7 @@ static int __Pyx_ParseOptionalKeywords( while (*name) { int cmp = (**name == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**name, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; @@ -8838,7 +8840,7 @@ static int __Pyx_ParseOptionalKeywords( while (argname != first_kw_arg) { int cmp = (**argname == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**argname, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; @@ -9122,7 +9124,7 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK -static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) { +static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON @@ -9226,7 +9228,7 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { if (__pyx_code_cache.count == __pyx_code_cache.max_count) { int new_max = __pyx_code_cache.max_count + 64; entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( - __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); if (unlikely(!entries)) { return; } diff --git a/tests/fixtures.py b/tests/fixtures.py index d04f1327..69f00c0a 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -194,11 +194,8 @@ async def _test_runner(prog, n=4, t=1, to_generate=[], k=1000, mixins=[]): @fixture def benchmark_runner(benchmark): - from honeybadgermpc.preprocessing import PreProcessedElements - def _benchmark_runner(prog, n=4, t=1, to_generate=[], k=1000, mixins=[]): - pp_elements = PreProcessedElements() - _preprocess(pp_elements, n, t, k, to_generate) + _preprocess(n, t, k, to_generate) config = _build_config(mixins) program_runner = TaskProgramRunner(n, t, config) @@ -208,6 +205,6 @@ def _benchmark_runner(prog, n=4, t=1, to_generate=[], k=1000, mixins=[]): def _work(): loop.run_until_complete(program_runner.join()) - benchmark(_work) + benchmark.pedantic(_work, iterations=100, rounds=10, warmup_rounds=10) return _benchmark_runner