• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python2
2
3import argparse
4import os
5import sys
6
7import szbuild
8
9from utils import FindBaseNaCl, shellcmd
10
11def main():
12    """Build native gcc-style executables for one or all Spec2K components.
13
14    Afterwards, the executables can be run from the
15    native_client/tests/spec2k/ directory as:
16    './run_all.sh RunBenchmarks SetupGccX8632Opt {train|ref} ...'
17    -- or --
18    './run_all.sh RunBenchmarks SetupPnaclX8632Opt {train|ref} ...'
19    -- or --
20    './run_all.sh RunBenchmarks SetupNonsfiX8632Opt {train|ref} ...'
21    """
22    nacl_root = FindBaseNaCl()
23    # Use the same default ordering as spec2k/run_all.sh.
24    components = [ '177.mesa', '179.art', '183.equake', '188.ammp', '164.gzip',
25                   '175.vpr', '176.gcc', '181.mcf', '186.crafty', '197.parser',
26                   '253.perlbmk', '254.gap', '255.vortex', '256.bzip2',
27                   '300.twolf', '252.eon' ]
28
29    argparser = argparse.ArgumentParser(description=main.__doc__)
30    szbuild.AddOptionalArgs(argparser)
31    argparser.add_argument('--run', dest='run', action='store_true',
32                           help='Run after building')
33    argparser.add_argument('comps', nargs='*', default=components)
34    args = argparser.parse_args()
35    bad = set(args.comps) - set(components)
36    if bad:
37        print 'Unknown component{s}: '.format(s='s' if len(bad) > 1 else '') + \
38            ' '.join(x for x in bad)
39        sys.exit(1)
40
41    # Fix up Subzero target strings for the run_all.sh script.
42    target_map = {
43         'arm32':'arm',
44         'x8632':'x8632',
45         'x8664':'x8664'
46         }
47    run_all_target = target_map[args.target] # fail if target not listed above
48
49    suffix = (
50        'pnacl.opt.{target}' if args.sandbox else
51        'nonsfi.opt.{target}' if args.nonsfi else
52        'gcc.opt.{target}').format(
53             target=run_all_target);
54    for comp in args.comps:
55        name = os.path.splitext(comp)[1] or comp
56        if name[0] == '.':
57            name = name[1:]
58        szbuild.ProcessPexe(args,
59                            ('{root}/tests/spec2k/{comp}/' +
60                             '{name}.opt.stripped.pexe'
61                             ).format(root=nacl_root, comp=comp, name=name),
62                            ('{root}/tests/spec2k/{comp}/' +
63                             '{name}.{suffix}'
64                             ).format(root=nacl_root, comp=comp, name=name,
65                                      suffix=suffix))
66    if args.run:
67        os.chdir('{root}/tests/spec2k'.format(root=FindBaseNaCl()))
68        setup = 'Setup' + ('Pnacl' if args.sandbox else
69                           'Nonsfi' if args.nonsfi else
70                           'Gcc') + {
71            'arm32': 'Arm',
72            'x8632': 'X8632',
73            'x8664': 'X8664'}[args.target] + 'Opt'
74        shellcmd(['./run_all.sh',
75                  'RunTimedBenchmarks',
76                  setup,
77                  'train'] + args.comps)
78
79if __name__ == '__main__':
80    main()
81