viff

changeset 913:93e3a461a024

Updated benchmark.py to take advantage of new mixins. The code was made much more modular and one can now start benchmarks which with or without active security (-a) and using either PRSS (--prss) or hyperinvertible matrices (--hyper, I like that option!) for the preprocessing.
author Martin Geisler <mg@daimi.au.dk>
date Mon, 15 Sep 2008 22:17:21 +0200
parents 201381ab3c4b
children baf787b7e39b
files apps/benchmark.py
diffstat 1 files changed, 53 insertions(+), 31 deletions(-) [+]
line diff
     1.1 --- a/apps/benchmark.py	Mon Sep 15 21:05:50 2008 +0200
     1.2 +++ b/apps/benchmark.py	Mon Sep 15 22:17:21 2008 +0200
     1.3 @@ -63,9 +63,9 @@
     1.4  
     1.5  from viff.field import GF, GF256
     1.6  from viff.runtime import Runtime, create_runtime, gather_shares
     1.7 -from viff.active import ActiveRuntime
     1.8 -from viff.comparison import Toft05Runtime, Toft07Runtime
     1.9 -from viff.comparison import ActiveToft05Runtime, ActiveToft07Runtime
    1.10 +from viff.active import BasicActiveRuntime, \
    1.11 +    TriplesHyperinvertibleMatricesMixin, TriplesPRSSMixin
    1.12 +from viff.comparison import ComparisonToft05Mixin, ComparisonToft07Mixin
    1.13  from viff.paillier import PaillierRuntime
    1.14  from viff.config import load_config
    1.15  from viff.util import find_prime
    1.16 @@ -89,12 +89,19 @@
    1.17      print "*" * 6
    1.18  
    1.19  
    1.20 -operations = ["mul", "mul-active", "comp", "comp-active",
    1.21 -              "compII", "compII-active", "mul-paillier"]
    1.22 +operations = ["mul", "compToft05", "compToft07"]
    1.23  
    1.24  parser = OptionParser()
    1.25  parser.add_option("-m", "--modulus",
    1.26                    help="lower limit for modulus (can be an expression)")
    1.27 +parser.add_option("-a", "--active", action="store_true",
    1.28 +                  help="use actively secure runtime")
    1.29 +parser.add_option("-2", "--twoplayer", action="store_true",
    1.30 +                  help="use twoplayer runtime")
    1.31 +parser.add_option("--prss", action="store_true",
    1.32 +                  help="use PRSS for preprocessing")
    1.33 +parser.add_option("--hyper", action="store_false", dest="prss",
    1.34 +                  help="use hyperinvertible matrices for preprocessing")
    1.35  parser.add_option("-c", "--count", type="int",
    1.36                    help="number of operations")
    1.37  parser.add_option("-o", "--operation", type="choice", choices=operations,
    1.38 @@ -105,6 +112,7 @@
    1.39                    help="execute operations in sequence")
    1.40  
    1.41  parser.set_defaults(modulus="30916444023318367583", count=10,
    1.42 +                    active=False, twoplayer=False, prss=True,
    1.43                      operation=operations[0], parallel=True)
    1.44  
    1.45  # Add standard VIFF options.
    1.46 @@ -130,7 +138,7 @@
    1.47          self.rt = rt
    1.48          self.operation = operation
    1.49  
    1.50 -        if isinstance(self.rt, ActiveRuntime):
    1.51 +        if isinstance(self.rt, BasicActiveRuntime):
    1.52              # TODO: Make this optional and maybe automatic. The
    1.53              # program descriptions below were found by carefully
    1.54              # studying the output reported when the benchmarks were
    1.55 @@ -138,20 +146,20 @@
    1.56              print "Starting preprocessing"
    1.57              if self.operation == operator.mul:
    1.58                  program_desc = {
    1.59 -                    ("prss_generate_triple", (Zp,)):
    1.60 +                    ("generate_triples", (Zp,)):
    1.61                          [(i, 1, 0) for i in range(3 + 2*count, 3 + 3*count)]
    1.62                      }
    1.63 -            elif isinstance(self.rt, ActiveToft05Runtime):
    1.64 +            elif isinstance(self.rt, ComparisonToft05Mixin):
    1.65                  program_desc = {
    1.66 -                    ("prss_generate_triple", (GF256,)):
    1.67 +                    ("generate_triples", (GF256,)):
    1.68                      sum([[(c, 64, i, 1, 1, 0) for i in range(2, 33)] +
    1.69                           [(c, 64, i, 3, 1, 0) for i in range(17, 33)]
    1.70                           for c in range(3 + 2*count, 3 + 3*count)],
    1.71                          [])
    1.72                      }
    1.73 -            elif isinstance(self.rt, ActiveToft07Runtime):
    1.74 +            elif isinstance(self.rt, ComparisonToft07Mixin):
    1.75                  program_desc = {
    1.76 -                    ("prss_generate_triple", (Zp,)):
    1.77 +                    ("generate_triples", (Zp,)):
    1.78                      sum([[(c, 2, 4, i, 2, 1, 0) for i in range(1, 33)] +
    1.79                           [(c, 2, 4, 99, 2, 1, 0)] +
    1.80                           [(c, 2, 4, i, 1, 0) for i in range(65, 98)]
    1.81 @@ -235,27 +243,41 @@
    1.82              record_stop(None, "sequential test")
    1.83              self.finished(None)
    1.84  
    1.85 -if options.operation == "mul":
    1.86 +if options.twoplayer:
    1.87 +    # Then there is just one possible runtime:
    1.88      operation = operator.mul
    1.89 -    runtime_class = Runtime
    1.90 -elif options.operation == "mul-active":
    1.91 -    operation = operator.mul
    1.92 -    runtime_class = ActiveRuntime
    1.93 -elif options.operation == "comp":
    1.94 -    operation = operator.ge
    1.95 -    runtime_class = Toft05Runtime
    1.96 -elif options.operation == "comp-active":
    1.97 -    operation = operator.ge
    1.98 -    runtime_class = ActiveToft05Runtime
    1.99 -elif options.operation == "compII":
   1.100 -    operation = operator.ge
   1.101 -    runtime_class = Toft07Runtime
   1.102 -elif options.operation == "compII-active":
   1.103 -    operation = operator.ge
   1.104 -    runtime_class = ActiveToft07Runtime
   1.105 -elif options.operation == "mul-paillier":
   1.106 -    operation = operator.mul
   1.107 -    runtime_class = PaillierRuntime
   1.108 +    bases = [PaillierRuntime]
   1.109 +else:
   1.110 +    # There are several options for a multiplayer runtime:
   1.111 +    if options.active:
   1.112 +        bases = [BasicActiveRuntime]
   1.113 +        if options.prss:
   1.114 +            bases.append(TriplesPRSSMixin)
   1.115 +        else:
   1.116 +            bases.append(TriplesHyperinvertibleMatricesMixin)
   1.117 +    else:
   1.118 +        bases = [Runtime]
   1.119 +
   1.120 +    if options.operation == "mul":
   1.121 +        operation = operator.mul
   1.122 +    elif options.operation == "compToft05":
   1.123 +        operation = operator.ge
   1.124 +        bases.append(ComparisonToft05Mixin)
   1.125 +    elif options.operation == "compToft07":
   1.126 +        operation = operator.ge
   1.127 +        bases.append(ComparisonToft07Mixin)
   1.128 +
   1.129 +print "Constructing runtime from:"
   1.130 +for base in bases:
   1.131 +    print "- %s" % base
   1.132 +
   1.133 +
   1.134 +# We must include at least one new-style class in bases. We include it
   1.135 +# last to avoid overriding __init__ from the other base classes.
   1.136 +bases.append(object)
   1.137 +
   1.138 +# Dynamically created class based on the choices above:
   1.139 +runtime_class = type("BenchmarkRuntime", tuple(bases), {})
   1.140  
   1.141  if options.parallel:
   1.142      benchmark = ParallelBenchmark