[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 |
---|
[844] | 12 | parser = argparse.ArgumentParser(description='Run simulation') |
---|
[807] | 13 | |
---|
| 14 | parser.add_argument( |
---|
[847] | 15 | '--path', '-p', type=str, dest='path', default=os.getcwd(), |
---|
[844] | 16 | help='relative or absolute path to the platform') |
---|
[807] | 17 | |
---|
| 18 | parser.add_argument( |
---|
[844] | 19 | '--output', '-o', type=str, dest='outpath', default='./output', |
---|
| 20 | help='relative or absolute path to the output directory') |
---|
[807] | 21 | |
---|
| 22 | parser.add_argument( |
---|
[844] | 23 | '--xsize', '-x', type=int, dest='x', default=2, |
---|
| 24 | help='# of clusters in a row') |
---|
[807] | 25 | |
---|
| 26 | parser.add_argument( |
---|
[844] | 27 | '--ysize', '-y', type=int, dest='y', default=2, |
---|
| 28 | help='# of clusters in a column') |
---|
[807] | 29 | |
---|
| 30 | parser.add_argument( |
---|
[844] | 31 | '--nprocs', '-n', type=int, dest='nprocs', default=4, |
---|
| 32 | help='# of processors per cluster') |
---|
[807] | 33 | |
---|
| 34 | parser.add_argument( |
---|
[844] | 35 | '--compile-only', '-c', dest='compileonly', action='store_true', |
---|
| 36 | help='generate config files and compile the platform. Do not simulate') |
---|
[807] | 37 | |
---|
[844] | 38 | parser.add_argument( |
---|
[847] | 39 | '--batch-mode', '-b', dest='batchmode', action='store_true', |
---|
| 40 | help='run simulation in batch mode: no interactive TTY or FrameBuffer') |
---|
[844] | 41 | |
---|
[855] | 42 | parser.add_argument( |
---|
| 43 | '--faulty-router', '-f', dest='faultyrouter', default=-1, |
---|
| 44 | help='ID (X,Y) of faulty router') |
---|
| 45 | |
---|
| 46 | parser.add_argument( |
---|
[859] | 47 | '--faulty-mask', '-m', dest='faultymask', default=0x1F, |
---|
| 48 | help='Disable mask for faulty router interfaces') |
---|
| 49 | |
---|
| 50 | parser.add_argument( |
---|
[855] | 51 | '--debug', '-g', dest='debug', nargs=4, |
---|
| 52 | help='needs four arguments: from, to, procid, memcid') |
---|
| 53 | |
---|
[807] | 54 | args = parser.parse_args() |
---|
| 55 | |
---|
| 56 | # faulty processor list |
---|
[844] | 57 | faultylist = [(0, 0, 1), (0, 0, 2), (0, 1, 2)] |
---|
[807] | 58 | |
---|
| 59 | # translate the relative path (if needed) into an absolute path |
---|
| 60 | basedir = os.path.abspath(args.path) |
---|
| 61 | outdir = os.path.abspath(args.outpath) |
---|
| 62 | print "[ run.py ] platform base directory: {0}".format(basedir) |
---|
| 63 | print "[ run.py ] output directory: {0}".format(outdir) |
---|
| 64 | |
---|
| 65 | # 1. generate configuration and ouput directories |
---|
| 66 | try: |
---|
| 67 | os.makedirs(os.path.join(outdir, "config"), 0755) |
---|
| 68 | except OSError: |
---|
| 69 | pass # directory already exists => do nothing |
---|
| 70 | |
---|
| 71 | # 2. generate hard_config.h and fault_config.h files |
---|
| 72 | faultpath = os.path.join(outdir, "config/fault_config.h") |
---|
| 73 | hardpath = os.path.join(outdir, "config/hard_config.h") |
---|
| 74 | xmlpath = os.path.join(outdir, "config/map.xml") |
---|
| 75 | arch.main(args.x, args.y, args.nprocs, hardpath, xmlpath) |
---|
| 76 | faultyprocs.generate(faultylist, faultpath) |
---|
| 77 | |
---|
| 78 | # create a log file |
---|
| 79 | logfile = open(os.path.join(outdir, "log"), "w") |
---|
| 80 | |
---|
| 81 | # 3. compile simulator executable |
---|
| 82 | dst = os.path.join(basedir, "hard_config.h") |
---|
[844] | 83 | if os.path.lexists(dst): |
---|
| 84 | os.unlink(dst) |
---|
| 85 | |
---|
[807] | 86 | os.symlink(hardpath, dst) |
---|
| 87 | |
---|
[812] | 88 | print "[ run.py ] compiling simulator" |
---|
[807] | 89 | command = [] |
---|
| 90 | command.extend(['make']) |
---|
| 91 | command.extend(['-C', basedir]) |
---|
| 92 | subprocess.call(command, stdout=logfile, stderr=logfile) |
---|
| 93 | |
---|
| 94 | # 4. compile distributed boot executable |
---|
| 95 | dst = os.path.join(outdir, "config/boot_config.h") |
---|
[844] | 96 | if os.path.lexists(dst): |
---|
| 97 | os.unlink(dst) |
---|
| 98 | |
---|
[807] | 99 | os.symlink(os.path.join(basedir, "soft/config/boot_config.h"), dst) |
---|
| 100 | |
---|
[844] | 101 | # stop after compiling the platform when the compile-only option is activated |
---|
| 102 | if args.compileonly == True: |
---|
| 103 | exit(0) |
---|
| 104 | |
---|
[812] | 105 | print "[ run.py ] compiling distributed boot procedure" |
---|
[807] | 106 | command = [] |
---|
| 107 | command.extend(['make']) |
---|
| 108 | command.extend(['-C', os.path.join(basedir, "soft")]) |
---|
| 109 | command.extend(["CONFDIR=" + outdir]) |
---|
| 110 | subprocess.call(command, stdout=logfile, stderr=logfile) |
---|
| 111 | |
---|
| 112 | # 5. execute simulator |
---|
| 113 | os.environ["DISTRIBUTED_BOOT"] = "1" |
---|
[847] | 114 | if args.batchmode: |
---|
[844] | 115 | os.environ["SOCLIB_FB"] = "HEADLESS" |
---|
| 116 | os.environ["SOCLIB_TTY"] = "FILES" |
---|
[807] | 117 | |
---|
| 118 | if (args.x * args.y) <= 4: |
---|
| 119 | ompthreads = args.x * args.y |
---|
| 120 | elif (args.x * args.y) <= 16: |
---|
| 121 | ompthreads = 4 |
---|
| 122 | else: |
---|
| 123 | ompthreads = 8 |
---|
| 124 | |
---|
[812] | 125 | print "[ run.py ] starting simulation" |
---|
[807] | 126 | command = [] |
---|
| 127 | command.extend([os.path.join(basedir, "simul.x")]) |
---|
| 128 | command.extend(["-SOFT", os.path.join(basedir, "soft/build/soft.elf")]) |
---|
| 129 | command.extend(["-DISK", "/dev/null"]) |
---|
| 130 | command.extend(["-THREADS", str(ompthreads)]) |
---|
[855] | 131 | |
---|
| 132 | if args.faultyrouter != -1: |
---|
| 133 | command.extend(["-FAULTY_ROUTER", str(args.faultyrouter)]) |
---|
[859] | 134 | command.extend(["-FAULTY_MASK", str(args.faultymask)]) |
---|
[855] | 135 | |
---|
| 136 | if args.debug != None: |
---|
| 137 | command.extend(["-DEBUG", str(args.debug[0])]); |
---|
| 138 | command.extend(["-NCYCLES", str(args.debug[1])]); |
---|
| 139 | command.extend(["-PROCID", str(args.debug[2])]); |
---|
| 140 | command.extend(["-MEMCID", str(args.debug[3])]); |
---|
| 141 | else: |
---|
| 142 | command.extend(["-NCYCLES", "1000000"]) |
---|
| 143 | |
---|
[807] | 144 | subprocess.call(command, stdout=logfile, stderr=logfile) |
---|
| 145 | |
---|
| 146 | logfile.close() |
---|
| 147 | |
---|
| 148 | # 6. move simulation terminal output into the target config dir |
---|
| 149 | os.rename("term0", os.path.join(outdir, "term")) |
---|
| 150 | |
---|
| 151 | # vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|