1 | #!/usr/bin/python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | |
---|
4 | import shutil |
---|
5 | from common import * |
---|
6 | |
---|
7 | |
---|
8 | granularities = [16] |
---|
9 | threads = [16, 64] |
---|
10 | use_rand_images = True |
---|
11 | img_size = 2048 |
---|
12 | use_dsk = True |
---|
13 | use_rand_img = True |
---|
14 | nb_simus_wrt_density = 2 # e.g. if 2, each simus processes 50 or 51 images |
---|
15 | |
---|
16 | rand_seed = 7 |
---|
17 | |
---|
18 | configs = [ |
---|
19 | {'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'1', 'ARSP':'1'}, |
---|
20 | #{'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'1', 'ARSP':'1'}, |
---|
21 | ] |
---|
22 | |
---|
23 | |
---|
24 | mode = 'simu' |
---|
25 | |
---|
26 | if mode == 'test': |
---|
27 | data_dir = 'data_test' |
---|
28 | else: |
---|
29 | data_dir = 'data' |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | # Directories definitions |
---|
34 | scripts_dir = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) |
---|
35 | giet_dir = os.path.abspath(os.path.join(scripts_dir, "..", "..", "..")) |
---|
36 | pyconf_file = os.path.join(scripts_dir, "config.py") |
---|
37 | # Contains run_simus_soclib.py, |
---|
38 | template_scripts_dir = os.path.join(scripts_dir, "template_scripts") |
---|
39 | |
---|
40 | |
---|
41 | check_pyconf_file(pyconf_file) |
---|
42 | |
---|
43 | exec(file(pyconf_file)) |
---|
44 | |
---|
45 | try: |
---|
46 | dsk_dir |
---|
47 | if not os.path.exists(dsk_dir): |
---|
48 | print("mkdir %s", dsk_dir) |
---|
49 | os.mkdir(dsk_dir) |
---|
50 | except NameError: |
---|
51 | print("*** Error: variable dsk_dir is not defined in %s file" % (short_path(pyconf_file))) |
---|
52 | sys.exit(1) |
---|
53 | except OSError: |
---|
54 | print("*** Error: Impossible to create directory %s" % (dsk_dir)) |
---|
55 | sys.exit(1) |
---|
56 | |
---|
57 | try: |
---|
58 | tsar_dir |
---|
59 | tsar_iob_dir = os.path.join(tsar_dir, "platforms", "tsar_generic_iob") |
---|
60 | except NameError: |
---|
61 | print("*** Error: variable tsar_dir is not defined in %s file" % (short_path(pyconf_file))) |
---|
62 | sys.exit(1) |
---|
63 | |
---|
64 | try: |
---|
65 | rand_img_dir |
---|
66 | if not os.path.exists(rand_img_dir): |
---|
67 | print("mkdir %s", rand_img_dir) |
---|
68 | os.mkdir(rand_img_dir) |
---|
69 | except NameError: |
---|
70 | print("*** Error: variable rand_img_dir, containing the path the random images (either pre-existing or to be generated), is not defined in %s file" % (short_path(pyconf_file))) |
---|
71 | sys.exit(1) |
---|
72 | except OSError: |
---|
73 | print("*** Error: Impossible to create directory %s" % (rand_img_dir)) |
---|
74 | sys.exit(1) |
---|
75 | |
---|
76 | try: |
---|
77 | preloader_dir |
---|
78 | except NameError: |
---|
79 | print("*** Error: variable preloader_dir is not defined in %s file" % (short_path(pyconf_file))) |
---|
80 | sys.exit(1) |
---|
81 | |
---|
82 | |
---|
83 | # Topcell files |
---|
84 | top_file = os.path.join(tsar_iob_dir, "top.cpp") |
---|
85 | desc_file = os.path.join(tsar_iob_dir, "top.desc") |
---|
86 | make_file = os.path.join(tsar_iob_dir, "Makefile") |
---|
87 | arch_file = os.path.join(tsar_iob_dir, "arch.py") |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | def create_config_file(filename, granularities, threads, start_density, end_density, config): |
---|
92 | print "# Creating file %s" % (filename) |
---|
93 | f = open(filename, "w") |
---|
94 | f.write("use_rand_img = %s\n" % str(use_rand_img)) |
---|
95 | f.write("granularities = [%s]\n" % str(granularities)) |
---|
96 | f.write("threads = [%s]\n" % str(threads)) |
---|
97 | f.write("start_density = %s\n" % str(start_density)) |
---|
98 | f.write("end_density = %s\n" % str(end_density)) |
---|
99 | f.write("img_size = %s\n" % str(img_size)) |
---|
100 | f.write("configs = [\n") |
---|
101 | f.write(" {") |
---|
102 | config_keys = list(config.keys()) # duplicates list |
---|
103 | config_keys = sorted(config_keys) |
---|
104 | first = True |
---|
105 | for key in config_keys: |
---|
106 | if not first: |
---|
107 | f.write(", ") |
---|
108 | f.write("'%s':'%s'" % (key, config[key])) |
---|
109 | first = False |
---|
110 | f.write("},\n") |
---|
111 | f.write("]\n") |
---|
112 | f.write('tsar_dir = "%s"\n' % tsar_dir) |
---|
113 | f.write('preloader_dir = "%s"\n' % preloader_dir) |
---|
114 | f.close() |
---|
115 | |
---|
116 | |
---|
117 | def giet_ignore_list(dir, files): |
---|
118 | ignore_list = [] |
---|
119 | if dir == giet_dir: |
---|
120 | ok_list = ["applications", "create_dmg", "hdd", "giet_boot", "giet_common", "giet_config.h", "giet_drivers", "giet_fat32", "giet_kernel", "giet_libs", "giet_python", "giet_xml", "images", "Makefile"] |
---|
121 | for file in files: |
---|
122 | if not file in ok_list: |
---|
123 | ignore_list.append(file) |
---|
124 | elif dir == os.path.join(giet_dir, "applications"): |
---|
125 | ok_list = ["rosenfeld"] |
---|
126 | for file in files: |
---|
127 | if not file in ok_list: |
---|
128 | ignore_list.append(file) |
---|
129 | elif dir == os.path.join(giet_dir, "applications", "rosenfeld"): |
---|
130 | ok_list = ["include", "Makefile", "nrc2", "rosenfeld.ld", "rosenfeld.py", "src", "src-par"] |
---|
131 | for file in files: |
---|
132 | if not file in ok_list: |
---|
133 | ignore_list.append(file) |
---|
134 | elif dir == os.path.join(giet_dir, "hdd"): |
---|
135 | for file in files: |
---|
136 | ignore_list.append(file) |
---|
137 | else: |
---|
138 | pass |
---|
139 | return ignore_list |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | def get_x_y_p(nb_procs): |
---|
144 | if nb_procs < 4: |
---|
145 | return 1, 1, nb_procs |
---|
146 | cpu_per_cluster = 4 |
---|
147 | x = 1 |
---|
148 | y = 1 |
---|
149 | to_x = True |
---|
150 | while (x * y * cpu_per_cluster < nb_procs): |
---|
151 | if to_x: |
---|
152 | x = x * 2 |
---|
153 | else: |
---|
154 | y = y * 2 |
---|
155 | to_x = not to_x |
---|
156 | return x, y, cpu_per_cluster |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | def gen_params_mk(copied_giet_dir, simul_dir, nthreads): |
---|
161 | x_size, y_size, cpu_per_cluster = get_x_y_p(nthreads) |
---|
162 | tmpl = ''' |
---|
163 | ARCH ?= %(arch_dir)s |
---|
164 | X_SIZE ?= %(x_size)d |
---|
165 | Y_SIZE ?= %(y_size)d |
---|
166 | NB_PROCS ?= %(nb_procs)d |
---|
167 | NB_TTYS ?= 3 |
---|
168 | FBF_WIDTH ?= 256 |
---|
169 | IOC_TYPE ?= BDV |
---|
170 | MWR_TYPE ?= CPY |
---|
171 | APPLIS ?= rosenfeld |
---|
172 | ''' % dict(arch_dir = simul_dir, |
---|
173 | x_size = x_size, |
---|
174 | y_size = y_size, |
---|
175 | nb_procs = cpu_per_cluster) |
---|
176 | params_mk_file = os.path.join(copied_giet_dir, "params.mk") |
---|
177 | f = open(params_mk_file, 'w') |
---|
178 | f.write(tmpl) |
---|
179 | f.close() |
---|
180 | |
---|
181 | # Computing start_density and end_density |
---|
182 | nb_density_base_per_simu = 101 / nb_simus_wrt_density |
---|
183 | nb_simus_left = 101 - nb_density_base_per_simu * nb_simus_wrt_density |
---|
184 | curr_density = 0 |
---|
185 | start_densities = {} |
---|
186 | end_densities = {} |
---|
187 | for simu_wrt_density in range(0, nb_simus_wrt_density): |
---|
188 | start_densities[simu_wrt_density] = curr_density |
---|
189 | if nb_simus_left > 0: |
---|
190 | curr_nb_simus = nb_density_base_per_simu + 1 |
---|
191 | nb_simus_left -= 1 |
---|
192 | else: |
---|
193 | curr_nb_simus = nb_density_base_per_simu |
---|
194 | end_densities[simu_wrt_density] = curr_density + curr_nb_simus - 1 |
---|
195 | curr_density += curr_nb_simus |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | for gran in granularities: |
---|
200 | for th in threads: |
---|
201 | for config in configs: |
---|
202 | for simu_wrt_density in range(0, nb_simus_wrt_density): |
---|
203 | start_density = start_densities[simu_wrt_density] |
---|
204 | end_density = end_densities[simu_wrt_density] |
---|
205 | |
---|
206 | features = config['FEATURES'] == '1' |
---|
207 | simul_dir = get_dirname(dsk_dir, th, config, features, gran, start_density, end_density, "rosen") |
---|
208 | if not os.path.exists(simul_dir): |
---|
209 | my_mkdir(simul_dir) |
---|
210 | my_cp(top_file, simul_dir) |
---|
211 | my_cp(desc_file, simul_dir) |
---|
212 | my_cp(make_file, simul_dir) |
---|
213 | my_cp(arch_file, simul_dir) |
---|
214 | |
---|
215 | create_config_file(os.path.join(simul_dir, "config.py"), gran, th, start_density, end_density, config) |
---|
216 | |
---|
217 | |
---|
218 | tmpl_script_files = [f for f in os.listdir(template_scripts_dir) if os.path.isfile(os.path.join(template_scripts_dir, f))] |
---|
219 | for tmpl_script_file in tmpl_script_files: |
---|
220 | my_cp(os.path.join(template_scripts_dir, tmpl_script_file), simul_dir) |
---|
221 | |
---|
222 | # Copy and compile the giet |
---|
223 | copied_giet_dir = os.path.join(simul_dir, "giet_vm") |
---|
224 | if not os.path.exists(copied_giet_dir): |
---|
225 | shutil.copytree(giet_dir, copied_giet_dir, symlinks = False, ignore = giet_ignore_list) |
---|
226 | my_chdir(copied_giet_dir) |
---|
227 | # Copy the correct image files |
---|
228 | if use_rand_img: |
---|
229 | for density in range(start_density, end_density + 1): |
---|
230 | img_filename = os.path.join(rand_img_dir, get_random_img_file(density, img_size, img_size, gran, rand_seed)) |
---|
231 | if not os.path.isfile(img_filename): |
---|
232 | print("# Generating random image %s with granularity = %d and density = %d" % (img_filename, gran, density)) |
---|
233 | gen_random_image(img_filename, img_size, img_size, gran, float(density) / 100, rand_seed) |
---|
234 | # We are forced to use a short image name for the giet because the hdd truncates after 8 characters, so all the |
---|
235 | # distinctive informations should be contained in 8 chars. |
---|
236 | target_img_filename = get_short_random_img_file(density, gran) |
---|
237 | my_cp(img_filename, os.path.join(copied_giet_dir, "images", target_img_filename)) |
---|
238 | else: |
---|
239 | print("*** Error: Only random images are currently supported\n"); |
---|
240 | sys.exit(1) |
---|
241 | |
---|
242 | # Generate the file params.mk |
---|
243 | gen_params_mk(copied_giet_dir, simul_dir, th) |
---|
244 | |
---|
245 | #cmd = ['make', 'clean-disk'] |
---|
246 | #print_and_call(cmd) |
---|
247 | |
---|
248 | #cmd = ['make'] |
---|
249 | #print_and_call(cmd) |
---|
250 | |
---|
251 | my_chdir(scripts_dir) |
---|
252 | # end density range |
---|
253 | # end config |
---|
254 | # end threads |
---|
255 | # end granularity |
---|
256 | |
---|
257 | print("# End of %s" % __file__) |
---|
258 | |
---|
259 | |
---|
260 | |
---|
261 | |
---|
262 | |
---|
263 | |
---|
264 | |
---|
265 | |
---|