-
Notifications
You must be signed in to change notification settings - Fork 0
/
proc_log.py
executable file
·150 lines (122 loc) · 4.91 KB
/
proc_log.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
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
#!/usr/bin/env python3
import argparse
from collections import Counter
import sys
def HEADER(text): return '\033[95m' + text + '\033[0m'
def OKBLUE(text): return '\033[94m' + text + '\033[0m'
def OKGREEN(text): return '\033[92m' + text + '\033[0m'
def WARNING(text): return '\033[93m' + text + '\033[0m'
def FAIL(text): return '\033[91m' + text + '\033[0m'
def BOLD(text): return '\033[1m' + text + '\033[0m'
def UNDERLINE(text): return '\033[4m' + text + '\033[0m'
# For parsing
# ...Greenspun's Tenth Rule, or something like that...
currOpStr = ''
# Really, these are (always?) tied together, but we'll keep them separate for now
# We'll use them like stacks that we push the currently-parsed Op onto
surfaces = []
ops = []
recordType = '' # enum surface, op
# could do this with sets.Set, but eh
allOps = ['conv', 'sdp', 'pdp', 'cdp', 'rubik', 'bdma']
class Surface:
def __init__(self, surfaceType):
self.surfaceType = surfaceType
class Op:
def __init__(self, opType):
self.opType = opType
# initialize opcounters
# TODO remove this (deprecated... or will be)
ctr = Counter()
bdma_ctr = conv_ctr = pdp_ctr = cdp_ctr = rubik_ctr = sdp_ctr = 0
parser = argparse.ArgumentParser(description='Preprocess a screen log from an NVDLA run.')
parser.add_argument('filepath', type=str, nargs=None,
help='the input file to be processed')
#parser.add_argument('-s', '--strip', action='store_true', help='whether/not to strip blank lines')
args = parser.parse_args()
if __name__ == '__main__':
lines = None
with open(args.filepath, 'r') as f:
lines = f.readlines()
lines = [l for l in lines if l != '\n']
print("%d lines parsed." % len(lines))
# capture the ./nvdla_runtime command as the first line
'''
start_idx = 0
for i, l in enumerate(lines):
if './nvdla_runtime' in l:
start_idx = i
break
'''
# TODO assumes ./nvdla_runtime command spans 2 lines
start_idx = lines.index('creating new runtime context...\n') - 2
end_idx = lines.index('Test pass\n')
lines = lines[start_idx:end_idx+1]
for i, l in enumerate(lines):
# TODO actually use regex
if 'NVDLA FW ROI' in l:
if '_surface_desc' in l:
opStrBegin = l.index('_') + 1
currOpStr = l[opStrBegin:opStrBegin+l[opStrBegin:].index('_')]
#print(currOpStr)
surfaces.append(Surface(currOpStr))
recordType = 'surface'
if '_op_desc' in l:
opStrBegin = l.index('_') + 1
currOpStr = l[opStrBegin:opStrBegin+l[opStrBegin:].index('_')]
#print(currOpStr)
ops.append(Op(currOpStr))
recordType = 'op'
if 'src_data' in l:
srcSizeStr = lines[i+6].split()[-1]
#print(srcSizeStr)
surfaces[-1].srcDataSize = int(srcSizeStr)
if 'weight_data' in l:
weightSizeStr = lines[i+6].split()[-1]
#print(srcSizeStr)
surfaces[-1].weightDataSize = int(weightSizeStr)
if 'dst_data' in l:
dstSizeStr = lines[i+6].split()[-1]
surfaces[-1].dstDataSize = int(dstSizeStr)
# These just print out the lines
'''
if 'HWLs done' in l:
sys.stdout.write(OKGREEN(l))
elif '-1' in l:
sys.stdout.write(OKBLUE(l))
elif 'NVDLA FW ROI' in l and '_desc' in l:
sys.stdout.write(FAIL(l))
if 'bdma' in l:
ctr['bdma'] += 1
elif 'conv' in l:
ctr['conv'] += 1
elif 'pdp' in l:
ctr['pdp'] += 1
elif 'cdp' in l:
ctr['cdp'] += 1
elif 'rubik' in l:
ctr['rubik'] += 1
else:
ctr['sdp'] += 1
else:
sys.stdout.write(l) # already includes newlines
'''
for item in ctr:
print('op %s performed %dX' %(item, ctr[item]/2))
for s in surfaces:
surfStr = s.surfaceType + ' ' + str(s.srcDataSize)
print(surfStr)
totalSrcData = sum(map(lambda s: s.srcDataSize if s.surfaceType == 'conv' else 0, surfaces))
totalWeightData = sum(map(lambda s: s.weightDataSize if s.surfaceType == 'conv' else 0, surfaces))
print("Total Source Data: " + str(totalSrcData))
print("Total Weight Data: " + str(totalWeightData))
print('-'*40)
for opType in allOps:
totalSrcData = sum(map(lambda s: s.srcDataSize if s.surfaceType == opType else 0, surfaces))
print(OKGREEN(opType + ' src data: ' + str(totalSrcData)))
if opType == 'conv':
totalWeightData = sum(map(lambda s: s.weightDataSize if s.surfaceType == 'conv' else 0, surfaces))
print(OKBLUE(opType + ' weight data: ' + str(totalWeightData)))
for opType in allOps:
totalDstData = sum(map(lambda s: s.dstDataSize if s.surfaceType == opType else 0, surfaces))
print(FAIL(opType + ' dst data: ' + str(totalDstData)))