kernel-tuner 0.1.2__tar.gz → 0.1.3__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.2 → kernel_tuner-0.1.3}/PKG-INFO +24 -54
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/README.rst +23 -53
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner/c.py +16 -5
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner/interface.py +5 -2
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner/util.py +31 -18
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner.egg-info/PKG-INFO +24 -54
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner.egg-info/SOURCES.txt +1 -0
- kernel_tuner-0.1.3/kernel_tuner.egg-info/requires.txt +1 -0
- kernel_tuner-0.1.3/requirements.txt +1 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/setup.py +6 -1
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/test/test_c_functions.py +6 -6
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/test/test_interface.py +2 -2
- kernel_tuner-0.1.2/requirements.txt +0 -7
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/LICENSE +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/MANIFEST.in +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner/__init__.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner/core.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner/cuda.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner/opencl.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner/runners/__init__.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner/runners/random_sample.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner/runners/sequential_brute_force.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner.egg-info/dependency_links.txt +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/kernel_tuner.egg-info/top_level.txt +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/setup.cfg +2 -2
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/test/test_cuda_functions.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/test/test_cuda_mocked.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/test/test_kernel_tuner.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/test/test_opencl_functions.py +0 -0
- {kernel_tuner-0.1.2 → kernel_tuner-0.1.3}/test/test_runners.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.3
|
|
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
|
|
@@ -44,41 +44,34 @@ Description: A simple CUDA/OpenCL kernel tuner in Python
|
|
|
44
44
|
Installation
|
|
45
45
|
------------
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
The easiest way to install the Kernel Tuner is using pip:
|
|
48
48
|
|
|
49
|
-
-
|
|
49
|
+
.. code-block:: bash
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
pip install kernel_tuner
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
- With a GitHub account: ``git clone git@github.com:benvanwerkhoven/kernel_tuner.git``
|
|
56
|
-
- Without GitHub account: ``git clone https://github.com/benvanwerkhoven/kernel_tuner.git``
|
|
57
|
-
|
|
58
|
-
- change into the top-level directory
|
|
53
|
+
But you can also install from the git repository. This way you also get the
|
|
54
|
+
examples and the tutorials:
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- install using
|
|
63
|
-
|
|
64
|
-
- ``pip install .``
|
|
56
|
+
.. code-block:: bash
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
- To tune CUDA kernels
|
|
58
|
+
git clone https://github.com/benvanwerkhoven/kernel_tuner.git
|
|
59
|
+
cd kernel_tuner
|
|
60
|
+
pip install -r requirements.txt
|
|
61
|
+
pip install .
|
|
62
|
+
|
|
63
|
+
To tune CUDA kernels:
|
|
73
64
|
|
|
74
|
-
-
|
|
75
|
-
- You can install PyCuda using ``pip install pycuda``
|
|
65
|
+
- First, make sure you have the `CUDA Toolkit <https://developer.nvidia.com/cuda-toolkit>`_ installed
|
|
66
|
+
- You can install PyCuda using ``pip install pycuda``
|
|
76
67
|
|
|
77
|
-
|
|
68
|
+
To tune OpenCL kernels:
|
|
78
69
|
|
|
79
|
-
-
|
|
70
|
+
- First, make sure you have an OpenCL compiler for your intended OpenCL platform
|
|
80
71
|
- You can install PyOpenCL using ``pip install pyopencl``
|
|
81
72
|
|
|
73
|
+
If you need more information about how to install the Kernel Tuner and all dependencies see the `installation guide <http://benvanwerkhoven.github.io/kernel_tuner/install.html>`__
|
|
74
|
+
|
|
82
75
|
Example usage
|
|
83
76
|
-------------
|
|
84
77
|
|
|
@@ -104,7 +97,7 @@ Description: A simple CUDA/OpenCL kernel tuner in Python
|
|
|
104
97
|
args = [c, a, b, n]
|
|
105
98
|
|
|
106
99
|
tune_params = dict()
|
|
107
|
-
tune_params["block_size_x"] = [
|
|
100
|
+
tune_params["block_size_x"] = [32, 64, 128, 256, 512]
|
|
108
101
|
|
|
109
102
|
tune_kernel("vector_add", kernel_string, size, args, tune_params)
|
|
110
103
|
|
|
@@ -136,7 +129,7 @@ Description: A simple CUDA/OpenCL kernel tuner in Python
|
|
|
136
129
|
Tuning host and kernel code
|
|
137
130
|
---------------------------
|
|
138
131
|
|
|
139
|
-
It is
|
|
132
|
+
It is possible to tune for combinations of tunable parameters in
|
|
140
133
|
both host and kernel code. This allows for a number of powerfull things,
|
|
141
134
|
such as tuning the number of streams for a kernel that uses CUDA Streams
|
|
142
135
|
or OpenCL Command Queues to overlap transfers between host and device
|
|
@@ -160,33 +153,10 @@ Description: A simple CUDA/OpenCL kernel tuner in Python
|
|
|
160
153
|
answer = [a+b, None, None] # the order matches the arguments (in args) to the kernel
|
|
161
154
|
tune_kernel("vector_add", kernel_string, size, args, tune_params, answer=answer)
|
|
162
155
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
The kernel tuner follows the Google Python style guide, with Sphinxdoc
|
|
167
|
-
docstrings for module public functions. If you want to contribute to the
|
|
168
|
-
project please fork it, create a branch including your addition, and
|
|
169
|
-
create a pull request.
|
|
170
|
-
|
|
171
|
-
The tests use relative imports and can be run directly after making
|
|
172
|
-
changes to the code. To run all tests use ``nosetests`` in the main
|
|
173
|
-
directory. To run the examples after code changes, you need to run
|
|
174
|
-
``pip install --upgrade .`` in the main directory. Documentation is
|
|
175
|
-
generated by typing ``make html`` in the doc directory, the contents of
|
|
176
|
-
``doc/build/html/`` should then be copied to ``sphinxdoc`` directory of
|
|
177
|
-
the ``gh-pages`` branch.
|
|
178
|
-
|
|
179
|
-
Before creating a pull request please ensure the following:
|
|
180
|
-
|
|
181
|
-
* You have written unit tests to test your additions and all unit tests pass
|
|
182
|
-
* The examples still work and produce the same (or better) results
|
|
183
|
-
* The code is compatible with both Python 2.7 and Python 3.5
|
|
184
|
-
* An entry about the change or addition is created in CHANGELOG.md
|
|
185
|
-
|
|
186
|
-
Contributing authors so far:
|
|
156
|
+
Contributing
|
|
157
|
+
------------
|
|
187
158
|
|
|
188
|
-
|
|
189
|
-
* Berend Weel
|
|
159
|
+
Please see the `Contributions Guide <http://benvanwerkhoven.github.io/kernel_tuner/contributing.html>`__.
|
|
190
160
|
|
|
191
161
|
Citation
|
|
192
162
|
--------
|
|
@@ -36,41 +36,34 @@ The full documentation is available
|
|
|
36
36
|
Installation
|
|
37
37
|
------------
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
The easiest way to install the Kernel Tuner is using pip:
|
|
40
40
|
|
|
41
|
-
-
|
|
41
|
+
.. code-block:: bash
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
pip install kernel_tuner
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
- With a GitHub account: ``git clone git@github.com:benvanwerkhoven/kernel_tuner.git``
|
|
48
|
-
- Without GitHub account: ``git clone https://github.com/benvanwerkhoven/kernel_tuner.git``
|
|
49
|
-
|
|
50
|
-
- change into the top-level directory
|
|
45
|
+
But you can also install from the git repository. This way you also get the
|
|
46
|
+
examples and the tutorials:
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
- install using
|
|
55
|
-
|
|
56
|
-
- ``pip install .``
|
|
48
|
+
.. code-block:: bash
|
|
57
49
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- To tune CUDA kernels
|
|
50
|
+
git clone https://github.com/benvanwerkhoven/kernel_tuner.git
|
|
51
|
+
cd kernel_tuner
|
|
52
|
+
pip install -r requirements.txt
|
|
53
|
+
pip install .
|
|
54
|
+
|
|
55
|
+
To tune CUDA kernels:
|
|
65
56
|
|
|
66
|
-
-
|
|
67
|
-
- You can install PyCuda using ``pip install pycuda``
|
|
57
|
+
- First, make sure you have the `CUDA Toolkit <https://developer.nvidia.com/cuda-toolkit>`_ installed
|
|
58
|
+
- You can install PyCuda using ``pip install pycuda``
|
|
68
59
|
|
|
69
|
-
|
|
60
|
+
To tune OpenCL kernels:
|
|
70
61
|
|
|
71
|
-
-
|
|
62
|
+
- First, make sure you have an OpenCL compiler for your intended OpenCL platform
|
|
72
63
|
- You can install PyOpenCL using ``pip install pyopencl``
|
|
73
64
|
|
|
65
|
+
If you need more information about how to install the Kernel Tuner and all dependencies see the `installation guide <http://benvanwerkhoven.github.io/kernel_tuner/install.html>`__
|
|
66
|
+
|
|
74
67
|
Example usage
|
|
75
68
|
-------------
|
|
76
69
|
|
|
@@ -96,7 +89,7 @@ The following shows a simple example for tuning a CUDA kernel:
|
|
|
96
89
|
args = [c, a, b, n]
|
|
97
90
|
|
|
98
91
|
tune_params = dict()
|
|
99
|
-
tune_params["block_size_x"] = [
|
|
92
|
+
tune_params["block_size_x"] = [32, 64, 128, 256, 512]
|
|
100
93
|
|
|
101
94
|
tune_kernel("vector_add", kernel_string, size, args, tune_params)
|
|
102
95
|
|
|
@@ -128,7 +121,7 @@ kernels and the scripts to tune them.
|
|
|
128
121
|
Tuning host and kernel code
|
|
129
122
|
---------------------------
|
|
130
123
|
|
|
131
|
-
It is
|
|
124
|
+
It is possible to tune for combinations of tunable parameters in
|
|
132
125
|
both host and kernel code. This allows for a number of powerfull things,
|
|
133
126
|
such as tuning the number of streams for a kernel that uses CUDA Streams
|
|
134
127
|
or OpenCL Command Queues to overlap transfers between host and device
|
|
@@ -152,33 +145,10 @@ expected output of the kernel. Input arguments are replaced with None.
|
|
|
152
145
|
answer = [a+b, None, None] # the order matches the arguments (in args) to the kernel
|
|
153
146
|
tune_kernel("vector_add", kernel_string, size, args, tune_params, answer=answer)
|
|
154
147
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
The kernel tuner follows the Google Python style guide, with Sphinxdoc
|
|
159
|
-
docstrings for module public functions. If you want to contribute to the
|
|
160
|
-
project please fork it, create a branch including your addition, and
|
|
161
|
-
create a pull request.
|
|
162
|
-
|
|
163
|
-
The tests use relative imports and can be run directly after making
|
|
164
|
-
changes to the code. To run all tests use ``nosetests`` in the main
|
|
165
|
-
directory. To run the examples after code changes, you need to run
|
|
166
|
-
``pip install --upgrade .`` in the main directory. Documentation is
|
|
167
|
-
generated by typing ``make html`` in the doc directory, the contents of
|
|
168
|
-
``doc/build/html/`` should then be copied to ``sphinxdoc`` directory of
|
|
169
|
-
the ``gh-pages`` branch.
|
|
170
|
-
|
|
171
|
-
Before creating a pull request please ensure the following:
|
|
172
|
-
|
|
173
|
-
* You have written unit tests to test your additions and all unit tests pass
|
|
174
|
-
* The examples still work and produce the same (or better) results
|
|
175
|
-
* The code is compatible with both Python 2.7 and Python 3.5
|
|
176
|
-
* An entry about the change or addition is created in CHANGELOG.md
|
|
177
|
-
|
|
178
|
-
Contributing authors so far:
|
|
148
|
+
Contributing
|
|
149
|
+
------------
|
|
179
150
|
|
|
180
|
-
|
|
181
|
-
* Berend Weel
|
|
151
|
+
Please see the `Contributions Guide <http://benvanwerkhoven.github.io/kernel_tuner/contributing.html>`__.
|
|
182
152
|
|
|
183
153
|
Citation
|
|
184
154
|
--------
|
|
@@ -61,14 +61,22 @@ class CFunctions(object):
|
|
|
61
61
|
self.arg_mapping[str(ctype_args[-1])] = arg.shape
|
|
62
62
|
elif numpy.isscalar(arg):
|
|
63
63
|
if hasattr(arg, 'dtype'):
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
np_to_c_type_map = { numpy.int32: C.c_int32,
|
|
65
|
+
numpy.int64: C.c_int64,
|
|
66
|
+
numpy.float32: C.c_float,
|
|
67
|
+
numpy.float64: C.c_double }
|
|
68
|
+
if type(arg) in np_to_c_type_map:
|
|
69
|
+
ctype_args.append(np_to_c_type_map[type(arg)](arg))
|
|
68
70
|
else:
|
|
69
71
|
raise TypeError("Argument is scalar with a dtype, but does not start with int or float")
|
|
70
72
|
else:
|
|
71
|
-
|
|
73
|
+
if isinstance(arg, int):
|
|
74
|
+
ctype_args.append(C.c_int(arg))
|
|
75
|
+
elif isinstance(arg, float):
|
|
76
|
+
ctype_args.append(C.c_float(arg))
|
|
77
|
+
else:
|
|
78
|
+
raise TypeError("Argument is scalar without dtype, and is not instance of int or float")
|
|
79
|
+
self.arg_mapping[str(ctype_args[-1])] = ()
|
|
72
80
|
else:
|
|
73
81
|
raise TypeError("Argument is not a numpy.ndarray and is not a scalar %s" % type(arg))
|
|
74
82
|
|
|
@@ -196,6 +204,9 @@ class CFunctions(object):
|
|
|
196
204
|
:returns: A robust average of values returned by the C function.
|
|
197
205
|
:rtype: float
|
|
198
206
|
"""
|
|
207
|
+
logging.debug("run_kernel")
|
|
208
|
+
logging.debug("arguments=" + str([str(arg) for arg in c_args]))
|
|
209
|
+
|
|
199
210
|
time = func(*c_args)
|
|
200
211
|
|
|
201
212
|
#I would like to replace the following with actually capturing
|
|
@@ -338,8 +338,11 @@ def run_kernel(kernel_name, original_kernel, problem_size, arguments,
|
|
|
338
338
|
#copy data in GPU memory back to the host
|
|
339
339
|
results = []
|
|
340
340
|
for i, arg in enumerate(arguments):
|
|
341
|
-
|
|
342
|
-
|
|
341
|
+
if numpy.isscalar(arg):
|
|
342
|
+
results.append(arg)
|
|
343
|
+
else:
|
|
344
|
+
results.append(numpy.zeros_like(arg))
|
|
345
|
+
dev.memcpy_dtoh(results[-1], gpu_args[i])
|
|
343
346
|
return results
|
|
344
347
|
|
|
345
348
|
|
|
@@ -5,18 +5,27 @@ import os
|
|
|
5
5
|
import errno
|
|
6
6
|
|
|
7
7
|
def get_instance_string(params):
|
|
8
|
+
""" combine the parameters to a string mostly used for debug output
|
|
9
|
+
use of OrderedDict is advised
|
|
10
|
+
"""
|
|
8
11
|
return "_".join([str(i) for i in params.values()])
|
|
9
12
|
|
|
10
13
|
def get_config_string(params):
|
|
14
|
+
""" return a compact string representation of a dictionary """
|
|
11
15
|
return "".join([k + "=" + str(v) + ", " for k,v in params.items()])
|
|
12
16
|
|
|
13
17
|
def get_kernel_string(original_kernel):
|
|
18
|
+
""" retrieves kernel string from a file if the string passed looks like filename
|
|
19
|
+
if the string does look like a filename, but the file does not exist, it
|
|
20
|
+
is assumed that the string is not a filename after all.
|
|
21
|
+
"""
|
|
14
22
|
kernel_string = original_kernel
|
|
15
23
|
if looks_like_a_filename(original_kernel):
|
|
16
24
|
kernel_string = read_file(original_kernel) or original_kernel
|
|
17
25
|
return kernel_string
|
|
18
26
|
|
|
19
27
|
def delete_temp_file(filename):
|
|
28
|
+
""" delete a temporary file, don't complain if is no longer exists """
|
|
20
29
|
try:
|
|
21
30
|
os.remove(filename)
|
|
22
31
|
except OSError as e:
|
|
@@ -24,6 +33,7 @@ def delete_temp_file(filename):
|
|
|
24
33
|
raise e
|
|
25
34
|
|
|
26
35
|
def get_temp_filename():
|
|
36
|
+
""" return a string in the form of temp_X, where X is a large integer """
|
|
27
37
|
random_large_int = numpy.random.randint(low=100, high=100000000000)
|
|
28
38
|
return 'temp_' + str(random_large_int)
|
|
29
39
|
|
|
@@ -33,7 +43,7 @@ def looks_like_a_filename(original_kernel):
|
|
|
33
43
|
if isinstance(original_kernel, str):
|
|
34
44
|
result = True
|
|
35
45
|
#test if not too long
|
|
36
|
-
if len(original_kernel) >
|
|
46
|
+
if len(original_kernel) > 250:
|
|
37
47
|
result = False
|
|
38
48
|
#test if not contains special characters
|
|
39
49
|
for c in "();{}\\":
|
|
@@ -48,13 +58,15 @@ def looks_like_a_filename(original_kernel):
|
|
|
48
58
|
return result
|
|
49
59
|
|
|
50
60
|
def read_file(filename):
|
|
61
|
+
""" return the contents of the file named filename or None if file not found """
|
|
51
62
|
if os.path.isfile(filename):
|
|
52
63
|
with open(filename, 'r') as f:
|
|
53
64
|
return f.read()
|
|
54
65
|
|
|
55
66
|
def write_file(filename, string):
|
|
56
|
-
|
|
67
|
+
""" dump the contents of string to a file called filename """
|
|
57
68
|
import sys
|
|
69
|
+
#ugly fix, hopefully we can find a better one
|
|
58
70
|
if sys.version_info[0] >= 3:
|
|
59
71
|
with open(filename, 'w', encoding="utf-8") as f:
|
|
60
72
|
f.write(string)
|
|
@@ -82,8 +94,7 @@ def get_problem_size(problem_size, params):
|
|
|
82
94
|
if isinstance(problem_size, (str,int,numpy.integer)):
|
|
83
95
|
problem_size = (problem_size, )
|
|
84
96
|
current_problem_size = [1, 1, 1]
|
|
85
|
-
for i in
|
|
86
|
-
s = problem_size[i]
|
|
97
|
+
for i, s in enumerate(problem_size):
|
|
87
98
|
if isinstance(s, str):
|
|
88
99
|
current_problem_size[i] = int(eval(replace_param_occurrences(s,params)))
|
|
89
100
|
elif isinstance(s, int) or isinstance(s, numpy.integer):
|
|
@@ -177,6 +188,7 @@ def replace_param_occurrences(string, params):
|
|
|
177
188
|
return string
|
|
178
189
|
|
|
179
190
|
def check_restrictions(restrictions, element, keys, verbose):
|
|
191
|
+
""" check whether a specific instance meets the search space restrictions """
|
|
180
192
|
params = dict(zip(keys, element))
|
|
181
193
|
for restrict in restrictions:
|
|
182
194
|
if not eval(replace_param_occurrences(restrict, params)):
|
|
@@ -187,25 +199,26 @@ def check_restrictions(restrictions, element, keys, verbose):
|
|
|
187
199
|
return True
|
|
188
200
|
|
|
189
201
|
def check_argument_list(args):
|
|
202
|
+
""" raise an exception if a kernel argument is of unsupported type """
|
|
190
203
|
for (i, arg) in enumerate(args):
|
|
191
204
|
if not isinstance(arg, (numpy.ndarray, numpy.generic)):
|
|
192
205
|
raise TypeError("Argument at position " + str(i) + " of type: " + str(type(arg)) + " should be of type numpy.ndarray or numpy scalar")
|
|
193
206
|
|
|
194
207
|
def setup_block_and_grid(dev, problem_size, grid_div_z, grid_div_y, grid_div_x, params, instance_string, verbose):
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
208
|
+
"""compute problem size, thread block and grid dimensions for this kernel"""
|
|
209
|
+
threads = get_thread_block_dimensions(params)
|
|
210
|
+
if numpy.prod(threads) > dev.max_threads:
|
|
211
|
+
if verbose:
|
|
212
|
+
print("skipping config", instance_string, "reason: too many threads per block")
|
|
213
|
+
return None, None
|
|
214
|
+
current_problem_size = get_problem_size(problem_size, params)
|
|
215
|
+
grid = get_grid_dimensions(current_problem_size, params, grid_div_z, grid_div_y, grid_div_x)
|
|
216
|
+
return threads, grid
|
|
204
217
|
|
|
205
218
|
def setup_kernel_strings(kernel_name, original_kernel, params, grid, instance_string):
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
219
|
+
"""create configuration specific kernel string"""
|
|
220
|
+
kernel_string = prepare_kernel_string(original_kernel, params, grid)
|
|
221
|
+
name = kernel_name + "_" + instance_string
|
|
222
|
+
kernel_string = kernel_string.replace(kernel_name, name)
|
|
223
|
+
return name, kernel_string
|
|
211
224
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.1
|
|
2
2
|
Name: kernel-tuner
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
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
|
|
@@ -44,41 +44,34 @@ Description: A simple CUDA/OpenCL kernel tuner in Python
|
|
|
44
44
|
Installation
|
|
45
45
|
------------
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
The easiest way to install the Kernel Tuner is using pip:
|
|
48
48
|
|
|
49
|
-
-
|
|
49
|
+
.. code-block:: bash
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
pip install kernel_tuner
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
- With a GitHub account: ``git clone git@github.com:benvanwerkhoven/kernel_tuner.git``
|
|
56
|
-
- Without GitHub account: ``git clone https://github.com/benvanwerkhoven/kernel_tuner.git``
|
|
57
|
-
|
|
58
|
-
- change into the top-level directory
|
|
53
|
+
But you can also install from the git repository. This way you also get the
|
|
54
|
+
examples and the tutorials:
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- install using
|
|
63
|
-
|
|
64
|
-
- ``pip install .``
|
|
56
|
+
.. code-block:: bash
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
- To tune CUDA kernels
|
|
58
|
+
git clone https://github.com/benvanwerkhoven/kernel_tuner.git
|
|
59
|
+
cd kernel_tuner
|
|
60
|
+
pip install -r requirements.txt
|
|
61
|
+
pip install .
|
|
62
|
+
|
|
63
|
+
To tune CUDA kernels:
|
|
73
64
|
|
|
74
|
-
-
|
|
75
|
-
- You can install PyCuda using ``pip install pycuda``
|
|
65
|
+
- First, make sure you have the `CUDA Toolkit <https://developer.nvidia.com/cuda-toolkit>`_ installed
|
|
66
|
+
- You can install PyCuda using ``pip install pycuda``
|
|
76
67
|
|
|
77
|
-
|
|
68
|
+
To tune OpenCL kernels:
|
|
78
69
|
|
|
79
|
-
-
|
|
70
|
+
- First, make sure you have an OpenCL compiler for your intended OpenCL platform
|
|
80
71
|
- You can install PyOpenCL using ``pip install pyopencl``
|
|
81
72
|
|
|
73
|
+
If you need more information about how to install the Kernel Tuner and all dependencies see the `installation guide <http://benvanwerkhoven.github.io/kernel_tuner/install.html>`__
|
|
74
|
+
|
|
82
75
|
Example usage
|
|
83
76
|
-------------
|
|
84
77
|
|
|
@@ -104,7 +97,7 @@ Description: A simple CUDA/OpenCL kernel tuner in Python
|
|
|
104
97
|
args = [c, a, b, n]
|
|
105
98
|
|
|
106
99
|
tune_params = dict()
|
|
107
|
-
tune_params["block_size_x"] = [
|
|
100
|
+
tune_params["block_size_x"] = [32, 64, 128, 256, 512]
|
|
108
101
|
|
|
109
102
|
tune_kernel("vector_add", kernel_string, size, args, tune_params)
|
|
110
103
|
|
|
@@ -136,7 +129,7 @@ Description: A simple CUDA/OpenCL kernel tuner in Python
|
|
|
136
129
|
Tuning host and kernel code
|
|
137
130
|
---------------------------
|
|
138
131
|
|
|
139
|
-
It is
|
|
132
|
+
It is possible to tune for combinations of tunable parameters in
|
|
140
133
|
both host and kernel code. This allows for a number of powerfull things,
|
|
141
134
|
such as tuning the number of streams for a kernel that uses CUDA Streams
|
|
142
135
|
or OpenCL Command Queues to overlap transfers between host and device
|
|
@@ -160,33 +153,10 @@ Description: A simple CUDA/OpenCL kernel tuner in Python
|
|
|
160
153
|
answer = [a+b, None, None] # the order matches the arguments (in args) to the kernel
|
|
161
154
|
tune_kernel("vector_add", kernel_string, size, args, tune_params, answer=answer)
|
|
162
155
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
The kernel tuner follows the Google Python style guide, with Sphinxdoc
|
|
167
|
-
docstrings for module public functions. If you want to contribute to the
|
|
168
|
-
project please fork it, create a branch including your addition, and
|
|
169
|
-
create a pull request.
|
|
170
|
-
|
|
171
|
-
The tests use relative imports and can be run directly after making
|
|
172
|
-
changes to the code. To run all tests use ``nosetests`` in the main
|
|
173
|
-
directory. To run the examples after code changes, you need to run
|
|
174
|
-
``pip install --upgrade .`` in the main directory. Documentation is
|
|
175
|
-
generated by typing ``make html`` in the doc directory, the contents of
|
|
176
|
-
``doc/build/html/`` should then be copied to ``sphinxdoc`` directory of
|
|
177
|
-
the ``gh-pages`` branch.
|
|
178
|
-
|
|
179
|
-
Before creating a pull request please ensure the following:
|
|
180
|
-
|
|
181
|
-
* You have written unit tests to test your additions and all unit tests pass
|
|
182
|
-
* The examples still work and produce the same (or better) results
|
|
183
|
-
* The code is compatible with both Python 2.7 and Python 3.5
|
|
184
|
-
* An entry about the change or addition is created in CHANGELOG.md
|
|
185
|
-
|
|
186
|
-
Contributing authors so far:
|
|
156
|
+
Contributing
|
|
157
|
+
------------
|
|
187
158
|
|
|
188
|
-
|
|
189
|
-
* Berend Weel
|
|
159
|
+
Please see the `Contributions Guide <http://benvanwerkhoven.github.io/kernel_tuner/contributing.html>`__.
|
|
190
160
|
|
|
191
161
|
Citation
|
|
192
162
|
--------
|
|
@@ -14,6 +14,7 @@ kernel_tuner/util.py
|
|
|
14
14
|
kernel_tuner.egg-info/PKG-INFO
|
|
15
15
|
kernel_tuner.egg-info/SOURCES.txt
|
|
16
16
|
kernel_tuner.egg-info/dependency_links.txt
|
|
17
|
+
kernel_tuner.egg-info/requires.txt
|
|
17
18
|
kernel_tuner.egg-info/top_level.txt
|
|
18
19
|
kernel_tuner/runners/__init__.py
|
|
19
20
|
kernel_tuner/runners/random_sample.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
numpy>=1.7.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
numpy>=1.7.1
|
|
@@ -8,9 +8,13 @@ def readme():
|
|
|
8
8
|
with open('README.rst') as f:
|
|
9
9
|
return f.read()
|
|
10
10
|
|
|
11
|
+
def required():
|
|
12
|
+
with open('requirements.txt') as f:
|
|
13
|
+
return f.read().splitlines()
|
|
14
|
+
|
|
11
15
|
setup(
|
|
12
16
|
name = "kernel_tuner",
|
|
13
|
-
version = "0.1.
|
|
17
|
+
version = "0.1.3",
|
|
14
18
|
author = "Ben van Werkhoven",
|
|
15
19
|
author_email = "b.vanwerkhoven@esciencecenter.nl",
|
|
16
20
|
description = ("A simple CUDA/OpenCL kernel tuner in Python"),
|
|
@@ -19,6 +23,7 @@ setup(
|
|
|
19
23
|
url = "http://benvanwerkhoven.github.io/kernel_tuner/",
|
|
20
24
|
packages=['kernel_tuner', 'kernel_tuner.runners'],
|
|
21
25
|
long_description=readme(),
|
|
26
|
+
install_requires=required(),
|
|
22
27
|
classifiers=[
|
|
23
28
|
'Environment :: Console',
|
|
24
29
|
'Intended Audience :: Developers',
|
|
@@ -48,14 +48,14 @@ def test_ready_argument_list2():
|
|
|
48
48
|
output_arg1 = numpy.ctypeslib.as_array(output[0], shape=arg1.shape)
|
|
49
49
|
|
|
50
50
|
assert output_arg1.dtype == 'float32'
|
|
51
|
-
assert isinstance(output[1],
|
|
52
|
-
assert isinstance(output[2],
|
|
53
|
-
assert isinstance(output[3],
|
|
51
|
+
assert isinstance(output[1], C.c_int)
|
|
52
|
+
assert isinstance(output[2], C.c_float)
|
|
53
|
+
assert isinstance(output[3], C.c_int)
|
|
54
54
|
|
|
55
55
|
assert all(output_arg1 == arg1)
|
|
56
|
-
assert output[1] == arg2
|
|
57
|
-
assert output[2] == arg3
|
|
58
|
-
assert output[3] == arg4
|
|
56
|
+
assert output[1].value == arg2
|
|
57
|
+
assert output[2].value == arg3
|
|
58
|
+
assert output[3].value == arg4
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
def test_ready_argument_list3():
|
|
@@ -96,11 +96,11 @@ def test_run_kernel(dev_interface):
|
|
|
96
96
|
args = [n]
|
|
97
97
|
tune_params = dict()
|
|
98
98
|
tune_params["block_size_x"] = 128
|
|
99
|
-
run_kernel("fake_kernel", kernel_string, problem_size, args, tune_params)
|
|
99
|
+
answer = run_kernel("fake_kernel", kernel_string, problem_size, args, tune_params)
|
|
100
100
|
|
|
101
101
|
assert dev.compile.call_count == 1
|
|
102
102
|
dev.run_kernel.assert_called_once_with('compile', 'ready_argument_list', (128, 1, 1), (10, 1, 1))
|
|
103
|
-
|
|
103
|
+
assert answer[0] == n
|
|
104
104
|
|
|
105
105
|
@patch('kernel_tuner.core.CudaFunctions')
|
|
106
106
|
def test_check_kernel_correctness(dev_interface):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|