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

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