Ignore:
Timestamp:
Jul 13, 2017, 11:01:58 AM (7 years ago)
Author:
meunier
Message:
  • Mise à jour NR2 et Rosenfeld
Location:
soft/giet_vm/applications/rosenfeld/scripts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/rosenfeld/scripts/common.py

    r822 r826  
    44import subprocess
    55import sys
    6 
    7 
     6import shutil
     7import random
    88
    99
     
    5151    shutil.copy(src, dst)
    5252
     53def 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
    5358
    5459def get_random_img_file(density, x, y, granularity, seed):
     
    6065
    6166    return "rand_" + str(x) + "_" + str(y) + "_" + density_str + "_G" + str(granularity) + ".pgm"
     67
     68
     69# for the HDD constraint of 8 chars
     70def 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
     84def 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
     112def 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
    62119
    63120
     
    74131        pass
    75132    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")
    77134   
    78135    return filename
    79 
    80 
    81 def get_graph_filename(dir, nthreads, config, ext):
    82     config_keys = list(config.keys()) # duplicates list
    83     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 filename
    87 
    88136
    89137
     
    92140    retval = subprocess.call(cmd)
    93141    return retval
     142
     143
     144def 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
    94150
    95151def print_and_popen(cmd, abs_outfile):
     
    113169
    114170
     171def 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  
    2222from common import *
    2323
     24# Creates graphes for random images with a density varying from 0 to 100%
    2425
    25 use_rand_images = True
    26 with_features = False
    2726
    28 threads = [1, 2, 4, 8, 16, 32, 64]
     27with_features = True
     28
     29threads = [1, 4, 16, 64]
    2930use_dsk = True
    3031img_size = 2048
    31 granularity = 1
     32granularities = [1, 4, 16]
    3233rand_seed = 7
    3334
     
    3637pyconf_file   = os.path.join(scripts_path, "config.py")
    3738
    38 base_data_dir  = "data"    # For timing information extracted
     39base_data_dir  = "data_2016_09_21"    # For timing information extracted
    3940base_graph_dir = "graphes" # For storing generated graphes
    4041
    4142
    42 # Each of these configuration must have been run with both features activated and deactivated
     43# if with_features, each of these configuration must have been run with both features activated and deactivated
    4344configs = [
    4445        #{'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'},
    4748        {'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'1'},
    4849]
     
    8788
    8889
     90# Phase 1: Extracting execution times
    8991exec_time = {}
    9092for config in configs:
     
    9395    for thread in threads:
    9496        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]))
    116121
    117122                   
    118123
    119 
     124# Phase 2: Creating plots
    120125for config in configs:
    121126    fconfig = frozenset(config.items())
    122127    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)]
    131143
    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)
    136150
    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)
    144161
    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)
    149166
    150167
  • soft/giet_vm/applications/rosenfeld/scripts/run_simus.py

    r823 r826  
    55# python 2 as it will execute on computation servers
    66
    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...
    99
    1010from __future__ import print_function
     
    2929base_logs_dir     = "logs"   # Log of execution, i.e. what is printed on screen
    3030base_data_dir     = "data"   # For timing information extracted
    31 base_rand_img_dir = "random_images" # For storing random images if using dsk
    3231
    3332
     
    4342# - With check_results, num_app_runs should be used, so as to have a number of checks equals to the number of runs,
    4443#     because only one check per application run is performed
    45 num_app_runs = 1        # Number of times the application is launched per configuration
    46 num_internal_runs = 20 # Number of times the image is processed inside the application
     44num_app_runs = 1       # Number of times the application is launched per configuration
     45num_internal_runs = 10 # Number of times the image is processed inside the application
    4746check_results = False
    4847eval_perf = True
    4948use_valgrind = False
    5049use_rand_images = True
    51 threads = [1, 2, 4, 8, 16, 32, 64]
    52 #threads = [1, 2]
     50threads = [1, 4, 16, 64]
    5351use_dsk = True
    5452# Using dsk will store generated random images, otherwise they are re-generated at each run to save disk space
     53granularities = [1, 4, 16]
     54img_size = 2048
    5555
    5656# Configurations
    5757configs = [
    5858        #{'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'},
    6060        #{'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'},
    6262        {'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'},
    6566]
    6667
     
    6869# Other parameters which shouldn't be changed
    6970rand_seed = 7
    70 granularity = 1 # constant for now
    71 img_size = 2048
    7271
    7372check_pyconf_file(pyconf_file)
     
    8382            os.mkdir(dsk_dir)
    8483    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)))
    8685        use_dsk = False
    8786    except OSError:
    8887        print("*** Warning: Impossible to create directory %s; using current directory for storing output files" % (dsk_dir))
    8988        use_dsk = False
     89
     90if 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)
    90102
    91103
     
    95107    logs_dir     = os.path.join(dsk_dir, base_logs_dir)
    96108    data_dir     = os.path.join(dsk_dir, base_data_dir)
    97     rand_img_dir = os.path.join(dsk_dir, base_rand_img_dir)
    98109else:
    99110    output_dir = os.path.join(scripts_path, base_output_dir)
     
    110121if check_results and num_internal_runs != 1:
    111122    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 = 255
    123             else:
    124                 px = 0
    125 
    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()
    137123
    138124
     
    186172    my_mkdir(data_dir)
    187173
    188 if use_dsk and not os.path.exists(rand_img_dir):
    189     my_mkdir(rand_img_dir)
    190 
    191 
    192174
    193175
     
    196178
    197179for config in configs:
    198     img_idx = 0
    199180    fconfig = frozenset(config.iteritems())
    200181    perf_array[fconfig] = {}
     
    210191    my_chdir(scripts_path)
    211192
    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:
    216199                random_img_file = get_random_img_file(img_idx, img_size, img_size, granularity, rand_seed)
    217200                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
    218206            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
    270319                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.