-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathparse_gpu_bandwidth.py
executable file
·65 lines (56 loc) · 1.95 KB
/
parse_gpu_bandwidth.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
#!/usr/bin/python
'''
Input: raw csv file from nvprof (data/raw directory)
Output: gpu_bw csv file for plot
'''
import sys
from datetime import datetime
import numpy as np
def main(input_fn):
'''
Read nvprof csv file and write individual csv files with HtoD, DtoH and
DtoD bandwidth
'''
with open(input_fn, 'r') as fid:
blob = fid.read()
lines = blob.split('\n')
out_string = "time,GPU,HtoD,DtoH,DtoD\n"
start = False
for line in lines:
if start and len(line) > 10:
GPU,HtoD, DtoH, DtoD = "","","",""
try:
GPU = line.split('Tesla K80 (')[1].split(')')[0]
write_flag = False
fields = line.split(',')
startTime = fields[0]
throughput = fields[idx]
if 'memcpy HtoD' in line:
write_flag = True
HtoD = throughput
if 'memcpy DtoH' in line:
write_flag = True
DtoH = throughput
if 'memcpy DtoD' in line:
write_flag = True
DtoD = throughput
if write_flag:
out_string += ','.join([startTime, GPU, HtoD, DtoH, DtoD]) + '\n'
except IndexError:
print 'Error in file=' + input_fn + ' with this line\n' + line + '\n'
if '"Start","Duration"' in line:
start = True
fields = line.replace('"', '').split(',')
idx = fields.index('Throughput')
# Now write output csv files
out_fn = input_fn.replace('gpu_bandwidth.csv',
'gpu_bandwidth.timeseries.csv')
if (out_fn == input_fn):
out_fn = out_fn + '1'
# write data to data/final directory
#out_fn = out_fn.replace('data/raw', 'data/final')
with open(out_fn, 'w') as fid:
fid.write(out_string)
#print 'Created file ' + out_fn
if __name__ == '__main__':
main(sys.argv[1])