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

Last change on this file since 853 was 847, checked in by cfuguet, 10 years ago

reconf: introducing a batchmode in the onerun.py script

  • Property svn:executable set to *
File size: 3.8 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
42args = parser.parse_args()
43
44# faulty processor list
45faultylist = [(0, 0, 1), (0, 0, 2), (0, 1, 2)]
46
47# translate the relative path (if needed) into an absolute path
48basedir = os.path.abspath(args.path)
49outdir = os.path.abspath(args.outpath)
50print "[ run.py ] platform base directory: {0}".format(basedir)
51print "[ run.py ] output directory: {0}".format(outdir)
52
53# 1. generate configuration and ouput directories
54try:
55    os.makedirs(os.path.join(outdir, "config"), 0755)
56except OSError:
57    pass # directory already exists => do nothing
58
59# 2. generate hard_config.h and fault_config.h files
60faultpath = os.path.join(outdir, "config/fault_config.h")
61hardpath = os.path.join(outdir, "config/hard_config.h")
62xmlpath = os.path.join(outdir, "config/map.xml")
63arch.main(args.x, args.y, args.nprocs, hardpath, xmlpath)
64faultyprocs.generate(faultylist, faultpath)
65
66# create a log file
67logfile = open(os.path.join(outdir, "log"), "w")
68
69# 3. compile simulator executable
70dst = os.path.join(basedir, "hard_config.h")
71if os.path.lexists(dst):
72    os.unlink(dst)
73
74os.symlink(hardpath, dst)
75
76print "[ run.py ] compiling simulator"
77command = []
78command.extend(['make'])
79command.extend(['-C', basedir])
80subprocess.call(command, stdout=logfile, stderr=logfile)
81
82# 4. compile distributed boot executable
83dst = os.path.join(outdir, "config/boot_config.h")
84if os.path.lexists(dst):
85    os.unlink(dst)
86
87os.symlink(os.path.join(basedir, "soft/config/boot_config.h"), dst)
88
89# stop after compiling the platform when the compile-only option is activated
90if args.compileonly == True:
91    exit(0)
92
93print "[ run.py ] compiling distributed boot procedure"
94command = []
95command.extend(['make'])
96command.extend(['-C', os.path.join(basedir, "soft")])
97command.extend(["CONFDIR=" + outdir])
98subprocess.call(command, stdout=logfile, stderr=logfile)
99
100# 5. execute simulator
101os.environ["DISTRIBUTED_BOOT"] = "1"
102if args.batchmode:
103    os.environ["SOCLIB_FB"] = "HEADLESS"
104    os.environ["SOCLIB_TTY"] = "FILES"
105
106if (args.x * args.y) <= 4:
107    ompthreads = args.x * args.y
108elif (args.x * args.y) <= 16:
109    ompthreads = 4
110else:
111    ompthreads = 8
112
113print "[ run.py ] starting simulation"
114command = []
115command.extend([os.path.join(basedir, "simul.x")])
116command.extend(["-SOFT", os.path.join(basedir, "soft/build/soft.elf")])
117command.extend(["-DISK", "/dev/null"])
118command.extend(["-THREADS", str(ompthreads)])
119command.extend(["-NCYCLES", "1000000"])
120subprocess.call(command, stdout=logfile, stderr=logfile)
121
122logfile.close()
123
124# 6. move simulation terminal output into the target config dir
125os.rename("term0", os.path.join(outdir, "term"))
126
127# vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Note: See TracBrowser for help on using the repository browser.