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

Last change on this file since 981 was 978, checked in by cfuguet, 10 years ago

reconf: use the reconf version of the dspin_local_crossbar

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