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

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

reconf: don't use all cpus when simulating with omp.

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