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

Last change on this file since 1010 was 836, checked in by meunier, 10 years ago

Trunk:

  • Cosmetic in mem_cache_directory.h and xram_transaction.h
  • Renamed mem_cache param dspin_in_width and dspin_out_width to memc_dspin_in_width and memc_dspin_out_width (because of a bug in soclib-cc ?). Should have updated these names in the .sd or .py files of all platforms
  • Updated the scripts for tsar_generic_xbar to take into account the ideal write-through + added a graph in create_graphs.py
  • Property svn:executable set to *
File size: 15.7 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
11
12# User parameters
13nb_procs = [ 4 ]
14#nb_procs = [ 1, 4, 8, 16, 32, 64, 128, 256 ]
15rerun_stats = False
16use_omp = False
17protocol = 'wtidl'
18
19#apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga', 'kmeans' ]
20#apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga' ]
21apps = [ 'radix' ]
22
23
24# Variables which could be changed but ought not to because they are reflected in the create_graphs.py script
25data_dir = 'data'
26log_init_name = protocol + '_stdo_'
27log_term_name = protocol + '_term_'
28
29# Global Variables
30
31all_apps = [ 'cholesky', 'fft', 'fft_ga', 'filter', 'filt_ga', 'histogram', 'kmeans', 'lu', 'mandel', 'mat_mult', 'pca', 'radix', 'radix_ga', 'showimg', ]
32# to come: 'barnes', 'fmm', 'ocean', 'raytrace', 'radiosity', 'waters', 'watern'
33
34all_protocols = [ 'dhccp', 'rwt', 'hmesi', 'wtidl' ]
35
36top_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
37config_name = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.py")
38
39scripts_path       = os.path.join(top_path, 'scripts')
40almos_path         = os.path.join(top_path, 'almos')
41soclib_conf_name   = os.path.join(top_path, "soclib.conf")
42topcell_name       = os.path.join(top_path, "top.cpp")
43arch_info_name     = os.path.join(almos_path, "arch-info-gen.info")
44arch_info_bib_name = os.path.join(almos_path, 'arch-info.bib')
45hdd_img_file_name  = os.path.join(almos_path, "hdd-img.bin")
46shrc_file_name     = os.path.join(almos_path, "shrc")
47hard_config_name   = os.path.join(almos_path, "hard_config.h")
48
49
50# Checks
51if protocol not in all_protocols:
52    help_str = '''
53*** Error: variable protocol has an unsupported value
54'''
55    print help_str
56    sys.exit()
57
58for the_app in apps:
59    if the_app not in all_apps:
60        print "*** Error: application %s is not defined" % (the_app)
61        sys.exit()
62
63if not os.path.isfile(config_name):
64    help_str = '''
65You should create a file named config.py in this directory with the following definitions:
66 - apps_dir:      path to almos-tsar-mipsel/apps directory
67 - almos_src_dir: path to almos source directory (for kernel and bootloader binaries)
68 - hdd_img_name:  path to the hdd image to use (will be copied but not modified)
69 - tsar_dir:      path to tsar repository
70Optional definitions (necessary if you want to use alternative protocols):
71 - rwt_dir:       path to the RWT repository
72 - hmesi_dir:     path to HMESI directory
73 - wtidl_dir:     path to the ideal write-through protocol directory
74*** Stopping execution
75'''
76    print help_str
77    sys.exit()
78
79# Loading config
80exec(file(config_name))
81
82# Check that variables and paths exist
83for var in [ 'apps_dir', 'almos_src_dir', 'hdd_img_name', 'tsar_dir' ]:
84    if eval(var) == "":
85        print "*** Error: variable %s not defined in config file" % (var)
86        sys.exit()
87    if not os.path.exists(eval(var)):
88        print "*** Error: variable %s does not define a valid path" % (var)
89        sys.exit()
90
91if protocol == "rwt":
92    if rwt_dir == "":
93        print "*** Error: variable rwt_dir not defined in config file"
94        sys.exit()
95    if not os.path.exists(rwt_dir):
96        print "*** Error: variable rwt_dir does not define a valid path"
97        sys.exit()
98
99if protocol == "hmesi":
100    if hmesi_dir == "":
101        print "*** Error: variable hmesi_dir not defined in config file"
102        sys.exit()
103    if not os.path.exists(hmesi_dir):
104        print "*** Error: variable hmesi_dir does not define a valid path"
105        sys.exit()
106
107if protocol == "wtidl":
108    if wtidl_dir == "":
109        print "*** Error: variable wtidl_dir not defined in config file"
110        sys.exit()
111    if not os.path.exists(wtidl_dir):
112        print "*** Error: variable wtidl_dir does not define a valid path"
113        sys.exit()
114
115
116
117
118#splash_app_dir = {}
119#splash_app_dir['barnes'] = 'apps/barnes'
120#splash_app_dir['fmm'] = 'apps/fmm'
121#splash_app_dir['ocean'] = 'apps/ocean/contiguous_partitions'
122#splash_app_dir['raytrace'] = 'apps/raytrace'
123#splash_app_dir['radiosity'] = 'apps/radiosity'
124#splash_app_dir['volrend'] = 'apps/volrend'
125#splash_app_dir['watern'] = 'apps/water-nsquared'
126#splash_app_dir['waters'] = 'apps/water-spatial'
127
128
129def get_x_y(nb_procs):
130    x = 1
131    y = 1
132    to_x = True
133    while (x * y * 4 < nb_procs):
134        if to_x:
135            x = x * 2
136        else:
137            y = y * 2
138        to_x = not to_x
139    return x, y
140
141
142def gen_soclib_conf():
143
144    if os.path.isfile(soclib_conf_name):
145        print "Updating file %s" % (soclib_conf_name)
146        # First, remove lines containing "addDescPath"
147        f = open(soclib_conf_name, "r")
148        lines = f.readlines()
149        f.close()
150
151        f = open(soclib_conf_name, "w")
152
153        for line in lines:
154            if not ("addDescPath" in line):
155                f.write(line)
156        f.close()
157    else:
158        print "Creating file %s" % (soclib_conf_name)
159        f = open(soclib_conf_name, "w")
160        f.close()
161
162    # Defining common and specific modules
163    common_modules = [
164            'lib/generic_llsc_global_table',
165            'modules/dspin_router_tsar', 
166            'modules/sdmmc',
167            'modules/vci_block_device_tsar',
168            'modules/vci_ethernet_tsar',
169            'modules/vci_io_bridge',
170            'modules/vci_iox_network',
171            'modules/vci_spi',
172            'platforms/tsar_generic_xbar/tsar_xbar_cluster'
173    ]
174
175    specific_modules = [
176            'communication',
177            'lib/generic_cache_tsar',
178            'modules/vci_cc_vcache_wrapper',
179            'modules/vci_mem_cache',
180    ]
181
182    f = open(soclib_conf_name, "a")
183    # Adding common modules
184    for common_module in common_modules:
185        f.write("config.addDescPath(\"%s/%s\")\n" % (tsar_dir, common_module))
186    #f.write("\n")
187
188    if protocol == "dhccp":
189        arch_dir = tsar_dir
190    elif protocol == "rwt":
191        arch_dir = rwt_dir
192    elif protocol == "hmesi":
193        arch_dir = hmesi_dir
194    elif protocol == "wtidl":
195        arch_dir = wtidl_dir
196    else:
197        assert(False)
198
199    for specific_module in specific_modules:
200        f.write("config.addDescPath(\"%s/%s\")\n" % (arch_dir, specific_module))
201
202    #f.write("\n")
203    f.close()
204
205
206def gen_hard_config(x, y, hard_config):
207   header = '''
208/* Generated from run_simus.py */
209
210#ifndef _HD_CONFIG_H
211#define _HD_CONFIG_H
212
213#define X_SIZE              %(x)d
214#define Y_SIZE              %(y)d
215#define NB_CLUSTERS         %(nb_clus)d
216#define NB_PROCS_MAX        4
217#define NB_TASKS_MAX        8
218
219#define NB_TIM_CHANNELS     32
220#define NB_DMA_CHANNELS     1
221
222#define NB_TTY_CHANNELS     4
223#define NB_IOC_CHANNELS     1
224#define NB_NIC_CHANNELS     0
225#define NB_CMA_CHANNELS     0
226
227#define USE_XICU            1
228#define IOMMU_ACTIVE        0
229
230#define IRQ_PER_PROCESSOR   1
231''' % dict(x = x, y = y, nb_clus = x * y)
232
233   if protocol == 'wtidl':
234       header += '#define WT_IDL\n'
235
236   header += '#endif //_HD_CONFIG_H\n'
237
238   file = open(hard_config, 'w')
239   file.write(header)
240   file.close()
241
242
243
244def gen_arch_info(x, y, arch_info, arch_info_bib):
245   old_path = os.getcwd()
246   print "cd", scripts_path
247   os.chdir(scripts_path)
248   print "./gen_arch_info_large.sh", str(x), str(y), ">", arch_info
249   output = subprocess.Popen([ './gen_arch_info_large.sh', str(x), str(y) ], stdout = subprocess.PIPE).communicate()[0]
250   os.chdir(almos_path)
251   file = open(arch_info, 'w')
252   file.write(output)
253   file.close()
254   print "./info2bib -i", arch_info, "-o", arch_info_bib
255   subprocess.call([ './info2bib', '-i', arch_info, '-o', arch_info_bib ])
256   print "cd", old_path
257   os.chdir(old_path)
258   
259
260def gen_sym_links():
261   old_path = os.getcwd()
262   print "cd", almos_path
263   os.chdir(almos_path)
264
265   target = os.path.join(almos_src_dir, 'tools/soclib-bootloader/bootloader-tsar-mipsel.bin')
266   link_name = 'bootloader-tsar-mipsel.bin'
267   if not os.path.isfile(link_name):
268      print "ln -s", target, link_name
269      os.symlink(target, link_name)
270
271   target = os.path.join(almos_src_dir, 'kernel/obj.tsar/almix-tsar-mipsel.bin')
272   link_name = 'kernel-soclib.bin'
273   if not os.path.isfile(link_name):
274      print "ln -s", target, link_name
275      os.symlink(target, link_name)
276
277   copied_hdd = 'hdd-img.bin'
278   print "cp", hdd_img_name, copied_hdd
279   shutil.copy(hdd_img_name, copied_hdd)
280
281   os.chdir(old_path)
282
283
284
285def compile_app(app_name, nprocs):
286
287   #if app_name in splash2:
288   #   app_dir_name = os.path.join(splash2_dir, splash_app_dir[app_name])
289   #elif app_name in splash2_ga:
290   #   app_dir_name = os.path.join(splash2_ga_dir, splash_ga_app_dir[app_name])
291   #else:
292   #   app_dir_name = os.path.join(apps_dir, app_name)
293
294     
295   app_dir_name = os.path.join(apps_dir, app_name)
296
297   old_path = os.getcwd()
298   print "cd", app_dir_name
299   os.chdir(app_dir_name)
300
301   # Compilation process is different in splash and other apps
302   #if app_name in splash2:
303   #   print "make clean"
304   #   subprocess.call([ 'make', 'clean' ])
305
306   #   print "rm Makefile"
307   #   subprocess.call([ 'rm', 'Makefile' ])
308
309   #   print "ln -s Makefile.soclib Makefile"
310   #   subprocess.call([ 'ln', '-s', 'Makefile.soclib', 'Makefile' ])
311
312   #   print "make"
313   #   subprocess.call([ 'make' ])
314
315   #else:
316   #   print "make clean"
317   #   subprocess.call([ 'make', 'clean' ])
318 
319   #   print "make TARGET=tsar"
320   #   subprocess.call([ 'make', 'TARGET=tsar' ])
321
322   print "make clean"
323   subprocess.call([ 'make', 'clean' ])
324 
325   print "make TARGET=tsar"
326   retval = subprocess.call([ 'make', 'TARGET=tsar' ])
327   if retval != 0:
328       sys.exit()
329   
330   # Creation/Modification du shrc de almos
331   if (app_name == "boot_only"):
332      shrc = "exec -p 0 /bin/boot_onl\n"
333   elif (app_name == "mandel"):
334      shrc = "exec -p 0 /bin/mandel -n%(nproc)d\n" % dict(nproc = nprocs)
335   elif (app_name == "filter"):
336      shrc = "exec -p 0 /bin/filter -l1024 -c1024 -n%(nproc)d /etc/img.raw\n" % dict(nproc = nprocs)
337   elif (app_name == "filt_ga"):
338      shrc = "exec -p 0 /bin/filt_ga -n%(nproc)d -i /etc/img.raw\n" % dict(nproc = nprocs)
339   elif (app_name == "histogram"):
340      shrc = "exec -p 0 /bin/histogra -n%(nproc)d /etc/histo.bmp\n" % dict(nproc = nprocs)
341   elif (app_name == "kmeans"):
342      shrc = "exec -p 0 /bin/kmeans -n %(nproc)d -p %(npoints)d\n" % dict(nproc = nprocs, npoints = 10000) # default npoints = 100000
343   elif (app_name == "pca"):
344      shrc = "exec -p 0 /bin/pca -n%(nproc)d\n" % dict(nproc = nprocs)
345   elif (app_name == "mat_mult"):
346      shrc = "exec -p 0 /bin/mat_mult -n%(nproc)d\n" % dict(nproc = nprocs)
347   elif (app_name == "showimg"):
348      shrc = "exec -p 0 /bin/showimg -i /etc/lena.sgi\n"
349   elif (app_name == "barnes"):
350      shrc = "exec -p 0 /bin/barnes -n%(nproc)d -b%(nbody)d\n" % dict(nproc = nprocs, nbody = 1024)
351   elif (app_name == "fmm"):
352      shrc = "exec -p 0 /bin/fmm -n%(nproc)d -p%(nparticles)d\n" % dict(nproc = nprocs, nparticles = 1024)
353   elif (app_name == "ocean"):
354      shrc = "exec -p 0 /bin/ocean -n%(nproc)d -m%(gridsize)d\n" % dict(nproc = nprocs, gridsize = 66)
355   elif (app_name == "radiosity"):
356      shrc = "exec -p 0 /bin/radiosit -n %(nproc)d -batch\n" % dict(nproc = nprocs)
357   elif (app_name == "raytrace"):
358      shrc = "exec -p 0 /bin/raytrace -n%(nproc)d /etc/tea.env\n" % dict(nproc = nprocs)
359   elif (app_name == "watern"):
360      shrc = "exec -p 0 /bin/watern -n%(nproc)d -m512\n" % dict(nproc = nprocs)
361   elif (app_name == "waters"):
362      shrc = "exec -p 0 /bin/waters -n%(nproc)d -m512\n" % dict(nproc = nprocs)
363   elif (app_name == "cholesky"):
364      shrc = "exec -p 0 /bin/cholesky -n%(nproc)d /etc/tk14.O\n" % dict(nproc = nprocs)
365   elif (app_name == "fft"):
366      shrc = "exec -p 0 /bin/fft -n%(nproc)d -m18\n" % dict(nproc = nprocs)
367   elif (app_name == "lu"):
368      shrc = "exec -p 0 /bin/lu -n%(nproc)d -m512\n" % dict(nproc = nprocs)
369   elif (app_name == "radix"):
370      shrc = "exec -p 0 /bin/radix -n%(nproc)d -k1024\n" % dict(nproc = nprocs) # test : 1024 ; simu : 2097152
371   elif (app_name == "radix_ga"):
372      shrc = "exec -p 0 /bin/radix_ga -n%(nproc)d -k2097152\n" % dict(nproc = nprocs) # p = proc, n = num_keys
373   elif (app_name == "fft_ga"):
374      shrc = "exec -p 0 /bin/fft_ga -n%(nproc)d -m18\n" % dict(nproc = nprocs)
375   else:
376      assert(False)
377   
378   file = open(shrc_file_name, 'w')
379   file.write(shrc)
380   file.close()
381
382   # Copie du binaire et du shrc dans l'image disque
383   print "mcopy -o -i", hdd_img_file_name, shrc_file_name, "::/etc/"
384   subprocess.call([ 'mcopy', '-o', '-i', hdd_img_file_name, shrc_file_name, '::/etc/' ])
385   print "mcopy -o -i", hdd_img_file_name, app_name, "::/bin/"
386   subprocess.call([ 'mcopy', '-o', '-i', hdd_img_file_name, app_name, '::/bin/' ])
387
388   print "cd", old_path
389   os.chdir(old_path)
390# end of compile_app
391
392
393print "mkdir -p", os.path.join(scripts_path, data_dir)
394subprocess.call([ 'mkdir', '-p', os.path.join(scripts_path, data_dir) ])
395
396gen_sym_links()
397gen_soclib_conf()
398
399for i in nb_procs:
400   x, y = get_x_y(i)
401   nthreads = min(4, x * y)
402   gen_hard_config(x, y, hard_config_name)
403   gen_arch_info(x, y, arch_info_name, arch_info_bib_name)
404
405   print "cd", top_path
406   os.chdir(top_path)
407   print "touch", topcell_name
408   subprocess.call([ 'touch', topcell_name ])
409   print "make"
410   retval = subprocess.call([ 'make' ])
411   if retval != 0:
412       sys.exit()
413
414   for app in apps:
415      print "cd", top_path
416      os.chdir(top_path)
417
418      compile_app(app, i)
419
420      # Launch simulation
421      if use_omp:
422         print "./simul.x -THREADS", nthreads, ">", os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
423         output = subprocess.Popen([ './simul.x', '-THREADS', str(nthreads) ], stdout = subprocess.PIPE).communicate()[0]
424      else:
425         print "./simul.x >", os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
426         output = subprocess.Popen([ './simul.x' ], stdout = subprocess.PIPE).communicate()[0]
427
428
429      # Write simulation results to data directory
430      print "cd", scripts_path
431      os.chdir(scripts_path)
432      filename = os.path.join(data_dir, app + '_' + log_init_name + str(i))
433      file = open(filename, 'w')
434      file.write(output)
435      file.close()
436
437      filename = os.path.join(scripts_path, data_dir, app + '_' + log_term_name + str(i))
438      print "mv", os.path.join(top_path, 'term1'), filename
439      subprocess.call([ 'mv', os.path.join(top_path, 'term1'), filename ])
440
441      if rerun_stats:
442         start2_found = False
443         end_found = False
444         for line in open(filename):
445            if "[THREAD_COMPUTE_START]" in line:
446               start2 = line.split()[-1]
447               start2_found = True
448            if "[THREAD_COMPUTE_END]" in line:
449               end = line.split()[-1]
450               end_found = True
451         assert(start2_found and end_found)
452         
453         print "cd", top_path
454         os.chdir(top_path)
455
456         # Relauching simulation with reset and dump of counters
457         if use_omp:
458            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))
459            output = subprocess.Popen([ './simul.x', '-THREADS', str(nthreads), '--reset-counters', start2, '--dump-counters', end ], stdout = subprocess.PIPE).communicate()[0]
460         else:
461            print "./simul.x --reset-counters %s --dump-counters %s >" % (start2, end), os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
462            output = subprocess.Popen([ './simul.x', '--reset-counters', start2, '--dump-counters', end ], stdout = subprocess.PIPE).communicate()[0]
463         
464         # Write simulation results (counters) to data directory
465         print "cd", scripts_path
466         os.chdir(scripts_path)
467         filename = os.path.join(data_dir, app + '_' + log_init_name + str(i))
468         file = open(filename, 'w')
469         file.write(output)
470         file.close()
471 
472
473## End of simulations
474
475
476
Note: See TracBrowser for help on using the repository browser.