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

Last change on this file since 927 was 927, checked in by cfuguet, 9 years ago

reconf: improve test scripts for tsar_generic_iob platform

  • Now it is possible to pass the number of OpenMP threads as a parameter
  • Property svn:executable set to *
File size: 6.8 KB
Line 
1#!/usr/bin/env python
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
11
12def run(args):
13    """ Execute the distributed bootloader providing permanent fault-recovery on
14    the TSAR platform.
15
16    Keyword arguments:
17    path         -- platform's base directory path
18    outpath      -- output's base directory path
19    x            -- number of clusters on the X coordinate
20    y            -- number of clusters on the Y coordinate
21    nprocs       -- number of processors per cluster
22    compileonly  -- stops after platform's compilation
23    batchmode    -- TTY and FB are only redirected to FILES
24    faultyrouter -- a list containing faulty routers' coordinates (t, x, y)
25    faultymask   -- a mask of disabled routers' interfaces
26    faultycore   -- a list containing faulty cores' coordinates (x, y, l)
27    debug        -- a list with debug's start cycle, stop cycle, PID and MID
28    """
29
30    # translate the relative path (if needed) into an absolute path
31    basedir = os.path.abspath(args.path)
32    outdir = os.path.abspath(args.outpath)
33    print "[ run.py ] platform base directory: {0}".format(basedir)
34    print "[ run.py ] output directory: {0}".format(outdir)
35
36    # 1. generate configuration and ouput directories
37    try:
38        os.makedirs(os.path.join(outdir, "config"), 0755)
39    except OSError:
40        pass # directory already exists => do nothing
41
42    # 2. generate hard_config.h and fault_config.h files
43    faultpath = os.path.join(outdir, "config/fault_config.h")
44    hardpath = os.path.join(outdir, "config/hard_config.h")
45    xmlpath = os.path.join(outdir, "config/giet.map.xml")
46    dtspath = os.path.join(outdir, "config/linux.dts")
47    arch.main(args.x, args.y, args.nprocs, hardpath, xmlpath, dtspath)
48    faultyprocs.generate(args.faultycore, faultpath)
49
50    # create a log file
51    logfile = open(os.path.join(outdir, "log"), "w")
52
53    # 3. compile simulator executable
54    dst = os.path.join(basedir, "hard_config.h")
55    if os.path.lexists(dst):
56        os.unlink(dst)
57
58    os.symlink(hardpath, dst)
59
60    print "[ run.py ] compiling simulator"
61    command = []
62    command.extend(['make'])
63    command.extend(['-C', basedir])
64    subprocess.call(command, stdout=logfile, stderr=logfile)
65
66    # 4. compile distributed boot executable
67    dst = os.path.join(outdir, "config/boot_config.h")
68    if os.path.lexists(dst):
69        os.unlink(dst)
70
71    os.symlink(os.path.join(basedir, "soft/test/config/boot_config.h"), dst)
72
73    print "[ run.py ] compiling distributed boot procedure"
74    command = []
75    command.extend(['make'])
76    command.extend(['-C', os.path.join(basedir, "soft")])
77    command.extend(["CONFDIR=" + outdir])
78    subprocess.call(command, stdout=logfile, stderr=logfile)
79
80    # stop after compiling when the compile-only option is activated
81    if args.compileonly == True:
82        exit(0)
83
84    # 5. execute simulator
85    os.environ["DISTRIBUTED_BOOT"] = "1"
86    os.environ["SOCLIB_FB"] = "HEADLESS"
87    if args.batchmode:
88        os.environ["SOCLIB_TTY"] = "FILES"
89
90    print "[ run.py ] starting simulation"
91    command = []
92    command.extend([os.path.join(basedir, "simul.x")])
93    command.extend(["-DSOFT", os.path.join(basedir, "soft/build/soft.elf")])
94    command.extend(["-SOFT", os.path.join(basedir,
95                   "soft/loader/build/loader.elf")])
96    command.extend(["-DISK", "file.dmg"])
97
98    if args.faultyrouter != None:
99        command.extend(["-FAULTY_MASK", str(args.faultymask)])
100        for f in args.faultyrouter:
101            command.extend(["-FAULTY_ROUTER", str(f[0]), str(f[1]), str(f[2])])
102
103    if args.debug != None:
104        command.extend(["-DEBUG", str(args.debug[0])]);
105        command.extend(["-NCYCLES", str(args.debug[1])]);
106        command.extend(["-PROCID", str(args.debug[2])]);
107        command.extend(["-MEMCID", str(args.debug[3])]);
108
109    elif os.environ.get('SOCLIB_GDB') == None:
110        # the procedure grows linearly with the diameter of the mesh.
111        maxcycles = 1500000 + (args.x + args.y) * 20000
112        command.extend(["-NCYCLES", str(maxcycles)])
113
114    # OpenMP number of threads definition
115    ompthreads = args.threads
116    if ompthreads < 0:
117        if os.environ.get('SOCLIB_GDB') != None:
118            ompthreads = 1
119
120        elif args.debug != None:
121            ompthreads = 1
122
123        else:
124            ompthreads = (args.x * args.y) / 4
125            cpucount = multiprocessing.cpu_count()
126            if ompthreads > cpucount: ompthreads = cpucount
127
128    command.extend(["-THREADS", str(ompthreads)])
129
130
131    logfile.write("Execute: {0}\n".format(" ".join(command)))
132    logfile.flush()
133
134    subprocess.call(command, stdout=logfile, stderr=logfile)
135
136    logfile.close()
137
138    # 6. move simulation terminal output into the target config dir
139    os.rename("term0", os.path.join(outdir, "term"))
140
141# get command-line arguments
142if __name__ == "__main__":
143    parser = argparse.ArgumentParser(description='Run simulation')
144
145    parser.add_argument(
146        '--path', '-p', type=str, dest='path', default=os.getcwd(),
147        help='relative or absolute path to the platform')
148
149    parser.add_argument(
150        '--output', '-o', type=str, dest='outpath', default='./output',
151        help='relative or absolute path to the output directory')
152
153    parser.add_argument(
154        '--xsize', '-x', type=int, dest='x', default=2,
155        help='# of clusters in a row')
156
157    parser.add_argument(
158        '--ysize', '-y', type=int, dest='y', default=2,
159        help='# of clusters in a column')
160
161    parser.add_argument(
162        '--nprocs', '-n', type=int, dest='nprocs', default=4,
163        help='# of processors per cluster')
164
165    parser.add_argument(
166        '--compile-only', '-c', dest='compileonly', action='store_true',
167        help='generate config files and compile the platform. Do not simulate')
168
169    parser.add_argument(
170        '--batch-mode', '-b', dest='batchmode', action='store_true',
171        help='run simulation in batch mode: no interactive TTY or FrameBuffer')
172
173    parser.add_argument(
174        '--faulty-router', '-fr', dest='faultyrouter', action='append', nargs=3,
175        help='ID (T,X,Y) of faulty router. The T is 0:CMD, 1:RSP')
176
177    parser.add_argument(
178        '--faulty-mask', '-m', dest='faultymask', default=0x1F,
179        help='Disable mask for faulty router interfaces')
180
181    parser.add_argument(
182        '--faulty-core', '-fc', dest='faultycore', action='append', nargs=3,
183        help='ID (X,Y,L) of faulty processor')
184
185    parser.add_argument(
186        '--debug', '-g', dest='debug', nargs=4,
187        help='needs four arguments: from, to, procid, memcid')
188
189    parser.add_argument(
190        '--threads', '-t', dest='threads', default=-1,
191        help='number of OpenMP threads')
192
193    run(parser.parse_args())
194
195# vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Note: See TracBrowser for help on using the repository browser.