-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmartApprox_routines.py
71 lines (52 loc) · 3 KB
/
SmartApprox_routines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import numpy as np
from common_params import *
def get_static_energy_fraction(results_type, app, input_type, probability, vdd):
data_app = [ energy_data[results_type][app][input_type][probability][vdd][x] for x in range(REPETITIONS) ]
idle_energy = np.mean( [ data_app[x]['Total Idle Energy (Active + Precharged)'] for x in range(REPETITIONS) ])
total_energy = np.mean( [ data_app[x]['Total Trace Energy'] for x in range(REPETITIONS) ] )
return idle_energy / total_energy
def get_approximate_dram_accesses_fraction(results_type, app, input_type):
approx_accesses = memory_data[results_type][app][input_type]['0']['Approximate DRAM']['accesses'][0]
dram_accesses = memory_data[results_type][app][input_type]['0']['DRAM']['accesses'][0]
return approx_accesses / float(dram_accesses)
def get_energy(results_type, app, input_type, vdd, error_scenario="median"):
if app in energies[results_type].keys():
if vdd == NOMINAL_VOLTAGE:
return 1.0
probability = probabilities_rt[error_scenario][float(vdd)]
non_zero_energies = list(filter(lambda x: x>0, [ energies[results_type][app][input_type][probability][vdd][i][0] for i in range(REPETITIONS) ]))
avg_energy = np.mean(non_zero_energies)
approx_accesses_fraction = get_approximate_dram_accesses_fraction(results_type, app, input_type)
static_energy_fraction = get_static_energy_fraction(results_type, app, input_type, probability, vdd)
return static_energy_fraction * avg_energy + (1.0 - static_energy_fraction) * approx_accesses_fraction * avg_energy
else:
return float(vdd)
def get_quality(results_type, app, input_type, vdd, error_scenario="median"):
if vdd == NOMINAL_VOLTAGE:
return 1.0
probability = probabilities_rt[error_scenario][float(vdd)]
avg_quality = np.mean(qualities[results_type][app][input_type][probability])
return avg_quality
def get_best_approx_level(app, quality_requirement, error_scenario="median"):
min_vdd_quality = NOMINAL_VOLTAGE
min_energy = get_energy(results_type, app, input_type, min_vdd_quality, error_scenario)
for vdd in vdds:
quality = get_quality(results_type, app, input_type, vdd, error_scenario)
if quality >= quality_requirement:
avg_energy = get_energy(results_type, app, input_type, vdd, error_scenario)
if avg_energy < min_energy:
min_energy = avg_energy
min_vdd_quality = vdd
return min_vdd_quality
def get_qualities(results_type, app, input_type, vdd, error_scenario="median"):
qualities_app=[]
for vdd in vdds:
quality = get_quality(results_type, app, input_type, vdd, error_scenario)
qualities_app.append(quality)
return qualities_app
def get_energies(results_type, app, input_type, vdd, error_scenario="median"):
energies_app=[]
for vdd in vdds:
energy = get_energy(results_type, app, input_type, vdd, error_scenario)
energies_app.append(energy)
return energies_app