-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimeSlackEval.py
102 lines (80 loc) · 3.46 KB
/
TimeSlackEval.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# This file is part of GenMap and released under the MIT License, see LICENSE.
# Author: Takuya Kojima
from EvalBase import EvalBase
from DataPathAnalysis import DataPathAnalysis
import networkx as nx
PENALTY_COST = -1000
class TimeSlackEval(EvalBase):
def __init__(self):
pass
@staticmethod
def eval(CGRA, app, sim_params, individual):
"""Return mapping width.
Args:
CGRA (PEArrayModel): A model of the CGRA
app (Application): An application to be optimized
sim_params (SimParameters): parameters for some simulations
individual (Individual): An individual to be evaluated
Returns:
int: mapping width
"""
body_bias = individual.getEvaluatedData("body_bias")
fastest_mode = False
if individual.isValid() == False:
if not body_bias is None:
if len(body_bias) == 0:
# in case of failure in body bias assign
fastest_mode = True
else:
return PENALTY_COST
delays = []
# get delay table for ALU
# key: node name of ALU
# value: list of delay value for each body bias voltage
op_attr = nx.get_node_attributes(app.getCompSubGraph(), "opcode")
delay_table = {CGRA.getNodeName("ALU", pos): \
sim_params.delay_info[op_attr[op_label] if op_label in op_attr.keys() else "CAT" ] \
for op_label, pos in individual.mapping.items()}
delay_table.update({v: sim_params.delay_info["SE"]\
for v in individual.routed_graph.nodes() if CGRA.isSE(v)})
# for routing ALU
for alu, flag in nx.get_node_attributes(individual.routed_graph,\
"route").items():
if flag:
delay_table[alu] = sim_params.delay_info[\
CGRA.getRoutingOpcode(alu)]
if not body_bias is None:
domains = CGRA.getBBdomains()
if fastest_mode:
# find fastest body bias voltage
fastest_bb = sorted(sim_params.delay_info["SE"])[-1]
body_bias = {domain_name: fastest_bb for domain_name in domains.keys()}
domain_table = {}
for v in individual.routed_graph.nodes():
for domain_name, resources in domains.items():
if CGRA.isALU(v):
if v in resources["ALU"]:
domain_table[v] = domain_name
break
elif CGRA.isSE(v):
if v in resources["SE"]:
domain_table[v] = domain_name
break
for dp in DataPathAnalysis.get_data_path(CGRA, individual):
if not body_bias is None:
delays.append(sum([delay_table[v][body_bias[domain_table[v]]] for v in dp]))
else:
delays.append(sum([list(delay_table[v].values())[0] for v in dp]))
time_slack = app.getClockPeriod(sim_params.getTimeUnit()) - max(delays)
if time_slack < 0:
individual.invalidate()
return time_slack
@staticmethod
def calc_delay(path, sim_params, body_bias):
pass
@staticmethod
def isMinimize():
return False
@staticmethod
def name():
return "Time_Slack"