kernel-tuner 0.2.0__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.
Files changed (47) hide show
  1. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/PKG-INFO +19 -14
  2. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/README.rst +12 -8
  3. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/c.py +60 -50
  4. kernel_tuner-0.3.0/kernel_tuner/core.py +497 -0
  5. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/cuda.py +120 -26
  6. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/interface.py +173 -126
  7. kernel_tuner-0.3.0/kernel_tuner/nvml.py +124 -0
  8. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/opencl.py +20 -16
  9. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/runners/sequential.py +31 -8
  10. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/strategies/basinhopping.py +5 -3
  11. kernel_tuner-0.3.0/kernel_tuner/strategies/bayes_opt.py +81 -0
  12. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/strategies/diff_evo.py +6 -4
  13. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/strategies/firefly_algorithm.py +6 -7
  14. kernel_tuner-0.3.0/kernel_tuner/strategies/genetic_algorithm.py +210 -0
  15. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/strategies/minimize.py +21 -23
  16. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/strategies/pso.py +3 -4
  17. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/strategies/random_sample.py +3 -1
  18. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/strategies/simulated_annealing.py +1 -2
  19. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/util.py +167 -75
  20. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner.egg-info/PKG-INFO +19 -14
  21. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner.egg-info/SOURCES.txt +3 -2
  22. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner.egg-info/requires.txt +3 -1
  23. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/setup.py +13 -7
  24. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/test/test_c_functions.py +49 -12
  25. kernel_tuner-0.3.0/test/test_core.py +176 -0
  26. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/test/test_cuda_functions.py +4 -10
  27. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/test/test_cuda_mocked.py +41 -8
  28. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/test/test_interface.py +3 -27
  29. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/test/test_opencl_functions.py +3 -8
  30. kernel_tuner-0.3.0/test/test_runners.py +96 -0
  31. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/test/test_util_functions.py +122 -86
  32. kernel_tuner-0.2.0/kernel_tuner/core.py +0 -306
  33. kernel_tuner-0.2.0/kernel_tuner/runners/noodles.py +0 -122
  34. kernel_tuner-0.2.0/kernel_tuner/strategies/genetic_algorithm.py +0 -117
  35. kernel_tuner-0.2.0/test/test_device_interface.py +0 -50
  36. kernel_tuner-0.2.0/test/test_runners.py +0 -169
  37. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/LICENSE +0 -0
  38. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/MANIFEST.in +0 -0
  39. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/__init__.py +0 -0
  40. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/runners/__init__.py +0 -0
  41. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/strategies/__init__.py +0 -0
  42. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/strategies/brute_force.py +0 -0
  43. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner/wrappers.py +0 -0
  44. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner.egg-info/dependency_links.txt +0 -0
  45. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/kernel_tuner.egg-info/top_level.txt +0 -0
  46. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/setup.cfg +0 -0
  47. {kernel_tuner-0.2.0 → kernel_tuner-0.3.0}/test/test_minimize.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kernel_tuner
3
- Version: 0.2.0
4
- Summary: A simple CUDA/OpenCL kernel tuner in Python
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
@@ -9,7 +9,7 @@ License: Apache 2.0
9
9
  Description: Kernel Tuner
10
10
  ============
11
11
 
12
- |Build Status| |Codacy Badge| |Codacy Badge2| |PyPi Badge|
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
- method="Powell"``. For a full overview of the supported search strategies and methods please see the `user
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
- A scientific paper about Kernel Tuner has been accepted for publication, please cite
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
- .. |Codacy Badge| image:: https://api.codacy.com/project/badge/grade/016dc85044ab4d57b777449d93275608
178
- :target: https://www.codacy.com/app/b-vanwerkhoven/kernel_tuner
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: doc
206
+ Provides-Extra: cuda_opencl
202
207
  Provides-Extra: tutorial
208
+ Provides-Extra: cuda
203
209
  Provides-Extra: opencl
204
- Provides-Extra: doc
@@ -1,7 +1,7 @@
1
1
  Kernel Tuner
2
2
  ============
3
3
 
4
- |Build Status| |Codacy Badge| |Codacy Badge2| |PyPi Badge|
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
- method="Powell"``. For a full overview of the supported search strategies and methods please see the `user
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
- A scientific paper about Kernel Tuner has been accepted for publication, please cite
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
- .. |Codacy Badge| image:: https://api.codacy.com/project/badge/grade/016dc85044ab4d57b777449d93275608
170
- :target: https://www.codacy.com/app/b-vanwerkhoven/kernel_tuner
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
- Argument = namedtuple("Argument", ["type", "shape"])
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,28 +82,29 @@ 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.generic)):
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
- arg_info = Argument(dtype_str, arg.shape)
93
+ data = arg.copy()
89
94
  if isinstance(arg, numpy.ndarray):
90
95
  if dtype_str in dtype_map.keys():
91
- ctype_args[i] = arg.ctypes.data_as(C.POINTER(dtype_map[dtype_str]))
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
- ctype_args[i] = dtype_map[dtype_str](arg)
97
- self.arg_mapping[str(i)] = arg_info
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
108
  def compile(self, kernel_name, kernel_string):
102
109
  """call the C compiler to compile the kernel, return the function
103
110
 
@@ -127,17 +134,23 @@ class CFunctions(object):
127
134
  else:
128
135
  compiler_options.append("-fopenmp")
129
136
 
137
+ # TODO: Get suffix from KernelSources, and adapt the logic below
138
+
139
+ #select right suffix based on compiler
140
+ suffix = ".cc"
141
+
130
142
  #detect whether to use nvcc as default instead of g++, may overrule an explicitly passed g++
131
- if ("#include <cuda" in kernel_string) or ("__global__" in kernel_string):
143
+ if ("#include <cuda" in kernel_string) or ("cudaMemcpy" in kernel_string):
132
144
  if self.compiler == "g++" and self.nvcc_available:
133
145
  self.compiler = "nvcc"
134
146
 
135
- #select right suffix based on compiler
136
- suffix = ".cc"
147
+ #if contains device code suffix .cu is required by nvcc
148
+ if self.compiler == "nvcc" and "__global__" in kernel_string:
149
+ suffix = ".cu"
137
150
  if self.compiler in ["gfortran", "pgfortran", "ftn", "ifort"]:
138
151
  suffix = ".F90"
152
+
139
153
  if self.compiler == "nvcc":
140
- suffix = suffix[:-1] + "u"
141
154
  compiler_options = ["-Xcompiler=" + c for c in compiler_options]
142
155
 
143
156
  if ".c" in suffix:
@@ -169,7 +182,6 @@ class CFunctions(object):
169
182
  elif self.compiler == "pgfortran":
170
183
  kernel_name = match.group(1) + "_" + kernel_name + "_"
171
184
 
172
-
173
185
  try:
174
186
  write_file(source_file, kernel_string)
175
187
 
@@ -194,7 +206,7 @@ class CFunctions(object):
194
206
  return func
195
207
 
196
208
 
197
- def benchmark(self, func, c_args, threads, grid, times):
209
+ def benchmark(self, func, c_args, threads, grid):
198
210
  """runs the kernel repeatedly, returns averaged returned value
199
211
 
200
212
  The C function tuning is a little bit more flexible than direct CUDA
@@ -215,7 +227,7 @@ class CFunctions(object):
215
227
  :param c_args: A list of arguments to the function, order should match the
216
228
  order in the code. The list should be prepared using
217
229
  ready_argument_list().
218
- :type c_args: list()
230
+ :type c_args: list(Argument)
219
231
 
220
232
  :param threads: Ignored, but left as argument for now to have the same
221
233
  interface as CudaFunctions and OpenCLFunctions.
@@ -225,14 +237,11 @@ class CFunctions(object):
225
237
  interface as CudaFunctions and OpenCLFunctions.
226
238
  :type grid: any
227
239
 
228
- :param times: Return the execution time of all iterations.
229
- :type times: bool
230
-
231
- :returns: All execution times, if times=True, or a robust average for the
232
- kernel execution time.
233
- :rtype: float
240
+ :returns: All execution times.
241
+ :rtype: dict()
234
242
  """
235
- time = []
243
+ result = dict()
244
+ result["times"] = []
236
245
  for _ in range(self.iterations):
237
246
  value = self.run_kernel(func, c_args, threads, grid)
238
247
 
@@ -243,19 +252,13 @@ class CFunctions(object):
243
252
  #
244
253
  #The current, less than ideal, scheme uses the convention that a
245
254
  #negative time indicates a 'too many resources requested for launch'
255
+ #which Kernel Tuner can silently ignore
246
256
  if value < 0.0:
247
257
  raise Exception("too many resources requested for launch")
248
258
 
249
- time.append(value)
250
- time = sorted(time)
251
- if times:
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
-
259
+ result["times"].append(value)
260
+ result["time"] = numpy.mean(result["times"])
261
+ return result
259
262
 
260
263
  def run_kernel(self, func, c_args, threads, grid):
261
264
  """runs the kernel once, returns whatever the kernel returns
@@ -266,7 +269,7 @@ class CFunctions(object):
266
269
  :param c_args: A list of arguments to the function, order should match the
267
270
  order in the code. The list should be prepared using
268
271
  ready_argument_list().
269
- :type c_args: list()
272
+ :type c_args: list(Argument)
270
273
 
271
274
  :param threads: Ignored, but left as argument for now to have the same
272
275
  interface as CudaFunctions and OpenCLFunctions.
@@ -280,40 +283,47 @@ class CFunctions(object):
280
283
  :rtype: float
281
284
  """
282
285
  logging.debug("run_kernel")
283
- logging.debug("arguments=" + str([str(arg) for arg in c_args]))
286
+ logging.debug("arguments=" + str([str(arg.ctypes) for arg in c_args]))
284
287
 
285
- time = func(*c_args)
288
+ time = func(*[arg.ctypes for arg in c_args])
286
289
 
287
290
  return time
288
291
 
289
-
290
292
  def memset(self, allocation, value, size):
291
293
  """set the memory in allocation to the value in value
292
294
 
293
- :param allocation: A memory allocation unit
294
- :type allocation: pycuda.driver.DeviceAllocation
295
+ :param allocation: An Argument for some memory allocation unit
296
+ :type allocation: Argument
295
297
 
296
298
  :param value: The value to set the memory to
297
- :type value: a single 32-bit float or int
299
+ :type value: a single 8-bit unsigned int
298
300
 
299
301
  :param size: The size of to the allocation unit in bytes
300
302
  :type size: int
301
303
  """
302
- C.memset(allocation, value, size)
303
-
304
+ C.memset(allocation.ctypes, value, size)
304
305
 
305
306
  def memcpy_dtoh(self, dest, src):
306
- """a simple memcpy expects a ctypes pointer, returns a numpy array
307
+ """a simple memcpy copying from an Argument to a numpy array
307
308
 
308
309
  :param dest: A numpy array to store the data
309
310
  :type dest: numpy.ndarray
310
311
 
311
- :param src: A ctypes pointer to some memory allocation
312
- :type src: ctypes.pointer
312
+ :param src: An Argument for some memory allocation
313
+ :type src: Argument
313
314
  """
314
- arginfo = self.arg_mapping[str(src)]
315
- dest[:] = numpy.ctypeslib.as_array(src, shape=arginfo.shape)
315
+ dest[:] = src.numpy
316
+
317
+ def memcpy_htod(self, dest, src):
318
+ """a simple memcpy copying from a numpy array to an Argument
316
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
317
327
 
318
328
  def cleanup_lib(self):
319
329
  """ unload the previously loaded shared library """