kernel-tuner 0.1.9__tar.gz → 0.3.0__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.9 → kernel_tuner-0.3.0}/PKG-INFO +50 -25
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/README.rst +39 -21
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/c.py +88 -56
- kernel_tuner-0.3.0/kernel_tuner/core.py +497 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/cuda.py +136 -37
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/interface.py +191 -119
- kernel_tuner-0.3.0/kernel_tuner/nvml.py +124 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/opencl.py +20 -16
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/runners/sequential.py +31 -8
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/strategies/basinhopping.py +5 -4
- kernel_tuner-0.3.0/kernel_tuner/strategies/bayes_opt.py +81 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/strategies/diff_evo.py +11 -28
- kernel_tuner-0.3.0/kernel_tuner/strategies/firefly_algorithm.py +115 -0
- kernel_tuner-0.3.0/kernel_tuner/strategies/genetic_algorithm.py +210 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/strategies/minimize.py +23 -27
- kernel_tuner-0.3.0/kernel_tuner/strategies/pso.py +112 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/strategies/random_sample.py +8 -2
- kernel_tuner-0.3.0/kernel_tuner/strategies/simulated_annealing.py +116 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/util.py +191 -96
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner.egg-info/PKG-INFO +50 -25
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner.egg-info/SOURCES.txt +7 -2
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner.egg-info/requires.txt +3 -1
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/setup.py +13 -7
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/test/test_c_functions.py +49 -12
- kernel_tuner-0.3.0/test/test_core.py +176 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/test/test_cuda_functions.py +4 -10
- kernel_tuner-0.3.0/test/test_cuda_mocked.py +136 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/test/test_interface.py +6 -30
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/test/test_opencl_functions.py +3 -8
- kernel_tuner-0.3.0/test/test_runners.py +96 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/test/test_util_functions.py +123 -87
- kernel_tuner-0.1.9/kernel_tuner/core.py +0 -306
- kernel_tuner-0.1.9/kernel_tuner/runners/noodles.py +0 -122
- kernel_tuner-0.1.9/test/test_cuda_mocked.py +0 -95
- kernel_tuner-0.1.9/test/test_device_interface.py +0 -50
- kernel_tuner-0.1.9/test/test_runners.py +0 -169
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/LICENSE +0 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/MANIFEST.in +0 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/__init__.py +0 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/runners/__init__.py +0 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/strategies/__init__.py +0 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/strategies/brute_force.py +0 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner/wrappers.py +0 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner.egg-info/dependency_links.txt +0 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/kernel_tuner.egg-info/top_level.txt +0 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/setup.cfg +0 -0
- {kernel_tuner-0.1.9 → kernel_tuner-0.3.0}/test/test_minimize.py +0 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
Metadata-Version:
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: kernel_tuner
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: An easy to use CUDA/OpenCL kernel tuner in Python
|
|
5
5
|
Home-page: http://benvanwerkhoven.github.io/kernel_tuner/
|
|
6
6
|
Author: Ben van Werkhoven
|
|
7
7
|
Author-email: b.vanwerkhoven@esciencecenter.nl
|
|
8
8
|
License: Apache 2.0
|
|
9
|
-
Description: Kernel Tuner
|
|
10
|
-
|
|
9
|
+
Description: Kernel Tuner
|
|
10
|
+
============
|
|
11
11
|
|
|
12
|
-
|Build Status| |
|
|
12
|
+
|Build Status| |CodeCov Badge| |PyPi Badge|
|
|
13
13
|
|
|
14
14
|
Kernel Tuner simplifies the software development of optimized and auto-tuned GPU programs, by enabling Python-based unit testing of GPU code and making it easy to develop scripts for auto-tuning GPU kernels. This also means no extensive changes and no new dependencies are required in the kernel code. The kernels can still be compiled and used as normal from any host programming language.
|
|
15
15
|
|
|
@@ -99,6 +99,23 @@ Description: Kernel Tuner: A Search-Optimizing GPU Code Auto-Tuner
|
|
|
99
99
|
and in the `Kernel Tuner
|
|
100
100
|
documentation pages <http://benvanwerkhoven.github.io/kernel_tuner/index.html>`__.
|
|
101
101
|
|
|
102
|
+
Search strategies for tuning
|
|
103
|
+
----------------------------
|
|
104
|
+
|
|
105
|
+
Kernel Tuner supports many optimization algorithms to accelerate the auto-tuning process. Currently
|
|
106
|
+
implemented search algorithms are: Brute Force (default), Nelder-Mead, Powell, CG, BFGS, L-BFGS-B, TNC,
|
|
107
|
+
COBYLA, SLSQP, Random Search, Basinhopping, Differential Evolution, a Genetic Algorithm, Particle Swarm
|
|
108
|
+
Optimization, the Firefly Algorithm, and Simulated Annealing.
|
|
109
|
+
|
|
110
|
+
.. image:: doc/gemm-amd-summary.png
|
|
111
|
+
:width: 100%
|
|
112
|
+
:align: center
|
|
113
|
+
|
|
114
|
+
Using a search strategy is easy, you only need to specify to ``tune_kernel`` which strategy and method
|
|
115
|
+
you would like to use, for example ``strategy="genetic_algorithm"`` or ``strategy="basinhopping"``.
|
|
116
|
+
For a full overview of the supported search strategies and methods please see the `user
|
|
117
|
+
api documentation <http://benvanwerkhoven.github.io/kernel_tuner/user-api.html>`__.
|
|
118
|
+
|
|
102
119
|
Tuning host and kernel code
|
|
103
120
|
---------------------------
|
|
104
121
|
|
|
@@ -113,12 +130,6 @@ Description: Kernel Tuner: A Search-Optimizing GPU Code Auto-Tuner
|
|
|
113
130
|
`documentation <http://benvanwerkhoven.github.io/kernel_tuner/hostcode.html>`__
|
|
114
131
|
for a detailed explanation of the kernel tuner Python script.
|
|
115
132
|
|
|
116
|
-
Search strategies for tuning
|
|
117
|
-
----------------------------
|
|
118
|
-
|
|
119
|
-
Kernel Tuner supports several strategies: brute_force (default), random_sample, minimize, basinhopping, and diff_evo (differential
|
|
120
|
-
evolution). Using different strategies is easy, you only need to specify to ``tune_kernel`` which strategy you would like to use, for example: ``strategy="basinhopping", method="TNC"``. For a full overview of the supported search strategies and methods please see the
|
|
121
|
-
`user api <http://benvanwerkhoven.github.io/kernel_tuner/user-api.html>`__.
|
|
122
133
|
|
|
123
134
|
Correctness verification
|
|
124
135
|
------------------------
|
|
@@ -140,33 +151,40 @@ Description: Kernel Tuner: A Search-Optimizing GPU Code Auto-Tuner
|
|
|
140
151
|
|
|
141
152
|
Citation
|
|
142
153
|
--------
|
|
143
|
-
|
|
154
|
+
The paper about `Kernel Tuner is published (Open Access) <https://www.sciencedirect.com/science/article/pii/S0167739X18313359>`__, please cite
|
|
155
|
+
Kernel Tuner as follows:
|
|
144
156
|
|
|
145
157
|
.. code:: latex
|
|
146
158
|
|
|
147
|
-
@
|
|
148
|
-
author
|
|
149
|
-
title
|
|
150
|
-
|
|
159
|
+
@article{kerneltuner,
|
|
160
|
+
author = {Ben van Werkhoven},
|
|
161
|
+
title = {Kernel Tuner: A search-optimizing GPU code auto-tuner},
|
|
162
|
+
journal = {Future Generation Computer Systems},
|
|
163
|
+
year = {2019},
|
|
164
|
+
volume = {90},
|
|
165
|
+
pages = {347-358},
|
|
166
|
+
doi = {https://doi.org/10.1016/j.future.2018.08.004},
|
|
151
167
|
}
|
|
152
168
|
|
|
153
169
|
Related work
|
|
154
170
|
------------
|
|
155
171
|
|
|
156
172
|
You may also like `CLTune <https://github.com/CNugteren/CLTune>`__ by
|
|
157
|
-
Cedric Nugteren. CLTune is a C++ library for kernel tuning
|
|
158
|
-
various advanced features like machine learning to optimize the time
|
|
159
|
-
spent on tuning kernels.
|
|
173
|
+
Cedric Nugteren. CLTune is a C++ library for kernel tuning.
|
|
160
174
|
|
|
161
175
|
.. |Build Status| image:: https://api.travis-ci.org/benvanwerkhoven/kernel_tuner.svg?branch=master
|
|
162
176
|
:target: https://travis-ci.org/benvanwerkhoven/kernel_tuner
|
|
163
|
-
.. |
|
|
164
|
-
:target: https://
|
|
165
|
-
.. |Codacy Badge2| image:: https://api.codacy.com/project/badge/coverage/016dc85044ab4d57b777449d93275608
|
|
166
|
-
:target: https://www.codacy.com/app/b-vanwerkhoven/kernel_tuner
|
|
177
|
+
.. |CodeCov Badge| image:: https://codecov.io/gh/benvanwerkhoven/kernel_tuner/branch/master/graph/badge.svg
|
|
178
|
+
:target: https://codecov.io/gh/benvanwerkhoven/kernel_tuner
|
|
167
179
|
.. |PyPi Badge| image:: https://img.shields.io/pypi/v/kernel_tuner.svg?colorB=blue
|
|
168
180
|
:target: https://pypi.python.org/pypi/kernel_tuner/
|
|
169
181
|
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
170
188
|
Keywords: auto-tuning gpu computing pycuda cuda pyopencl opencl
|
|
171
189
|
Platform: UNKNOWN
|
|
172
190
|
Classifier: Environment :: Console
|
|
@@ -176,9 +194,16 @@ Classifier: Intended Audience :: Education
|
|
|
176
194
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
177
195
|
Classifier: Natural Language :: English
|
|
178
196
|
Classifier: Operating System :: POSIX :: Linux
|
|
179
|
-
Classifier: Programming Language :: Python :: 2.7
|
|
180
197
|
Classifier: Programming Language :: Python :: 3.5
|
|
198
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
199
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
181
200
|
Classifier: Topic :: Scientific/Engineering
|
|
182
201
|
Classifier: Topic :: Software Development
|
|
183
202
|
Classifier: Topic :: System :: Distributed Computing
|
|
184
203
|
Classifier: Development Status :: 4 - Beta
|
|
204
|
+
Provides-Extra: dev
|
|
205
|
+
Provides-Extra: doc
|
|
206
|
+
Provides-Extra: cuda_opencl
|
|
207
|
+
Provides-Extra: tutorial
|
|
208
|
+
Provides-Extra: cuda
|
|
209
|
+
Provides-Extra: opencl
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Kernel Tuner
|
|
2
|
-
|
|
1
|
+
Kernel Tuner
|
|
2
|
+
============
|
|
3
3
|
|
|
4
|
-
|Build Status| |
|
|
4
|
+
|Build Status| |CodeCov Badge| |PyPi Badge|
|
|
5
5
|
|
|
6
6
|
Kernel Tuner simplifies the software development of optimized and auto-tuned GPU programs, by enabling Python-based unit testing of GPU code and making it easy to develop scripts for auto-tuning GPU kernels. This also means no extensive changes and no new dependencies are required in the kernel code. The kernels can still be compiled and used as normal from any host programming language.
|
|
7
7
|
|
|
@@ -91,6 +91,23 @@ You can find many - more extensive - example codes, in the
|
|
|
91
91
|
and in the `Kernel Tuner
|
|
92
92
|
documentation pages <http://benvanwerkhoven.github.io/kernel_tuner/index.html>`__.
|
|
93
93
|
|
|
94
|
+
Search strategies for tuning
|
|
95
|
+
----------------------------
|
|
96
|
+
|
|
97
|
+
Kernel Tuner supports many optimization algorithms to accelerate the auto-tuning process. Currently
|
|
98
|
+
implemented search algorithms are: Brute Force (default), Nelder-Mead, Powell, CG, BFGS, L-BFGS-B, TNC,
|
|
99
|
+
COBYLA, SLSQP, Random Search, Basinhopping, Differential Evolution, a Genetic Algorithm, Particle Swarm
|
|
100
|
+
Optimization, the Firefly Algorithm, and Simulated Annealing.
|
|
101
|
+
|
|
102
|
+
.. image:: doc/gemm-amd-summary.png
|
|
103
|
+
:width: 100%
|
|
104
|
+
:align: center
|
|
105
|
+
|
|
106
|
+
Using a search strategy is easy, you only need to specify to ``tune_kernel`` which strategy and method
|
|
107
|
+
you would like to use, for example ``strategy="genetic_algorithm"`` or ``strategy="basinhopping"``.
|
|
108
|
+
For a full overview of the supported search strategies and methods please see the `user
|
|
109
|
+
api documentation <http://benvanwerkhoven.github.io/kernel_tuner/user-api.html>`__.
|
|
110
|
+
|
|
94
111
|
Tuning host and kernel code
|
|
95
112
|
---------------------------
|
|
96
113
|
|
|
@@ -105,12 +122,6 @@ and the
|
|
|
105
122
|
`documentation <http://benvanwerkhoven.github.io/kernel_tuner/hostcode.html>`__
|
|
106
123
|
for a detailed explanation of the kernel tuner Python script.
|
|
107
124
|
|
|
108
|
-
Search strategies for tuning
|
|
109
|
-
----------------------------
|
|
110
|
-
|
|
111
|
-
Kernel Tuner supports several strategies: brute_force (default), random_sample, minimize, basinhopping, and diff_evo (differential
|
|
112
|
-
evolution). Using different strategies is easy, you only need to specify to ``tune_kernel`` which strategy you would like to use, for example: ``strategy="basinhopping", method="TNC"``. For a full overview of the supported search strategies and methods please see the
|
|
113
|
-
`user api <http://benvanwerkhoven.github.io/kernel_tuner/user-api.html>`__.
|
|
114
125
|
|
|
115
126
|
Correctness verification
|
|
116
127
|
------------------------
|
|
@@ -132,29 +143,36 @@ Please see the `Contributions Guide <http://benvanwerkhoven.github.io/kernel_tun
|
|
|
132
143
|
|
|
133
144
|
Citation
|
|
134
145
|
--------
|
|
135
|
-
|
|
146
|
+
The paper about `Kernel Tuner is published (Open Access) <https://www.sciencedirect.com/science/article/pii/S0167739X18313359>`__, please cite
|
|
147
|
+
Kernel Tuner as follows:
|
|
136
148
|
|
|
137
149
|
.. code:: latex
|
|
138
150
|
|
|
139
|
-
@
|
|
140
|
-
author
|
|
141
|
-
title
|
|
142
|
-
|
|
151
|
+
@article{kerneltuner,
|
|
152
|
+
author = {Ben van Werkhoven},
|
|
153
|
+
title = {Kernel Tuner: A search-optimizing GPU code auto-tuner},
|
|
154
|
+
journal = {Future Generation Computer Systems},
|
|
155
|
+
year = {2019},
|
|
156
|
+
volume = {90},
|
|
157
|
+
pages = {347-358},
|
|
158
|
+
doi = {https://doi.org/10.1016/j.future.2018.08.004},
|
|
143
159
|
}
|
|
144
160
|
|
|
145
161
|
Related work
|
|
146
162
|
------------
|
|
147
163
|
|
|
148
164
|
You may also like `CLTune <https://github.com/CNugteren/CLTune>`__ by
|
|
149
|
-
Cedric Nugteren. CLTune is a C++ library for kernel tuning
|
|
150
|
-
various advanced features like machine learning to optimize the time
|
|
151
|
-
spent on tuning kernels.
|
|
165
|
+
Cedric Nugteren. CLTune is a C++ library for kernel tuning.
|
|
152
166
|
|
|
153
167
|
.. |Build Status| image:: https://api.travis-ci.org/benvanwerkhoven/kernel_tuner.svg?branch=master
|
|
154
168
|
:target: https://travis-ci.org/benvanwerkhoven/kernel_tuner
|
|
155
|
-
.. |
|
|
156
|
-
:target: https://
|
|
157
|
-
.. |Codacy Badge2| image:: https://api.codacy.com/project/badge/coverage/016dc85044ab4d57b777449d93275608
|
|
158
|
-
:target: https://www.codacy.com/app/b-vanwerkhoven/kernel_tuner
|
|
169
|
+
.. |CodeCov Badge| image:: https://codecov.io/gh/benvanwerkhoven/kernel_tuner/branch/master/graph/badge.svg
|
|
170
|
+
:target: https://codecov.io/gh/benvanwerkhoven/kernel_tuner
|
|
159
171
|
.. |PyPi Badge| image:: https://img.shields.io/pypi/v/kernel_tuner.svg?colorB=blue
|
|
160
172
|
:target: https://pypi.python.org/pypi/kernel_tuner/
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
@@ -4,6 +4,7 @@ from collections import namedtuple
|
|
|
4
4
|
import subprocess
|
|
5
5
|
import platform
|
|
6
6
|
import errno
|
|
7
|
+
import re
|
|
7
8
|
import logging
|
|
8
9
|
import ctypes as C
|
|
9
10
|
import _ctypes
|
|
@@ -17,10 +18,17 @@ dtype_map = {"int8": C.c_int8,
|
|
|
17
18
|
"int16": C.c_int16,
|
|
18
19
|
"int32": C.c_int32,
|
|
19
20
|
"int64": C.c_int64,
|
|
21
|
+
"uint8": C.c_uint8,
|
|
22
|
+
"uint16": C.c_uint16,
|
|
23
|
+
"uint32": C.c_uint32,
|
|
24
|
+
"uint64": C.c_uint64,
|
|
20
25
|
"float32": C.c_float,
|
|
21
26
|
"float64": C.c_double}
|
|
22
27
|
|
|
23
|
-
|
|
28
|
+
# This represents an individual kernel argument.
|
|
29
|
+
# It contains a numpy object (ndarray or number) and a ctypes object with a copy
|
|
30
|
+
# of the argument data. For an ndarray, the ctypes object is a wrapper for the ndarray's data.
|
|
31
|
+
Argument = namedtuple("Argument", ["numpy", "ctypes"])
|
|
24
32
|
|
|
25
33
|
|
|
26
34
|
class CFunctions(object):
|
|
@@ -38,7 +46,6 @@ class CFunctions(object):
|
|
|
38
46
|
self.compiler = compiler or "g++" # use gcc by default
|
|
39
47
|
self.lib = None
|
|
40
48
|
self.using_openmp = False
|
|
41
|
-
self.arg_mapping = dict()
|
|
42
49
|
|
|
43
50
|
try:
|
|
44
51
|
cc_version = str(subprocess.check_output([self.compiler, "--version"]))
|
|
@@ -75,28 +82,29 @@ class CFunctions(object):
|
|
|
75
82
|
:type arguments: list(numpy objects)
|
|
76
83
|
|
|
77
84
|
:returns: A list of arguments that can be passed to the C function.
|
|
78
|
-
:rtype: list()
|
|
85
|
+
:rtype: list(Argument)
|
|
79
86
|
"""
|
|
80
|
-
ctype_args = [None for _ in arguments]
|
|
81
|
-
self.arg_mapping = dict()
|
|
87
|
+
ctype_args = [ None for _ in arguments]
|
|
82
88
|
|
|
83
89
|
for i, arg in enumerate(arguments):
|
|
84
|
-
if not isinstance(arg, (numpy.ndarray, numpy.
|
|
90
|
+
if not isinstance(arg, (numpy.ndarray, numpy.number)):
|
|
85
91
|
raise TypeError("Argument is not numpy ndarray or numpy scalar %s" % type(arg))
|
|
86
92
|
dtype_str = str(arg.dtype)
|
|
87
|
-
|
|
93
|
+
data = arg.copy()
|
|
88
94
|
if isinstance(arg, numpy.ndarray):
|
|
89
95
|
if dtype_str in dtype_map.keys():
|
|
90
|
-
|
|
96
|
+
# In numpy <= 1.15, ndarray.ctypes.data_as does not itself keep a reference
|
|
97
|
+
# to its underlying array, so we need to store a reference to arg.copy()
|
|
98
|
+
# in the Argument object manually to avoid it being deleted.
|
|
99
|
+
# (This changed in numpy > 1.15.)
|
|
100
|
+
data_ctypes = data.ctypes.data_as(C.POINTER(dtype_map[dtype_str]))
|
|
91
101
|
else:
|
|
92
102
|
raise TypeError("unknown dtype for ndarray")
|
|
93
|
-
self.arg_mapping[str(ctype_args[i])] = arg_info
|
|
94
103
|
elif isinstance(arg, numpy.generic):
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
data_ctypes = dtype_map[dtype_str](arg)
|
|
105
|
+
ctype_args[i] = Argument(numpy=data, ctypes=data_ctypes)
|
|
97
106
|
return ctype_args
|
|
98
107
|
|
|
99
|
-
|
|
100
108
|
def compile(self, kernel_name, kernel_string):
|
|
101
109
|
"""call the C compiler to compile the kernel, return the function
|
|
102
110
|
|
|
@@ -115,25 +123,41 @@ class CFunctions(object):
|
|
|
115
123
|
if self.lib != None:
|
|
116
124
|
self.cleanup_lib()
|
|
117
125
|
|
|
118
|
-
suffix = ".cc"
|
|
119
|
-
|
|
120
|
-
if not "extern \"C\"" in kernel_string:
|
|
121
|
-
kernel_string = "extern \"C\" {\n" + kernel_string + "\n}"
|
|
122
|
-
|
|
123
126
|
compiler_options = ["-fPIC"]
|
|
124
|
-
|
|
127
|
+
|
|
128
|
+
#detect openmp
|
|
129
|
+
if "#include <omp.h>" in kernel_string or "use omp_lib" in kernel_string:
|
|
125
130
|
logging.debug('set using_openmp to true')
|
|
126
131
|
self.using_openmp = True
|
|
127
|
-
|
|
132
|
+
if self.compiler == "pgfortran":
|
|
133
|
+
compiler_options.append("-mp")
|
|
134
|
+
else:
|
|
135
|
+
compiler_options.append("-fopenmp")
|
|
128
136
|
|
|
129
|
-
|
|
130
|
-
|
|
137
|
+
# TODO: Get suffix from KernelSources, and adapt the logic below
|
|
138
|
+
|
|
139
|
+
#select right suffix based on compiler
|
|
140
|
+
suffix = ".cc"
|
|
141
|
+
|
|
142
|
+
#detect whether to use nvcc as default instead of g++, may overrule an explicitly passed g++
|
|
143
|
+
if ("#include <cuda" in kernel_string) or ("cudaMemcpy" in kernel_string):
|
|
144
|
+
if self.compiler == "g++" and self.nvcc_available:
|
|
131
145
|
self.compiler = "nvcc"
|
|
132
146
|
|
|
147
|
+
#if contains device code suffix .cu is required by nvcc
|
|
148
|
+
if self.compiler == "nvcc" and "__global__" in kernel_string:
|
|
149
|
+
suffix = ".cu"
|
|
150
|
+
if self.compiler in ["gfortran", "pgfortran", "ftn", "ifort"]:
|
|
151
|
+
suffix = ".F90"
|
|
152
|
+
|
|
133
153
|
if self.compiler == "nvcc":
|
|
134
|
-
suffix = suffix[:-1] + "u"
|
|
135
154
|
compiler_options = ["-Xcompiler=" + c for c in compiler_options]
|
|
136
155
|
|
|
156
|
+
if ".c" in suffix:
|
|
157
|
+
if not "extern \"C\"" in kernel_string:
|
|
158
|
+
kernel_string = "extern \"C\" {\n" + kernel_string + "\n}"
|
|
159
|
+
|
|
160
|
+
#copy user specified compiler options to current list
|
|
137
161
|
if self.compiler_options:
|
|
138
162
|
compiler_options += self.compiler_options
|
|
139
163
|
|
|
@@ -148,6 +172,16 @@ class CFunctions(object):
|
|
|
148
172
|
source_file = get_temp_filename(suffix=suffix)
|
|
149
173
|
filename = ".".join(source_file.split(".")[:-1])
|
|
150
174
|
|
|
175
|
+
#detect Fortran modules
|
|
176
|
+
match = re.search(r"\s*module\s+([a-zA-Z_]*)", kernel_string)
|
|
177
|
+
if match:
|
|
178
|
+
if self.compiler == "gfortran":
|
|
179
|
+
kernel_name = "__" + match.group(1) + "_MOD_" + kernel_name
|
|
180
|
+
elif self.compiler in ["ftn", "ifort"]:
|
|
181
|
+
kernel_name = match.group(1) + "_mp_" + kernel_name + "_"
|
|
182
|
+
elif self.compiler == "pgfortran":
|
|
183
|
+
kernel_name = match.group(1) + "_" + kernel_name + "_"
|
|
184
|
+
|
|
151
185
|
try:
|
|
152
186
|
write_file(source_file, kernel_string)
|
|
153
187
|
|
|
@@ -158,8 +192,8 @@ class CFunctions(object):
|
|
|
158
192
|
subprocess.check_call([self.compiler, "-c", source_file] + compiler_options + ["-o", filename + ".o"])
|
|
159
193
|
subprocess.check_call([self.compiler, filename + ".o"] + compiler_options + ["-shared", "-o", filename + lib_extension] + lib_args)
|
|
160
194
|
|
|
161
|
-
self.lib = numpy.ctypeslib.load_library(filename, '.')
|
|
162
195
|
|
|
196
|
+
self.lib = numpy.ctypeslib.load_library(filename, '.')
|
|
163
197
|
func = getattr(self.lib, kernel_name)
|
|
164
198
|
func.restype = C.c_float
|
|
165
199
|
|
|
@@ -172,7 +206,7 @@ class CFunctions(object):
|
|
|
172
206
|
return func
|
|
173
207
|
|
|
174
208
|
|
|
175
|
-
def benchmark(self, func, c_args, threads, grid
|
|
209
|
+
def benchmark(self, func, c_args, threads, grid):
|
|
176
210
|
"""runs the kernel repeatedly, returns averaged returned value
|
|
177
211
|
|
|
178
212
|
The C function tuning is a little bit more flexible than direct CUDA
|
|
@@ -193,7 +227,7 @@ class CFunctions(object):
|
|
|
193
227
|
:param c_args: A list of arguments to the function, order should match the
|
|
194
228
|
order in the code. The list should be prepared using
|
|
195
229
|
ready_argument_list().
|
|
196
|
-
:type c_args: list()
|
|
230
|
+
:type c_args: list(Argument)
|
|
197
231
|
|
|
198
232
|
:param threads: Ignored, but left as argument for now to have the same
|
|
199
233
|
interface as CudaFunctions and OpenCLFunctions.
|
|
@@ -203,14 +237,11 @@ class CFunctions(object):
|
|
|
203
237
|
interface as CudaFunctions and OpenCLFunctions.
|
|
204
238
|
:type grid: any
|
|
205
239
|
|
|
206
|
-
:
|
|
207
|
-
:
|
|
208
|
-
|
|
209
|
-
:returns: All execution times, if times=True, or a robust average for the
|
|
210
|
-
kernel execution time.
|
|
211
|
-
:rtype: float
|
|
240
|
+
:returns: All execution times.
|
|
241
|
+
:rtype: dict()
|
|
212
242
|
"""
|
|
213
|
-
|
|
243
|
+
result = dict()
|
|
244
|
+
result["times"] = []
|
|
214
245
|
for _ in range(self.iterations):
|
|
215
246
|
value = self.run_kernel(func, c_args, threads, grid)
|
|
216
247
|
|
|
@@ -221,19 +252,13 @@ class CFunctions(object):
|
|
|
221
252
|
#
|
|
222
253
|
#The current, less than ideal, scheme uses the convention that a
|
|
223
254
|
#negative time indicates a 'too many resources requested for launch'
|
|
255
|
+
#which Kernel Tuner can silently ignore
|
|
224
256
|
if value < 0.0:
|
|
225
257
|
raise Exception("too many resources requested for launch")
|
|
226
258
|
|
|
227
|
-
|
|
228
|
-
time =
|
|
229
|
-
|
|
230
|
-
return time
|
|
231
|
-
else:
|
|
232
|
-
if self.iterations > 4:
|
|
233
|
-
return numpy.mean(time[1:-1])
|
|
234
|
-
else:
|
|
235
|
-
return numpy.mean(time)
|
|
236
|
-
|
|
259
|
+
result["times"].append(value)
|
|
260
|
+
result["time"] = numpy.mean(result["times"])
|
|
261
|
+
return result
|
|
237
262
|
|
|
238
263
|
def run_kernel(self, func, c_args, threads, grid):
|
|
239
264
|
"""runs the kernel once, returns whatever the kernel returns
|
|
@@ -244,7 +269,7 @@ class CFunctions(object):
|
|
|
244
269
|
:param c_args: A list of arguments to the function, order should match the
|
|
245
270
|
order in the code. The list should be prepared using
|
|
246
271
|
ready_argument_list().
|
|
247
|
-
:type c_args: list()
|
|
272
|
+
:type c_args: list(Argument)
|
|
248
273
|
|
|
249
274
|
:param threads: Ignored, but left as argument for now to have the same
|
|
250
275
|
interface as CudaFunctions and OpenCLFunctions.
|
|
@@ -258,40 +283,47 @@ class CFunctions(object):
|
|
|
258
283
|
:rtype: float
|
|
259
284
|
"""
|
|
260
285
|
logging.debug("run_kernel")
|
|
261
|
-
logging.debug("arguments=" + str([str(arg) for arg in c_args]))
|
|
286
|
+
logging.debug("arguments=" + str([str(arg.ctypes) for arg in c_args]))
|
|
262
287
|
|
|
263
|
-
time = func(*c_args)
|
|
288
|
+
time = func(*[arg.ctypes for arg in c_args])
|
|
264
289
|
|
|
265
290
|
return time
|
|
266
291
|
|
|
267
|
-
|
|
268
292
|
def memset(self, allocation, value, size):
|
|
269
293
|
"""set the memory in allocation to the value in value
|
|
270
294
|
|
|
271
|
-
:param allocation:
|
|
272
|
-
:type allocation:
|
|
295
|
+
:param allocation: An Argument for some memory allocation unit
|
|
296
|
+
:type allocation: Argument
|
|
273
297
|
|
|
274
298
|
:param value: The value to set the memory to
|
|
275
|
-
:type value: a single
|
|
299
|
+
:type value: a single 8-bit unsigned int
|
|
276
300
|
|
|
277
301
|
:param size: The size of to the allocation unit in bytes
|
|
278
302
|
:type size: int
|
|
279
303
|
"""
|
|
280
|
-
C.memset(allocation, value, size)
|
|
281
|
-
|
|
304
|
+
C.memset(allocation.ctypes, value, size)
|
|
282
305
|
|
|
283
306
|
def memcpy_dtoh(self, dest, src):
|
|
284
|
-
"""a simple memcpy
|
|
307
|
+
"""a simple memcpy copying from an Argument to a numpy array
|
|
285
308
|
|
|
286
309
|
:param dest: A numpy array to store the data
|
|
287
310
|
:type dest: numpy.ndarray
|
|
288
311
|
|
|
289
|
-
:param src:
|
|
290
|
-
:type src:
|
|
312
|
+
:param src: An Argument for some memory allocation
|
|
313
|
+
:type src: Argument
|
|
291
314
|
"""
|
|
292
|
-
|
|
293
|
-
|
|
315
|
+
dest[:] = src.numpy
|
|
316
|
+
|
|
317
|
+
def memcpy_htod(self, dest, src):
|
|
318
|
+
"""a simple memcpy copying from a numpy array to an Argument
|
|
294
319
|
|
|
320
|
+
:param dest: An Argument for some memory allocation
|
|
321
|
+
:type dst: Argument
|
|
322
|
+
|
|
323
|
+
:param src: A numpy array containing the source data
|
|
324
|
+
:type src: numpy.ndarray
|
|
325
|
+
"""
|
|
326
|
+
dest.numpy[:] = src
|
|
295
327
|
|
|
296
328
|
def cleanup_lib(self):
|
|
297
329
|
""" unload the previously loaded shared library """
|