-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel_segment.py
119 lines (99 loc) · 3.28 KB
/
kernel_segment.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
import time
import datetime
import sys,urllib,urllib2
import csv
import os, glob, re
import cPickle as pickle
import numpy as np
import ConfigParser
import json
import pandas as pd
logRoot = 'logs/v100-vgg-logs'
splitword = 'maxwell_scudnn_128x64_relu_small_nn' # for vgg
# splitword = 'maxwell_scudnn_128x64_relu_medium_nn' # for googlenet
keywords = []
metrics_filelist = glob.glob(r'%s/*metrics.log' % logRoot)
metrics_filelist.sort()
coreBase = 0
memBase = 0
head = ["appName", "coreF", "memF", "kernel", "count", "aver_time", "std_time", "coeff. of var."]
# prepare csv file
csvfile = open('%s-segment.csv' % logRoot, 'wb')
csvWriter = csv.writer(csvfile, dialect='excel')
# write table head
csvWriter.writerow(head)
# extract information of one iteration
f = open(metrics_filelist[0], 'r')
content = f.readlines()
f.close()
split_idx = [i for i in range(len(content)) if splitword in content[i]]
for i in range(split_idx[0], split_idx[1]):
line = content[i]
# print line
if "[CUDA " in line:
continue
infor_line = line.split()
infor_grid = " ".join(infor_line[2:5])
infor_block = " ".join(infor_line[5:8])
if infor_line[18] == 'void':
infor_kernel = " ".join(infor_line[18:20])
else:
infor_kernel = infor_line[18]
newkey = '.*'.join([infor_grid, infor_block, infor_kernel])
# print newkey
if newkey not in keywords:
keywords.append(newkey)
keywords.append("[CUDA memcpy HtoD]")
keywords.append("[CUDA memcpy DtoH]")
keywords.append("[CUDA memset]")
for key in keywords:
print key
for fp in metrics_filelist:
# print fp
baseInfo = fp.split('_')
appName = baseInfo[1]
coreF = str(int(baseInfo[2][4:]) + coreBase)
memF = str(int(baseInfo[3][3:]) + memBase)
# extract all kernels
for keyword in keywords:
rec = [appName, coreF, memF, keyword]
print rec
# extract execution time information
f = open(fp, 'r')
content = f.readlines()
f.close()
# arg = content[0][4:].strip()
# rec.append(arg)
# regex = re.compile(r'\d+\.\d+ (iter/s).')
keyword = keyword.replace("(", "\(")
keyword = keyword.replace(")", "\)")
keyword = keyword.replace("[", "\[")
keyword = keyword.replace("]", "\]")
regex = re.compile(keyword)
# print filter(regex.search, content)
time = filter(regex.search, content)
# time = [1.0 / float(line.split()[-7][1:]) for line in time]
print len(time)
# print time[0]
rec.append(len(time))
# if len(time) < 50:
# continue
time = [line.split()[1] for line in time]
for i in range(len(time)):
if 'ms' in time[i]:
time[i] = float(time[i][:-2]) / 1e3
elif 'us' in time[i]:
time[i] = float(time[i][:-2]) / 1e6
elif 'ns' in time[i]:
time[i] = float(time[i][:-2]) / 1e9
else:
time[i] = float(time[i][:-1])
time.sort()
# time = time[len(time)/3:len(time)*2/3]
aver_time = np.mean(time)
std_time = np.std(time)
rec.append(str(aver_time))
rec.append(str(std_time))
rec.append("%f" % (std_time / aver_time))
print rec
csvWriter.writerow(rec)