source: soft/giet_vm/applications/rosenfeld/scripts/create_graph.py @ 822

Last change on this file since 822 was 822, checked in by meunier, 8 years ago

In rosenfeld:

  • Updated nrio0, nrio1, nrio2, nrio1f, nrio2f, nrio1x, nrbool1, nrbool2 and nralloc1 in the nrc2 lib in order to use macro-typed functions
  • Updated the simulation script to include performance evaluation with random images, and a script to generate graphs
  • Updated the clock.h to use 64-bit integers, which potentially breaks the printing on the giet
  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#!/dsk/l1/misc/meunier/tools/bin/python3
2# -*- coding: utf-8 -*-
3
4# Note:
5# This code requires python 3, and I haven't found
6# a proper way of mixing python 2 and 3 without using
7# the she/bang line at the top, which includes a local
8# path...
9
10from __future__ import print_function
11import os
12import sys
13import re
14import subprocess
15import shutil
16import filecmp
17import random
18
19from stack import Stack
20
21from common import *
22
23
24use_rand_images = True
25with_features = True
26
27threads = [1, 2, 4]
28nb_step = 0
29use_dsk = True
30img_size = 1024
31granularity = 1
32rand_seed = 7
33
34top_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
35scripts_path  = os.path.join(top_path, 'scripts')
36pyconf_file   = os.path.join(scripts_path, "config.py")
37
38base_data_dir  = "data"    # For timing information extracted
39base_graph_dir = "graphes" # For storing generated graphes
40
41
42# Each of these configuration must have been run with both features activated and deactivated
43configs = [
44        {'SLOW':'1', 'FAST':'0', 'PARMERGE':'0', 'ARSP':'0'},
45        {'SLOW':'0', 'FAST':'1', 'PARMERGE':'0', 'ARSP':'0'},
46        #{'SLOW':'1', 'FAST':'0', 'PARMERGE':'0', 'ARSP':'0'},
47        #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'0', 'ARSP':'0'},
48        #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'0'},
49        #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'1'},
50]
51
52
53# Loading config file
54with open(pyconf_file) as f:
55    code = compile(f.read(), pyconf_file, 'exec')
56    exec(code)
57
58if use_dsk:
59    try:
60        dsk_dir
61        if not os.path.exists(dsk_dir):
62            print("*** Warning: variable dsk_dir is not defined in %s file; using current directory for reading data files" % (short_path(pyconf_file)))
63            use_dsk = False
64    except OSError:
65        print("*** Warning: directory %s does not exist; using current directory for reading data files" % (dsk_dir))
66        use_dsk = False
67
68# Updating output directories
69if use_dsk:
70    data_dir     = os.path.join(dsk_dir, base_data_dir)
71    graph_dir    = os.path.join(dsk_dir, base_graph_dir)
72else:
73    data_dir   = os.path.join(scripts_path, base_data_dir)
74    graph_dir  = os.path.join(scripts_path, base_graph_dir)
75
76
77
78if not os.path.exists(graph_dir):
79    my_mkdir(graph_dir)
80
81
82
83if with_features:
84    features = ["FT", "NF"] # Features and No-Features
85else:
86    features = ["NF"] # No features only
87
88
89exec_time = {}
90for config in configs:
91    fconfig = frozenset(config.items())
92    exec_time[fconfig] = {}
93    for thread in threads:
94        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]))
116
117                   
118
119
120for config in configs:
121    fconfig = frozenset(config.items())
122    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(exec_time[fconfig][thread]["NF"][density][0]) for density in range(0, 101)] # Parallel Labeling
128        YPAR2 = [float(exec_time[fconfig][thread]["NF"][density][1]) for density in range(0, 101)] # Merging (Parallel or Pyramidal)
129        YPTC2 = [float(exec_time[fconfig][thread]["NF"][density][2]) for density in range(0, 101)] # Parallel Transitive Closure
130        YPAR3 = [float(exec_time[fconfig][thread]["NF"][density][3]) for density in range(0, 101)] # Parallel Relabeling
131
132        plotter.add_y(YPAR1)
133        plotter.add_y(YPAR2)
134        plotter.add_y(YPTC2)
135        # Not displaying PAR3
136
137        if with_features:
138            YPAR1f = [float(exec_time[fconfig][thread]["FT"][density][0]) for density in range(0, 101)] # Parallel Labeling
139            YPAR2f = [float(exec_time[fconfig][thread]["FT"][density][1]) 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)
144
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)
149
150
151
152
153
154
Note: See TracBrowser for help on using the repository browser.