This repository was archived by the owner on Aug 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbandwidth.py
More file actions
executable file
·98 lines (80 loc) · 3.75 KB
/
Copy pathbandwidth.py
File metadata and controls
executable file
·98 lines (80 loc) · 3.75 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
#!/usr/bin/env python
# coding=utf8
# This file is part of clBandwidth.
#
# clBandwidth is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# clBandwidth is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with clBandwidth. If not, see <http://www.gnu.org/licenses/>.
#
# (c) 2011 Matthias Bach <bach@compeng.uni-frankfurt.de>
import pyopencl as cl
import optparse
from runner import *
if __name__ == '__main__':
parser = optparse.OptionParser(description='Benchmark global memory bandwidth')
parser.add_option('-d', '--device', type=int, metavar='I', help='The device to use for the measurement')
parser.add_option('-p', '--plot', action='store_true', default=False, help='Make a plot of the measurements')
parser.add_option('-e', '--plot-errorbars', action='store_true', default=False, help='Add error bars to the plot')
parser.add_option('-m', '--plot-marker', type=float, dest='plot_markers', action='append', metavar='GB/s', help='Add a marker to the plot at the given performance')
parser.add_option('-o', '--plot-file', metavar='FILE', help='File to store the plot in (Display if unset)')
parser.add_option('-g', '--global-threads', type=int, metavar='NUM', help='The number of global threads to use')
parser.add_option('-l', '--local-threads', type=int, metavar='NUM', help='The number of global threads to use')
parser.add_option('-s', '--mem-size', type=int, metavar='BYTE', help='Memory size in byte')
(args, rem) = parser.parse_args()
runner_args = {}
if args.device != None:
runner_args['device'] = args.device
if args.global_threads != None:
runner_args['global_threads'] = args.global_threads
if args.local_threads != None:
runner_args['local_threads'] = args.local_threads
if args.mem_size != None:
runner_args['max_mem_size'] = args.mem_size
runner = Runner(**runner_args)
datapoints = []
print '#Kernel Bytes nanos (rel err) GB/s'
for kernel in runner.get_kernel_names():
try:
datapoints.append(runner.benchmark(kernel))
except (cl.RuntimeError, cl.LogicError) as ex:
# On Apples OpenCL retrieving the profiling information sometimes seems to fail for no good reason
# In addition, sometimes the queue becomes invalid
print 'Error benchmarking {0}: {1}'.format(kernel, ex)
for datapoint in datapoints:
print '{0.kernel} {0.bytes_transferred} {0.time:.0f} ({1:.1%}) {0.bandwidth}'.format(datapoint, datapoint.time_std / datapoint.time)
if args.plot:
import matplotlib.pyplot as plt # by including it here we won't need it unless we want to plot
bandwidths = map(lambda p: p.bandwidth, datapoints)
xticks = map(lambda p: p.kernel, datapoints)
if args.plot_errorbars:
errs = map(lambda p: p.time_std / p.time * p.bandwidth, datapoints)
ind = np.arange(len(datapoints)) + 0.5
plt.figure(figsize=(2 + len(datapoints) * .25,12))
plt.axes([0.125,.4,.775,.5])
plt.title('Global Memory Bandwidth')
plt.ylabel('GB/s')
if args.plot_errorbars:
plt.bar(ind, bandwidths, align='center', yerr=errs, ecolor='black')
else:
plt.bar(ind, bandwidths, align='center')
# handle markers
if args.plot_markers:
for marker in args.plot_markers:
plt.axhline(y=marker, color='r')
# Avoid the error bars triggering the lower quadrant to show
ymin, ymax = plt.ylim()
plt.ylim(0, ymax)
plt.xticks(ind, xticks, rotation='vertical')
if args.plot_file:
plt.savefig(args.plot_file)
else:
plt.show()