pyopencl 2024.2__cp312-cp312-macosx_10_14_x86_64.whl

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.

Potentially problematic release.


This version of pyopencl might be problematic. Click here for more details.

Files changed (122) hide show
  1. pyopencl/__init__.py +2393 -0
  2. pyopencl/_cl.cpython-312-darwin.so +0 -0
  3. pyopencl/_cluda.py +54 -0
  4. pyopencl/_mymako.py +14 -0
  5. pyopencl/algorithm.py +1444 -0
  6. pyopencl/array.py +3427 -0
  7. pyopencl/bitonic_sort.py +238 -0
  8. pyopencl/bitonic_sort_templates.py +594 -0
  9. pyopencl/cache.py +534 -0
  10. pyopencl/capture_call.py +176 -0
  11. pyopencl/characterize/__init__.py +433 -0
  12. pyopencl/characterize/performance.py +237 -0
  13. pyopencl/cl/pyopencl-airy.cl +324 -0
  14. pyopencl/cl/pyopencl-bessel-j-complex.cl +238 -0
  15. pyopencl/cl/pyopencl-bessel-j.cl +1084 -0
  16. pyopencl/cl/pyopencl-bessel-y.cl +435 -0
  17. pyopencl/cl/pyopencl-complex.h +303 -0
  18. pyopencl/cl/pyopencl-eval-tbl.cl +120 -0
  19. pyopencl/cl/pyopencl-hankel-complex.cl +444 -0
  20. pyopencl/cl/pyopencl-random123/array.h +325 -0
  21. pyopencl/cl/pyopencl-random123/openclfeatures.h +93 -0
  22. pyopencl/cl/pyopencl-random123/philox.cl +486 -0
  23. pyopencl/cl/pyopencl-random123/threefry.cl +864 -0
  24. pyopencl/clmath.py +280 -0
  25. pyopencl/clrandom.py +408 -0
  26. pyopencl/cltypes.py +137 -0
  27. pyopencl/compyte/__init__.py +0 -0
  28. pyopencl/compyte/array.py +214 -0
  29. pyopencl/compyte/dtypes.py +290 -0
  30. pyopencl/compyte/ndarray/__init__.py +0 -0
  31. pyopencl/compyte/ndarray/gen_elemwise.py +1907 -0
  32. pyopencl/compyte/ndarray/gen_reduction.py +1511 -0
  33. pyopencl/compyte/ndarray/setup_opencl.py +101 -0
  34. pyopencl/compyte/ndarray/test_gpu_elemwise.py +411 -0
  35. pyopencl/compyte/ndarray/test_gpu_ndarray.py +487 -0
  36. pyopencl/elementwise.py +1164 -0
  37. pyopencl/invoker.py +418 -0
  38. pyopencl/ipython_ext.py +68 -0
  39. pyopencl/reduction.py +780 -0
  40. pyopencl/scan.py +1898 -0
  41. pyopencl/tools.py +1513 -0
  42. pyopencl/version.py +3 -0
  43. pyopencl-2024.2.data/data/CITATION.cff +74 -0
  44. pyopencl-2024.2.data/data/LICENSE +282 -0
  45. pyopencl-2024.2.data/data/Makefile.in +21 -0
  46. pyopencl-2024.2.data/data/README.rst +70 -0
  47. pyopencl-2024.2.data/data/README_SETUP.txt +34 -0
  48. pyopencl-2024.2.data/data/aksetup_helper.py +1013 -0
  49. pyopencl-2024.2.data/data/configure.py +6 -0
  50. pyopencl-2024.2.data/data/contrib/cldis.py +91 -0
  51. pyopencl-2024.2.data/data/contrib/fortran-to-opencl/README +29 -0
  52. pyopencl-2024.2.data/data/contrib/fortran-to-opencl/translate.py +1441 -0
  53. pyopencl-2024.2.data/data/contrib/pyopencl.vim +84 -0
  54. pyopencl-2024.2.data/data/doc/Makefile +23 -0
  55. pyopencl-2024.2.data/data/doc/algorithm.rst +214 -0
  56. pyopencl-2024.2.data/data/doc/array.rst +305 -0
  57. pyopencl-2024.2.data/data/doc/conf.py +26 -0
  58. pyopencl-2024.2.data/data/doc/howto.rst +105 -0
  59. pyopencl-2024.2.data/data/doc/index.rst +137 -0
  60. pyopencl-2024.2.data/data/doc/make_constants.py +561 -0
  61. pyopencl-2024.2.data/data/doc/misc.rst +885 -0
  62. pyopencl-2024.2.data/data/doc/runtime.rst +51 -0
  63. pyopencl-2024.2.data/data/doc/runtime_const.rst +30 -0
  64. pyopencl-2024.2.data/data/doc/runtime_gl.rst +78 -0
  65. pyopencl-2024.2.data/data/doc/runtime_memory.rst +527 -0
  66. pyopencl-2024.2.data/data/doc/runtime_platform.rst +184 -0
  67. pyopencl-2024.2.data/data/doc/runtime_program.rst +364 -0
  68. pyopencl-2024.2.data/data/doc/runtime_queue.rst +182 -0
  69. pyopencl-2024.2.data/data/doc/subst.rst +36 -0
  70. pyopencl-2024.2.data/data/doc/tools.rst +4 -0
  71. pyopencl-2024.2.data/data/doc/types.rst +42 -0
  72. pyopencl-2024.2.data/data/examples/black-hole-accretion.py +2227 -0
  73. pyopencl-2024.2.data/data/examples/demo-struct-reduce.py +75 -0
  74. pyopencl-2024.2.data/data/examples/demo.py +39 -0
  75. pyopencl-2024.2.data/data/examples/demo_array.py +32 -0
  76. pyopencl-2024.2.data/data/examples/demo_array_svm.py +37 -0
  77. pyopencl-2024.2.data/data/examples/demo_elementwise.py +34 -0
  78. pyopencl-2024.2.data/data/examples/demo_elementwise_complex.py +53 -0
  79. pyopencl-2024.2.data/data/examples/demo_mandelbrot.py +183 -0
  80. pyopencl-2024.2.data/data/examples/demo_meta_codepy.py +56 -0
  81. pyopencl-2024.2.data/data/examples/demo_meta_template.py +55 -0
  82. pyopencl-2024.2.data/data/examples/dump-performance.py +38 -0
  83. pyopencl-2024.2.data/data/examples/dump-properties.py +86 -0
  84. pyopencl-2024.2.data/data/examples/gl_interop_demo.py +84 -0
  85. pyopencl-2024.2.data/data/examples/gl_particle_animation.py +218 -0
  86. pyopencl-2024.2.data/data/examples/ipython-demo.ipynb +203 -0
  87. pyopencl-2024.2.data/data/examples/median-filter.py +99 -0
  88. pyopencl-2024.2.data/data/examples/n-body.py +1070 -0
  89. pyopencl-2024.2.data/data/examples/narray.py +37 -0
  90. pyopencl-2024.2.data/data/examples/noisyImage.jpg +0 -0
  91. pyopencl-2024.2.data/data/examples/pi-monte-carlo.py +1166 -0
  92. pyopencl-2024.2.data/data/examples/svm.py +82 -0
  93. pyopencl-2024.2.data/data/examples/transpose.py +229 -0
  94. pyopencl-2024.2.data/data/pytest.ini +3 -0
  95. pyopencl-2024.2.data/data/src/bitlog.cpp +51 -0
  96. pyopencl-2024.2.data/data/src/bitlog.hpp +83 -0
  97. pyopencl-2024.2.data/data/src/clinfo_ext.h +134 -0
  98. pyopencl-2024.2.data/data/src/mempool.hpp +444 -0
  99. pyopencl-2024.2.data/data/src/pyopencl_ext.h +77 -0
  100. pyopencl-2024.2.data/data/src/tools.hpp +90 -0
  101. pyopencl-2024.2.data/data/src/wrap_cl.cpp +61 -0
  102. pyopencl-2024.2.data/data/src/wrap_cl.hpp +5853 -0
  103. pyopencl-2024.2.data/data/src/wrap_cl_part_1.cpp +369 -0
  104. pyopencl-2024.2.data/data/src/wrap_cl_part_2.cpp +702 -0
  105. pyopencl-2024.2.data/data/src/wrap_constants.cpp +1274 -0
  106. pyopencl-2024.2.data/data/src/wrap_helpers.hpp +213 -0
  107. pyopencl-2024.2.data/data/src/wrap_mempool.cpp +731 -0
  108. pyopencl-2024.2.data/data/test/add-vectors-32.spv +0 -0
  109. pyopencl-2024.2.data/data/test/add-vectors-64.spv +0 -0
  110. pyopencl-2024.2.data/data/test/empty-header.h +1 -0
  111. pyopencl-2024.2.data/data/test/test_algorithm.py +1180 -0
  112. pyopencl-2024.2.data/data/test/test_array.py +2392 -0
  113. pyopencl-2024.2.data/data/test/test_arrays_in_structs.py +100 -0
  114. pyopencl-2024.2.data/data/test/test_clmath.py +529 -0
  115. pyopencl-2024.2.data/data/test/test_clrandom.py +75 -0
  116. pyopencl-2024.2.data/data/test/test_enqueue_copy.py +271 -0
  117. pyopencl-2024.2.data/data/test/test_wrapper.py +1554 -0
  118. pyopencl-2024.2.dist-info/LICENSE +282 -0
  119. pyopencl-2024.2.dist-info/METADATA +105 -0
  120. pyopencl-2024.2.dist-info/RECORD +122 -0
  121. pyopencl-2024.2.dist-info/WHEEL +5 -0
  122. pyopencl-2024.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,238 @@
1
+ __copyright__ = """
2
+ Copyright (c) 2011, Eric Bainville
3
+ Copyright (c) 2015, Ilya Efimoff
4
+ All rights reserved.
5
+ """
6
+
7
+ # based on code at http://www.bealto.com/gpu-sorting_intro.html
8
+
9
+ __license__ = """
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are met:
12
+
13
+ 1. Redistributions of source code must retain the above copyright notice, this
14
+ list of conditions and the following disclaimer.
15
+
16
+ 2. Redistributions in binary form must reproduce the above copyright notice,
17
+ this list of conditions and the following disclaimer in the documentation
18
+ and/or other materials provided with the distribution.
19
+
20
+ 3. Neither the name of the copyright holder nor the names of its contributors
21
+ may be used to endorse or promote products derived from this software without
22
+ specific prior written permission.
23
+
24
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ """
35
+
36
+ from functools import reduce
37
+ from operator import mul
38
+
39
+ from mako.template import Template
40
+ from pytools import memoize_method
41
+
42
+ import pyopencl as cl
43
+ import pyopencl.bitonic_sort_templates as _tmpl
44
+ from pyopencl.tools import dtype_to_ctype
45
+
46
+
47
+ def _is_power_of_2(n):
48
+ from pyopencl.tools import bitlog2
49
+ return n == 0 or 2**bitlog2(n) == n
50
+
51
+
52
+ class BitonicSort:
53
+ """Sort an array (or one axis of one) using a sorting network.
54
+
55
+ Will only work if the axis of the array to be sorted has a length
56
+ that is a power of 2.
57
+
58
+ .. versionadded:: 2015.2
59
+
60
+ .. seealso:: :class:`pyopencl.algorithm.RadixSort`
61
+
62
+ .. automethod:: __call__
63
+ """
64
+
65
+ kernels_srcs = {
66
+ "B2": _tmpl.ParallelBitonic_B2,
67
+ "B4": _tmpl.ParallelBitonic_B4,
68
+ "B8": _tmpl.ParallelBitonic_B8,
69
+ "B16": _tmpl.ParallelBitonic_B16,
70
+ "C4": _tmpl.ParallelBitonic_C4,
71
+ "BL": _tmpl.ParallelBitonic_Local,
72
+ "BLO": _tmpl.ParallelBitonic_Local_Optim,
73
+ "PML": _tmpl.ParallelMerge_Local
74
+ }
75
+
76
+ def __init__(self, context):
77
+ self.context = context
78
+
79
+ def __call__(self, arr, idx=None, queue=None, wait_for=None, axis=0):
80
+ """
81
+ :arg arr: the array to be sorted. Will be overwritten with the sorted array.
82
+ :arg idx: an array of indices to be tracked along with the sorting of *arr*
83
+ :arg queue: a :class:`pyopencl.CommandQueue`, defaults to the array's queue
84
+ if None
85
+ :arg wait_for: a list of :class:`pyopencl.Event` instances or None
86
+ :arg axis: the axis of the array by which to sort
87
+
88
+ :returns: a tuple (sorted_array, event)
89
+ """
90
+
91
+ if queue is None:
92
+ queue = arr.queue
93
+
94
+ if wait_for is None:
95
+ wait_for = []
96
+ wait_for = wait_for + arr.events
97
+
98
+ last_evt = cl.enqueue_marker(queue, wait_for=wait_for)
99
+
100
+ if arr.shape[axis] == 0:
101
+ return arr, last_evt
102
+
103
+ if not _is_power_of_2(arr.shape[axis]):
104
+ raise ValueError("sorted array axis length must be a power of 2")
105
+
106
+ if idx is None:
107
+ argsort = 0
108
+ else:
109
+ argsort = 1
110
+
111
+ run_queue = self.sort_b_prepare_wl(
112
+ argsort,
113
+ arr.dtype,
114
+ idx.dtype if idx is not None else None, arr.shape,
115
+ axis)
116
+
117
+ knl, nt, wg, aux = run_queue[0]
118
+
119
+ if idx is not None:
120
+ if aux:
121
+ last_evt = knl(
122
+ queue, (nt,), wg, arr.data, idx.data,
123
+ cl.LocalMemory(
124
+ _tmpl.LOCAL_MEM_FACTOR*wg[0]*arr.dtype.itemsize),
125
+ cl.LocalMemory(
126
+ _tmpl.LOCAL_MEM_FACTOR*wg[0]*idx.dtype.itemsize),
127
+ wait_for=[last_evt])
128
+ for knl, nt, wg, _ in run_queue[1:]:
129
+ last_evt = knl(
130
+ queue, (nt,), wg, arr.data, idx.data,
131
+ wait_for=[last_evt])
132
+
133
+ else:
134
+ if aux:
135
+ last_evt = knl(
136
+ queue, (nt,), wg, arr.data,
137
+ cl.LocalMemory(
138
+ _tmpl.LOCAL_MEM_FACTOR*wg[0]*4*arr.dtype.itemsize),
139
+ wait_for=[last_evt])
140
+ for knl, nt, wg, _ in run_queue[1:]:
141
+ last_evt = knl(queue, (nt,), wg, arr.data, wait_for=[last_evt])
142
+
143
+ return arr, last_evt
144
+
145
+ @memoize_method
146
+ def get_program(self, letter, argsort, params):
147
+ defstpl = Template(_tmpl.defines)
148
+
149
+ defs = defstpl.render(
150
+ NS="\\", argsort=argsort, inc=params[0], dir=params[1],
151
+ dtype=params[2], idxtype=params[3],
152
+ dsize=params[4], nsize=params[5])
153
+
154
+ kid = Template(self.kernels_srcs[letter]).render(argsort=argsort)
155
+
156
+ prg = cl.Program(self.context, defs + kid).build()
157
+ return prg
158
+
159
+ @memoize_method
160
+ def sort_b_prepare_wl(self, argsort, key_dtype, idx_dtype, shape, axis):
161
+ key_ctype = dtype_to_ctype(key_dtype)
162
+
163
+ if idx_dtype is None:
164
+ idx_ctype = "uint" # Dummy
165
+
166
+ else:
167
+ idx_ctype = dtype_to_ctype(idx_dtype)
168
+
169
+ run_queue = []
170
+ ds = int(shape[axis])
171
+ size = reduce(mul, shape)
172
+ ndim = len(shape)
173
+
174
+ ns = reduce(mul, shape[(axis+1):]) if axis < ndim-1 else 1
175
+
176
+ ds = int(shape[axis])
177
+ allowb4 = True
178
+ allowb8 = True
179
+ allowb16 = True
180
+
181
+ dev = self.context.devices[0]
182
+
183
+ # {{{ find workgroup size
184
+
185
+ wg = min(ds, dev.max_work_group_size)
186
+
187
+ available_lmem = dev.local_mem_size
188
+ while True:
189
+ lmem_size = _tmpl.LOCAL_MEM_FACTOR*wg*key_dtype.itemsize
190
+ if argsort:
191
+ lmem_size += _tmpl.LOCAL_MEM_FACTOR*wg*idx_dtype.itemsize
192
+
193
+ if lmem_size + 512 > available_lmem:
194
+ wg //= 2
195
+
196
+ if not wg:
197
+ raise RuntimeError(
198
+ "too little local memory available on '%s'"
199
+ % dev)
200
+
201
+ else:
202
+ break
203
+
204
+ # }}}
205
+
206
+ length = wg >> 1
207
+ prg = self.get_program(
208
+ "BLO", argsort, (1, 1, key_ctype, idx_ctype, ds, ns))
209
+ run_queue.append((prg.run, size, (wg,), True))
210
+
211
+ while length < ds:
212
+ inc = length
213
+ while inc > 0:
214
+ ninc = 0
215
+ direction = length << 1
216
+ if allowb16 and inc >= 8 and ninc == 0:
217
+ letter = "B16"
218
+ ninc = 4
219
+ elif allowb8 and inc >= 4 and ninc == 0:
220
+ letter = "B8"
221
+ ninc = 3
222
+ elif allowb4 and inc >= 2 and ninc == 0:
223
+ letter = "B4"
224
+ ninc = 2
225
+ elif inc >= 0:
226
+ letter = "B2"
227
+ ninc = 1
228
+
229
+ nthreads = size >> ninc
230
+
231
+ prg = self.get_program(letter, argsort,
232
+ (inc, direction, key_ctype, idx_ctype, ds, ns))
233
+ run_queue.append((prg.run, nthreads, None, False,))
234
+ inc >>= ninc
235
+
236
+ length <<= 1
237
+
238
+ return run_queue