Commit 9bb9ab8f5d660b739af8109e0356721c296ae0cb

Authored by Rizwana Begum
1 parent 4628b929

notuning vs wtuning

Showing 1 changed file with 204 additions and 0 deletions
figures/notuning_wtuning.py 0 → 100644
  1 +import os, sys, argparse
  2 +import numpy
  3 +import matplotlib.pyplot as plt
  4 +import json
  5 +from pylab import *
  6 +from mpl_toolkits.mplot3d import Axes3D
  7 +from matplotlib.patches import Rectangle
  8 +from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
  9 +from sets import Set
  10 +
  11 +from common import *
  12 +
  13 +def get_energy(frontiers_data, cpu_freq, mem_freq, sample):
  14 + for point in frontiers_data["data"][sample]:
  15 + if point["cpu_freq"] == cpu_freq:
  16 + if point["mem_freq"] == mem_freq:
  17 + return point["energy"]
  18 +
  19 +def get_performance(frontiers_data, cpu_freq, mem_freq, sample):
  20 + for point in frontiers_data["data"][sample]:
  21 + if point["cpu_freq"] == cpu_freq:
  22 + if point["mem_freq"] == mem_freq:
  23 + return point["performance"]
  24 +
  25 +def get_aggr_energy(frontiers_data, cpu_freq, mem_freq):
  26 + for point in frontiers_data["data"]:
  27 + if point["cpu_freq"] == cpu_freq:
  28 + if point["mem_freq"] == mem_freq:
  29 + return point["energy"]
  30 +
  31 +def get_aggr_performance(frontiers_data, cpu_freq, mem_freq):
  32 + for point in frontiers_data["data"]:
  33 + if point["cpu_freq"] == cpu_freq:
  34 + if point["mem_freq"] == mem_freq:
  35 + return point["performance"]
  36 +
  37 +def get_no_tuning_energy_performance(args, budget, bmark):
  38 + dir_path = args.input_dir
  39 +
  40 + # finding points with 3% threshold of target budget/inefficiency
  41 + thresh = 3
  42 +
  43 + bmarkDirPath = os.path.join(os.path.join(dir_path, "aggr_data"), bmark)
  44 + frontiers_file = os.path.join(bmarkDirPath, "frontiers.json")
  45 + frontiers_data = json.loads(open(frontiers_file).read())
  46 +
  47 + filtered_data=[]
  48 + for point in frontiers_data["data"]:
  49 + #filtering all those points which have inefficiency with error% of the budget
  50 + if point["inefficiency"] <= budget:
  51 + filtered_data.append(point)
  52 + elif (point["inefficiency"] - budget) * 100 / budget <= thresh:
  53 + filtered_data.append(point)
  54 +
  55 + #finding the point with highest performance among filtered data
  56 + optimal_point = filtered_data[0]
  57 + for point in filtered_data:
  58 + if point["speedup"] > optimal_point["speedup"]:
  59 + optimal_point = point
  60 +
  61 + energy = get_aggr_energy(frontiers_data, optimal_point["cpu_freq"], optimal_point["mem_freq"])
  62 + performance = get_aggr_performance(frontiers_data, optimal_point["cpu_freq"], optimal_point["mem_freq"])
  63 + energy = energy/1e6
  64 + performance = performance/1e6
  65 +
  66 + return (energy, performance)
  67 +
  68 +def energy_time(args, budget_list, cluster_thresh, perf_cost, energy_cost):
  69 + dir_path = args.input_dir
  70 + output_dir_path = args.output_dir
  71 +
  72 + benchmarks, labels = get_benchmarks(args)
  73 +# benchmarks =['bzip2']
  74 + #plot constants
  75 + cpuflist = get_cpu_freq_plot_list(args)
  76 + memflist = get_mem_freq_plot_list(args)
  77 +
  78 + # finding points with 3% threshold of target budget/inefficiency
  79 + thresh = 3
  80 + energy_data = [ [] for thresh in budget_list]
  81 + performance_data = [ [] for thresh in budget_list]
  82 + for bmark in benchmarks:
  83 + data = []
  84 + for budget_index, budget in enumerate(budget_list):
  85 + print "Inefficiency Budget: "+str(budget)+" Benchmark: "+bmark
  86 +
  87 + energy_notuning, performance_notuning = get_no_tuning_energy_performance(args, budget, bmark)
  88 + print "no.tuning: performance (ms): "+str(performance_notuning)+" energy(mJ): "+str(energy_notuning)
  89 +
  90 + bmarkDirPath = os.path.join(os.path.join(dir_path, "per_sample_data"), bmark)
  91 + frontiers_file = os.path.join(bmarkDirPath, "per_sample_frontiers.json")
  92 + frontiers_data = json.loads(open(frontiers_file).read())
  93 +
  94 + data_to_plot=[]
  95 + sample_points=[]
  96 + cpu_rectangle_points=[]
  97 + for data in frontiers_data["data"]:
  98 + filtered_data=[]
  99 + #filtering all those points which have inefficiency with error% of the budget
  100 + for point in data:
  101 + if point["inefficiency"] <= budget:
  102 + filtered_data.append(point)
  103 + elif (point["inefficiency"] - budget) * 100 / budget <= thresh:
  104 + filtered_data.append(point)
  105 +
  106 + #finding the point with highest performance among filtered data
  107 + optimal_point = filtered_data[0]
  108 + for point in filtered_data:
  109 + if point["speedup"] > optimal_point["speedup"]:
  110 + optimal_point = point
  111 +
  112 + local_rect_points=[]
  113 + for point in filtered_data:
  114 + if (optimal_point["speedup"] - point["speedup"]) < 0:
  115 + print "something is wrong!"
  116 +
  117 + if (optimal_point["speedup"] - point["speedup"]) * 100 / optimal_point["speedup"] <= cluster_thresh:
  118 + data_to_plot.append(point)
  119 + sample_points.append(frontiers_data["data"].index(data))
  120 + local_rect_points.append(point)
  121 +
  122 + cpufpoints = [cpuf for cpuf in [data_to_plot[sample]["cpu_freq"] for sample in range(len(data_to_plot))]]
  123 + memfpoints = [memf for memf in [data_to_plot[sample]["mem_freq"] for sample in range(len(data_to_plot))]]
  124 + samplepoints = sample_points
  125 +
  126 + #Total number of transitions
  127 + num_transitions = 0.0
  128 + #Available settings for (CPU, MEM)
  129 + settings_available = Set()
  130 + index = 0
  131 + current_sample = -1
  132 + length = 1
  133 + lengths = []
  134 + prev_tr_sample = 0
  135 + energy = 0
  136 + performance = 0
  137 + while index < len( samplepoints ):
  138 + current_sample = samplepoints[index]
  139 +
  140 + #Construct the current settings
  141 + current_settings = Set()
  142 + while index < len( samplepoints ) and samplepoints[index] == current_sample:
  143 + current_settings.add((cpufpoints[index],memfpoints[index]))
  144 + index = index + 1
  145 +
  146 + #Compute the common points between current and what is available
  147 + common_points = current_settings.intersection(settings_available)
  148 +
  149 + if (len(common_points) == 0 or index == len( samplepoints )):
  150 + # find the point with highest cpu and mem freq
  151 + if (current_sample !=0 ):
  152 + optimal_point = settings_available.pop()
  153 + settings_available.add(optimal_point)
  154 + for point in settings_available:
  155 + if point[0] > optimal_point[0]:
  156 + optimal_point = point
  157 + elif point[0] == optimal_point[0]:
  158 + if point[1] > optimal_point[1]:
  159 + optimal_point = point
  160 + done = 0
  161 + idx = prev_tr_sample+1
  162 + while done == 0:
  163 + energy += get_energy(frontiers_data, optimal_point[0], optimal_point[1], idx)
  164 + performance += get_performance(frontiers_data, optimal_point[0], optimal_point[1], idx)
  165 + if idx == samplepoints[index-1]:
  166 + done = 1
  167 + else:
  168 + idx += 1
  169 +
  170 + prev_tr_sample = samplepoints[index-1]
  171 +
  172 + # When there are no common points, transition
  173 + if (len(common_points) == 0):
  174 + settings_available = current_settings #all current settings are now available
  175 + #Ignore the transition if it's the first sample
  176 + if (current_sample!=0):
  177 + num_transitions += 1
  178 + else: # Continue with the common points
  179 + settings_available = common_points
  180 +
  181 + # Record the length if we need to transition or we are at the end
  182 + if (len(common_points) == 0 or index == len( samplepoints )):
  183 + #Ignore the length if the transition is for the first sample
  184 + if (current_sample!=0):
  185 + lengths.append(length)
  186 + #reset the length
  187 + length = 1
  188 + else: #otherwise, just increment the length
  189 + length += 1
  190 +
  191 + energy = (energy + (num_transitions * energy_cost))/1e6
  192 + performance = (performance +(num_transitions * perf_cost))/1e6
  193 + energy_data[budget_index].append(energy)
  194 + performance_data[budget_index].append(performance)
  195 + print "w.tuning: performance (ms): "+str(performance)+" energy(mJ): "+str(energy) +"\n"
  196 +
  197 +def main(argv):
  198 + args = parse(argv)
  199 +
  200 + for thresh in [0.0]:
  201 + energy_time(args, [1.0,1.1, 1.2, 1.3,1.6,3.0], thresh, 0, 0)
  202 +
  203 +if __name__ == "__main__":
  204 + main(sys.argv)
... ...