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

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

reconf: improve platform configuration scripts for OpenMP

  • Property svn:executable set to *
File size: 6.2 KB
RevLine 
[902]1#!/usr/bin/env python
[807]2# @date   22 September, 2014
3# @author cfuguet <cesar.fuguet-tortolero@lip6.fr>
4
5import os
6import subprocess
7import arch
8import faultyprocs
9import argparse
[906]10import multiprocessing
[807]11
[890]12def run(args):
13    """ Execute the distributed bootloader providing permanent fault-recovery on
14    the TSAR platform.
[807]15
[890]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
[904]24    faultyrouter -- a list containing faulty routers' coordinates (t, x, y)
[890]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    """
[807]29
[890]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)
[807]35
[890]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
[807]41
[890]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/map.xml")
46    arch.main(args.x, args.y, args.nprocs, hardpath, xmlpath)
47    faultyprocs.generate(args.faultycore, faultpath)
[807]48
[890]49    # create a log file
50    logfile = open(os.path.join(outdir, "log"), "w")
[807]51
[890]52    # 3. compile simulator executable
53    dst = os.path.join(basedir, "hard_config.h")
54    if os.path.lexists(dst):
55        os.unlink(dst)
[807]56
[890]57    os.symlink(hardpath, dst)
[844]58
[890]59    print "[ run.py ] compiling simulator"
60    command = []
61    command.extend(['make'])
62    command.extend(['-C', basedir])
63    subprocess.call(command, stdout=logfile, stderr=logfile)
[855]64
[890]65    # 4. compile distributed boot executable
66    dst = os.path.join(outdir, "config/boot_config.h")
67    if os.path.lexists(dst):
68        os.unlink(dst)
[859]69
[890]70    os.symlink(os.path.join(basedir, "soft/config/boot_config.h"), dst)
[855]71
[890]72    # stop after compiling the platform when the compile-only option is activated
73    if args.compileonly == True:
74        exit(0)
[807]75
[890]76    print "[ run.py ] compiling distributed boot procedure"
77    command = []
78    command.extend(['make'])
79    command.extend(['-C', os.path.join(basedir, "soft")])
80    command.extend(["CONFDIR=" + outdir])
81    subprocess.call(command, stdout=logfile, stderr=logfile)
[807]82
[890]83    # 5. execute simulator
84    os.environ["DISTRIBUTED_BOOT"] = "1"
85    if args.batchmode:
86        os.environ["SOCLIB_FB"] = "HEADLESS"
87        os.environ["SOCLIB_TTY"] = "FILES"
[807]88
[906]89    ompthreads = (args.x * args.y) / 4
90    cpucount = multiprocessing.cpu_count()
91    if ompthreads > cpucount: ompthreads = cpucount
[807]92
[890]93    print "[ run.py ] starting simulation"
94    command = []
95    command.extend([os.path.join(basedir, "simul.x")])
96    command.extend(["-SOFT", os.path.join(basedir, "soft/build/soft.elf")])
97    command.extend(["-DISK", "/dev/null"])
98    command.extend(["-THREADS", str(ompthreads)])
[807]99
[890]100    if args.faultyrouter != None:
101        command.extend(["-FAULTY_MASK", str(args.faultymask)])
102        for f in args.faultyrouter:
[904]103            command.extend(["-FAULTY_ROUTER", str(f[0]), str(f[1]), str(f[2])])
[807]104
[890]105    if args.debug != None:
106        command.extend(["-DEBUG", str(args.debug[0])]);
107        command.extend(["-NCYCLES", str(args.debug[1])]);
108        command.extend(["-PROCID", str(args.debug[2])]);
109        command.extend(["-MEMCID", str(args.debug[3])]);
110    else:
[893]111        # by observation, the procedure grows linearly with the diameter of the mesh.
[904]112        maxcycles = 400000 + (args.x + args.y) * 20000;
[893]113        command.extend(["-NCYCLES", str(maxcycles)])
[844]114
[893]115    logfile.write("Execute: {0}\n".format(" ".join(command)))
116    logfile.flush()
117
[890]118    subprocess.call(command, stdout=logfile, stderr=logfile)
[807]119
[890]120    logfile.close()
[807]121
[890]122    # 6. move simulation terminal output into the target config dir
123    os.rename("term0", os.path.join(outdir, "term"))
[844]124
[890]125# get command-line arguments
126if __name__ == "__main__":
127    parser = argparse.ArgumentParser(description='Run simulation')
[807]128
[890]129    parser.add_argument(
130        '--path', '-p', type=str, dest='path', default=os.getcwd(),
131        help='relative or absolute path to the platform')
[844]132
[890]133    parser.add_argument(
134        '--output', '-o', type=str, dest='outpath', default='./output',
135        help='relative or absolute path to the output directory')
[807]136
[890]137    parser.add_argument(
138        '--xsize', '-x', type=int, dest='x', default=2,
139        help='# of clusters in a row')
[807]140
[890]141    parser.add_argument(
142        '--ysize', '-y', type=int, dest='y', default=2,
143        help='# of clusters in a column')
[807]144
[890]145    parser.add_argument(
146        '--nprocs', '-n', type=int, dest='nprocs', default=4,
147        help='# of processors per cluster')
[855]148
[890]149    parser.add_argument(
150        '--compile-only', '-c', dest='compileonly', action='store_true',
151        help='generate config files and compile the platform. Do not simulate')
[855]152
[890]153    parser.add_argument(
154        '--batch-mode', '-b', dest='batchmode', action='store_true',
155        help='run simulation in batch mode: no interactive TTY or FrameBuffer')
[855]156
[890]157    parser.add_argument(
[904]158        '--faulty-router', '-fr', dest='faultyrouter', action='append', nargs=3,
159        help='ID (T,X,Y) of faulty router. The T is 0:CMD, 1:RSP')
[807]160
[890]161    parser.add_argument(
162        '--faulty-mask', '-m', dest='faultymask', default=0x1F,
163        help='Disable mask for faulty router interfaces')
[807]164
[890]165    parser.add_argument(
166        '--faulty-core', '-fc', dest='faultycore', action='append', nargs=3,
167        help='ID (X,Y,L) of faulty processor')
[807]168
[890]169    parser.add_argument(
170        '--debug', '-g', dest='debug', nargs=4,
171        help='needs four arguments: from, to, procid, memcid')
172
173    run(parser.parse_args())
174
[807]175# vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Note: See TracBrowser for help on using the repository browser.