viff

changeset 1236:5aa1a609ae35

Refactored options to be more generic in terms of supported runtimes and mixins.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Wed, 07 Oct 2009 12:02:23 +0200
parents 3fba16c51e71
children 4b6f9e4db99e
files apps/benchmark.py
diffstat 1 files changed, 51 insertions(+), 39 deletions(-) [+]
line diff
     1.1 --- a/apps/benchmark.py	Wed Oct 07 12:02:23 2009 +0200
     1.2 +++ b/apps/benchmark.py	Wed Oct 07 12:02:23 2009 +0200
     1.3 @@ -94,18 +94,30 @@
     1.4      print "Time per %s operation: %.0f ms" % (what, 1000*(stop-start) / count)
     1.5      print "*" * 6
     1.6  
     1.7 +operations = {"mul": (operator.mul,[]),
     1.8 +              "compToft05": (operator.ge, [ComparisonToft05Mixin]),
     1.9 +              "compToft07": (operator.ge, [ComparisonToft07Mixin]),
    1.10 +              "eq": (operator.eq, [ProbabilisticEqualityMixin])}
    1.11  
    1.12 -operations = ["mul", "compToft05", "compToft07", "eq"]
    1.13 +runtimes = {"PassiveRuntime": PassiveRuntime,
    1.14 +            "PaillierRuntime": PaillierRuntime, 
    1.15 +            "BasicActiveRuntime": BasicActiveRuntime}
    1.16 +
    1.17 +mixins = {"TriplesHyperinvertibleMatricesMixin" : TriplesHyperinvertibleMatricesMixin, 
    1.18 +          "TriplesPRSSMixin": TriplesPRSSMixin, 
    1.19 +          "ComparisonToft05Mixin": ComparisonToft05Mixin,
    1.20 +          "ComparisonToft07Mixin": ComparisonToft07Mixin, 
    1.21 +          "ProbabilisticEqualityMixin": ProbabilisticEqualityMixin}
    1.22  
    1.23  parser = OptionParser(usage="Usage: %prog [options] config_file")
    1.24  parser.add_option("-m", "--modulus",
    1.25                    help="lower limit for modulus (can be an expression)")
    1.26 -parser.add_option("-a", "--active", action="store_true",
    1.27 -                  help="use actively secure runtime")
    1.28 -parser.add_option("--passive", action="store_false", dest="active",
    1.29 -                  help="use passively secure runtime")
    1.30 -parser.add_option("-2", "--twoplayer", action="store_true",
    1.31 -                  help="use twoplayer runtime")
    1.32 +parser.add_option("-r", "--runtime", type="choice", choices=runtimes.keys(),
    1.33 +                  help="the name of the basic runtime to test")
    1.34 +parser.add_option("-n", "--num_players", action="store_true", dest="num_players",
    1.35 +                  help="number of players")
    1.36 +parser.add_option("--mixins", type="choice", choices=mixins.keys(),
    1.37 +                  help="operation to benchmark")
    1.38  parser.add_option("--prss", action="store_true",
    1.39                    help="use PRSS for preprocessing")
    1.40  parser.add_option("--hyper", action="store_false", dest="prss",
    1.41 @@ -114,7 +126,7 @@
    1.42                    help="corruption threshold")
    1.43  parser.add_option("-c", "--count", type="int",
    1.44                    help="number of operations")
    1.45 -parser.add_option("-o", "--operation", type="choice", choices=operations,
    1.46 +parser.add_option("-o", "--operation", type="choice", choices=operations.keys(),
    1.47                    help="operation to benchmark")
    1.48  parser.add_option("-p", "--parallel", action="store_true",
    1.49                    help="execute operations in parallel")
    1.50 @@ -122,10 +134,12 @@
    1.51                    help="execute operations in sequence")
    1.52  parser.add_option("-f", "--fake", action="store_true",
    1.53                    help="skip local computations using fake field elements")
    1.54 +parser.add_option("--args", type="string",
    1.55 +                  help="additional arguments to the runtime, the format is a comma separated list of id=value pairs e.g. --args s=1,d=0,lambda=1")
    1.56  
    1.57  parser.set_defaults(modulus=2**65, threshold=1, count=10,
    1.58 -                    active=False, twoplayer=False, prss=True,
    1.59 -                    operation=operations[0], parallel=True, fake=False)
    1.60 +                    runtime=runtimes.keys()[0], mixins=mixins.keys(), num_players=2, prss=True,
    1.61 +                    operation=operations.keys()[0], parallel=True, fake=False)
    1.62  
    1.63  # Add standard VIFF options.
    1.64  Runtime.add_options(parser)
    1.65 @@ -285,41 +299,26 @@
    1.66              record_stop(None, "sequential test")
    1.67              self.finished(None)
    1.68  
    1.69 -mixins = []
    1.70 -if options.twoplayer:
    1.71 -    # Then there is just one possible runtime:
    1.72 -    operation = operator.mul
    1.73 -    base_runtime_class = PaillierRuntime
    1.74 -else:
    1.75 -    # There are several options for a multiplayer runtime:
    1.76 -    if options.active:
    1.77 -        base_runtime_class = BasicActiveRuntime
    1.78 -        if options.prss:
    1.79 -            mixins.append(TriplesPRSSMixin)
    1.80 -        else:
    1.81 -            mixins.append(TriplesHyperinvertibleMatricesMixin)
    1.82 -    else:
    1.83 -        base_runtime_class = PassiveRuntime
    1.84 +# Identify the base runtime class.
    1.85 +base_runtime_class = runtimes[options.runtime]
    1.86  
    1.87 -    if options.operation == "mul":
    1.88 -        operation = operator.mul
    1.89 -    elif options.operation == "compToft05":
    1.90 -        operation = operator.ge
    1.91 -        mixins.append(ComparisonToft05Mixin)
    1.92 -    elif options.operation == "compToft07":
    1.93 -        operation = operator.ge
    1.94 -        mixins.append(ComparisonToft07Mixin)
    1.95 -    elif options.operation == "eq":
    1.96 -        operation = operator.eq
    1.97 -        mixins.append(ProbabilisticEqualityMixin)
    1.98 +# Identify the additional mixins.
    1.99 +actual_mixins = []
   1.100 +if options.mixins != "":
   1.101 +    actual_mixins = [mixins[mixin] for mixin in options.mixins.split(',')]
   1.102 +
   1.103 +
   1.104 +# Identify the operation and it mixin dependencies.
   1.105 +operation = operations[options.operation][0]
   1.106 +actual_mixins += operations[options.operation][1]
   1.107  
   1.108  print "Using the base runtime: %s." % base_runtime_class
   1.109 -if mixins:
   1.110 +if actual_mixins:
   1.111      print "With the following mixins:"
   1.112 -    for mixin in mixins:
   1.113 +    for mixin in actual_mixins:
   1.114          print "- %s" % mixin
   1.115  
   1.116 -runtime_class = make_runtime_class(base_runtime_class, mixins)
   1.117 +runtime_class = make_runtime_class(base_runtime_class, actual_mixins)
   1.118  
   1.119  if options.parallel:
   1.120      benchmark = ParallelBenchmark
   1.121 @@ -328,6 +327,19 @@
   1.122  
   1.123  pre_runtime = create_runtime(id, players, options.threshold,
   1.124                               options, runtime_class)
   1.125 +
   1.126 +def update_args(runtime, options):
   1.127 +    args = {}
   1.128 +    if options.args != "":
   1.129 +        for arg in options.args.split(','):
   1.130 +            id, value = arg.split('=')
   1.131 +            args[id] = long(value)
   1.132 +        runtime.setArgs(args)
   1.133 +    return runtime
   1.134 +
   1.135 +
   1.136 +pre_runtime.addCallback(update_args, options)
   1.137 +
   1.138  pre_runtime.addCallback(benchmark, operation)
   1.139  
   1.140  print "#### Starting reactor ###"