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

Last change on this file since 788 was 779, checked in by meunier, 10 years ago

Trunk:

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