source: trunk/platforms/tsar_generic_xbar/scripts/run_simus.py @ 777

Last change on this file since 777 was 752, checked in by meunier, 10 years ago
  • Added initialization to some components in order to avoid valgrind errors
  • Corrected two bugs which caused the simulations to be non-deterministic:
    • one in the memcache (possibly uninitialized paddr variable used for cache access, modifying LRU bits)
    • one in the run_simus.py script (replacing a file with an identical file in a hdd image does modify its size)
  • Property svn:executable set to *
File size: 12.2 KB
Line 
1#!/usr/bin/python
2
3import subprocess
4import os
5import sys
6import shutil
7
8#TODO: recopier les fichiers d'entrees dans le script en fonction de l'appli selectionnee
9# Par exemple, tk14.O pour LU, img.raw pour ep_filter, etc.
10
11data_dir = 'data'
12log_init_name = 'log_init_'
13log_term_name = 'log_term_'
14
15
16nb_procs = [ 4 ]
17#nb_procs = [ 16, 32, 64, 128, 256 ]
18rerun_stats = True
19use_omp = False
20
21#apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga', 'kmeans' ]
22#apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga' ]
23
24
25all_apps = [ 'cholesky', 'fft', 'fft_ga', 'filter', 'filt_ga', 'histogram', 'kmeans', 'lu', 'mandel', 'mat_mult', 'pca', 'radix', 'radix_ga', 'showimg', ]
26# to come: 'barnes', 'fmm', 'ocean', 'raytrace', 'radiosity', 'waters', 'watern'
27
28apps = [ 'cholesky' ]
29
30
31config_name = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.py")
32if not os.path.isfile(config_name):
33   help_str = '''
34You should create a file named config.py in this directory with the following definitions:
35 - apps_dir:      path to almos-tsar-mipsel/apps directory
36 - almos_src_dir: path to almos source directory (for kernel and bootloader binaries)
37 - hdd_img_name:  path to the hdd image to use
38*** Stopping execution
39'''
40   print help_str
41   sys.exit()
42
43exec(file(config_name))
44
45top_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
46
47scripts_path       = os.path.join(top_path, 'scripts')
48almos_path         = os.path.join(top_path, 'almos')
49arch_info_name     = os.path.join(almos_path, "arch-info-gen.info")
50arch_info_bib_name = os.path.join(almos_path, 'arch-info.bib')
51hdd_img_file_name  = os.path.join(almos_path, "hdd-img.bin")
52shrc_file_name     = os.path.join(almos_path, "shrc")
53hard_config_name   = os.path.join(almos_path, "hard_config.h")
54
55topcell_name = "top.cpp"
56
57
58#splash_app_dir = {}
59#splash_app_dir['barnes'] = 'apps/barnes'
60#splash_app_dir['fmm'] = 'apps/fmm'
61#splash_app_dir['ocean'] = 'apps/ocean/contiguous_partitions'
62#splash_app_dir['raytrace'] = 'apps/raytrace'
63#splash_app_dir['radiosity'] = 'apps/radiosity'
64#splash_app_dir['volrend'] = 'apps/volrend'
65#splash_app_dir['watern'] = 'apps/water-nsquared'
66#splash_app_dir['waters'] = 'apps/water-spatial'
67#
68#splash_app_dir['cholesky'] = 'kernels/cholesky'
69#splash_app_dir['fft'] = 'kernels/fft'
70#splash_app_dir['lu'] = 'kernels/lu/contiguous_blocks'
71#splash_app_dir['radix'] = 'kernels/radix'
72#
73#splash_ga_app_dir = {}
74#splash_ga_app_dir['radix_ga'] = 'apps/radix'
75#splash_ga_app_dir['fft_ga'] = 'apps/fft'
76
77
78def get_x_y(nb_procs):
79   x = 1
80   y = 1
81   to_x = True
82   while (x * y * 4 < nb_procs):
83      if to_x:
84         x = x * 2
85      else:
86         y = y * 2
87      to_x = not to_x
88   return x, y
89
90
91
92def gen_hard_config(x, y, hard_config):
93   header = '''
94/* Generated from run_simus.py */
95
96#ifndef _HD_CONFIG_H
97#define _HD_CONFIG_H
98
99#define  X_SIZE              %(x)d
100#define  Y_SIZE              %(y)d
101#define  NB_CLUSTERS         %(nb_clus)d
102#define  NB_PROCS_MAX        4
103#define  NB_TASKS_MAX        8
104
105#define  NB_TIM_CHANNELS     32
106#define  NB_DMA_CHANNELS     1
107
108#define  NB_TTY_CHANNELS     4
109#define  NB_IOC_CHANNELS     1
110#define  NB_NIC_CHANNELS     0
111#define  NB_CMA_CHANNELS     0
112
113#define  USE_XICU            1
114#define  IOMMU_ACTIVE        0
115
116#define   IRQ_PER_PROCESSOR   1
117
118#endif //_HD_CONFIG_H
119''' % dict(x = x, y = y, nb_clus = x * y)
120   file = open(hard_config, 'w')
121   file.write(header)
122   file.close()
123
124
125def gen_arch_info(x, y, arch_info, arch_info_bib):
126   old_path = os.getcwd()
127   print "cd", scripts_path
128   os.chdir(scripts_path)
129   print "./gen_arch_info_large.sh", str(x), str(y), ">", arch_info
130   output = subprocess.Popen([ './gen_arch_info_large.sh', str(x), str(y) ], stdout = subprocess.PIPE).communicate()[0]
131   os.chdir(almos_path)
132   file = open(arch_info, 'w')
133   file.write(output)
134   file.close()
135   print "./info2bib -i", arch_info, "-o", arch_info_bib
136   subprocess.call([ './info2bib', '-i', arch_info, '-o', arch_info_bib ])
137   print "cd", old_path
138   os.chdir(old_path)
139   
140
141def gen_sym_links():
142   old_path = os.getcwd()
143   print "cd", almos_path
144   os.chdir(almos_path)
145
146   target = os.path.join(almos_src_dir, 'tools/soclib-bootloader/bootloader-tsar-mipsel.bin')
147   link_name = 'bootloader-tsar-mipsel.bin'
148   if not os.path.isfile(link_name):
149      print "ln -s", target, link_name
150      os.symlink(target, link_name)
151
152   target = os.path.join(almos_src_dir, 'kernel/obj.tsar/almix-tsar-mipsel.bin')
153   link_name = 'kernel-soclib.bin'
154   if not os.path.isfile(link_name):
155      print "ln -s", target, link_name
156      os.symlink(target, link_name)
157
158   copied_hdd = 'hdd-img.bin'
159   print "cp", hdd_img_name, copied_hdd
160   shutil.copy(hdd_img_name, copied_hdd)
161
162   os.chdir(old_path)
163
164
165
166def compile_app(app_name, nprocs):
167
168   #if app_name in splash2:
169   #   app_dir_name = os.path.join(splash2_dir, splash_app_dir[app_name])
170   #elif app_name in splash2_ga:
171   #   app_dir_name = os.path.join(splash2_ga_dir, splash_ga_app_dir[app_name])
172   #else:
173   #   app_dir_name = os.path.join(apps_dir, app_name)
174
175     
176   app_dir_name = os.path.join(apps_dir, app_name)
177
178   old_path = os.getcwd()
179   print "cd", app_dir_name
180   os.chdir(app_dir_name)
181
182   # Compilation process is different in splash and other apps
183   #if app_name in splash2:
184   #   print "make clean"
185   #   subprocess.call([ 'make', 'clean' ])
186
187   #   print "rm Makefile"
188   #   subprocess.call([ 'rm', 'Makefile' ])
189
190   #   print "ln -s Makefile.soclib Makefile"
191   #   subprocess.call([ 'ln', '-s', 'Makefile.soclib', 'Makefile' ])
192
193   #   print "make"
194   #   subprocess.call([ 'make' ])
195
196   #elif app_name in splash2_ga:
197   #   print "make clean"
198   #   subprocess.call([ 'make', 'clean' ])
199
200   #   print "make"
201   #   subprocess.call([ 'make' ])
202
203   #else:
204   #   print "make clean"
205   #   subprocess.call([ 'make', 'clean' ])
206 
207   #   print "make TARGET=tsar"
208   #   subprocess.call([ 'make', 'TARGET=tsar' ])
209
210   print "make clean"
211   subprocess.call([ 'make', 'clean' ])
212 
213   print "make TARGET=tsar"
214   subprocess.call([ 'make', 'TARGET=tsar' ])
215   
216   # Creation/Modification du shrc de almos
217   if (app_name == "boot_only"):
218      shrc = "exec -p 0 /bin/boot_onl\n"
219   elif (app_name == "mandel"):
220      shrc = "exec -p 0 /bin/mandel -n%(nproc)d\n" % dict(nproc = nprocs)
221   elif (app_name == "filter"):
222      shrc = "exec -p 0 /bin/filter -l1024 -c1024 -n%(nproc)d /etc/img.raw\n" % dict(nproc = nprocs)
223   elif (app_name == "filt_ga"):
224      shrc = "exec -p 0 /bin/filt_ga -n%(nproc)d -i /etc/img.raw\n" % dict(nproc = nprocs)
225   elif (app_name == "histogram"):
226      shrc = "exec -p 0 /bin/histogra -n%(nproc)d /etc/histo.bmp\n" % dict(nproc = nprocs)
227   elif (app_name == "kmeans"):
228      shrc = "exec -p 0 /bin/kmeans -n %(nproc)d -p %(npoints)d\n" % dict(nproc = nprocs, npoints = 10000) # default npoints = 100000
229   elif (app_name == "pca"):
230      shrc = "exec -p 0 /bin/pca -n%(nproc)d\n" % dict(nproc = nprocs)
231   elif (app_name == "mat_mult"):
232      shrc = "exec -p 0 /bin/mat_mult -n%(nproc)d\n" % dict(nproc = nprocs)
233   elif (app_name == "showimg"):
234      shrc = "exec -p 0 /bin/showimg -i /etc/lena.sgi\n"
235   elif (app_name == "barnes"):
236      shrc = "exec -p 0 /bin/barnes -n%(nproc)d -b%(nbody)d\n" % dict(nproc = nprocs, nbody = 1024)
237   elif (app_name == "fmm"):
238      shrc = "exec -p 0 /bin/fmm -n%(nproc)d -p%(nparticles)d\n" % dict(nproc = nprocs, nparticles = 1024)
239   elif (app_name == "ocean"):
240      shrc = "exec -p 0 /bin/ocean -n%(nproc)d -m%(gridsize)d\n" % dict(nproc = nprocs, gridsize = 66)
241   elif (app_name == "radiosity"):
242      shrc = "exec -p 0 /bin/radiosit -n %(nproc)d -batch\n" % dict(nproc = nprocs)
243   elif (app_name == "raytrace"):
244      shrc = "exec -p 0 /bin/raytrace -n%(nproc)d /etc/tea.env\n" % dict(nproc = nprocs)
245   elif (app_name == "watern"):
246      shrc = "exec -p 0 /bin/watern -n%(nproc)d -m512\n" % dict(nproc = nprocs)
247   elif (app_name == "waters"):
248      shrc = "exec -p 0 /bin/waters -n%(nproc)d -m512\n" % dict(nproc = nprocs)
249   elif (app_name == "cholesky"):
250      shrc = "exec -p 0 /bin/cholesky -n%(nproc)d /etc/tk14.O\n" % dict(nproc = nprocs)
251   elif (app_name == "fft"):
252      shrc = "exec -p 0 /bin/fft -n%(nproc)d -m18\n" % dict(nproc = nprocs)
253   elif (app_name == "lu"):
254      shrc = "exec -p 0 /bin/lu -n%(nproc)d -m512\n" % dict(nproc = nprocs)
255   elif (app_name == "radix"):
256      shrc = "exec -p 0 /bin/radix -n%(nproc)d -k1024\n" % dict(nproc = nprocs) # test : 1024 ; simu : 2097152
257   elif (app_name == "radix_ga"):
258      shrc = "exec -p 0 /bin/radix_ga -n%(nproc)d -k2097152\n" % dict(nproc = nprocs) # p = proc, n = num_keys
259   elif (app_name == "fft_ga"):
260      shrc = "exec -p 0 /bin/fft_ga -n%(nproc)d -m18\n" % dict(nproc = nprocs)
261   else:
262      assert(False)
263   
264   file = open(shrc_file_name, 'w')
265   file.write(shrc)
266   file.close()
267
268   # Copie du binaire et du shrc dans l'image disque
269   print "mcopy -o -i", hdd_img_file_name, shrc_file_name, "::/etc/"
270   subprocess.call([ 'mcopy', '-o', '-i', hdd_img_file_name, shrc_file_name, '::/etc/' ])
271   print "mcopy -o -i", hdd_img_file_name, app_name, "::/bin/"
272   subprocess.call([ 'mcopy', '-o', '-i', hdd_img_file_name, app_name, '::/bin/' ])
273
274   print "cd", old_path
275   os.chdir(old_path)
276# end of compile_app
277
278
279print "mkdir -p", os.path.join(scripts_path, data_dir)
280subprocess.call([ 'mkdir', '-p', os.path.join(scripts_path, data_dir) ])
281
282gen_sym_links()
283
284for i in nb_procs:
285   x, y = get_x_y(i)
286   nthreads = min(4, x * y)
287   gen_hard_config(x, y, hard_config_name)
288   gen_arch_info(x, y, arch_info_name, arch_info_bib_name)
289
290   print "cd", top_path
291   os.chdir(top_path)
292   print "touch", topcell_name
293   subprocess.call([ 'touch', topcell_name ])
294   print "make"
295   subprocess.call([ 'make' ])
296   
297   for app in apps:
298      print "cd", top_path
299      os.chdir(top_path)
300
301      compile_app(app, i)
302
303      # Launch simulation
304      if use_omp:
305         print "./simul.x -THREADS", nthreads, ">", os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
306         output = subprocess.Popen([ './simul.x', '-THREADS', str(nthreads) ], stdout = subprocess.PIPE).communicate()[0]
307      else:
308         print "./simul.x >", os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
309         output = subprocess.Popen([ './simul.x' ], stdout = subprocess.PIPE).communicate()[0]
310
311
312      # Write simulation results to data directory
313      print "cd", scripts_path
314      os.chdir(scripts_path)
315      filename = os.path.join(data_dir, app + '_' + log_init_name + str(i))
316      file = open(filename, 'w')
317      file.write(output)
318      file.close()
319
320      filename = os.path.join(scripts_path, data_dir, app + '_' + log_term_name + str(i))
321      print "mv", os.path.join(top_path, 'term1'), filename
322      subprocess.call([ 'mv', os.path.join(top_path, 'term1'), filename ])
323
324      if rerun_stats:
325         start2_found = False
326         end_found = False
327         for line in open(filename):
328            if "[THREAD_COMPUTE_START]" in line:
329               start2 = line.split()[-1]
330               start2_found = True
331            if "[THREAD_COMPUTE_END]" in line:
332               end = line.split()[-1]
333               end_found = True
334         assert(start2_found and end_found)
335         
336         print "cd", top_path
337         os.chdir(top_path)
338
339         # Relauching simulation with reset and dump of counters
340         if use_omp:
341            print "./simul.x -THREADS", nthreads, "--reset-counters %s --dump-counters %s >" % (start2, end), os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
342            output = subprocess.Popen([ './simul.x', '-THREADS', str(nthreads), '--reset-counters', start2, '--dump-counters', end ], stdout = subprocess.PIPE).communicate()[0]
343         else:
344            print "./simul.x --reset-counters %s --dump-counters %s >" % (start2, end), os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
345            output = subprocess.Popen([ './simul.x', '--reset-counters', start2, '--dump-counters', end ], stdout = subprocess.PIPE).communicate()[0]
346         
347         # Write simulation results (counters) to data directory
348         print "cd", scripts_path
349         os.chdir(scripts_path)
350         filename = os.path.join(data_dir, app + '_' + log_init_name + str(i))
351         file = open(filename, 'w')
352         file.write(output)
353         file.close()
354 
355
356## End of simulations
357
358
359
Note: See TracBrowser for help on using the repository browser.