Changeset 826 for soft/giet_vm/applications/rosenfeld/scripts
- Timestamp:
- Jul 13, 2017, 11:01:58 AM (7 years ago)
- Location:
- soft/giet_vm/applications/rosenfeld/scripts
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/scripts/common.py
r822 r826 4 4 import subprocess 5 5 import sys 6 7 6 import shutil 7 import random 8 8 9 9 … … 51 51 shutil.copy(src, dst) 52 52 53 def my_symlink(target, link_name): 54 if not os.path.exists(link_name): 55 print("ln -s %s %s" % (short_path(target), short_path(link_name))) 56 os.symlink(target, link_name) 57 53 58 54 59 def get_random_img_file(density, x, y, granularity, seed): … … 60 65 61 66 return "rand_" + str(x) + "_" + str(y) + "_" + density_str + "_G" + str(granularity) + ".pgm" 67 68 69 # for the HDD constraint of 8 chars 70 def get_short_random_img_file(density, granularity): 71 density_str = str(density) 72 granularity_str = str(granularity) 73 if density < 10: 74 density_str = "0" + density_str 75 if density < 100: 76 density_str = "0" + density_str 77 if granularity < 10: 78 granularity_str = "0" + granularity_str 79 80 return "G" + granularity_str + "_D" + density_str + ".pgm" 81 82 83 84 def get_dirname(dir, nthreads, config, ftrs, granularity, start_den, end_den, basename): 85 start_den_str = str(start_den) 86 end_den_str = str(end_den) 87 if start_den < 10: 88 start_den_str = "0" + start_den_str 89 if start_den < 100: 90 start_den_str = "0" + start_den_str 91 if end_den < 10: 92 end_den_str = "0" + end_den_str 93 if end_den < 100: 94 end_den_str = "0" + end_den_str 95 96 if ftrs: 97 ftrs_str = "_FEATURES_1" 98 else: 99 ftrs_str = "_FEATURES_0" 100 101 config_keys = list(config.keys()) # duplicates list 102 try: 103 config_keys.remove('FEATURES') 104 except: 105 pass 106 config_keys = sorted(config_keys) 107 dirname = os.path.join(dir, basename + "_T" + str(nthreads) + "_G" + str(granularity) + "_D" + start_den_str + "-" + end_den_str + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ftrs_str) 108 109 return dirname 110 111 112 def get_graph_filename(dir, nthreads, granularity, config, ext): 113 config_keys = list(config.keys()) # duplicates list 114 config_keys = sorted(config_keys) 115 filename = os.path.join(dir, "random_T" + str(nthreads) + "_G" + str(granularity) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ext) 116 117 return filename 118 62 119 63 120 … … 74 131 pass 75 132 config_keys = sorted(config_keys) 76 filename = os.path.join(dir, basename + "_ " + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ftrs_str + ".txt")133 filename = os.path.join(dir, basename + "_T" + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ftrs_str + ".txt") 77 134 78 135 return filename 79 80 81 def get_graph_filename(dir, nthreads, config, ext):82 config_keys = list(config.keys()) # duplicates list83 config_keys = sorted(config_keys)84 filename = os.path.join(dir, "random_" + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ext)85 86 return filename87 88 136 89 137 … … 92 140 retval = subprocess.call(cmd) 93 141 return retval 142 143 144 def print_call_and_check(cmd): 145 retval = print_and_call(cmd) 146 if retval != 0: 147 print("*** Error: command '%s' returned %d\n" % (subprocess.list2cmdline(cmd), retval)) 148 sys.exit(1) 149 94 150 95 151 def print_and_popen(cmd, abs_outfile): … … 113 169 114 170 171 def gen_random_image(filename, x, y, granularity, density, seed): 172 random.seed(seed) 173 img = [[0 for a in range(x)] for b in range(y)] 174 for i in range(0, x, granularity): 175 for j in range(0, y, granularity): 176 r = random.random(); 177 if r < density: 178 px = 255 179 else: 180 px = 0 181 182 for di in range(0, granularity): 183 for dj in range(0, granularity): 184 if i + di < x and j + dj < y: 185 img[i + di][j + dj] = px; 186 187 f = open(filename, 'wb') 188 f.write("P5\n%d %d\n255\n" % (x, y)) 189 for j in range(0, y): 190 bimg = bytearray(img[j]) 191 f.write(bimg) 192 f.close() 193 194 -
soft/giet_vm/applications/rosenfeld/scripts/create_graph.py
r823 r826 22 22 from common import * 23 23 24 # Creates graphes for random images with a density varying from 0 to 100% 24 25 25 use_rand_images = True26 with_features = False27 26 28 threads = [1, 2, 4, 8, 16, 32, 64] 27 with_features = True 28 29 threads = [1, 4, 16, 64] 29 30 use_dsk = True 30 31 img_size = 2048 31 granularit y = 132 granularities = [1, 4, 16] 32 33 rand_seed = 7 33 34 … … 36 37 pyconf_file = os.path.join(scripts_path, "config.py") 37 38 38 base_data_dir = "data " # For timing information extracted39 base_data_dir = "data_2016_09_21" # For timing information extracted 39 40 base_graph_dir = "graphes" # For storing generated graphes 40 41 41 42 42 # Each of these configuration must have been run with both features activated and deactivated43 # if with_features, each of these configuration must have been run with both features activated and deactivated 43 44 configs = [ 44 45 #{'SLOW':'1', 'FAST':'0', 'PARMERGE':'0', 'ARSP':'0'}, 45 #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'0', 'ARSP':'0'},46 #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'0'},46 {'SLOW':'0', 'FAST':'1', 'PARMERGE':'0', 'ARSP':'0'}, 47 {'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'0'}, 47 48 {'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'1'}, 48 49 ] … … 87 88 88 89 90 # Phase 1: Extracting execution times 89 91 exec_time = {} 90 92 for config in configs: … … 93 95 for thread in threads: 94 96 exec_time[fconfig][thread] = {} 95 for ftrs in features: # Features or No features 96 exec_time[fconfig][thread][ftrs] = {} 97 for density in range(0, 101): 98 exec_time[fconfig][thread][ftrs][density] = {} 99 random_img_file = get_random_img_file(density, img_size, img_size, granularity, rand_seed) 100 img_basename = os.path.splitext(random_img_file)[0] 101 log_file = get_filename(data_dir, thread, config, ftrs == "FT", img_basename) 102 lines = open(log_file, 'r') 103 for line in lines: 104 tokens = line.split() 105 if len(tokens) == 0: 106 continue 107 tag = tokens[0] 108 pattern = re.compile('\[STEP_([0-9]+)\]') 109 match = pattern.match(tag) 110 if match: 111 step = int(match.group(1)) 112 nb_step = max(int(step) + 1, nb_step) 113 value = tokens[len(tokens) - 1] 114 exec_time[fconfig][thread][ftrs][density][step] = value 115 #print("exec_time[fconfig][%d][%s][%d][%s] = %s" % (thread, ftrs, density, step, exec_time[fconfig][thread][ftrs][density][step])) 97 for granularity in granularities: 98 exec_time[fconfig][thread][granularity] = {} 99 for ftrs in features: # Features or No features 100 exec_time[fconfig][thread][granularity][ftrs] = {} 101 for density in range(0, 101): 102 exec_time[fconfig][thread][granularity][ftrs][density] = {} 103 random_img_file = get_random_img_file(density, img_size, img_size, granularity, rand_seed) 104 #random_img_file = get_short_random_img_file(density, granularity) 105 img_basename = os.path.splitext(random_img_file)[0] 106 log_file = get_filename(data_dir, thread, config, ftrs == "FT", img_basename) 107 lines = open(log_file, 'r') 108 for line in lines: 109 tokens = line.split() 110 if len(tokens) == 0: 111 continue 112 tag = tokens[0] 113 pattern = re.compile('\[STEP_([0-9]+)\]') 114 match = pattern.match(tag) 115 if match: 116 step = int(match.group(1)) 117 nb_step = max(int(step) + 1, nb_step) 118 value = tokens[len(tokens) - 1] 119 exec_time[fconfig][thread][granularity][ftrs][density][step] = value 120 #print("exec_time[fconfig][%d][%d][%s][%d][%s] = %s" % (thread, granularity, ftrs, density, step, exec_time[fconfig][thread][granularity][ftrs][density][step])) 116 121 117 122 118 123 119 124 # Phase 2: Creating plots 120 125 for config in configs: 121 126 fconfig = frozenset(config.items()) 122 127 for thread in threads: 123 plotter = Stack(["red", "blue", "#CAFE01", "#CA01FE", "#01CAFE"], "Légende", "X", "Y") 124 X = [x for x in range(0, 101)] 125 plotter.add_x(X) 126 assert(nb_step == 4) 127 YPAR1 = [float(int(exec_time[fconfig][thread]["NF"][density][0]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Labeling 128 YPAR2 = [float(int(exec_time[fconfig][thread]["NF"][density][1]) / math.pow(img_size, 2)) for density in range(0, 101)] # Merging (Parallel or Pyramidal) 129 YPTC2 = [float(int(exec_time[fconfig][thread]["NF"][density][2]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Transitive Closure 130 YPAR3 = [float(int(exec_time[fconfig][thread]["NF"][density][3]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Relabeling 128 for granularity in granularities: 129 plotter = Stack(["red", "blue", "green", "orange", "pink", "purple"], "Légende", "X", "Y") 130 X = [x for x in range(0, 101)] 131 plotter.add_x(X) 132 assert(nb_step == 5) 133 # Parallel Labeling 134 YPAR1 = [float(int(exec_time[fconfig][thread][granularity]["NF"][density][0]) / math.pow(img_size, 2)) for density in range(0, 101)] 135 # Merging (Parallel or Pyramidal) 136 YPAR2 = [float(int(exec_time[fconfig][thread][granularity]["NF"][density][1]) / math.pow(img_size, 2)) for density in range(0, 101)] 137 # Parallel Transitive Closure 138 YPTC2 = [float(int(exec_time[fconfig][thread][granularity]["NF"][density][2]) / math.pow(img_size, 2)) for density in range(0, 101)] 139 # Propagate Features if Features and ARSP, nothing otherwise 140 YPRF2 = [float(int(exec_time[fconfig][thread][granularity]["NF"][density][3]) / math.pow(img_size, 2)) for density in range(0, 101)] 141 # Parallel Relabelling 142 YPAR3 = [float(int(exec_time[fconfig][thread][granularity]["NF"][density][4]) / math.pow(img_size, 2)) for density in range(0, 101)] 131 143 132 plotter.add_y(YPAR1) 133 plotter.add_y(YPAR2) 134 plotter.add_y(YPTC2) 135 # Not displaying PAR3 144 plotter.add_y(YPAR1) 145 plotter.add_y(YPAR2) 146 plotter.add_y(YPTC2) 147 plotter.add_y(YPRF2) 148 # displaying PAR3 149 plotter.add_y(YPAR3) 136 150 137 if with_features: 138 YPAR1f = [float(int(exec_time[fconfig][thread]["FT"][density][0]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Labeling 139 YPAR2f = [float(int(exec_time[fconfig][thread]["FT"][density][1]) / math.pow(img_size, 2)) for density in range(0, 101)] # Merging (Parallel or Pyramidal) 140 deltaYPAR1 = [max(0, x - y) for x, y in zip (YPAR1f, YPAR1)] 141 deltaYPAR2 = [max(0, x - y) for x, y in zip (YPAR2f, YPAR2)] 142 YFTC = [x + y for x, y in zip (deltaYPAR1, deltaYPAR2)] # Features Computation 143 plotter.add_y(YFTC) 151 if with_features: 152 YPAR1F = [float(int(exec_time[fconfig][thread][granularity]["FT"][density][0]) / math.pow(img_size, 2)) for density in range(0, 101)] 153 YPAR2F = [float(int(exec_time[fconfig][thread][granularity]["FT"][density][1]) / math.pow(img_size, 2)) for density in range(0, 101)] 154 YPTC2F = [float(int(exec_time[fconfig][thread][granularity]["FT"][density][2]) / math.pow(img_size, 2)) for density in range(0, 101)] 155 YPRF2F = [float(int(exec_time[fconfig][thread][granularity]["FT"][density][3]) / math.pow(img_size, 2)) for density in range(0, 101)] 156 YPAR3F = [float(int(exec_time[fconfig][thread][granularity]["FT"][density][4]) / math.pow(img_size, 2)) for density in range(0, 101)] 157 TotalNF = [x + y + z + t + u for x, y, z, t, u in zip(YPAR1, YPAR2, YPTC2, YPRF2, YPAR3)] # Total No Features 158 TotalFT = [x + y + z + t + u for x, y, z, t, u in zip(YPAR1F, YPAR2F, YPTC2F, YPRF2F, YPAR3F)] # Total with Features 159 YFCT = [max(0, x - y) for x, y in zip(TotalFT, TotalNF)] # Difference = Features Computation Time 160 plotter.add_y(YFCT) 144 161 145 plotter.plot()146 graph_name = get_graph_filename(graph_dir, thread, config, ".pdf")147 print("# Creating graph %s" % short_path(graph_name))148 plotter.save(graph_name)162 plotter.plot() 163 graph_name = get_graph_filename(graph_dir, thread, granularity, config, ".pdf") 164 print("# Creating graph %s" % short_path(graph_name)) 165 plotter.save(graph_name) 149 166 150 167 -
soft/giet_vm/applications/rosenfeld/scripts/run_simus.py
r823 r826 5 5 # python 2 as it will execute on computation servers 6 6 7 # TODO:8 # Can we do something about assert in perf eval?7 # FIXME? 8 # When deactivating assert for perf eval, exec times are slower... 9 9 10 10 from __future__ import print_function … … 29 29 base_logs_dir = "logs" # Log of execution, i.e. what is printed on screen 30 30 base_data_dir = "data" # For timing information extracted 31 base_rand_img_dir = "random_images" # For storing random images if using dsk32 31 33 32 … … 43 42 # - With check_results, num_app_runs should be used, so as to have a number of checks equals to the number of runs, 44 43 # because only one check per application run is performed 45 num_app_runs = 1 46 num_internal_runs = 20# Number of times the image is processed inside the application44 num_app_runs = 1 # Number of times the application is launched per configuration 45 num_internal_runs = 10 # Number of times the image is processed inside the application 47 46 check_results = False 48 47 eval_perf = True 49 48 use_valgrind = False 50 49 use_rand_images = True 51 threads = [1, 2, 4, 8, 16, 32, 64] 52 #threads = [1, 2] 50 threads = [1, 4, 16, 64] 53 51 use_dsk = True 54 52 # Using dsk will store generated random images, otherwise they are re-generated at each run to save disk space 53 granularities = [1, 4, 16] 54 img_size = 2048 55 55 56 56 # Configurations 57 57 configs = [ 58 58 #{'SLOW':'1', 'FAST':'0', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'}, 59 #{'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'},59 {'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'}, 60 60 #{'SLOW':'1', 'FAST':'0', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'}, 61 #{'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'},61 {'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'}, 62 62 {'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'1', 'ARSP':'0'}, 63 #{'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'1', 'ARSP':'0'}, 64 #{'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'1', 'ARSP':'1'}, 63 {'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'1', 'ARSP':'0'}, 64 {'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'1', 'ARSP':'1'}, 65 {'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'1', 'ARSP':'1'}, 65 66 ] 66 67 … … 68 69 # Other parameters which shouldn't be changed 69 70 rand_seed = 7 70 granularity = 1 # constant for now71 img_size = 204872 71 73 72 check_pyconf_file(pyconf_file) … … 83 82 os.mkdir(dsk_dir) 84 83 except NameError: 85 print("*** Warning: variable dsk_dir is not defined in %s file; using current directory for storing output files" % (short_path(pyconf_file)))84 print("*** Warning: variable dsk_dir is not defined in file %s; using current directory for storing output files" % (short_path(pyconf_file))) 86 85 use_dsk = False 87 86 except OSError: 88 87 print("*** Warning: Impossible to create directory %s; using current directory for storing output files" % (dsk_dir)) 89 88 use_dsk = False 89 90 if use_rand_images: 91 try: 92 rand_img_dir 93 if not os.path.exists(rand_img_dir): 94 print("mkdir %s", rand_img_dir) 95 os.mkdir(rand_img_dir) 96 except NameError: 97 print("*** Error: variable rand_img_dir, containing the path the directory of the random images (either pre-existing or to be generated), is not defined in file %s" % (short_path(pyconf_file))) 98 sys.exit(1) 99 except OSError: 100 print("*** Error: Impossible to create directory %s" % (rand_img_dir)) 101 sys.exit(1) 90 102 91 103 … … 95 107 logs_dir = os.path.join(dsk_dir, base_logs_dir) 96 108 data_dir = os.path.join(dsk_dir, base_data_dir) 97 rand_img_dir = os.path.join(dsk_dir, base_rand_img_dir)98 109 else: 99 110 output_dir = os.path.join(scripts_path, base_output_dir) … … 110 121 if check_results and num_internal_runs != 1: 111 122 print("*** Warning: using check_results with num_internal_runs != 1\n") 112 113 114 115 def gen_random_image(filename, x, y, granularity, density, seed):116 random.seed(seed)117 img = [[0 for a in range(x)] for b in range(y)]118 for i in range(0, x, granularity):119 for j in range(0, y, granularity):120 r = random.random();121 if r < density:122 px = 255123 else:124 px = 0125 126 for di in range(0, granularity):127 for dj in range(0, granularity):128 if i + di < x and j + dj < y:129 img[i + di][j + dj] = px;130 131 f = open(filename, 'wb')132 f.write("P5\n%d %d\n255\n" % (x, y))133 for j in range(0, y):134 bimg = bytearray(img[j])135 f.write(bimg)136 f.close()137 123 138 124 … … 186 172 my_mkdir(data_dir) 187 173 188 if use_dsk and not os.path.exists(rand_img_dir):189 my_mkdir(rand_img_dir)190 191 192 174 193 175 … … 196 178 197 179 for config in configs: 198 img_idx = 0199 180 fconfig = frozenset(config.iteritems()) 200 181 perf_array[fconfig] = {} … … 210 191 my_chdir(scripts_path) 211 192 212 while not use_rand_images and img_idx != len(images) or use_rand_images and img_idx != 101: 213 # Compute image and stat filenames 214 if use_rand_images: 215 if use_dsk: 193 for granularity in granularities: 194 perf_array[fconfig][granularity] = {} 195 img_idx = 0 196 while not use_rand_images and img_idx != len(images) or use_rand_images and img_idx != 101: 197 # Compute image and stat filenames 198 if use_rand_images: 216 199 random_img_file = get_random_img_file(img_idx, img_size, img_size, granularity, rand_seed) 217 200 random_img_file = os.path.join(rand_img_dir, random_img_file) 201 if not os.path.isfile(random_img_file): 202 # We generate the random image if it does not exist 203 print("# Generating random image %s with granularity = %d and density = %d" % (random_img_file, granularity, img_idx)) 204 gen_random_image(random_img_file, img_size, img_size, granularity, float(img_idx) / 100, rand_seed) 205 image = random_img_file 218 206 else: 219 random_img_file = "random.pgm" 220 if not (use_dsk and os.path.isfile(random_img_file)): 221 # We re-generate the random image if not using the dsk or if it does not exist 222 print("# Generating random image %s with density = %d" % (random_img_file, img_idx)) 223 gen_random_image(random_img_file, img_size, img_size, 1, float(img_idx) / 100, rand_seed) 224 225 image = random_img_file 226 else: 227 image = images[img_idx] 228 img_basename = os.path.splitext(os.path.basename(image))[0] 229 perf_array[fconfig][img_basename] = {} 230 ref_bmpfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + "_ref.bmp") 231 ref_statfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + "_ref.txt") 232 233 for nthreads in threads: 234 perf_array[fconfig][img_basename][nthreads] = {} 235 for run in range(num_app_runs): 236 if not os.path.exists(ref_bmpfile): 237 bmpfile = ref_bmpfile 238 else: 239 bmpfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + ".bmp") 240 if os.path.exists(bmpfile): 241 os.remove(bmpfile) 242 243 if not os.path.exists(ref_statfile): 244 statfile = ref_statfile 245 else: 246 statfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + ".txt") 247 248 cmd = [] 249 if use_valgrind: 250 cmd.append('valgrind') 251 252 cmd.extend([short_path(binary_file), '-n', str(nthreads), '-i', short_path(image)]) 253 254 if num_internal_runs > 1: 255 cmd.extend(['-r', str(num_internal_runs)]) 256 257 if check_results: 258 cmd.extend(['-o', short_path(bmpfile), '-g']) 259 260 if check_results and features: 261 cmd.append('-d') 262 263 config_keys = config.keys() 264 logfile = get_filename(logs_dir, nthreads, config, features, img_basename) 265 output = print_and_popen(cmd, logfile) 266 outlines = output.splitlines() 267 268 # if performance evaluation, get timing measurements 269 # Only the last application run is considered 207 image = images[img_idx] 208 img_basename = os.path.splitext(os.path.basename(image))[0] 209 perf_array[fconfig][granularity][img_basename] = {} 210 ref_bmpfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + "_ref.bmp") 211 ref_statfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + "_ref.txt") 212 213 for nthreads in threads: 214 perf_array[fconfig][granularity][img_basename][nthreads] = {} 215 for run in range(num_app_runs): 216 if not os.path.exists(ref_bmpfile): 217 # Generating the reference file if it does not exist 218 bmpfile = ref_bmpfile 219 else: 220 bmpfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + ".bmp") 221 if os.path.exists(bmpfile): 222 os.remove(bmpfile) 223 224 if not os.path.exists(ref_statfile): 225 statfile = ref_statfile 226 else: 227 statfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + ".txt") 228 if os.path.exists(statfile): 229 os.remove(statfile) 230 231 cmd = [] 232 if use_valgrind: 233 cmd.append('valgrind') 234 235 cmd.extend([short_path(binary_file), '-n', str(nthreads), '-i', short_path(image)]) 236 237 if num_internal_runs > 1: 238 cmd.extend(['-r', str(num_internal_runs)]) 239 240 if check_results: 241 cmd.extend(['-o', short_path(bmpfile), '-g']) 242 243 if check_results and features: 244 cmd.append('-d') 245 246 config_keys = config.keys() 247 logfile = get_filename(logs_dir, nthreads, config, features, img_basename) 248 output = print_and_popen(cmd, logfile) 249 outlines = output.splitlines() 250 251 # if performance evaluation, get timing measurements 252 # Only the last application run is considered 253 if eval_perf: 254 for line in outlines: 255 tokens = line.split() 256 if len(tokens) == 0: 257 continue 258 tag = tokens[0] 259 pattern = re.compile('\[THREAD_STEP_([0-9]+)\]'); 260 match = pattern.match(tag) 261 if match: 262 step = match.group(1) 263 value = tokens[len(tokens) - 1] 264 perf_array[fconfig][granularity][img_basename][nthreads][step] = int(value) 265 266 267 # Checking against reference output image 268 if check_results and bmpfile != ref_bmpfile: 269 print("diff %s %s" % (short_path(bmpfile), short_path(ref_bmpfile))) 270 if not filecmp.cmp(bmpfile, ref_bmpfile): 271 print("*** Error: files %s and %s differ" % (short_path(bmpfile), short_path(ref_bmpfile))) 272 sys.exit(1) 273 274 # Checking for valgrind errors 275 if use_valgrind: 276 if not "== ERROR SUMMARY: 0 errors from 0 contexts" in output: 277 print("*** Error: Valgrind error") 278 sys.exit(1) 279 if not "== All heap blocks were freed -- no leaks are possible" in output: 280 print("*** Error: Valgrind detected a memory leak") 281 sys.exit(1) 282 283 # Extracting features for correctness verification 284 if check_results and features: 285 stat_array = {} 286 in_stats = False 287 index = 0 288 for line in outlines: 289 if "[STATS]" in line: 290 in_stats = True 291 continue 292 if "[/STATS]" in line: 293 in_stats = False 294 break 295 if in_stats: 296 tokens = line.split() 297 assert(len(tokens) == 8) 298 stat_array[index] = {} 299 for j in range(len(tokens)): 300 stat_array[index][j] = tokens[j] 301 index += 1 302 303 # Dump stat array in stat file 304 file = open(statfile, 'w') 305 for i in range(len(stat_array)): 306 for j in range(8): # 8 is the number of features per element 307 file.write("%s " % stat_array[i][j]) 308 file.write("\n"); 309 file.close() 310 311 # Comparison to reference 312 if statfile != ref_statfile: 313 print("diff %s %s" % (short_path(statfile), short_path(ref_statfile))) 314 if not filecmp.cmp(statfile, ref_statfile): 315 print("*** Error: feature files %s and %s differ" % (short_path(statfile), short_path(ref_statfile))) 316 sys.exit(1) 317 318 # End of the num_runs simus 270 319 if eval_perf: 271 for line in outlines: 272 tokens = line.split() 273 if len(tokens) == 0: 274 continue 275 tag = tokens[0] 276 pattern = re.compile('\[THREAD_STEP_([0-9]+)\]'); 277 match = pattern.match(tag) 278 if match: 279 step = match.group(1) 280 value = tokens[len(tokens) - 1] 281 perf_array[fconfig][img_basename][nthreads][step] = int(value) 282 283 284 # Checking against reference output image 285 if check_results and bmpfile != ref_bmpfile: 286 print("diff %s %s" % (short_path(bmpfile), short_path(ref_bmpfile))) 287 if not filecmp.cmp(bmpfile, ref_bmpfile): 288 print("*** Error: files %s and %s differ" % (short_path(bmpfile), short_path(ref_bmpfile))) 289 sys.exit(1) 290 291 # Checking for valgrind errors 292 if use_valgrind: 293 if not "== ERROR SUMMARY: 0 errors from 0 contexts" in output: 294 print("*** Error: Valgrind error") 295 sys.exit(1) 296 if not "== All heap blocks were freed -- no leaks are possible" in output: 297 print("*** Error: Valgrind detected a memory leak") 298 sys.exit(1) 299 300 # Extracting features for correctness verification 301 if check_results and features: 302 stat_array = {} 303 in_stats = False 304 index = 0 305 for line in outlines: 306 if "[STATS]" in line: 307 in_stats = True 308 continue 309 if "[/STATS]" in line: 310 in_stats = False 311 break 312 if in_stats: 313 tokens = line.split() 314 assert(len(tokens) == 8) 315 stat_array[index] = {} 316 for j in range(len(tokens)): 317 stat_array[index][j] = tokens[j] 318 index += 1 319 320 # Dump stat array in stat file 321 file = open(statfile, 'w') 322 for i in range(len(stat_array)): 323 for j in range(8): 324 file.write("%s " % stat_array[i][j]) 325 file.write("\n"); 326 file.close() 327 328 # Comparison to reference 329 if statfile != ref_statfile: 330 print("diff %s %s" % (short_path(statfile), short_path(ref_statfile))) 331 if not filecmp.cmp(statfile, ref_statfile): 332 print("*** Error: feature files %s and %s differ" % (short_path(statfile), short_path(ref_statfile))) 333 sys.exit(1) 334 335 # End of the num_runs simus 336 if eval_perf: 337 if use_rand_images: 338 idx = img_idx 339 else: 340 idx = None 341 datafile = get_filename(data_dir, nthreads, config, features, img_basename) 342 file = open(datafile, 'w') 343 for step in sorted(perf_array[fconfig][img_basename][nthreads].keys()): 344 # Average time for each step 345 file.write("[STEP_%s] %d\n" % (step, perf_array[fconfig][img_basename][nthreads][step])) 346 347 img_idx += 1 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 320 datafile = get_filename(data_dir, nthreads, config, features, img_basename) 321 file = open(datafile, 'w') 322 for step in sorted(perf_array[fconfig][granularity][img_basename][nthreads].keys()): 323 # Average time for each step 324 file.write("[STEP_%s] %d\n" % (step, perf_array[fconfig][granularity][img_basename][nthreads][step])) 325 326 img_idx += 1 327 #end image list (101 rand or explicit list) 328 #end granularity 329 #end config 330 331 332 333 334 335 336 337 338 339 340 341 342 343
Note: See TracChangeset
for help on using the changeset viewer.