Changeset 74ec742 for benchmark/rmit.py


Ignore:
Timestamp:
May 20, 2022, 10:36:45 AM (3 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
25fa20a
Parents:
29d8c02 (diff), 7831e8fb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/rmit.py

    r29d8c02 r74ec742  
    4646                pass
    4747
    48         if re.search("^[0-9-,]+$", values):
     48        if values.startswith('\\'):
     49                return key, values[1:].split(',')
     50        elif re.search("^[0-9-,]+$", values):
    4951                values = parse_range(values)
    5052                return key, [v for v in values]
     
    6365        return eval(fmt)
    6466
     67# Evaluate all the options
     68# options can be of the for key = val or key = some_math(other_key)
     69# produce a list of all the options to replace some_math(other_key) with actual value
    6570def eval_options(opts):
     71        # Find all the options with dependencies
    6672        dependents = [d for d in opts.values() if type(d) is DependentOpt]
     73
     74        # we need to find all the straglers
    6775        processed = []
    68         nopts = []
     76
     77        # extract all the necessary inputs
     78        input_keys = {}
    6979        for d in dependents:
     80                # Mark the dependent as seen
    7081                processed.append(d.key)
    71                 lists = []
     82
     83                # process each of the dependencies
    7284                for dvar in d.vars:
     85                        # Check that it depends on something that exists
    7386                        if not dvar in opts.keys():
    7487                                print('ERROR: extra pattern option {}:{} uses unknown key {}'.format(d.key,d.value,dvar), file=sys.stderr)
    7588                                sys.exit(1)
    7689
    77                         lists.append([(dvar, o) for o in opts[dvar]])
     90                        # Check that it's not nested
     91                        if type(dvar) is DependentOpt:
     92                                print('ERROR: dependent options cannot be nested {}:{} uses key {}'.format(d.key,d.value,dvar), file=sys.stderr)
     93                                sys.exit(1)
     94
     95                        # Add the values to the input keys
     96                        if dvar not in input_keys:
     97                                input_keys[dvar] = opts[dvar]
     98                        else :
     99                                if input_keys[dvar] != opts[dvar]:
     100                                        print('INTERNAL ERROR: repeat input do not match {}:{} vs {}'.format(dvar,opts[dvar],input_keys[dvar]), file=sys.stderr)
     101                                        sys.exit(1)
     102
     103                        # Mark the input as seen
    78104                        processed.append(dvar)
    79105
    80                 kopt = []
    81                 for vals in list(itertools.product(*lists)):
    82                         res = ['-{}'.format(d.key), "{}".format(eval_one(d.value, vals))]
    83                         for k, v in vals:
    84                                 res.extend(['-{}'.format(k), "{}".format(v)])
    85                         kopt.append(res)
    86                 nopts.append(kopt)
    87 
    88 
    89         for k, vals in opts.items():
    90                 if k not in processed:
    91                         kopt = []
    92                         for v in vals:
    93                                 kopt.append(['-{}'.format(k), "{}".format(v)])
    94                         nopts.append(kopt)
    95 
    96         return nopts
     106        # add in all the straglers they should cause too many problems
     107        for k, v in opts.items():
     108                if type(v) is DependentOpt:
     109                        continue
     110
     111                if k in processed:
     112                        # consistency check
     113                        if k not in input_keys:
     114                                print('INTERNAL ERROR: key \'{}\' marked as processed but not in input_keys'.format(k), file=sys.stderr)
     115                                sys.exit(1)
     116                        continue
     117
     118                # consistency check
     119                if k in input_keys:
     120                        print('INTERNAL ERROR: key \'{}\' in input_keys but not marked as processed'.format(k), file=sys.stderr)
     121                        sys.exit(1)
     122
     123                # add the straggler
     124                input_keys[k] = v
     125
     126        # flatten the dict into a list of pairs so it's easier to work with
     127        input_list = []
     128        for k, v in input_keys.items():
     129                input_list.append([(k, o) for o in v])
     130
     131        # evaluate all the dependents
     132        # they are not allowed to produce new values so it's a one-to-one mapping from here
     133        evaluated = []
     134        for inputs in list(itertools.product(*input_list)):
     135                this_eval = list(inputs)
     136                for d in dependents:
     137                        this_eval.append((d.key, eval_one(d.value, inputs)))
     138
     139                evaluated.append(this_eval)
     140
     141        # reformat everything to a list of arguments
     142        formated = []
     143        for o in evaluated:
     144                inner = []
     145                for k,v in o:
     146                        inner.append("-{}".format(k))
     147                        inner.append("{}".format(v))
     148
     149                # print(inner)
     150                formated.append(inner)
     151
     152        return formated
    97153
    98154# returns the first option with key 'opt'
     
    122178        known_hosts = {
    123179                "jax": {
    124                         range(  1,  24) : "48-71",
    125                         range( 25,  48) : "48-71,144-167",
    126                         range( 49,  96) : "48-95,144-191",
    127                         range( 97, 144) : "24-95,120-191",
    128                         range(145, 192) : "0-95,96-191",
     180                        range(  1,  25) : "48-71",
     181                        range( 25,  49) : "48-71,144-167",
     182                        range( 49,  97) : "48-95,144-191",
     183                        range( 97, 145) : "24-95,120-191",
     184                        range(145, 193) : "0-95,96-191",
    129185                },
    130186        }
     
    184240
    185241        except:
    186                 print('ERROR: invalid arguments', file=sys.stderr)
    187                 parser.print_help(sys.stderr)
    188242                sys.exit(1)
    189243
     
    215269        # Figure out all the combinations to run
    216270        actions = []
    217         for p in itertools.product(range(options.trials), commands, *opts):
     271        for p in itertools.product(range(options.trials), commands, opts):
    218272                act = [p[1]]
    219273                for o in p[2:]:
     
    281335
    282336        if options.file != sys.stdout:
    283                 print("Done");                                                                                ")
     337                print("Done                                                                                ")
Note: See TracChangeset for help on using the changeset viewer.