-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsta-feedback.py
More file actions
226 lines (208 loc) · 10.1 KB
/
sta-feedback.py
File metadata and controls
226 lines (208 loc) · 10.1 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
"""
Usage:
heatmap.py (-d <directives>) (-t <sta-report>) [-s <cell_sizes>]
heatmap.py (--help|-h)
Options:
-d <directives> Directives file (.part, no escape chars)
-t <sta-report> STA report (.rpt)
-s <cell_sizes> CellSizes.out
-h --help Print this help
"""
from docopt import docopt
from alive_progress import alive_bar
import sys
import re
if __name__ == "__main__":
balanceMitigation = False
args = docopt(__doc__)
if args["-d"]:
directivesFile = args["-d"]
if args["-t"]:
staFile = args["-t"]
if args["-s"]:
cellSizesFile = args["-s"]
balanceMitigation = True
with open(directivesFile, 'r') as f:
lines = f.readlines()
##############################################
# Extract cells and the die on which they lie
##############################################
cells = dict() # {cell name : die number 0 or 1}
for line in lines:
cells[line.split(' ')[0]] = int(line.split(' ')[1])
if balanceMitigation:
#####################
# Extract cell sizes
#####################
cellSizes = dict() # {cell name: area [float]}
with open(cellSizesFile, 'r') as f:
lines = f.readlines()
for line in lines[1:]:
cellSizes[line.split(' ')[0].replace('\\', '')] = float(line.split(' ')[1]) * float(line.split(' ')[2])
############################################
# What is the current partitioning balance?
############################################
botArea = 0
topArea = 0
for cell in cells:
if cells[cell] == 0:
botArea += cellSizes[cell]
elif cells[cell] == 1:
topArea += cellSizes[cell]
balance = botArea/topArea
currentBalance = balance
print("Balance of bottom die area: {}".format(balance))
#############################
# Set output files full path
#############################
directivesPostSTAFile = '_'.join(['.'.join(directivesFile.split('.')[:-1]), "post-STA.txt"])
print(directivesPostSTAFile)
fixfilePostSTAFile = '_'.join(['.'.join(directivesFile.split('.')[:-1]), "post-STA_fixfile.hgr"])
with open(staFile, 'r') as f:
lines = f.readlines()
startDie = 0 # 0 = bottom, 1 = top
endDie = 0 # 0 = bottom, 1 = top
level = 0 # 0 => start and end in bot, no transition allowed
# 1 => start and end in top, no transition allowed
# 2 => start in bot and end in top, max 1 transition allowed
# 3 => start in top and end in bot, max 1 transition allowed
inPath = False
cellsInPath = list()
movedCellsCount = 0
pathAnalysed = 0
print("Checking the paths")
with alive_bar(len(lines)) as bar:
for line in lines:
bar()
if not inPath:
#####################
# Check type of path
#####################
if "Endpoint:" in line:
if "topDiei" in line:
endDie = 1
elif "botDiei" in line:
endDie = 0
if "Beginpoint:" in line:
if "topDiei" in line:
startDie = 1
if endDie == 0:
level = 3
elif endDie == 1:
level = 1
elif "topDiei" in line:
startDie = 0
if endDie == 0:
level = 0
elif endDie == 1:
level = 2
if "Timing Path:" in line:
inPath = True
pathAnalysed += 1
# print("I'm in path {}".format(pathAnalysed))
elif inPath:
if "VIOLATED" in line or "Other End Path:" in line:
inPath = False
cellsInPath = list()
# print("Not in path anymore")
match = re.search('^(botDiei|topDiei)/([^/]+)/[A-Z0-9]+\s', line.strip())
# print("Level {}".format(level))
if match:
die = match.group(1)
cell = match.group(2)
if cell in cells:
cellsInPath.append(cell)
if "-----------------------" in line and len(cellsInPath) > 0:
if level == 0:
# All cells should be on bottom.
for cell in cellsInPath:
cells[cell] = 0
elif level == 1:
# All cells should be on top.
for cell in cellsInPath:
cells[cell] = 1
###########################################
# Get over the list of cells and fix them.
###########################################
if balanceMitigation:
# print("Balance mitigation activated")
pathTotalArea = 0
for cell in cellsInPath:
pathTotalArea += cellSizes[cell]
pivotPointArea = pathTotalArea*balance
if level == 2:# bot -> top
sumArea = 0 # Area of cells to fix in bottom
for i in range(len(cellsInPath)):
cell = cellsInPath[i]
if (sumArea + cellSizes[cell]) < pivotPointArea:
sumArea += cellSizes[cell]
cells[cell] = 0
elif (sumArea + cellSizes[cell]) >= pivotPointArea:
if currentBalance <= balance:
# Deficit in bottom
sumArea += cellSizes[cell]
cells[cell] = 0
for cell in cellsInPath[i+1:]:
cells[cell] = 1
# print("currentBalance {}".format(currentBalance))
currentBalance = (botArea+sumArea)/(topArea-(pathTotalArea-sumArea)) # bot/top
# print("currentBalance (post-mod) {}".format(currentBalance))
break
elif currentBalance > balance:
# Overpopulation in bottom
for cell in cellsInPath[i+1:]:
cells[cell] = 1
currentBalance = (botArea+sumArea)/(topArea-(pathTotalArea-sumArea)) # bot/top
break
if level == 3:# top -> bot
sumArea = pathTotalArea # Area of cells to fix in bottom
# This time we decrement the total area because we assume that everything is in the bottom
# and that we fix cells in the top one at a time.
for i in range(len(cellsInPath)):
cell = cellsInPath[i]
if (sumArea - cellSizes[cell]) > pivotPointArea:
sumArea -= cellSizes[cell]
cells[cell] = 1
elif (sumArea - cellSizes[cell]) <= pivotPointArea:
if currentBalance <= balance:
# Deficit in bottom
for cell in cellsInPath[i:]:
cells[cell] = 0
currentBalance = (botArea+sumArea)/(topArea-(pathTotalArea-sumArea)) # bot/top
break
elif currentBalance > balance:
# Overpopulation in bottom
cells[cell] = 1
for cell in cellsInPath[i+1:]:
cells[cell] = 0
currentBalance = (botArea+sumArea)/(topArea-(pathTotalArea-sumArea)) # bot/top
break
else:
#######################################################################
# Default: split the path in half based on the amount of cells in path
#######################################################################
# print("No balance mitigation")
if level == 2:
# Half the list on bottom, other half in top
for cell in cellsInPath[:int(len(cellsInPath)/2)]:
cells[cell] = 0
for cell in cellsInPath[int(len(cellsInPath)/2):]:
cells[cell] = 1
if level == 3:
# Half the list on top, other half in bottom
for cell in cellsInPath[:int(len(cellsInPath)/2)]:
cells[cell] = 1
for cell in cellsInPath[int(len(cellsInPath)/2):]:
cells[cell] = 0
if balanceMitigation:
print("Final bottom area balance: {}".format(currentBalance))
print("Analysed paths: {}".format(pathAnalysed))
postSTADirectivesStr = ""
fixfileStr = ""
for cell in cells:
postSTADirectivesStr += cell.strip() + " " + str(cells[cell]).strip() + "\n"
fixfileStr += str(cells[cell]).strip() + "\n"
with open(directivesPostSTAFile, 'w') as f:
f.write(postSTADirectivesStr)
with open(fixfilePostSTAFile, 'w') as f:
f.write(fixfileStr)