kernel-tuner 0.1.7__tar.gz → 0.1.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/PKG-INFO +11 -20
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/README.rst +10 -19
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/c.py +25 -8
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/core.py +33 -5
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/cuda.py +30 -11
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/interface.py +40 -9
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/opencl.py +23 -7
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/runners/noodles.py +1 -1
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/runners/sequential.py +5 -2
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/strategies/diff_evo.py +0 -1
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/util.py +107 -8
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner.egg-info/PKG-INFO +11 -20
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner.egg-info/SOURCES.txt +0 -1
- kernel_tuner-0.1.8/kernel_tuner.egg-info/requires.txt +37 -0
- kernel_tuner-0.1.8/setup.py +54 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/test/test_c_functions.py +5 -5
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/test/test_cuda_functions.py +13 -12
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/test/test_cuda_mocked.py +2 -4
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/test/test_interface.py +14 -12
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/test/test_minimize.py +1 -1
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/test/test_opencl_functions.py +35 -17
- kernel_tuner-0.1.8/test/test_runners.py +169 -0
- kernel_tuner-0.1.8/test/test_util_functions.py +467 -0
- kernel_tuner-0.1.7/kernel_tuner.egg-info/requires.txt +0 -2
- kernel_tuner-0.1.7/requirements.txt +0 -2
- kernel_tuner-0.1.7/setup.py +0 -41
- kernel_tuner-0.1.7/test/test_runners.py +0 -125
- kernel_tuner-0.1.7/test/test_util_functions.py +0 -279
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/LICENSE +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/MANIFEST.in +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/__init__.py +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/runners/__init__.py +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/strategies/__init__.py +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/strategies/basinhopping.py +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/strategies/brute_force.py +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/strategies/minimize.py +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner/strategies/random_sample.py +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner.egg-info/dependency_links.txt +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/kernel_tuner.egg-info/top_level.txt +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/setup.cfg +0 -0
- {kernel_tuner-0.1.7 → kernel_tuner-0.1.8}/test/test_device_interface.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.1
|
|
2
2
|
Name: kernel_tuner
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.8
|
|
4
4
|
Summary: A simple CUDA/OpenCL kernel tuner in Python
|
|
5
5
|
Home-page: http://benvanwerkhoven.github.io/kernel_tuner/
|
|
6
6
|
Author: Ben van Werkhoven
|
|
@@ -26,31 +26,22 @@ Description: Kernel Tuner: A simple CUDA/OpenCL Auto-Tuner in Python
|
|
|
26
26
|
|
|
27
27
|
The easiest way to install the Kernel Tuner is using pip:
|
|
28
28
|
|
|
29
|
-
.. code-block:: bash
|
|
30
|
-
|
|
31
|
-
pip install kernel_tuner
|
|
32
|
-
|
|
33
|
-
But you can also install from the git repository. This way you also get the
|
|
34
|
-
examples and the tutorials:
|
|
35
|
-
|
|
36
|
-
.. code-block:: bash
|
|
37
|
-
|
|
38
|
-
git clone https://github.com/benvanwerkhoven/kernel_tuner.git
|
|
39
|
-
cd kernel_tuner
|
|
40
|
-
pip install .
|
|
41
|
-
|
|
42
29
|
To tune CUDA kernels:
|
|
43
30
|
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
- First, make sure you have the `CUDA Toolkit <https://developer.nvidia.com/cuda-toolkit>`_ installed
|
|
32
|
+
- Then type: ``pip install kernel_tuner[cuda]``
|
|
46
33
|
|
|
47
34
|
To tune OpenCL kernels:
|
|
48
35
|
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
- First, make sure you have an OpenCL compiler for your intended OpenCL platform
|
|
37
|
+
- Then type: ``pip install kernel_tuner[opencl]``
|
|
38
|
+
|
|
39
|
+
Or both:
|
|
40
|
+
|
|
41
|
+
- ``pip install kernel_tuner[cuda,opencl]``
|
|
51
42
|
|
|
52
|
-
|
|
53
|
-
dependencies
|
|
43
|
+
More information about how to install Kernel Tuner and its
|
|
44
|
+
dependencies can be found in the `installation guide
|
|
54
45
|
<http://benvanwerkhoven.github.io/kernel_tuner/install.html>`__
|
|
55
46
|
|
|
56
47
|
Example usage
|
|
@@ -18,31 +18,22 @@ Installation
|
|
|
18
18
|
|
|
19
19
|
The easiest way to install the Kernel Tuner is using pip:
|
|
20
20
|
|
|
21
|
-
.. code-block:: bash
|
|
22
|
-
|
|
23
|
-
pip install kernel_tuner
|
|
24
|
-
|
|
25
|
-
But you can also install from the git repository. This way you also get the
|
|
26
|
-
examples and the tutorials:
|
|
27
|
-
|
|
28
|
-
.. code-block:: bash
|
|
29
|
-
|
|
30
|
-
git clone https://github.com/benvanwerkhoven/kernel_tuner.git
|
|
31
|
-
cd kernel_tuner
|
|
32
|
-
pip install .
|
|
33
|
-
|
|
34
21
|
To tune CUDA kernels:
|
|
35
22
|
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
- First, make sure you have the `CUDA Toolkit <https://developer.nvidia.com/cuda-toolkit>`_ installed
|
|
24
|
+
- Then type: ``pip install kernel_tuner[cuda]``
|
|
38
25
|
|
|
39
26
|
To tune OpenCL kernels:
|
|
40
27
|
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
- First, make sure you have an OpenCL compiler for your intended OpenCL platform
|
|
29
|
+
- Then type: ``pip install kernel_tuner[opencl]``
|
|
30
|
+
|
|
31
|
+
Or both:
|
|
32
|
+
|
|
33
|
+
- ``pip install kernel_tuner[cuda,opencl]``
|
|
43
34
|
|
|
44
|
-
|
|
45
|
-
dependencies
|
|
35
|
+
More information about how to install Kernel Tuner and its
|
|
36
|
+
dependencies can be found in the `installation guide
|
|
46
37
|
<http://benvanwerkhoven.github.io/kernel_tuner/install.html>`__
|
|
47
38
|
|
|
48
39
|
Example usage
|
|
@@ -149,8 +149,12 @@ class CFunctions(object):
|
|
|
149
149
|
try:
|
|
150
150
|
write_file(source_file, kernel_string)
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
lib_extension = ".so"
|
|
153
|
+
if platform.system() == "Darwin":
|
|
154
|
+
lib_extension = ".dylib"
|
|
155
|
+
|
|
156
|
+
subprocess.check_call([self.compiler, "-c", source_file] + compiler_options + ["-o", filename + ".o"])
|
|
157
|
+
subprocess.check_call([self.compiler, filename + ".o"] + compiler_options + ["-shared", "-o", filename + lib_extension] + lib_args)
|
|
154
158
|
|
|
155
159
|
self.lib = numpy.ctypeslib.load_library(filename, '.')
|
|
156
160
|
|
|
@@ -161,11 +165,12 @@ class CFunctions(object):
|
|
|
161
165
|
delete_temp_file(source_file)
|
|
162
166
|
delete_temp_file(filename+".o")
|
|
163
167
|
delete_temp_file(filename+".so")
|
|
168
|
+
delete_temp_file(filename+".dylib")
|
|
164
169
|
|
|
165
170
|
|
|
166
171
|
return func
|
|
167
172
|
|
|
168
|
-
def benchmark(self, func, c_args, threads, grid):
|
|
173
|
+
def benchmark(self, func, c_args, threads, grid, times):
|
|
169
174
|
"""runs the kernel repeatedly, returns averaged returned value
|
|
170
175
|
|
|
171
176
|
The C function tuning is a little bit more flexible than direct CUDA
|
|
@@ -196,10 +201,14 @@ class CFunctions(object):
|
|
|
196
201
|
interface as CudaFunctions and OpenCLFunctions.
|
|
197
202
|
:type grid: any
|
|
198
203
|
|
|
199
|
-
:
|
|
204
|
+
:param times: Return the execution time of all iterations.
|
|
205
|
+
:type times: bool
|
|
206
|
+
|
|
207
|
+
:returns: All execution times, if times=True, or a robust average for the
|
|
208
|
+
kernel execution time.
|
|
200
209
|
:rtype: float
|
|
201
210
|
"""
|
|
202
|
-
|
|
211
|
+
time = []
|
|
203
212
|
for _ in range(self.iterations):
|
|
204
213
|
value = self.run_kernel(func, c_args, threads, grid)
|
|
205
214
|
|
|
@@ -213,9 +222,15 @@ class CFunctions(object):
|
|
|
213
222
|
if value < 0.0:
|
|
214
223
|
raise Exception("too many resources requested for launch")
|
|
215
224
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
225
|
+
time.append(value)
|
|
226
|
+
time = sorted(time)
|
|
227
|
+
if times:
|
|
228
|
+
return time
|
|
229
|
+
else:
|
|
230
|
+
if self.iterations > 4:
|
|
231
|
+
return numpy.mean(time[1:-1])
|
|
232
|
+
else:
|
|
233
|
+
return numpy.mean(time)
|
|
219
234
|
|
|
220
235
|
|
|
221
236
|
def run_kernel(self, func, c_args, threads, grid):
|
|
@@ -282,3 +297,5 @@ class CFunctions(object):
|
|
|
282
297
|
#OpenMP will core dump when unloaded, this is a well-known issue with OpenMP
|
|
283
298
|
logging.debug('unloading shared library')
|
|
284
299
|
_ctypes.dlclose(self.lib._handle)
|
|
300
|
+
|
|
301
|
+
units = {}
|
|
@@ -43,6 +43,9 @@ class DeviceInterface(object):
|
|
|
43
43
|
:param iterations: Number of iterations to be used when benchmarking using this device.
|
|
44
44
|
:type iterations: int
|
|
45
45
|
|
|
46
|
+
:param times: Return the execution time of all iterations.
|
|
47
|
+
:type times: bool
|
|
48
|
+
|
|
46
49
|
"""
|
|
47
50
|
logging.debug('DeviceInterface instantiated, lang=%s', lang)
|
|
48
51
|
|
|
@@ -57,11 +60,12 @@ class DeviceInterface(object):
|
|
|
57
60
|
raise Exception("Sorry, support for languages other than CUDA, OpenCL, or C is not implemented yet")
|
|
58
61
|
self.lang = lang
|
|
59
62
|
self.dev = dev
|
|
63
|
+
self.units = dev.units
|
|
60
64
|
self.name = dev.name
|
|
61
65
|
if not quiet:
|
|
62
66
|
print("Using: " + self.dev.name)
|
|
63
67
|
|
|
64
|
-
def benchmark(self, func, gpu_args, instance, verbose):
|
|
68
|
+
def benchmark(self, func, gpu_args, instance, times, verbose):
|
|
65
69
|
"""benchmark the kernel instance"""
|
|
66
70
|
logging.debug('benchmark ' + instance.name)
|
|
67
71
|
logging.debug('thread block dimensions x,y,z=%d,%d,%d', *instance.threads)
|
|
@@ -69,13 +73,14 @@ class DeviceInterface(object):
|
|
|
69
73
|
|
|
70
74
|
time = None
|
|
71
75
|
try:
|
|
72
|
-
time = self.dev.benchmark(func, gpu_args, instance.threads, instance.grid)
|
|
76
|
+
time = self.dev.benchmark(func, gpu_args, instance.threads, instance.grid, times)
|
|
73
77
|
except Exception as e:
|
|
74
78
|
#some launches may fail because too many registers are required
|
|
75
79
|
#to run the kernel given the current thread block size
|
|
76
80
|
#the desired behavior is to simply skip over this configuration
|
|
77
81
|
#and proceed to try the next one
|
|
78
|
-
|
|
82
|
+
skippable_exceptions = ["too many resources requested for launch", "OUT_OF_RESOURCES", "INVALID_WORK_GROUP_SIZE"]
|
|
83
|
+
if any([skip_str in str(e) for skip_str in skippable_exceptions]):
|
|
79
84
|
logging.debug('benchmark fails due to runtime failure too many resources required')
|
|
80
85
|
if verbose:
|
|
81
86
|
print("skipping config", instance.name, "reason: too many resources requested for launch")
|
|
@@ -90,6 +95,9 @@ class DeviceInterface(object):
|
|
|
90
95
|
logging.debug('check_kernel_correctness')
|
|
91
96
|
params = instance.params
|
|
92
97
|
|
|
98
|
+
if len(instance.arguments) != len(answer):
|
|
99
|
+
raise TypeError("The length of argument list and provided results do not match.")
|
|
100
|
+
|
|
93
101
|
#zero GPU memory for output arguments
|
|
94
102
|
for i, arg in enumerate(instance.arguments):
|
|
95
103
|
if answer[i] is not None:
|
|
@@ -114,6 +122,26 @@ class DeviceInterface(object):
|
|
|
114
122
|
for i, arg in enumerate(instance.arguments):
|
|
115
123
|
expected = answer[i]
|
|
116
124
|
if expected is not None:
|
|
125
|
+
if verify is not None:
|
|
126
|
+
if not isinstance(expected, numpy.ndarray):
|
|
127
|
+
raise TypeError("Element " + str(i) + " of the expected results list should be a numpy.ndarray")
|
|
128
|
+
else:
|
|
129
|
+
if isinstance(expected, numpy.ndarray) and isinstance(arg, numpy.ndarray):
|
|
130
|
+
if expected.dtype != arg.dtype:
|
|
131
|
+
raise TypeError("Element " + str(i)
|
|
132
|
+
+ " of the expected results list is not the same as the kernel output: "
|
|
133
|
+
+ str(expected.dtype) + " != " + str(arg.dtype) + ".")
|
|
134
|
+
if expected.size != arg.size:
|
|
135
|
+
raise TypeError("Element " + str(i)
|
|
136
|
+
+ " of the expected results list has a different size than "
|
|
137
|
+
+ "the kernel output: "
|
|
138
|
+
+ str(expected.size) + " != " + str(arg.size) + ".")
|
|
139
|
+
elif isinstance(expected, numpy.numeric) and isinstance(arg, numpy.numeric):
|
|
140
|
+
if expected.dtype != arg.dtype:
|
|
141
|
+
raise TypeError("Element " + str(i)
|
|
142
|
+
+ " of the expected results list is not the same as the kernel output: "
|
|
143
|
+
+ str(expected.dtype) + " != " + str(arg.dtype) + ".")
|
|
144
|
+
|
|
117
145
|
result_host = numpy.zeros_like(arg)
|
|
118
146
|
self.dev.memcpy_dtoh(result_host, gpu_args[i])
|
|
119
147
|
|
|
@@ -172,7 +200,7 @@ class DeviceInterface(object):
|
|
|
172
200
|
self.check_kernel_correctness(func, gpu_args, instance, tuning_options.answer, tuning_options.atol, tuning_options.verify, verbose)
|
|
173
201
|
|
|
174
202
|
#benchmark
|
|
175
|
-
time = self.benchmark(func, gpu_args, instance, verbose)
|
|
203
|
+
time = self.benchmark(func, gpu_args, instance, tuning_options.times, verbose)
|
|
176
204
|
|
|
177
205
|
except Exception as e:
|
|
178
206
|
#dump kernel_string to temp file
|
|
@@ -223,7 +251,7 @@ class DeviceInterface(object):
|
|
|
223
251
|
|
|
224
252
|
#insert default block_size_names if needed
|
|
225
253
|
if not kernel_options.block_size_names:
|
|
226
|
-
kernel_options.block_size_names =
|
|
254
|
+
kernel_options.block_size_names = util.default_block_size_names
|
|
227
255
|
|
|
228
256
|
#setup thread block and grid dimensions
|
|
229
257
|
threads, grid = util.setup_block_and_grid(kernel_options.problem_size, grid_div, params, kernel_options.block_size_names)
|
|
@@ -8,9 +8,15 @@ import numpy
|
|
|
8
8
|
#and run tests without pycuda installed
|
|
9
9
|
try:
|
|
10
10
|
import pycuda.driver as drv
|
|
11
|
-
from pycuda.compiler import SourceModule, DynamicSourceModule
|
|
12
11
|
except ImportError:
|
|
13
12
|
drv = None
|
|
13
|
+
try:
|
|
14
|
+
from pycuda.compiler import SourceModule
|
|
15
|
+
except ImportError:
|
|
16
|
+
SourceModule = None
|
|
17
|
+
try:
|
|
18
|
+
from pycuda.compiler import DynamicSourceModule
|
|
19
|
+
except ImportError:
|
|
14
20
|
DynamicSourceModule = None
|
|
15
21
|
|
|
16
22
|
|
|
@@ -31,6 +37,7 @@ class CudaFunctions(object):
|
|
|
31
37
|
:param iterations: Number of iterations used while benchmarking a kernel, 7 by default.
|
|
32
38
|
:type iterations: int
|
|
33
39
|
"""
|
|
40
|
+
self.allocations = []
|
|
34
41
|
if not drv:
|
|
35
42
|
raise ImportError("Error: pycuda not installed, please install e.g. using 'pip install pycuda'.")
|
|
36
43
|
|
|
@@ -40,7 +47,7 @@ class CudaFunctions(object):
|
|
|
40
47
|
#inspect device properties
|
|
41
48
|
devprops = {str(k): v for (k, v) in self.context.get_device().get_attributes().items()}
|
|
42
49
|
self.max_threads = devprops['MAX_THREADS_PER_BLOCK']
|
|
43
|
-
self.cc = str(devprops
|
|
50
|
+
self.cc = str(devprops.get('COMPUTE_CAPABILITY_MAJOR','0')) + str(devprops.get('COMPUTE_CAPABILITY_MINOR','0'))
|
|
44
51
|
self.iterations = iterations
|
|
45
52
|
self.current_module = None
|
|
46
53
|
self.compiler_options = compiler_options or []
|
|
@@ -55,7 +62,6 @@ class CudaFunctions(object):
|
|
|
55
62
|
env["device_properties"] = devprops
|
|
56
63
|
self.env = env
|
|
57
64
|
self.name = env["device_name"]
|
|
58
|
-
self.allocations = []
|
|
59
65
|
|
|
60
66
|
def __del__(self):
|
|
61
67
|
for gpu_mem in self.allocations:
|
|
@@ -113,8 +119,9 @@ class CudaFunctions(object):
|
|
|
113
119
|
else:
|
|
114
120
|
source_mod = SourceModule
|
|
115
121
|
|
|
116
|
-
self.current_module = source_mod(kernel_string, options=
|
|
117
|
-
arch='compute_' + self.cc
|
|
122
|
+
self.current_module = source_mod(kernel_string, options=compiler_options + ["-e", kernel_name],
|
|
123
|
+
arch=('compute_' + self.cc) if self.cc != "00" else None,
|
|
124
|
+
code=('sm_' + self.cc) if self.cc != "00" else None,
|
|
118
125
|
cache_dir=False, no_extern_c=no_extern_c)
|
|
119
126
|
|
|
120
127
|
|
|
@@ -127,7 +134,7 @@ class CudaFunctions(object):
|
|
|
127
134
|
raise e
|
|
128
135
|
|
|
129
136
|
|
|
130
|
-
def benchmark(self, func, gpu_args, threads, grid):
|
|
137
|
+
def benchmark(self, func, gpu_args, threads, grid, times):
|
|
131
138
|
"""runs the kernel and measures time repeatedly, returns average time
|
|
132
139
|
|
|
133
140
|
Runs the kernel and measures kernel execution time repeatedly, number of
|
|
@@ -153,21 +160,31 @@ class CudaFunctions(object):
|
|
|
153
160
|
of the grid
|
|
154
161
|
:type grid: tuple(int, int)
|
|
155
162
|
|
|
156
|
-
:
|
|
163
|
+
:param times: Return the execution time of all iterations.
|
|
164
|
+
:type times: bool
|
|
165
|
+
|
|
166
|
+
:returns: All execution times, if times=True, or a robust average for the
|
|
167
|
+
kernel execution time.
|
|
157
168
|
:rtype: float
|
|
158
169
|
"""
|
|
159
170
|
start = drv.Event()
|
|
160
171
|
end = drv.Event()
|
|
161
|
-
|
|
172
|
+
time = []
|
|
162
173
|
for _ in range(self.iterations):
|
|
163
174
|
self.context.synchronize()
|
|
164
175
|
start.record()
|
|
165
176
|
self.run_kernel(func, gpu_args, threads, grid)
|
|
166
177
|
end.record()
|
|
167
178
|
self.context.synchronize()
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
179
|
+
time.append(end.time_since(start))
|
|
180
|
+
time = sorted(time)
|
|
181
|
+
if times:
|
|
182
|
+
return time
|
|
183
|
+
else:
|
|
184
|
+
if self.iterations > 4:
|
|
185
|
+
return numpy.mean(time[1:-1])
|
|
186
|
+
else:
|
|
187
|
+
return numpy.mean(time)
|
|
171
188
|
|
|
172
189
|
def copy_constant_memory_args(self, cmem_args):
|
|
173
190
|
"""adds constant memory arguments to the most recently compiled module
|
|
@@ -239,3 +256,5 @@ class CudaFunctions(object):
|
|
|
239
256
|
drv.memcpy_dtoh(dest, src)
|
|
240
257
|
else:
|
|
241
258
|
dest = src
|
|
259
|
+
|
|
260
|
+
units = {'time': 'ms'}
|
|
@@ -231,6 +231,8 @@ _tuning_options = Options([
|
|
|
231
231
|
("iterations", ("""The number of times a kernel should be executed and
|
|
232
232
|
its execution time measured when benchmarking a kernel, 7 by default.""",
|
|
233
233
|
"int")),
|
|
234
|
+
("times", ("""Returns the execution time of all iterations of a
|
|
235
|
+
kernel execution. False by default.""", "bool")),
|
|
234
236
|
("verbose", ("""Sets whether or not to report about configurations that
|
|
235
237
|
were skipped during the search. This could be due to several reasons:
|
|
236
238
|
|
|
@@ -290,13 +292,21 @@ def tune_kernel(kernel_name, kernel_string, problem_size, arguments,
|
|
|
290
292
|
restrictions=None, answer=None, atol=1e-6, verify=None, verbose=False,
|
|
291
293
|
lang=None, device=0, platform=0, cmem_args=None,
|
|
292
294
|
num_threads=1, use_noodles=False, sample_fraction=False, compiler=None, compiler_options=None, log=None,
|
|
293
|
-
iterations=7, block_size_names=None, quiet=False, strategy=None, method=None):
|
|
295
|
+
iterations=7, times=False, block_size_names=None, quiet=False, strategy=None, method=None):
|
|
294
296
|
|
|
295
297
|
if log:
|
|
296
298
|
logging.basicConfig(filename=kernel_name + datetime.now().strftime('%Y%m%d-%H:%M:%S') + '.log', level=log)
|
|
297
299
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
+
_check_user_input(kernel_name, kernel_string, arguments, block_size_names)
|
|
301
|
+
|
|
302
|
+
# check for forbidden names in tune parameters
|
|
303
|
+
util.check_tune_params_list(tune_params)
|
|
304
|
+
|
|
305
|
+
# check whether block_size_names are used as expected
|
|
306
|
+
util.check_block_size_params_names_list(block_size_names, tune_params)
|
|
307
|
+
|
|
308
|
+
if iterations < 1:
|
|
309
|
+
raise ValueError("Iterations should be at least one!")
|
|
300
310
|
|
|
301
311
|
#sort all the options into separate dicts
|
|
302
312
|
opts = locals()
|
|
@@ -364,11 +374,13 @@ def tune_kernel(kernel_name, kernel_string, problem_size, arguments,
|
|
|
364
374
|
results, env = strategy.tune(runner, kernel_options, device_options, tuning_options)
|
|
365
375
|
|
|
366
376
|
#finished iterating over search space
|
|
367
|
-
if
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
377
|
+
if not device_options.quiet:
|
|
378
|
+
if results: #checks if results is not empty
|
|
379
|
+
best_config = min(results, key=lambda x: x['time'])
|
|
380
|
+
units = getattr(runner, "units", None)
|
|
381
|
+
print("best performing configuration:", util.get_config_string(best_config, units=units))
|
|
382
|
+
else:
|
|
383
|
+
print("no results to report")
|
|
372
384
|
|
|
373
385
|
del runner.dev
|
|
374
386
|
|
|
@@ -412,6 +424,8 @@ def run_kernel(kernel_name, kernel_string, problem_size, arguments,
|
|
|
412
424
|
lang=None, device=0, platform=0, cmem_args=None, compiler=None, compiler_options=None,
|
|
413
425
|
block_size_names=None, quiet=False):
|
|
414
426
|
|
|
427
|
+
_check_user_input(kernel_name, kernel_string, arguments, block_size_names)
|
|
428
|
+
|
|
415
429
|
#sort options into separate dicts
|
|
416
430
|
opts = locals()
|
|
417
431
|
kernel_options = Options([(k, opts[k]) for k in _kernel_options.keys()])
|
|
@@ -421,7 +435,6 @@ def run_kernel(kernel_name, kernel_string, problem_size, arguments,
|
|
|
421
435
|
dev = core.DeviceInterface(kernel_string, iterations=1, **device_options)
|
|
422
436
|
|
|
423
437
|
#move data to the GPU
|
|
424
|
-
util.check_argument_list(arguments)
|
|
425
438
|
gpu_args = dev.ready_argument_list(arguments)
|
|
426
439
|
|
|
427
440
|
instance = None
|
|
@@ -431,6 +444,9 @@ def run_kernel(kernel_name, kernel_string, problem_size, arguments,
|
|
|
431
444
|
if instance is None:
|
|
432
445
|
raise Exception("cannot create kernel instance, too many threads per block")
|
|
433
446
|
|
|
447
|
+
# see if the kernel arguments have correct type
|
|
448
|
+
util.check_argument_list(instance.name, instance.kernel_string, arguments)
|
|
449
|
+
|
|
434
450
|
#compile the kernel
|
|
435
451
|
func = dev.compile_kernel(instance, False)
|
|
436
452
|
if func is None:
|
|
@@ -462,3 +478,18 @@ def run_kernel(kernel_name, kernel_string, problem_size, arguments,
|
|
|
462
478
|
|
|
463
479
|
|
|
464
480
|
run_kernel.__doc__ = _run_kernel_docstring
|
|
481
|
+
|
|
482
|
+
def _check_user_input(kernel_name, kernel_string, arguments, block_size_names):
|
|
483
|
+
# see if the kernel arguments have correct type
|
|
484
|
+
if not callable(kernel_string):
|
|
485
|
+
if isinstance(kernel_string, list):
|
|
486
|
+
for file in kernel_string:
|
|
487
|
+
util.check_argument_list(kernel_name, util.get_kernel_string(file), arguments)
|
|
488
|
+
else:
|
|
489
|
+
util.check_argument_list(kernel_name, util.get_kernel_string(kernel_string), arguments)
|
|
490
|
+
else:
|
|
491
|
+
logging.debug("Checking of arguments list not supported yet for code generators.")
|
|
492
|
+
|
|
493
|
+
# check for types and length of block_size_names
|
|
494
|
+
util.check_block_size_names(block_size_names)
|
|
495
|
+
|
|
@@ -86,7 +86,7 @@ class OpenCLFunctions(object):
|
|
|
86
86
|
func = getattr(prg, kernel_name)
|
|
87
87
|
return func
|
|
88
88
|
|
|
89
|
-
def benchmark(self, func, gpu_args, threads, grid):
|
|
89
|
+
def benchmark(self, func, gpu_args, threads, grid, times):
|
|
90
90
|
"""runs the kernel and measures time repeatedly, returns average time
|
|
91
91
|
|
|
92
92
|
Runs the kernel and measures kernel execution time repeatedly, number of
|
|
@@ -112,18 +112,28 @@ class OpenCLFunctions(object):
|
|
|
112
112
|
of the NDRange.
|
|
113
113
|
:type grid: tuple(int, int)
|
|
114
114
|
|
|
115
|
-
:
|
|
115
|
+
:param times: Return the execution time of all iterations.
|
|
116
|
+
:type times: bool
|
|
117
|
+
|
|
118
|
+
:returns: All execution times, if times=True, or a robust average for the
|
|
119
|
+
kernel execution time.
|
|
116
120
|
:rtype: float
|
|
117
121
|
"""
|
|
118
122
|
global_size = (grid[0]*threads[0], grid[1]*threads[1], grid[2]*threads[2])
|
|
119
123
|
local_size = threads
|
|
120
|
-
|
|
124
|
+
time = []
|
|
121
125
|
for _ in range(self.iterations):
|
|
122
126
|
event = func(self.queue, global_size, local_size, *gpu_args)
|
|
123
127
|
event.wait()
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
time.append((event.profile.end - event.profile.start)*1e-6)
|
|
129
|
+
time = sorted(time)
|
|
130
|
+
if times:
|
|
131
|
+
return time
|
|
132
|
+
else:
|
|
133
|
+
if self.iterations > 4:
|
|
134
|
+
return numpy.mean(time[1:-1])
|
|
135
|
+
else:
|
|
136
|
+
return numpy.mean(time)
|
|
127
137
|
|
|
128
138
|
def run_kernel(self, func, gpu_args, threads, grid):
|
|
129
139
|
"""runs the OpenCL kernel passed as 'func'
|
|
@@ -163,7 +173,11 @@ class OpenCLFunctions(object):
|
|
|
163
173
|
|
|
164
174
|
"""
|
|
165
175
|
if isinstance(buffer, cl.Buffer):
|
|
166
|
-
|
|
176
|
+
try:
|
|
177
|
+
cl.enqueue_fill_buffer(self.queue, buffer, numpy.uint32(value), 0, size)
|
|
178
|
+
except AttributeError:
|
|
179
|
+
src=numpy.zeros(size, dtype='uint8')+numpy.uint8(value)
|
|
180
|
+
cl.enqueue_copy(self.queue, buffer, src)
|
|
167
181
|
|
|
168
182
|
def memcpy_dtoh(self, dest, src):
|
|
169
183
|
"""perform a device to host memory copy
|
|
@@ -176,3 +190,5 @@ class OpenCLFunctions(object):
|
|
|
176
190
|
"""
|
|
177
191
|
if isinstance(src, cl.Buffer):
|
|
178
192
|
cl.enqueue_copy(self.queue, dest, src)
|
|
193
|
+
|
|
194
|
+
units = {'time': 'ms'}
|
|
@@ -28,6 +28,8 @@ class SequentialRunner(object):
|
|
|
28
28
|
|
|
29
29
|
#detect language and create high-level device interface
|
|
30
30
|
self.dev = DeviceInterface(kernel_options.kernel_string, iterations=iterations, **device_options)
|
|
31
|
+
self.units = self.dev.units
|
|
32
|
+
self.quiet = device_options.quiet
|
|
31
33
|
|
|
32
34
|
#move data to the GPU
|
|
33
35
|
self.gpu_args = self.dev.ready_argument_list(kernel_options.arguments)
|
|
@@ -68,9 +70,10 @@ class SequentialRunner(object):
|
|
|
68
70
|
|
|
69
71
|
#print and append to results
|
|
70
72
|
params['time'] = time
|
|
71
|
-
output_string = get_config_string(params)
|
|
73
|
+
output_string = get_config_string(params, self.units)
|
|
72
74
|
logging.debug(output_string)
|
|
73
|
-
|
|
75
|
+
if not self.quiet:
|
|
76
|
+
print(output_string)
|
|
74
77
|
results.append(params)
|
|
75
78
|
|
|
76
79
|
return results, self.dev.get_environment()
|