-
Notifications
You must be signed in to change notification settings - Fork 5
/
run-prof.py
executable file
·125 lines (91 loc) · 2.88 KB
/
run-prof.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
#!/usr/bin/env python
from __future__ import print_function
metrics = [
"flop_count_sp",
"flop_sp_efficiency",
"shared_store_transactions",
"shared_load_transactions",
"local_load_transactions",
"local_store_transactions",
"gld_transactions",
"gst_transactions",
"gld_throughput",
"gst_throughput",
"gld_requested_throughput",
"gld_efficiency",
"gst_requested_throughput",
"gst_efficiency",
"l2_read_transactions",
"l2_write_transactions",
"l2_utilization",
"l1_cache_global_hit_rate",
"l1_shared_utilization",
"l2_l1_read_hit_rate"
]
cmd_parts = [
"nvprof",
"--csv",
"--metrics " + ",".join(metrics),
"./multorture",
]
import time
now = time.time()
# timestamp for spreadsheet
timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
output_fname = time.strftime("prof-%Y-%m-%d-%H%M%S.csv", time.localtime(now))
# TODO: use subprocess instead
import commands
# get git hash (does not check for local modifications though...)
git_hash = commands.getoutput("git rev-parse HEAD")
# check if there were modified files
status, dummy = commands.getstatusoutput("git diff --quiet")
assert status in (0,256), "status was " + str(status)
if status == 256:
git_hash += "+modif"
# run the profiler
output = commands.getoutput(" ".join(cmd_parts))
lines = output.splitlines()
import re
while lines:
line = lines.pop(0)
if re.match("==\d+== Metric result:$", line):
break
fout = open(output_fname, "w")
is_first = True
# keep a copy of the CSV values to read from them afterwards
csv_buffer = ""
while lines:
line = lines.pop(0)
csv_buffer += line + "\n"
if is_first:
print('"time","git_hash",%s' % line, file = fout)
is_first = False
else:
print('"%s","%s",%s' % (timestamp, git_hash,line), file = fout)
#----------
# parse CSV to produce some ASCII tables
#----------
import cStringIO as StringIO
import csv
csv_buffer = StringIO.StringIO(csv_buffer)
reader = csv.DictReader(csv_buffer)
# first index is metric name
# second index is kernel name
# value is average value of metric
data = {}
for line in reader:
# TODO: we could move this up
kernel_name = line['Kernel']
kernel_name = re.match("^(void )?([a-zA-Z0-9_]+)", kernel_name).group(2)
data.setdefault(line["Metric Name"], {})[kernel_name] = line['Avg']
# print kernels ordered by selected metric
for selected_metric in [ "gld_throughput", "flop_sp_efficiency"]:
print(selected_metric + ":")
def parse_func(item):
item = re.sub("[^0-9\.]","", item)
return float(item)
kernels = data[selected_metric].keys()
for kernel in sorted(kernels, key = lambda kernel: parse_func(data[selected_metric][kernel]), reverse = True):
print(" %-40s: %s" % (kernel, data[selected_metric][kernel]))
print()
print("wrote",output_fname)