kernel-tuner 0.2.0__tar.gz → 0.3.1__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.2.0 → kernel_tuner-0.3.1}/PKG-INFO +18 -13
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/README.rst +12 -8
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/c.py +73 -55
- kernel_tuner-0.3.1/kernel_tuner/core.py +500 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/cuda.py +138 -27
- kernel_tuner-0.3.1/kernel_tuner/cupy_backend.py +331 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/interface.py +179 -126
- kernel_tuner-0.3.1/kernel_tuner/kernelbuilder.py +98 -0
- kernel_tuner-0.3.1/kernel_tuner/nvml.py +124 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/opencl.py +23 -19
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/runners/sequential.py +31 -8
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/strategies/basinhopping.py +5 -3
- kernel_tuner-0.3.1/kernel_tuner/strategies/bayes_opt.py +92 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/strategies/diff_evo.py +6 -4
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/strategies/firefly_algorithm.py +6 -7
- kernel_tuner-0.3.1/kernel_tuner/strategies/genetic_algorithm.py +210 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/strategies/minimize.py +21 -23
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/strategies/pso.py +3 -4
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/strategies/random_sample.py +3 -1
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/strategies/simulated_annealing.py +1 -2
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/util.py +166 -75
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner.egg-info/PKG-INFO +18 -13
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner.egg-info/SOURCES.txt +5 -2
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner.egg-info/requires.txt +3 -1
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/setup.py +13 -7
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/test/test_c_functions.py +83 -13
- kernel_tuner-0.3.1/test/test_core.py +176 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/test/test_cuda_functions.py +12 -12
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/test/test_cuda_mocked.py +45 -9
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/test/test_interface.py +6 -30
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/test/test_opencl_functions.py +9 -9
- kernel_tuner-0.3.1/test/test_runners.py +96 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/test/test_util_functions.py +123 -86
- kernel_tuner-0.2.0/kernel_tuner/core.py +0 -306
- kernel_tuner-0.2.0/kernel_tuner/runners/noodles.py +0 -122
- kernel_tuner-0.2.0/kernel_tuner/strategies/genetic_algorithm.py +0 -117
- kernel_tuner-0.2.0/test/test_device_interface.py +0 -50
- kernel_tuner-0.2.0/test/test_runners.py +0 -169
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/LICENSE +0 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/MANIFEST.in +0 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/__init__.py +0 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/runners/__init__.py +0 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/strategies/__init__.py +0 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/strategies/brute_force.py +0 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner/wrappers.py +0 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner.egg-info/dependency_links.txt +0 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/kernel_tuner.egg-info/top_level.txt +0 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/setup.cfg +0 -0
- {kernel_tuner-0.2.0 → kernel_tuner-0.3.1}/test/test_minimize.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: kernel_tuner
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.3.1
|
|
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
|
|
@@ -9,7 +9,7 @@ License: Apache 2.0
|
|
|
9
9
|
Description: Kernel Tuner
|
|
10
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
|
|
|
@@ -112,8 +112,8 @@ Description: Kernel Tuner
|
|
|
112
112
|
:align: center
|
|
113
113
|
|
|
114
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
|
-
|
|
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
117
|
api documentation <http://benvanwerkhoven.github.io/kernel_tuner/user-api.html>`__.
|
|
118
118
|
|
|
119
119
|
Tuning host and kernel code
|
|
@@ -151,7 +151,7 @@ Description: Kernel Tuner
|
|
|
151
151
|
|
|
152
152
|
Citation
|
|
153
153
|
--------
|
|
154
|
-
|
|
154
|
+
The paper about `Kernel Tuner is published (Open Access) <https://www.sciencedirect.com/science/article/pii/S0167739X18313359>`__, please cite
|
|
155
155
|
Kernel Tuner as follows:
|
|
156
156
|
|
|
157
157
|
.. code:: latex
|
|
@@ -174,13 +174,17 @@ Description: Kernel Tuner
|
|
|
174
174
|
|
|
175
175
|
.. |Build Status| image:: https://api.travis-ci.org/benvanwerkhoven/kernel_tuner.svg?branch=master
|
|
176
176
|
:target: https://travis-ci.org/benvanwerkhoven/kernel_tuner
|
|
177
|
-
.. |
|
|
178
|
-
:target: https://
|
|
179
|
-
.. |Codacy Badge2| image:: https://api.codacy.com/project/badge/coverage/016dc85044ab4d57b777449d93275608
|
|
180
|
-
: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
|
|
181
179
|
.. |PyPi Badge| image:: https://img.shields.io/pypi/v/kernel_tuner.svg?colorB=blue
|
|
182
180
|
:target: https://pypi.python.org/pypi/kernel_tuner/
|
|
183
181
|
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
184
188
|
Keywords: auto-tuning gpu computing pycuda cuda pyopencl opencl
|
|
185
189
|
Platform: UNKNOWN
|
|
186
190
|
Classifier: Environment :: Console
|
|
@@ -190,15 +194,16 @@ Classifier: Intended Audience :: Education
|
|
|
190
194
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
191
195
|
Classifier: Natural Language :: English
|
|
192
196
|
Classifier: Operating System :: POSIX :: Linux
|
|
193
|
-
Classifier: Programming Language :: Python :: 2.7
|
|
194
197
|
Classifier: Programming Language :: Python :: 3.5
|
|
198
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
199
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
195
200
|
Classifier: Topic :: Scientific/Engineering
|
|
196
201
|
Classifier: Topic :: Software Development
|
|
197
202
|
Classifier: Topic :: System :: Distributed Computing
|
|
198
203
|
Classifier: Development Status :: 4 - Beta
|
|
199
|
-
Provides-Extra: cuda_opencl
|
|
200
|
-
Provides-Extra: cuda
|
|
201
204
|
Provides-Extra: dev
|
|
205
|
+
Provides-Extra: cuda
|
|
202
206
|
Provides-Extra: tutorial
|
|
203
207
|
Provides-Extra: opencl
|
|
208
|
+
Provides-Extra: cuda_opencl
|
|
204
209
|
Provides-Extra: doc
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Kernel Tuner
|
|
2
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
|
|
|
@@ -104,8 +104,8 @@ Optimization, the Firefly Algorithm, and Simulated Annealing.
|
|
|
104
104
|
:align: center
|
|
105
105
|
|
|
106
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
|
-
|
|
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
109
|
api documentation <http://benvanwerkhoven.github.io/kernel_tuner/user-api.html>`__.
|
|
110
110
|
|
|
111
111
|
Tuning host and kernel code
|
|
@@ -143,7 +143,7 @@ Please see the `Contributions Guide <http://benvanwerkhoven.github.io/kernel_tun
|
|
|
143
143
|
|
|
144
144
|
Citation
|
|
145
145
|
--------
|
|
146
|
-
|
|
146
|
+
The paper about `Kernel Tuner is published (Open Access) <https://www.sciencedirect.com/science/article/pii/S0167739X18313359>`__, please cite
|
|
147
147
|
Kernel Tuner as follows:
|
|
148
148
|
|
|
149
149
|
.. code:: latex
|
|
@@ -166,9 +166,13 @@ Cedric Nugteren. CLTune is a C++ library for kernel tuning.
|
|
|
166
166
|
|
|
167
167
|
.. |Build Status| image:: https://api.travis-ci.org/benvanwerkhoven/kernel_tuner.svg?branch=master
|
|
168
168
|
:target: https://travis-ci.org/benvanwerkhoven/kernel_tuner
|
|
169
|
-
.. |
|
|
170
|
-
:target: https://
|
|
171
|
-
.. |Codacy Badge2| image:: https://api.codacy.com/project/badge/coverage/016dc85044ab4d57b777449d93275608
|
|
172
|
-
: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
|
|
173
171
|
.. |PyPi Badge| image:: https://img.shields.io/pypi/v/kernel_tuner.svg?colorB=blue
|
|
174
172
|
:target: https://pypi.python.org/pypi/kernel_tuner/
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
@@ -18,10 +18,17 @@ dtype_map = {"int8": C.c_int8,
|
|
|
18
18
|
"int16": C.c_int16,
|
|
19
19
|
"int32": C.c_int32,
|
|
20
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,
|
|
21
25
|
"float32": C.c_float,
|
|
22
26
|
"float64": C.c_double}
|
|
23
27
|
|
|
24
|
-
|
|
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"])
|
|
25
32
|
|
|
26
33
|
|
|
27
34
|
class CFunctions(object):
|
|
@@ -39,7 +46,6 @@ class CFunctions(object):
|
|
|
39
46
|
self.compiler = compiler or "g++" # use gcc by default
|
|
40
47
|
self.lib = None
|
|
41
48
|
self.using_openmp = False
|
|
42
|
-
self.arg_mapping = dict()
|
|
43
49
|
|
|
44
50
|
try:
|
|
45
51
|
cc_version = str(subprocess.check_output([self.compiler, "--version"]))
|
|
@@ -76,29 +82,30 @@ class CFunctions(object):
|
|
|
76
82
|
:type arguments: list(numpy objects)
|
|
77
83
|
|
|
78
84
|
:returns: A list of arguments that can be passed to the C function.
|
|
79
|
-
:rtype: list()
|
|
85
|
+
:rtype: list(Argument)
|
|
80
86
|
"""
|
|
81
|
-
ctype_args = [None for _ in arguments]
|
|
82
|
-
self.arg_mapping = dict()
|
|
87
|
+
ctype_args = [ None for _ in arguments]
|
|
83
88
|
|
|
84
89
|
for i, arg in enumerate(arguments):
|
|
85
|
-
if not isinstance(arg, (numpy.ndarray, numpy.
|
|
90
|
+
if not isinstance(arg, (numpy.ndarray, numpy.number)):
|
|
86
91
|
raise TypeError("Argument is not numpy ndarray or numpy scalar %s" % type(arg))
|
|
87
92
|
dtype_str = str(arg.dtype)
|
|
88
|
-
|
|
93
|
+
data = arg.copy()
|
|
89
94
|
if isinstance(arg, numpy.ndarray):
|
|
90
95
|
if dtype_str in dtype_map.keys():
|
|
91
|
-
|
|
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]))
|
|
92
101
|
else:
|
|
93
102
|
raise TypeError("unknown dtype for ndarray")
|
|
94
|
-
self.arg_mapping[str(ctype_args[i])] = arg_info
|
|
95
103
|
elif isinstance(arg, numpy.generic):
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
data_ctypes = dtype_map[dtype_str](arg)
|
|
105
|
+
ctype_args[i] = Argument(numpy=data, ctypes=data_ctypes)
|
|
98
106
|
return ctype_args
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
def compile(self, kernel_name, kernel_string):
|
|
108
|
+
def compile(self, kernel_instance):
|
|
102
109
|
"""call the C compiler to compile the kernel, return the function
|
|
103
110
|
|
|
104
111
|
:param kernel_name: The name of the kernel to be compiled, used to lookup the
|
|
@@ -111,7 +118,9 @@ class CFunctions(object):
|
|
|
111
118
|
:returns: An ctypes function that can be called directly.
|
|
112
119
|
:rtype: ctypes._FuncPtr
|
|
113
120
|
"""
|
|
114
|
-
logging.debug('compiling ' +
|
|
121
|
+
logging.debug('compiling ' + kernel_instance.name)
|
|
122
|
+
|
|
123
|
+
kernel_string = kernel_instance.kernel_string
|
|
115
124
|
|
|
116
125
|
if self.lib != None:
|
|
117
126
|
self.cleanup_lib()
|
|
@@ -127,19 +136,31 @@ class CFunctions(object):
|
|
|
127
136
|
else:
|
|
128
137
|
compiler_options.append("-fopenmp")
|
|
129
138
|
|
|
139
|
+
#if filename is known, use that one
|
|
140
|
+
suffix = kernel_instance.kernel_source.get_user_suffix()
|
|
141
|
+
|
|
142
|
+
#if code contains device code, suffix .cu is required
|
|
143
|
+
device_code_signals = ["__global", "__syncthreads()", "threadIdx"]
|
|
144
|
+
if any([snippet in kernel_string for snippet in device_code_signals]):
|
|
145
|
+
suffix = ".cu"
|
|
146
|
+
|
|
130
147
|
#detect whether to use nvcc as default instead of g++, may overrule an explicitly passed g++
|
|
131
|
-
if ("#include <cuda" in kernel_string) or ("
|
|
148
|
+
if (suffix == ".cu") or ("#include <cuda" in kernel_string) or ("cudaMemcpy" in kernel_string):
|
|
132
149
|
if self.compiler == "g++" and self.nvcc_available:
|
|
133
150
|
self.compiler = "nvcc"
|
|
134
151
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
if suffix is None:
|
|
153
|
+
#select right suffix based on compiler
|
|
154
|
+
suffix = ".cc"
|
|
155
|
+
|
|
156
|
+
if self.compiler in ["gfortran", "pgfortran", "ftn", "ifort"]:
|
|
157
|
+
suffix = ".F90"
|
|
158
|
+
|
|
139
159
|
if self.compiler == "nvcc":
|
|
140
|
-
suffix = suffix[:-1] + "u"
|
|
141
160
|
compiler_options = ["-Xcompiler=" + c for c in compiler_options]
|
|
142
161
|
|
|
162
|
+
#this basically checks if we aren't compiling Fortran
|
|
163
|
+
#at the moment any C, C++, or CUDA code is assumed to use extern "C" linkage
|
|
143
164
|
if ".c" in suffix:
|
|
144
165
|
if not "extern \"C\"" in kernel_string:
|
|
145
166
|
kernel_string = "extern \"C\" {\n" + kernel_string + "\n}"
|
|
@@ -169,7 +190,6 @@ class CFunctions(object):
|
|
|
169
190
|
elif self.compiler == "pgfortran":
|
|
170
191
|
kernel_name = match.group(1) + "_" + kernel_name + "_"
|
|
171
192
|
|
|
172
|
-
|
|
173
193
|
try:
|
|
174
194
|
write_file(source_file, kernel_string)
|
|
175
195
|
|
|
@@ -182,7 +202,7 @@ class CFunctions(object):
|
|
|
182
202
|
|
|
183
203
|
|
|
184
204
|
self.lib = numpy.ctypeslib.load_library(filename, '.')
|
|
185
|
-
func = getattr(self.lib,
|
|
205
|
+
func = getattr(self.lib, kernel_instance.name)
|
|
186
206
|
func.restype = C.c_float
|
|
187
207
|
|
|
188
208
|
finally:
|
|
@@ -194,7 +214,7 @@ class CFunctions(object):
|
|
|
194
214
|
return func
|
|
195
215
|
|
|
196
216
|
|
|
197
|
-
def benchmark(self, func, c_args, threads, grid
|
|
217
|
+
def benchmark(self, func, c_args, threads, grid):
|
|
198
218
|
"""runs the kernel repeatedly, returns averaged returned value
|
|
199
219
|
|
|
200
220
|
The C function tuning is a little bit more flexible than direct CUDA
|
|
@@ -215,7 +235,7 @@ class CFunctions(object):
|
|
|
215
235
|
:param c_args: A list of arguments to the function, order should match the
|
|
216
236
|
order in the code. The list should be prepared using
|
|
217
237
|
ready_argument_list().
|
|
218
|
-
:type c_args: list()
|
|
238
|
+
:type c_args: list(Argument)
|
|
219
239
|
|
|
220
240
|
:param threads: Ignored, but left as argument for now to have the same
|
|
221
241
|
interface as CudaFunctions and OpenCLFunctions.
|
|
@@ -225,14 +245,11 @@ class CFunctions(object):
|
|
|
225
245
|
interface as CudaFunctions and OpenCLFunctions.
|
|
226
246
|
:type grid: any
|
|
227
247
|
|
|
228
|
-
:
|
|
229
|
-
:
|
|
230
|
-
|
|
231
|
-
:returns: All execution times, if times=True, or a robust average for the
|
|
232
|
-
kernel execution time.
|
|
233
|
-
:rtype: float
|
|
248
|
+
:returns: All execution times.
|
|
249
|
+
:rtype: dict()
|
|
234
250
|
"""
|
|
235
|
-
|
|
251
|
+
result = dict()
|
|
252
|
+
result["times"] = []
|
|
236
253
|
for _ in range(self.iterations):
|
|
237
254
|
value = self.run_kernel(func, c_args, threads, grid)
|
|
238
255
|
|
|
@@ -243,19 +260,13 @@ class CFunctions(object):
|
|
|
243
260
|
#
|
|
244
261
|
#The current, less than ideal, scheme uses the convention that a
|
|
245
262
|
#negative time indicates a 'too many resources requested for launch'
|
|
263
|
+
#which Kernel Tuner can silently ignore
|
|
246
264
|
if value < 0.0:
|
|
247
265
|
raise Exception("too many resources requested for launch")
|
|
248
266
|
|
|
249
|
-
|
|
250
|
-
time =
|
|
251
|
-
|
|
252
|
-
return time
|
|
253
|
-
else:
|
|
254
|
-
if self.iterations > 4:
|
|
255
|
-
return numpy.mean(time[1:-1])
|
|
256
|
-
else:
|
|
257
|
-
return numpy.mean(time)
|
|
258
|
-
|
|
267
|
+
result["times"].append(value)
|
|
268
|
+
result["time"] = numpy.mean(result["times"])
|
|
269
|
+
return result
|
|
259
270
|
|
|
260
271
|
def run_kernel(self, func, c_args, threads, grid):
|
|
261
272
|
"""runs the kernel once, returns whatever the kernel returns
|
|
@@ -266,7 +277,7 @@ class CFunctions(object):
|
|
|
266
277
|
:param c_args: A list of arguments to the function, order should match the
|
|
267
278
|
order in the code. The list should be prepared using
|
|
268
279
|
ready_argument_list().
|
|
269
|
-
:type c_args: list()
|
|
280
|
+
:type c_args: list(Argument)
|
|
270
281
|
|
|
271
282
|
:param threads: Ignored, but left as argument for now to have the same
|
|
272
283
|
interface as CudaFunctions and OpenCLFunctions.
|
|
@@ -280,40 +291,47 @@ class CFunctions(object):
|
|
|
280
291
|
:rtype: float
|
|
281
292
|
"""
|
|
282
293
|
logging.debug("run_kernel")
|
|
283
|
-
logging.debug("arguments=" + str([str(arg) for arg in c_args]))
|
|
294
|
+
logging.debug("arguments=" + str([str(arg.ctypes) for arg in c_args]))
|
|
284
295
|
|
|
285
|
-
time = func(*c_args)
|
|
296
|
+
time = func(*[arg.ctypes for arg in c_args])
|
|
286
297
|
|
|
287
298
|
return time
|
|
288
299
|
|
|
289
|
-
|
|
290
300
|
def memset(self, allocation, value, size):
|
|
291
301
|
"""set the memory in allocation to the value in value
|
|
292
302
|
|
|
293
|
-
:param allocation:
|
|
294
|
-
:type allocation:
|
|
303
|
+
:param allocation: An Argument for some memory allocation unit
|
|
304
|
+
:type allocation: Argument
|
|
295
305
|
|
|
296
306
|
:param value: The value to set the memory to
|
|
297
|
-
:type value: a single
|
|
307
|
+
:type value: a single 8-bit unsigned int
|
|
298
308
|
|
|
299
309
|
:param size: The size of to the allocation unit in bytes
|
|
300
310
|
:type size: int
|
|
301
311
|
"""
|
|
302
|
-
C.memset(allocation, value, size)
|
|
303
|
-
|
|
312
|
+
C.memset(allocation.ctypes, value, size)
|
|
304
313
|
|
|
305
314
|
def memcpy_dtoh(self, dest, src):
|
|
306
|
-
"""a simple memcpy
|
|
315
|
+
"""a simple memcpy copying from an Argument to a numpy array
|
|
307
316
|
|
|
308
317
|
:param dest: A numpy array to store the data
|
|
309
318
|
:type dest: numpy.ndarray
|
|
310
319
|
|
|
311
|
-
:param src:
|
|
312
|
-
:type src:
|
|
320
|
+
:param src: An Argument for some memory allocation
|
|
321
|
+
:type src: Argument
|
|
313
322
|
"""
|
|
314
|
-
|
|
315
|
-
|
|
323
|
+
dest[:] = src.numpy
|
|
324
|
+
|
|
325
|
+
def memcpy_htod(self, dest, src):
|
|
326
|
+
"""a simple memcpy copying from a numpy array to an Argument
|
|
316
327
|
|
|
328
|
+
:param dest: An Argument for some memory allocation
|
|
329
|
+
:type dst: Argument
|
|
330
|
+
|
|
331
|
+
:param src: A numpy array containing the source data
|
|
332
|
+
:type src: numpy.ndarray
|
|
333
|
+
"""
|
|
334
|
+
dest.numpy[:] = src
|
|
317
335
|
|
|
318
336
|
def cleanup_lib(self):
|
|
319
337
|
""" unload the previously loaded shared library """
|