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

Last change on this file since 889 was 889, checked in by cfuguet, 8 years ago

reconf: support multiple faulty routers in the platform

  • Each faulty router can be passed as a main parameter and should be preceeded with -FAULTY_ROUTER.
  • The same thing is supported by the onerun.py script.
  • Property svn:executable set to *
File size: 4.6 KB
Line 
1#!/usr/bin/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
10
11# get command-line arguments
12parser = argparse.ArgumentParser(description='Run simulation')
13
14parser.add_argument(
15    '--path', '-p', type=str, dest='path', default=os.getcwd(),
16    help='relative or absolute path to the platform')
17
18parser.add_argument(
19    '--output', '-o', type=str, dest='outpath', default='./output',
20    help='relative or absolute path to the output directory')
21
22parser.add_argument(
23    '--xsize', '-x', type=int, dest='x', default=2,
24    help='# of clusters in a row')
25
26parser.add_argument(
27    '--ysize', '-y', type=int, dest='y', default=2,
28    help='# of clusters in a column')
29
30parser.add_argument(
31    '--nprocs', '-n', type=int, dest='nprocs', default=4,
32    help='# of processors per cluster')
33
34parser.add_argument(
35    '--compile-only', '-c', dest='compileonly', action='store_true',
36    help='generate config files and compile the platform. Do not simulate')
37
38parser.add_argument(
39    '--batch-mode', '-b', dest='batchmode', action='store_true',
40    help='run simulation in batch mode: no interactive TTY or FrameBuffer')
41
42parser.add_argument(
43    '--faulty-router', '-f', dest='faultyrouter', action='append',
44    help='ID (X,Y) of faulty router')
45
46parser.add_argument(
47    '--faulty-mask', '-m', dest='faultymask', default=0x1F,
48    help='Disable mask for faulty router interfaces')
49
50parser.add_argument(
51    '--debug', '-g', dest='debug', nargs=4,
52    help='needs four arguments: from, to, procid, memcid')
53
54args = parser.parse_args()
55
56# faulty processor list
57faultylist = [(0, 0, 1), (0, 0, 2), (0, 1, 2)]
58
59# translate the relative path (if needed) into an absolute path
60basedir = os.path.abspath(args.path)
61outdir = os.path.abspath(args.outpath)
62print "[ run.py ] platform base directory: {0}".format(basedir)
63print "[ run.py ] output directory: {0}".format(outdir)
64
65# 1. generate configuration and ouput directories
66try:
67    os.makedirs(os.path.join(outdir, "config"), 0755)
68except OSError:
69    pass # directory already exists => do nothing
70
71# 2. generate hard_config.h and fault_config.h files
72faultpath = os.path.join(outdir, "config/fault_config.h")
73hardpath = os.path.join(outdir, "config/hard_config.h")
74xmlpath = os.path.join(outdir, "config/map.xml")
75arch.main(args.x, args.y, args.nprocs, hardpath, xmlpath)
76faultyprocs.generate(faultylist, faultpath)
77
78# create a log file
79logfile = open(os.path.join(outdir, "log"), "w")
80
81# 3. compile simulator executable
82dst = os.path.join(basedir, "hard_config.h")
83if os.path.lexists(dst):
84    os.unlink(dst)
85
86os.symlink(hardpath, dst)
87
88print "[ run.py ] compiling simulator"
89command = []
90command.extend(['make'])
91command.extend(['-C', basedir])
92subprocess.call(command, stdout=logfile, stderr=logfile)
93
94# 4. compile distributed boot executable
95dst = os.path.join(outdir, "config/boot_config.h")
96if os.path.lexists(dst):
97    os.unlink(dst)
98
99os.symlink(os.path.join(basedir, "soft/config/boot_config.h"), dst)
100
101# stop after compiling the platform when the compile-only option is activated
102if args.compileonly == True:
103    exit(0)
104
105print "[ run.py ] compiling distributed boot procedure"
106command = []
107command.extend(['make'])
108command.extend(['-C', os.path.join(basedir, "soft")])
109command.extend(["CONFDIR=" + outdir])
110subprocess.call(command, stdout=logfile, stderr=logfile)
111
112# 5. execute simulator
113os.environ["DISTRIBUTED_BOOT"] = "1"
114if args.batchmode:
115    os.environ["SOCLIB_FB"] = "HEADLESS"
116    os.environ["SOCLIB_TTY"] = "FILES"
117
118if (args.x * args.y) <= 4:
119    ompthreads = args.x * args.y
120elif (args.x * args.y) <= 16:
121    ompthreads = 4
122else:
123    ompthreads = 8
124
125print "[ run.py ] starting simulation"
126command = []
127command.extend([os.path.join(basedir, "simul.x")])
128command.extend(["-SOFT", os.path.join(basedir, "soft/build/soft.elf")])
129command.extend(["-DISK", "/dev/null"])
130command.extend(["-THREADS", str(ompthreads)])
131
132if args.faultyrouter != None:
133    command.extend(["-FAULTY_MASK", str(args.faultymask)])
134    for f in args.faultyrouter:
135        command.extend(["-FAULTY_ROUTER", str(f)])
136
137if args.debug != None:
138    command.extend(["-DEBUG", str(args.debug[0])]);
139    command.extend(["-NCYCLES", str(args.debug[1])]);
140    command.extend(["-PROCID", str(args.debug[2])]);
141    command.extend(["-MEMCID", str(args.debug[3])]);
142else:
143    command.extend(["-NCYCLES", "1000000"])
144
145subprocess.call(command, stdout=logfile, stderr=logfile)
146
147logfile.close()
148
149# 6. move simulation terminal output into the target config dir
150os.rename("term0", os.path.join(outdir, "term"))
151
152# vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Note: See TracBrowser for help on using the repository browser.