[807] | 1 | #!/usr/bin/python |
---|
| 2 | # @date 22 September, 2014 |
---|
| 3 | # @author cfuguet <cesar.fuguet-tortolero@lip6.fr> |
---|
| 4 | |
---|
| 5 | import os |
---|
| 6 | import subprocess |
---|
| 7 | import arch |
---|
| 8 | import faultyprocs |
---|
| 9 | import argparse |
---|
| 10 | |
---|
| 11 | # get command-line arguments |
---|
| 12 | parser = argparse.ArgumentParser(description = 'Run simulation') |
---|
| 13 | |
---|
| 14 | parser.add_argument( |
---|
| 15 | type = str, dest = 'path', |
---|
| 16 | help = 'relative or absolute path to the platform') |
---|
| 17 | |
---|
| 18 | parser.add_argument( |
---|
| 19 | '--output', '-o', type = str, dest = 'outpath', default = './output', |
---|
| 20 | help = 'relative or absolute path to the output directory') |
---|
| 21 | |
---|
| 22 | parser.add_argument( |
---|
| 23 | '--xsize', '-x', type = int, dest = 'x', default = 2, |
---|
| 24 | help = '# of clusters in a row') |
---|
| 25 | |
---|
| 26 | parser.add_argument( |
---|
| 27 | '--ysize', '-y', type = int, dest = 'y', default = 2, |
---|
| 28 | help = '# of clusters in a column') |
---|
| 29 | |
---|
| 30 | parser.add_argument( |
---|
| 31 | '--nprocs', '-n', type = int, dest = 'nprocs', default = 4, |
---|
| 32 | help = '# of processors per cluster') |
---|
| 33 | |
---|
| 34 | parser.add_argument( |
---|
| 35 | '--quiet', '-q', type = bool, dest = 'quiet', default = False, |
---|
| 36 | help = 'be quiet!!!' ) |
---|
| 37 | |
---|
| 38 | args = parser.parse_args() |
---|
| 39 | |
---|
| 40 | # faulty processor list |
---|
| 41 | faultylist = [(0,0,1), (0,0,2), (0,1,2)] |
---|
| 42 | |
---|
| 43 | # translate the relative path (if needed) into an absolute path |
---|
| 44 | basedir = os.path.abspath(args.path) |
---|
| 45 | outdir = os.path.abspath(args.outpath) |
---|
| 46 | print "[ run.py ] platform base directory: {0}".format(basedir) |
---|
| 47 | print "[ run.py ] output directory: {0}".format(outdir) |
---|
| 48 | |
---|
| 49 | # 1. generate configuration and ouput directories |
---|
| 50 | try: |
---|
| 51 | os.makedirs(os.path.join(outdir, "config"), 0755) |
---|
| 52 | except OSError: |
---|
| 53 | pass # directory already exists => do nothing |
---|
| 54 | |
---|
| 55 | # 2. generate hard_config.h and fault_config.h files |
---|
| 56 | faultpath = os.path.join(outdir, "config/fault_config.h") |
---|
| 57 | hardpath = os.path.join(outdir, "config/hard_config.h") |
---|
| 58 | xmlpath = os.path.join(outdir, "config/map.xml") |
---|
| 59 | arch.main(args.x, args.y, args.nprocs, hardpath, xmlpath) |
---|
| 60 | faultyprocs.generate(faultylist, faultpath) |
---|
| 61 | |
---|
| 62 | # create a log file |
---|
| 63 | logfile = open(os.path.join(outdir, "log"), "w") |
---|
| 64 | |
---|
| 65 | # 3. compile simulator executable |
---|
| 66 | dst = os.path.join(basedir, "hard_config.h") |
---|
| 67 | if os.path.lexists(dst): os.unlink(dst) |
---|
| 68 | os.symlink(hardpath, dst) |
---|
| 69 | |
---|
[812] | 70 | print "[ run.py ] compiling simulator" |
---|
[807] | 71 | command = [] |
---|
| 72 | command.extend(['make']) |
---|
| 73 | command.extend(['-C', basedir]) |
---|
| 74 | subprocess.call(command, stdout=logfile, stderr=logfile) |
---|
| 75 | |
---|
| 76 | # 4. compile distributed boot executable |
---|
| 77 | dst = os.path.join(outdir, "config/boot_config.h") |
---|
| 78 | if os.path.lexists(dst): os.unlink(dst) |
---|
| 79 | os.symlink(os.path.join(basedir, "soft/config/boot_config.h"), dst) |
---|
| 80 | |
---|
[812] | 81 | print "[ run.py ] compiling distributed boot procedure" |
---|
[807] | 82 | command = [] |
---|
| 83 | command.extend(['make']) |
---|
| 84 | command.extend(['-C', os.path.join(basedir, "soft")]) |
---|
| 85 | command.extend(["CONFDIR=" + outdir]) |
---|
| 86 | subprocess.call(command, stdout=logfile, stderr=logfile) |
---|
| 87 | |
---|
| 88 | # 5. execute simulator |
---|
| 89 | os.environ["DISTRIBUTED_BOOT"] = "1" |
---|
[841] | 90 | os.environ["SOCLIB_FB"] = "HEADLESS" |
---|
[807] | 91 | if args.quiet: os.environ["SOCLIB_TTY"] = "FILES" |
---|
| 92 | |
---|
| 93 | if (args.x * args.y) <= 4: |
---|
| 94 | ompthreads = args.x * args.y |
---|
| 95 | elif (args.x * args.y) <= 16: |
---|
| 96 | ompthreads = 4 |
---|
| 97 | else: |
---|
| 98 | ompthreads = 8 |
---|
| 99 | |
---|
[812] | 100 | print "[ run.py ] starting simulation" |
---|
[807] | 101 | command = [] |
---|
| 102 | command.extend([os.path.join(basedir, "simul.x")]) |
---|
| 103 | command.extend(["-SOFT", os.path.join(basedir, "soft/build/soft.elf")]) |
---|
| 104 | command.extend(["-DISK", "/dev/null"]) |
---|
| 105 | command.extend(["-THREADS", str(ompthreads)]) |
---|
| 106 | command.extend(["-NCYCLES", "1000000"]) |
---|
| 107 | subprocess.call(command, stdout=logfile, stderr=logfile) |
---|
| 108 | |
---|
| 109 | logfile.close() |
---|
| 110 | |
---|
| 111 | # 6. move simulation terminal output into the target config dir |
---|
| 112 | os.rename("term0", os.path.join(outdir, "term")) |
---|
| 113 | |
---|
| 114 | # vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|