[724] | 1 | #!/usr/bin/python |
---|
| 2 | |
---|
| 3 | import subprocess |
---|
| 4 | import os |
---|
| 5 | import 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 | |
---|
| 10 | data_dir = 'data' |
---|
| 11 | log_init_name = 'log_init_' |
---|
| 12 | log_term_name = 'log_term_' |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | nb_procs = [ 4 ] |
---|
| 16 | #nb_procs = [ 1, 4, 8, 16, 32, 64, 128, 256 ] |
---|
| 17 | rerun_stats = True |
---|
| 18 | use_omp = False |
---|
| 19 | |
---|
| 20 | #apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga', 'kmeans' ] |
---|
| 21 | #apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga' ] |
---|
| 22 | apps = [ 'filt_ga' ] |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | all_apps = [ 'mandel', 'filter', 'filt_ga', 'histogram', 'kmeans', 'barnes', 'fmm', 'ocean', 'raytrace', 'radiosity', 'waters', 'watern', 'cholesky', 'lu', 'fft', 'radix', 'fft_ga', 'radix_ga', 'kmeans' ] |
---|
| 26 | splash2 = [ 'barnes', 'fmm', 'ocean', 'radiosity', 'raytrace', 'watern', 'waters', 'cholesky', 'lu', 'fft', 'radix' ] |
---|
| 27 | splash2_ga = [ 'radix_ga', 'fft_ga' ] |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | config_name = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.py") |
---|
| 31 | if not os.path.isfile(config_name): |
---|
| 32 | help_str = ''' |
---|
| 33 | You 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 | |
---|
| 42 | exec(file(config_name)) |
---|
| 43 | |
---|
| 44 | top_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..") |
---|
| 45 | |
---|
| 46 | splash2_dir = os.path.join(apps_dir, 'splash2/codes') |
---|
| 47 | splash2_ga_dir = os.path.join(apps_dir, 'splash2_ga') |
---|
| 48 | |
---|
| 49 | scripts_path = os.path.join(top_path, 'scripts') |
---|
| 50 | almos_path = os.path.join(top_path, 'almos') |
---|
| 51 | arch_info_name = os.path.join(almos_path, "arch-info-gen.info") |
---|
| 52 | arch_info_bib_name = os.path.join(almos_path, 'arch-info.bib') |
---|
| 53 | hdd_img_file_name = os.path.join(almos_path, "hdd-img.bin") |
---|
| 54 | shrc_file_name = os.path.join(almos_path, "shrc") |
---|
| 55 | hard_config_name = os.path.join(almos_path, "hard_config.h") |
---|
| 56 | |
---|
| 57 | topcell_name = "top.cpp" |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | splash_app_dir = {} |
---|
| 61 | splash_app_dir['barnes'] = 'apps/barnes' |
---|
| 62 | splash_app_dir['fmm'] = 'apps/fmm' |
---|
| 63 | splash_app_dir['ocean'] = 'apps/ocean/contiguous_partitions' |
---|
| 64 | splash_app_dir['raytrace'] = 'apps/raytrace' |
---|
| 65 | splash_app_dir['radiosity'] = 'apps/radiosity' |
---|
| 66 | #splash_app_dir['volrend'] = 'apps/volrend' |
---|
| 67 | splash_app_dir['watern'] = 'apps/water-nsquared' |
---|
| 68 | splash_app_dir['waters'] = 'apps/water-spatial' |
---|
| 69 | |
---|
| 70 | splash_app_dir['cholesky'] = 'kernels/cholesky' |
---|
| 71 | splash_app_dir['fft'] = 'kernels/fft' |
---|
| 72 | splash_app_dir['lu'] = 'kernels/lu/contiguous_blocks' |
---|
| 73 | splash_app_dir['radix'] = 'kernels/radix' |
---|
| 74 | |
---|
| 75 | splash_ga_app_dir = {} |
---|
| 76 | splash_ga_app_dir['radix_ga'] = 'apps/radix' |
---|
| 77 | splash_ga_app_dir['fft_ga'] = 'apps/fft' |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | def get_x_y(nb_procs): |
---|
| 81 | x = 1 |
---|
| 82 | y = 1 |
---|
| 83 | to_x = True |
---|
| 84 | while (x * y * 4 < nb_procs): |
---|
| 85 | if to_x: |
---|
| 86 | x = x * 2 |
---|
| 87 | else: |
---|
| 88 | y = y * 2 |
---|
| 89 | to_x = not to_x |
---|
| 90 | return x, y |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | def gen_hard_config(x, y, hard_config): |
---|
| 95 | header = ''' |
---|
| 96 | /* Generated from run_simus.py */ |
---|
| 97 | |
---|
| 98 | #ifndef _HD_CONFIG_H |
---|
| 99 | #define _HD_CONFIG_H |
---|
| 100 | |
---|
| 101 | #define X_SIZE %(x)d |
---|
| 102 | #define Y_SIZE %(y)d |
---|
| 103 | #define NB_CLUSTERS %(nb_clus)d |
---|
| 104 | #define NB_PROCS_MAX 4 |
---|
| 105 | #define NB_TASKS_MAX 8 |
---|
| 106 | |
---|
| 107 | #define NB_TIM_CHANNELS 32 |
---|
| 108 | #define NB_DMA_CHANNELS 1 |
---|
| 109 | |
---|
| 110 | #define NB_TTY_CHANNELS 4 |
---|
| 111 | #define NB_IOC_CHANNELS 1 |
---|
| 112 | #define NB_NIC_CHANNELS 0 |
---|
| 113 | #define NB_CMA_CHANNELS 0 |
---|
| 114 | |
---|
| 115 | #define USE_XICU 1 |
---|
| 116 | #define IOMMU_ACTIVE 0 |
---|
| 117 | |
---|
| 118 | #define IRQ_PER_PROCESSOR 1 |
---|
| 119 | |
---|
| 120 | #endif //_HD_CONFIG_H |
---|
| 121 | ''' % dict(x = x, y = y, nb_clus = x * y) |
---|
| 122 | file = open(hard_config, 'w') |
---|
| 123 | file.write(header) |
---|
| 124 | file.close() |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | def gen_arch_info(x, y, arch_info, arch_info_bib): |
---|
| 128 | old_path = os.getcwd() |
---|
| 129 | print "cd", scripts_path |
---|
| 130 | os.chdir(scripts_path) |
---|
| 131 | print "./gen_arch_info_large.sh", str(x), str(y), ">", arch_info |
---|
| 132 | output = subprocess.Popen([ './gen_arch_info_large.sh', str(x), str(y) ], stdout = subprocess.PIPE).communicate()[0] |
---|
| 133 | os.chdir(almos_path) |
---|
| 134 | file = open(arch_info, 'w') |
---|
| 135 | file.write(output) |
---|
| 136 | file.close() |
---|
| 137 | print "./info2bib -i", arch_info, "-o", arch_info_bib |
---|
| 138 | subprocess.call([ './info2bib', '-i', arch_info, '-o', arch_info_bib ]) |
---|
| 139 | print "cd", old_path |
---|
| 140 | os.chdir(old_path) |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | def gen_sym_links(): |
---|
| 144 | old_path = os.getcwd() |
---|
| 145 | print "cd", almos_path |
---|
| 146 | os.chdir(almos_path) |
---|
| 147 | |
---|
| 148 | target = os.path.join(almos_src_dir, 'tools/soclib-bootloader/bootloader-tsar-mipsel.bin') |
---|
| 149 | link_name = 'bootloader-tsar-mipsel.bin' |
---|
| 150 | if not os.path.isfile(link_name): |
---|
| 151 | print "ln -s", target, link_name |
---|
| 152 | os.symlink(target, link_name) |
---|
| 153 | |
---|
| 154 | target = os.path.join(almos_src_dir, 'kernel/obj.tsar/almix-tsar-mipsel.bin') |
---|
| 155 | link_name = 'kernel-soclib.bin' |
---|
| 156 | if not os.path.isfile(link_name): |
---|
| 157 | print "ln -s", target, link_name |
---|
| 158 | os.symlink(target, link_name) |
---|
| 159 | |
---|
| 160 | target = hdd_img_name |
---|
| 161 | link_name = 'hdd-img.bin' |
---|
| 162 | if not os.path.isfile(link_name): |
---|
| 163 | print "ln -s", target, link_name |
---|
| 164 | os.symlink(target, link_name) |
---|
| 165 | |
---|
| 166 | os.chdir(old_path) |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | def compile_app(app_name, nprocs): |
---|
| 171 | |
---|
| 172 | if app_name in splash2: |
---|
| 173 | app_dir_name = os.path.join(splash2_dir, splash_app_dir[app_name]) |
---|
| 174 | elif app_name in splash2_ga: |
---|
| 175 | app_dir_name = os.path.join(splash2_ga_dir, splash_ga_app_dir[app_name]) |
---|
| 176 | else: |
---|
| 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 | # Creation/Modification du shrc de almos |
---|
| 212 | if (app_name == "boot_only"): |
---|
| 213 | shrc = "exec -p 0 /bin/boot_onl\n" |
---|
| 214 | elif (app_name == "mandel"): |
---|
| 215 | shrc = "exec -p 0 /bin/mandel -n%(nproc)d\n" % dict(nproc = nprocs) |
---|
| 216 | elif (app_name == "filter"): |
---|
| 217 | #shrc = "exec -p 0 /bin/filter /etc/imgs.raw 512 512\n" |
---|
| 218 | shrc = "exec -p 0 /bin/filter -l1024 -c1024 -n%(nproc)d /etc/img.raw\n" % dict(nproc = nprocs) |
---|
| 219 | elif (app_name == "filt_ga"): |
---|
| 220 | shrc = "exec -p 0 /bin/filt_ga -n%(nproc)d -i /etc/img.raw\n" % dict(nproc = nprocs) |
---|
| 221 | elif (app_name == "histogram"): |
---|
| 222 | shrc = "exec -p 0 /bin/histogra -n%(nproc)d /etc/histo.bmp\n" % dict(nproc = nprocs) |
---|
| 223 | elif (app_name == "kmeans"): |
---|
| 224 | shrc = "exec -p 0 /bin/kmeans -n %(nproc)d -p %(npoints)d\n" % dict(nproc = nprocs, npoints = 10000) # default npoints = 100000 |
---|
| 225 | elif (app_name == "showimg"): |
---|
| 226 | shrc = "exec -p 0 /bin/showimg -p1 -i /etc/lena.sgi -o /dev/fb0\n" |
---|
| 227 | elif (app_name == "barnes"): |
---|
| 228 | shrc = "exec -p 0 /bin/barnes -n%(nproc)d -b%(nbody)d\n" % dict(nproc = nprocs, nbody = 1024) |
---|
| 229 | elif (app_name == "fmm"): |
---|
| 230 | shrc = "exec -p 0 /bin/fmm -n%(nproc)d -p%(nparticles)d\n" % dict(nproc = nprocs, nparticles = 1024) |
---|
| 231 | elif (app_name == "ocean"): |
---|
| 232 | shrc = "exec -p 0 /bin/ocean -n%(nproc)d -m%(gridsize)d\n" % dict(nproc = nprocs, gridsize = 66) |
---|
| 233 | elif (app_name == "radiosity"): |
---|
| 234 | shrc = "exec -p 0 /bin/radiosit -n %(nproc)d -batch\n" % dict(nproc = nprocs) |
---|
| 235 | elif (app_name == "raytrace"): |
---|
| 236 | shrc = "exec -p 0 /bin/raytrace -n%(nproc)d /etc/tea.env\n" % dict(nproc = nprocs) |
---|
| 237 | elif (app_name == "watern"): |
---|
| 238 | shrc = "exec -p 0 /bin/watern -n%(nproc)d -m512\n" % dict(nproc = nprocs) |
---|
| 239 | elif (app_name == "waters"): |
---|
| 240 | shrc = "exec -p 0 /bin/waters -n%(nproc)d -m512\n" % dict(nproc = nprocs) |
---|
| 241 | elif (app_name == "cholesky"): |
---|
| 242 | shrc = "exec -p 0 /bin/cholesky -n%(nproc)d /etc/tk14.O\n" % dict(nproc = nprocs) |
---|
| 243 | elif (app_name == "fft"): |
---|
| 244 | shrc = "exec -p 0 /bin/fft -n%(nproc)d -m10\n" % dict(nproc = nprocs) |
---|
| 245 | elif (app_name == "lu"): |
---|
| 246 | shrc = "exec -p 0 /bin/lu -n%(nproc)d -m512\n" % dict(nproc = nprocs) |
---|
| 247 | elif (app_name == "radix"): |
---|
| 248 | shrc = "exec -p 0 /bin/radix -n%(nproc)d -k1024\n" % dict(nproc = nprocs) # test : 1024 ; simu : 65536 |
---|
| 249 | elif (app_name == "radix_ga"): |
---|
| 250 | shrc = "exec -p 0 /bin/radix_ga -p%(nproc)d -n262144\n" % dict(nproc = nprocs) # p = proc, n = num_keys |
---|
| 251 | elif (app_name == "fft_ga"): |
---|
| 252 | shrc = "exec -p 0 /bin/fft_ga -P%(nproc)d -M16\n" % dict(nproc = nprocs) |
---|
| 253 | else: |
---|
| 254 | assert(False) |
---|
| 255 | |
---|
| 256 | file = open(shrc_file_name, 'w') |
---|
| 257 | file.write(shrc) |
---|
| 258 | file.close() |
---|
| 259 | |
---|
| 260 | # Copie du binaire et du shrc dans l'image disque |
---|
| 261 | print "mcopy -o -i", hdd_img_file_name, shrc_file_name, "::/etc/" |
---|
| 262 | subprocess.call([ 'mcopy', '-o', '-i', hdd_img_file_name, shrc_file_name, '::/etc/' ]) |
---|
| 263 | print "mcopy -o -i", hdd_img_file_name, app_name, "::/bin/" |
---|
| 264 | subprocess.call([ 'mcopy', '-o', '-i', hdd_img_file_name, app_name, '::/bin/' ]) |
---|
| 265 | |
---|
| 266 | print "cd", old_path |
---|
| 267 | os.chdir(old_path) |
---|
| 268 | # end of compile_app |
---|
| 269 | |
---|
| 270 | |
---|
| 271 | print "mkdir -p", os.path.join(scripts_path, data_dir) |
---|
| 272 | subprocess.call([ 'mkdir', '-p', os.path.join(scripts_path, data_dir) ]) |
---|
| 273 | |
---|
| 274 | gen_sym_links() |
---|
| 275 | |
---|
| 276 | for i in nb_procs: |
---|
| 277 | x, y = get_x_y(i) |
---|
| 278 | nthreads = min(4, x * y) |
---|
| 279 | gen_hard_config(x, y, hard_config_name) |
---|
| 280 | gen_arch_info(x, y, arch_info_name, arch_info_bib_name) |
---|
| 281 | |
---|
| 282 | print "cd", top_path |
---|
| 283 | os.chdir(top_path) |
---|
| 284 | print "touch", topcell_name |
---|
| 285 | subprocess.call([ 'touch', topcell_name ]) |
---|
| 286 | print "make" |
---|
| 287 | subprocess.call([ 'make' ]) |
---|
| 288 | |
---|
| 289 | for app in apps: |
---|
| 290 | print "cd", top_path |
---|
| 291 | os.chdir(top_path) |
---|
| 292 | |
---|
| 293 | compile_app(app, i) |
---|
| 294 | |
---|
| 295 | # Launch simulation |
---|
| 296 | if use_omp: |
---|
| 297 | print "./simul.x -THREADS", nthreads, ">", os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i)) |
---|
| 298 | output = subprocess.Popen([ './simul.x', '-THREADS', str(nthreads) ], stdout = subprocess.PIPE).communicate()[0] |
---|
| 299 | else: |
---|
| 300 | print "./simul.x >", os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i)) |
---|
| 301 | output = subprocess.Popen([ './simul.x' ], stdout = subprocess.PIPE).communicate()[0] |
---|
| 302 | |
---|
| 303 | |
---|
| 304 | # Write simulation results to data directory |
---|
| 305 | print "cd", scripts_path |
---|
| 306 | os.chdir(scripts_path) |
---|
| 307 | filename = os.path.join(data_dir, app + '_' + log_init_name + str(i)) |
---|
| 308 | file = open(filename, 'w') |
---|
| 309 | file.write(output) |
---|
| 310 | file.close() |
---|
| 311 | |
---|
| 312 | filename = os.path.join(scripts_path, data_dir, app + '_' + log_term_name + str(i)) |
---|
| 313 | print "mv", os.path.join(top_path, 'term1'), filename |
---|
| 314 | subprocess.call([ 'mv', os.path.join(top_path, 'term1'), filename ]) |
---|
| 315 | |
---|
| 316 | if rerun_stats: |
---|
| 317 | start2_found = False |
---|
| 318 | end_found = False |
---|
| 319 | for line in open(filename): |
---|
| 320 | if "[START2]" in line: |
---|
| 321 | start2 = line.split()[-1] |
---|
| 322 | start2_found = True |
---|
| 323 | if "[END]" in line: |
---|
| 324 | end = line.split()[-1] |
---|
| 325 | end_found = True |
---|
| 326 | assert(start2_found and end_found) |
---|
| 327 | |
---|
| 328 | print "cd", top_path |
---|
| 329 | os.chdir(top_path) |
---|
| 330 | |
---|
| 331 | # Relauching simulation with reset and dump of counters |
---|
| 332 | if use_omp: |
---|
| 333 | 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)) |
---|
| 334 | output = subprocess.Popen([ './simul.x', '-THREADS', str(nthreads), '--reset-counters', start2, '--dump-counters', end ], stdout = subprocess.PIPE).communicate()[0] |
---|
| 335 | else: |
---|
| 336 | print "./simul.x --reset-counters %s --dump-counters %s >" % (start2, end), os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i)) |
---|
| 337 | output = subprocess.Popen([ './simul.x', '--reset-counters', start2, '--dump-counters', end ], stdout = subprocess.PIPE).communicate()[0] |
---|
| 338 | |
---|
| 339 | # Write simulation results (counters) to data directory |
---|
| 340 | print "cd", scripts_path |
---|
| 341 | os.chdir(scripts_path) |
---|
| 342 | filename = os.path.join(data_dir, app + '_' + log_init_name + str(i)) |
---|
| 343 | file = open(filename, 'w') |
---|
| 344 | file.write(output) |
---|
| 345 | file.close() |
---|
| 346 | |
---|
| 347 | |
---|
| 348 | ## End of simulations |
---|
| 349 | |
---|
| 350 | |
---|
| 351 | |
---|