source: branches/reconfiguration/platforms/tsar_generic_iob/scripts/onerun.py @ 997

Last change on this file since 997 was 991, checked in by cfuguet, 10 years ago

reconf: force the python version 2.7 in simulation scripts.

  • Property svn:executable set to *
File size: 8.6 KB
Line 
1#!/usr/bin/env python2.7
2# @date   22 September, 2014
3# @author cfuguet <cesar.fuguet-tortolero@lip6.fr>
4
5import os
6import shutil
7import subprocess
8import arch
9import faultyprocs
10import argparse
11import multiprocessing
12import math
13
14def run(args):
15    """ Execute the distributed bootloader providing permanent fault-recovery on
16    the TSAR platform.
17
18    Keyword arguments:
19    path         -- platform's base directory path
20    outpath      -- output's base directory path
21    x            -- number of clusters on the X coordinate
22    y            -- number of clusters on the Y coordinate
23    nprocs       -- number of processors per cluster
24    compileonly  -- stops after platform's compilation
25    batchmode    -- TTY and FB are only redirected to FILES
26    faultyrouter -- a list containing faulty routers' coordinates (t, x, y)
27    faultymask   -- a mask of disabled routers' interfaces
28    faultycore   -- a list containing faulty cores' coordinates (x, y, l)
29    debug        -- a list with debug's start cycle, PID and MID
30    threads      -- number of OpenMP threads
31    firmdebug    -- activate the DEBUG compilation mode on software
32    diskimage    -- relative or absolute path to the disk image
33    force        -- create configuration files (or overwrite them)
34    """
35
36    # translate the relative path (if needed) into an absolute path
37    basedir = os.path.abspath(args.path)
38    outdir = os.path.abspath(args.outpath)
39    print "[ run.py ] platform base directory: {0}".format(basedir)
40    print "[ run.py ] output directory: {0}".format(outdir)
41
42    # 1. generate configuration and ouput directories
43    try:
44        os.makedirs(os.path.join(outdir, "config"), 0755)
45    except OSError:
46        pass # directory already exists => do nothing
47
48    # 2. generate hard_config.h and fault_config.h files
49    faultpath = os.path.join(outdir, "config/fault_config.h")
50    hardpath = os.path.join(outdir, "config/hard_config.h")
51    xmlpath = os.path.join(outdir, "config/giet.map.xml")
52    if args.linux:
53        dtspath = os.path.join(outdir, "config/platform.dts")
54    else:
55        dtspath = None
56
57    exist = True
58    exist = exist and os.path.exists(faultpath)
59    exist = exist and os.path.exists(hardpath)
60    exist = exist and os.path.exists(xmlpath)
61    if args.linux: exist = exist and os.path.exists(dtspath)
62
63    if not args.force and exist:
64        print "[ run.py ] Warning: Reusing existing configuration files. "
65        print "[ run.py ] Script arguments will be ignored (no --force option)"
66        cmd = raw_input('[ run.py ] Would you like to continue (y/n): ')
67        if cmd == 'n': exit(0)
68        if cmd == 'y': pass
69        else: exit(1)
70    else:
71        arch.main(args.x, args.y, args.nprocs, hardpath, xmlpath, dtspath)
72        faultyprocs.generate(args.faultycore, faultpath)
73
74    # create a log file
75    logfile = open(os.path.join(outdir, "log"), "w")
76
77    # 3. compile simulator executable
78    dst = os.path.join(basedir, "hard_config.h")
79    if os.path.lexists(dst):
80        os.unlink(dst)
81
82    os.symlink(hardpath, dst)
83
84    print "[ run.py ] compiling simulator"
85    command = []
86    command.extend(['make'])
87    command.extend(['-C', basedir])
88    subprocess.check_call(command, stdout=logfile, stderr=logfile)
89
90    # 4. compile distributed boot executable
91    dst = os.path.join(outdir, "config/boot_config.h")
92    if os.path.lexists(dst):
93        os.unlink(dst)
94
95    os.symlink(os.path.join(basedir, "soft/test/config/boot_config.h"), dst)
96
97    print "[ run.py ] compiling distributed boot procedure"
98    command = []
99    command.extend(['make'])
100    command.extend(['-C', os.path.join(basedir, "soft")])
101    command.extend(["CONFIG=" + outdir])
102    command.extend(["DEBUG=" + str(args.firmdebug)])
103    if args.linux:
104        command.extend(["PATCHER_OS=1"])
105    else:
106        command.extend(["PATCHER_OS=0"])
107
108    subprocess.check_call(command, stdout=logfile, stderr=logfile)
109
110    # stop after compiling when the compile-only option is activated
111    if args.compileonly == True: exit(0)
112
113    # 5. execute simulator
114    os.environ["DISTRIBUTED_BOOT"] = "1"
115    os.environ["SOCLIB_FB"] = "HEADLESS"
116    if args.batchmode:
117        os.environ["SOCLIB_TTY"] = "FILES"
118
119    print "[ run.py ] starting simulation"
120    command = []
121    command.extend([os.path.join(basedir, "simul.x")])
122    command.extend(["-DSOFT", "soft/build/boot.elf"])
123    command.extend(["-SOFT", "soft/build/loader.elf"])
124    command.extend(["-DISK", args.diskimage])
125
126    if args.faultyrouter != None:
127        command.extend(["-FAULTY_MASK", str(args.faultymask)])
128        for f in args.faultyrouter:
129            command.extend(["-FAULTY_ROUTER", str(f[0]), str(f[1]), str(f[2])])
130
131    if args.debug != None:
132        command.extend(["-DEBUG", str(args.debug[0])]);
133        command.extend(["-PROCID", str(args.debug[1])]);
134        command.extend(["-MEMCID", str(args.debug[2])]);
135        command.extend(["-IOB", "1"]);
136
137    if args.ncycles > 0:
138        command.extend(["-NCYCLES", str(args.ncycles)])
139
140    elif os.environ.get('SOCLIB_GDB') == None:
141        # the procedure grows linearly with the diameter of the mesh.
142        # maxcycles = 1500000 + (args.x + args.y) * 20000
143        # command.extend(["-NCYCLES", str(maxcycles)])
144        command.extend(["-NCYCLES", str(200000000)])
145
146    # OpenMP number of threads definition
147    ompthreads = args.threads
148    if ompthreads < 1:
149        ompthreads = math.ceil(float(args.x * args.y) / 4)
150
151        # be nice and don't use all available processors
152        maxcpu = math.ceil(float(multiprocessing.cpu_count()) * 2/3)
153        if ompthreads > maxcpu: ompthreads = maxcpu
154
155    command.extend(["-THREADS", str(ompthreads)])
156
157    logfile.write("Execute: {0}\n".format(" ".join(command)))
158    logfile.flush()
159
160    subprocess.check_call(command, stdout=logfile, stderr=logfile)
161
162    logfile.close()
163
164    # 6. move simulation terminal output into the target config dir
165    if os.path.lexists("term0"):
166        shutil.copy2("term0", os.path.join(outdir, "term"))
167
168# get command-line arguments
169if __name__ == "__main__":
170    parser = argparse.ArgumentParser(description='Run simulation')
171
172    parser.add_argument(
173        '--path', '-p', type=str, dest='path', default=os.getcwd(),
174        help='relative or absolute path to the platform')
175
176    parser.add_argument(
177        '--output', '-o', type=str, dest='outpath', default='./output',
178        help='relative or absolute path to the output directory')
179
180    parser.add_argument(
181        '--xsize', '-x', type=int, dest='x', default=2,
182        help='# of clusters in a row')
183
184    parser.add_argument(
185        '--ysize', '-y', type=int, dest='y', default=2,
186        help='# of clusters in a column')
187
188    parser.add_argument(
189        '--nprocs', '-n', type=int, dest='nprocs', default=4,
190        help='# of processors per cluster')
191
192    parser.add_argument(
193        '--compile-only', '-c', dest='compileonly', action='store_true',
194        help='generate config files and compile the platform. Do not simulate')
195
196    parser.add_argument(
197        '--batch-mode', '-b', dest='batchmode', action='store_true',
198        help='run simulation in batch mode: no interactive TTY or FrameBuffer')
199
200    parser.add_argument(
201        '--faulty-router', '-fr', dest='faultyrouter', action='append', nargs=3,
202        help='ID (T,X,Y) of faulty router. The T is 0:CMD, 1:RSP')
203
204    parser.add_argument(
205        '--faulty-mask', '-m', dest='faultymask', default=0x1F,
206        help='Disable mask for faulty router interfaces')
207
208    parser.add_argument(
209        '--faulty-core', '-fc', dest='faultycore', action='append', nargs=3,
210        help='ID (X,Y,L) of faulty processor')
211
212    parser.add_argument(
213        '--debug', '-g', dest='debug', nargs=3,
214        help='needs four arguments: from, procid, memcid')
215
216    parser.add_argument(
217        '--threads', '-t', type=int, dest='threads', default=1,
218        help='number of OpenMP threads')
219
220    parser.add_argument(
221        '--firmware-debug', '-fg', dest='firmdebug', default=0,
222        help='activate the DEBUG compilation mode on software')
223
224    parser.add_argument(
225        '--disk-image', '-di', dest='diskimage', default="/dev/null",
226        help='relative or absolute path to the external firmware')
227
228    parser.add_argument(
229        '--force', '-f', dest='force', action='store_true',
230        help='create configuration files (or overwrite them)')
231
232    parser.add_argument(
233        '--linux', dest='linux', action='store_true',
234        help='generate linux device tree and compile bootloader ' +
235             'with linux specifics')
236
237    parser.add_argument(
238        '--ncycles', type=int, dest='ncycles', default=-1,
239        help='max simulation cycles')
240
241    run(parser.parse_args())
242
243# vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Note: See TracBrowser for help on using the repository browser.