source: soft/giet_vm/applications/rosenfeld/scripts/common.py @ 824

Last change on this file since 824 was 822, checked in by meunier, 9 years ago

In rosenfeld:

  • Updated nrio0, nrio1, nrio2, nrio1f, nrio2f, nrio1x, nrbool1, nrbool2 and nralloc1 in the nrc2 lib in order to use macro-typed functions
  • Updated the simulation script to include performance evaluation with random images, and a script to generate graphs
  • Updated the clock.h to use 64-bit integers, which potentially breaks the printing on the giet
File size: 3.0 KB
Line 
1
2from __future__ import print_function
3import os
4import subprocess
5import sys
6
7
8
9
10def short_path(name):
11    abs_path = os.path.abspath(name)
12    rel_path = os.path.relpath(name)
13    if len(abs_path) < len(rel_path):
14        return abs_path
15    else:
16        return rel_path
17
18
19def check_pyconf_file(pyconf_file):
20    if not os.path.isfile(pyconf_file):
21        help_str = '''
22You should create a file named %s in this directory with the following definitions:
23 - ... (to complete)
24Optional definitions:
25 - dsk_dir: path to a local storage (typically in /dsk/l1/misc) to store generated data and images
26*** Stopping execution
27''' % (short_path(pyconf_file))
28        print(help_str)
29        sys.exit()
30
31
32   
33def my_mkdir(abs_dirname):
34    dirname = short_path(abs_dirname)
35    try:
36        print("mkdir %s" % (dirname))
37        os.mkdir(dirname)
38    except OSError:
39        print("*** Error: impossible to create directory %s" % (dirname), file = sys.stderr)
40        sys.exit(1)
41
42def my_chdir(abs_dirname):
43    dirname = short_path(abs_dirname)
44    print("cd %s" % (dirname));
45    os.chdir(dirname)
46
47def my_cp(abs_src, abs_dst):
48    src = short_path(abs_src)
49    dst = short_path(abs_dst)
50    print("cp %s %s" % (src, dst))
51    shutil.copy(src, dst)
52
53
54def get_random_img_file(density, x, y, granularity, seed):
55    density_str = str(density)
56    if density < 10:
57        density_str = "0" + density_str
58    if density < 100:
59        density_str = "0" + density_str
60
61    return "rand_" + str(x) + "_" + str(y) + "_" + density_str + "_G" + str(granularity) + ".pgm"
62
63
64def get_filename(dir, nthreads, config, ftrs, basename):
65    if ftrs:
66        ftrs_str = "_FEATURES_1"
67    else:
68        ftrs_str = "_FEATURES_0"
69
70    config_keys = list(config.keys()) # duplicates list
71    try:
72        config_keys.remove('FEATURES')
73    except:
74        pass
75    config_keys = sorted(config_keys)
76    filename = os.path.join(dir, basename + "_" + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ftrs_str + ".txt")
77   
78    return filename
79
80
81def get_graph_filename(dir, nthreads, config, ext):
82    config_keys = list(config.keys()) # duplicates list
83    config_keys = sorted(config_keys)
84    filename = os.path.join(dir, "random_" + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ext)
85   
86    return filename
87
88
89
90def print_and_call(cmd):
91    print(subprocess.list2cmdline(cmd))
92    retval = subprocess.call(cmd)
93    return retval
94
95def print_and_popen(cmd, abs_outfile):
96    outfile = short_path(abs_outfile)
97    print(subprocess.list2cmdline(cmd), end = "")
98    print(" >", outfile)
99    child = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
100    output = child.communicate()[0]
101    retval = child.returncode
102               
103    # Write simulation results to log file
104    file = open(outfile, 'w')
105    file.write(output)
106    file.close()
107
108    if retval != 0:
109        print("*** Error while executing command '%s'" % subprocess.list2cmdline(cmd))
110        sys.exit(1)
111
112    return output
113
114
Note: See TracBrowser for help on using the repository browser.