numba-cuda 0.0.1__py3-none-any.whl → 0.0.13__py3-none-any.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.
Files changed (233) hide show
  1. _numba_cuda_redirector.pth +1 -0
  2. _numba_cuda_redirector.py +74 -0
  3. numba_cuda/VERSION +1 -0
  4. numba_cuda/__init__.py +5 -0
  5. numba_cuda/_version.py +19 -0
  6. numba_cuda/numba/cuda/__init__.py +22 -0
  7. numba_cuda/numba/cuda/api.py +526 -0
  8. numba_cuda/numba/cuda/api_util.py +30 -0
  9. numba_cuda/numba/cuda/args.py +77 -0
  10. numba_cuda/numba/cuda/cg.py +62 -0
  11. numba_cuda/numba/cuda/codegen.py +378 -0
  12. numba_cuda/numba/cuda/compiler.py +422 -0
  13. numba_cuda/numba/cuda/cpp_function_wrappers.cu +47 -0
  14. numba_cuda/numba/cuda/cuda_fp16.h +3631 -0
  15. numba_cuda/numba/cuda/cuda_fp16.hpp +2465 -0
  16. numba_cuda/numba/cuda/cuda_paths.py +258 -0
  17. numba_cuda/numba/cuda/cudadecl.py +806 -0
  18. numba_cuda/numba/cuda/cudadrv/__init__.py +9 -0
  19. numba_cuda/numba/cuda/cudadrv/devicearray.py +904 -0
  20. numba_cuda/numba/cuda/cudadrv/devices.py +248 -0
  21. numba_cuda/numba/cuda/cudadrv/driver.py +3201 -0
  22. numba_cuda/numba/cuda/cudadrv/drvapi.py +398 -0
  23. numba_cuda/numba/cuda/cudadrv/dummyarray.py +452 -0
  24. numba_cuda/numba/cuda/cudadrv/enums.py +607 -0
  25. numba_cuda/numba/cuda/cudadrv/error.py +36 -0
  26. numba_cuda/numba/cuda/cudadrv/libs.py +176 -0
  27. numba_cuda/numba/cuda/cudadrv/ndarray.py +20 -0
  28. numba_cuda/numba/cuda/cudadrv/nvrtc.py +260 -0
  29. numba_cuda/numba/cuda/cudadrv/nvvm.py +707 -0
  30. numba_cuda/numba/cuda/cudadrv/rtapi.py +10 -0
  31. numba_cuda/numba/cuda/cudadrv/runtime.py +142 -0
  32. numba_cuda/numba/cuda/cudaimpl.py +1055 -0
  33. numba_cuda/numba/cuda/cudamath.py +140 -0
  34. numba_cuda/numba/cuda/decorators.py +189 -0
  35. numba_cuda/numba/cuda/descriptor.py +33 -0
  36. numba_cuda/numba/cuda/device_init.py +89 -0
  37. numba_cuda/numba/cuda/deviceufunc.py +908 -0
  38. numba_cuda/numba/cuda/dispatcher.py +1057 -0
  39. numba_cuda/numba/cuda/errors.py +59 -0
  40. numba_cuda/numba/cuda/extending.py +7 -0
  41. numba_cuda/numba/cuda/initialize.py +13 -0
  42. numba_cuda/numba/cuda/intrinsic_wrapper.py +77 -0
  43. numba_cuda/numba/cuda/intrinsics.py +198 -0
  44. numba_cuda/numba/cuda/kernels/__init__.py +0 -0
  45. numba_cuda/numba/cuda/kernels/reduction.py +262 -0
  46. numba_cuda/numba/cuda/kernels/transpose.py +65 -0
  47. numba_cuda/numba/cuda/libdevice.py +3382 -0
  48. numba_cuda/numba/cuda/libdevicedecl.py +17 -0
  49. numba_cuda/numba/cuda/libdevicefuncs.py +1057 -0
  50. numba_cuda/numba/cuda/libdeviceimpl.py +83 -0
  51. numba_cuda/numba/cuda/mathimpl.py +448 -0
  52. numba_cuda/numba/cuda/models.py +48 -0
  53. numba_cuda/numba/cuda/nvvmutils.py +235 -0
  54. numba_cuda/numba/cuda/printimpl.py +86 -0
  55. numba_cuda/numba/cuda/random.py +292 -0
  56. numba_cuda/numba/cuda/simulator/__init__.py +38 -0
  57. numba_cuda/numba/cuda/simulator/api.py +110 -0
  58. numba_cuda/numba/cuda/simulator/compiler.py +9 -0
  59. numba_cuda/numba/cuda/simulator/cudadrv/__init__.py +2 -0
  60. numba_cuda/numba/cuda/simulator/cudadrv/devicearray.py +432 -0
  61. numba_cuda/numba/cuda/simulator/cudadrv/devices.py +117 -0
  62. numba_cuda/numba/cuda/simulator/cudadrv/driver.py +62 -0
  63. numba_cuda/numba/cuda/simulator/cudadrv/drvapi.py +4 -0
  64. numba_cuda/numba/cuda/simulator/cudadrv/dummyarray.py +4 -0
  65. numba_cuda/numba/cuda/simulator/cudadrv/error.py +6 -0
  66. numba_cuda/numba/cuda/simulator/cudadrv/libs.py +2 -0
  67. numba_cuda/numba/cuda/simulator/cudadrv/nvvm.py +29 -0
  68. numba_cuda/numba/cuda/simulator/cudadrv/runtime.py +19 -0
  69. numba_cuda/numba/cuda/simulator/kernel.py +308 -0
  70. numba_cuda/numba/cuda/simulator/kernelapi.py +495 -0
  71. numba_cuda/numba/cuda/simulator/reduction.py +15 -0
  72. numba_cuda/numba/cuda/simulator/vector_types.py +58 -0
  73. numba_cuda/numba/cuda/simulator_init.py +17 -0
  74. numba_cuda/numba/cuda/stubs.py +902 -0
  75. numba_cuda/numba/cuda/target.py +440 -0
  76. numba_cuda/numba/cuda/testing.py +202 -0
  77. numba_cuda/numba/cuda/tests/__init__.py +58 -0
  78. numba_cuda/numba/cuda/tests/cudadrv/__init__.py +8 -0
  79. numba_cuda/numba/cuda/tests/cudadrv/test_array_attr.py +145 -0
  80. numba_cuda/numba/cuda/tests/cudadrv/test_context_stack.py +145 -0
  81. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py +375 -0
  82. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_auto_context.py +21 -0
  83. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py +179 -0
  84. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_driver.py +235 -0
  85. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_libraries.py +22 -0
  86. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_memory.py +193 -0
  87. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +547 -0
  88. numba_cuda/numba/cuda/tests/cudadrv/test_deallocations.py +249 -0
  89. numba_cuda/numba/cuda/tests/cudadrv/test_detect.py +81 -0
  90. numba_cuda/numba/cuda/tests/cudadrv/test_emm_plugins.py +192 -0
  91. numba_cuda/numba/cuda/tests/cudadrv/test_events.py +38 -0
  92. numba_cuda/numba/cuda/tests/cudadrv/test_host_alloc.py +65 -0
  93. numba_cuda/numba/cuda/tests/cudadrv/test_init.py +139 -0
  94. numba_cuda/numba/cuda/tests/cudadrv/test_inline_ptx.py +37 -0
  95. numba_cuda/numba/cuda/tests/cudadrv/test_is_fp16.py +12 -0
  96. numba_cuda/numba/cuda/tests/cudadrv/test_linker.py +317 -0
  97. numba_cuda/numba/cuda/tests/cudadrv/test_managed_alloc.py +127 -0
  98. numba_cuda/numba/cuda/tests/cudadrv/test_mvc.py +54 -0
  99. numba_cuda/numba/cuda/tests/cudadrv/test_nvvm_driver.py +199 -0
  100. numba_cuda/numba/cuda/tests/cudadrv/test_pinned.py +37 -0
  101. numba_cuda/numba/cuda/tests/cudadrv/test_profiler.py +20 -0
  102. numba_cuda/numba/cuda/tests/cudadrv/test_ptds.py +149 -0
  103. numba_cuda/numba/cuda/tests/cudadrv/test_reset_device.py +36 -0
  104. numba_cuda/numba/cuda/tests/cudadrv/test_runtime.py +85 -0
  105. numba_cuda/numba/cuda/tests/cudadrv/test_select_device.py +41 -0
  106. numba_cuda/numba/cuda/tests/cudadrv/test_streams.py +122 -0
  107. numba_cuda/numba/cuda/tests/cudapy/__init__.py +8 -0
  108. numba_cuda/numba/cuda/tests/cudapy/cache_usecases.py +234 -0
  109. numba_cuda/numba/cuda/tests/cudapy/cache_with_cpu_usecases.py +41 -0
  110. numba_cuda/numba/cuda/tests/cudapy/extensions_usecases.py +58 -0
  111. numba_cuda/numba/cuda/tests/cudapy/jitlink.ptx +30 -0
  112. numba_cuda/numba/cuda/tests/cudapy/recursion_usecases.py +100 -0
  113. numba_cuda/numba/cuda/tests/cudapy/test_alignment.py +42 -0
  114. numba_cuda/numba/cuda/tests/cudapy/test_array.py +260 -0
  115. numba_cuda/numba/cuda/tests/cudapy/test_array_args.py +201 -0
  116. numba_cuda/numba/cuda/tests/cudapy/test_array_methods.py +35 -0
  117. numba_cuda/numba/cuda/tests/cudapy/test_atomics.py +1620 -0
  118. numba_cuda/numba/cuda/tests/cudapy/test_blackscholes.py +120 -0
  119. numba_cuda/numba/cuda/tests/cudapy/test_boolean.py +24 -0
  120. numba_cuda/numba/cuda/tests/cudapy/test_caching.py +545 -0
  121. numba_cuda/numba/cuda/tests/cudapy/test_casting.py +257 -0
  122. numba_cuda/numba/cuda/tests/cudapy/test_cffi.py +33 -0
  123. numba_cuda/numba/cuda/tests/cudapy/test_compiler.py +276 -0
  124. numba_cuda/numba/cuda/tests/cudapy/test_complex.py +296 -0
  125. numba_cuda/numba/cuda/tests/cudapy/test_complex_kernel.py +20 -0
  126. numba_cuda/numba/cuda/tests/cudapy/test_const_string.py +129 -0
  127. numba_cuda/numba/cuda/tests/cudapy/test_constmem.py +176 -0
  128. numba_cuda/numba/cuda/tests/cudapy/test_cooperative_groups.py +147 -0
  129. numba_cuda/numba/cuda/tests/cudapy/test_cuda_array_interface.py +435 -0
  130. numba_cuda/numba/cuda/tests/cudapy/test_cuda_jit_no_types.py +90 -0
  131. numba_cuda/numba/cuda/tests/cudapy/test_datetime.py +94 -0
  132. numba_cuda/numba/cuda/tests/cudapy/test_debug.py +101 -0
  133. numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py +221 -0
  134. numba_cuda/numba/cuda/tests/cudapy/test_device_func.py +222 -0
  135. numba_cuda/numba/cuda/tests/cudapy/test_dispatcher.py +700 -0
  136. numba_cuda/numba/cuda/tests/cudapy/test_enums.py +121 -0
  137. numba_cuda/numba/cuda/tests/cudapy/test_errors.py +79 -0
  138. numba_cuda/numba/cuda/tests/cudapy/test_exception.py +174 -0
  139. numba_cuda/numba/cuda/tests/cudapy/test_extending.py +155 -0
  140. numba_cuda/numba/cuda/tests/cudapy/test_fastmath.py +244 -0
  141. numba_cuda/numba/cuda/tests/cudapy/test_forall.py +52 -0
  142. numba_cuda/numba/cuda/tests/cudapy/test_freevar.py +29 -0
  143. numba_cuda/numba/cuda/tests/cudapy/test_frexp_ldexp.py +66 -0
  144. numba_cuda/numba/cuda/tests/cudapy/test_globals.py +60 -0
  145. numba_cuda/numba/cuda/tests/cudapy/test_gufunc.py +456 -0
  146. numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scalar.py +159 -0
  147. numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +95 -0
  148. numba_cuda/numba/cuda/tests/cudapy/test_idiv.py +37 -0
  149. numba_cuda/numba/cuda/tests/cudapy/test_inspect.py +165 -0
  150. numba_cuda/numba/cuda/tests/cudapy/test_intrinsics.py +1106 -0
  151. numba_cuda/numba/cuda/tests/cudapy/test_ipc.py +318 -0
  152. numba_cuda/numba/cuda/tests/cudapy/test_iterators.py +99 -0
  153. numba_cuda/numba/cuda/tests/cudapy/test_lang.py +64 -0
  154. numba_cuda/numba/cuda/tests/cudapy/test_laplace.py +119 -0
  155. numba_cuda/numba/cuda/tests/cudapy/test_libdevice.py +187 -0
  156. numba_cuda/numba/cuda/tests/cudapy/test_lineinfo.py +199 -0
  157. numba_cuda/numba/cuda/tests/cudapy/test_localmem.py +164 -0
  158. numba_cuda/numba/cuda/tests/cudapy/test_mandel.py +37 -0
  159. numba_cuda/numba/cuda/tests/cudapy/test_math.py +786 -0
  160. numba_cuda/numba/cuda/tests/cudapy/test_matmul.py +74 -0
  161. numba_cuda/numba/cuda/tests/cudapy/test_minmax.py +113 -0
  162. numba_cuda/numba/cuda/tests/cudapy/test_montecarlo.py +22 -0
  163. numba_cuda/numba/cuda/tests/cudapy/test_multigpu.py +140 -0
  164. numba_cuda/numba/cuda/tests/cudapy/test_multiprocessing.py +46 -0
  165. numba_cuda/numba/cuda/tests/cudapy/test_multithreads.py +101 -0
  166. numba_cuda/numba/cuda/tests/cudapy/test_nondet.py +49 -0
  167. numba_cuda/numba/cuda/tests/cudapy/test_operator.py +401 -0
  168. numba_cuda/numba/cuda/tests/cudapy/test_optimization.py +86 -0
  169. numba_cuda/numba/cuda/tests/cudapy/test_overload.py +335 -0
  170. numba_cuda/numba/cuda/tests/cudapy/test_powi.py +124 -0
  171. numba_cuda/numba/cuda/tests/cudapy/test_print.py +128 -0
  172. numba_cuda/numba/cuda/tests/cudapy/test_py2_div_issue.py +33 -0
  173. numba_cuda/numba/cuda/tests/cudapy/test_random.py +104 -0
  174. numba_cuda/numba/cuda/tests/cudapy/test_record_dtype.py +610 -0
  175. numba_cuda/numba/cuda/tests/cudapy/test_recursion.py +125 -0
  176. numba_cuda/numba/cuda/tests/cudapy/test_reduction.py +76 -0
  177. numba_cuda/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py +83 -0
  178. numba_cuda/numba/cuda/tests/cudapy/test_serialize.py +85 -0
  179. numba_cuda/numba/cuda/tests/cudapy/test_slicing.py +37 -0
  180. numba_cuda/numba/cuda/tests/cudapy/test_sm.py +444 -0
  181. numba_cuda/numba/cuda/tests/cudapy/test_sm_creation.py +205 -0
  182. numba_cuda/numba/cuda/tests/cudapy/test_sync.py +271 -0
  183. numba_cuda/numba/cuda/tests/cudapy/test_transpose.py +80 -0
  184. numba_cuda/numba/cuda/tests/cudapy/test_ufuncs.py +277 -0
  185. numba_cuda/numba/cuda/tests/cudapy/test_userexc.py +47 -0
  186. numba_cuda/numba/cuda/tests/cudapy/test_vector_type.py +307 -0
  187. numba_cuda/numba/cuda/tests/cudapy/test_vectorize.py +283 -0
  188. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_complex.py +20 -0
  189. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_decor.py +69 -0
  190. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_device.py +36 -0
  191. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +37 -0
  192. numba_cuda/numba/cuda/tests/cudapy/test_warning.py +139 -0
  193. numba_cuda/numba/cuda/tests/cudapy/test_warp_ops.py +276 -0
  194. numba_cuda/numba/cuda/tests/cudasim/__init__.py +6 -0
  195. numba_cuda/numba/cuda/tests/cudasim/support.py +6 -0
  196. numba_cuda/numba/cuda/tests/cudasim/test_cudasim_issues.py +102 -0
  197. numba_cuda/numba/cuda/tests/data/__init__.py +0 -0
  198. numba_cuda/numba/cuda/tests/data/cuda_include.cu +5 -0
  199. numba_cuda/numba/cuda/tests/data/error.cu +7 -0
  200. numba_cuda/numba/cuda/tests/data/jitlink.cu +23 -0
  201. numba_cuda/numba/cuda/tests/data/jitlink.ptx +51 -0
  202. numba_cuda/numba/cuda/tests/data/warn.cu +7 -0
  203. numba_cuda/numba/cuda/tests/doc_examples/__init__.py +6 -0
  204. numba_cuda/numba/cuda/tests/doc_examples/ffi/__init__.py +0 -0
  205. numba_cuda/numba/cuda/tests/doc_examples/ffi/functions.cu +49 -0
  206. numba_cuda/numba/cuda/tests/doc_examples/test_cg.py +77 -0
  207. numba_cuda/numba/cuda/tests/doc_examples/test_cpu_gpu_compat.py +76 -0
  208. numba_cuda/numba/cuda/tests/doc_examples/test_ffi.py +82 -0
  209. numba_cuda/numba/cuda/tests/doc_examples/test_laplace.py +155 -0
  210. numba_cuda/numba/cuda/tests/doc_examples/test_matmul.py +173 -0
  211. numba_cuda/numba/cuda/tests/doc_examples/test_montecarlo.py +109 -0
  212. numba_cuda/numba/cuda/tests/doc_examples/test_random.py +59 -0
  213. numba_cuda/numba/cuda/tests/doc_examples/test_reduction.py +76 -0
  214. numba_cuda/numba/cuda/tests/doc_examples/test_sessionize.py +130 -0
  215. numba_cuda/numba/cuda/tests/doc_examples/test_ufunc.py +50 -0
  216. numba_cuda/numba/cuda/tests/doc_examples/test_vecadd.py +73 -0
  217. numba_cuda/numba/cuda/tests/nocuda/__init__.py +8 -0
  218. numba_cuda/numba/cuda/tests/nocuda/test_dummyarray.py +359 -0
  219. numba_cuda/numba/cuda/tests/nocuda/test_function_resolution.py +36 -0
  220. numba_cuda/numba/cuda/tests/nocuda/test_import.py +49 -0
  221. numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py +238 -0
  222. numba_cuda/numba/cuda/tests/nocuda/test_nvvm.py +54 -0
  223. numba_cuda/numba/cuda/types.py +37 -0
  224. numba_cuda/numba/cuda/ufuncs.py +662 -0
  225. numba_cuda/numba/cuda/vector_types.py +209 -0
  226. numba_cuda/numba/cuda/vectorizers.py +252 -0
  227. numba_cuda-0.0.13.dist-info/LICENSE +25 -0
  228. numba_cuda-0.0.13.dist-info/METADATA +69 -0
  229. numba_cuda-0.0.13.dist-info/RECORD +231 -0
  230. {numba_cuda-0.0.1.dist-info → numba_cuda-0.0.13.dist-info}/WHEEL +1 -1
  231. numba_cuda-0.0.1.dist-info/METADATA +0 -10
  232. numba_cuda-0.0.1.dist-info/RECORD +0 -5
  233. {numba_cuda-0.0.1.dist-info → numba_cuda-0.0.13.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,902 @@
1
+ """
2
+ This scripts specifies all PTX special objects.
3
+ """
4
+ import numpy as np
5
+ from collections import defaultdict
6
+ import functools
7
+ import itertools
8
+ from inspect import Signature, Parameter
9
+
10
+
11
+ class Stub(object):
12
+ '''
13
+ A stub object to represent special objects that are meaningless
14
+ outside the context of a CUDA kernel
15
+ '''
16
+ _description_ = '<ptx special value>'
17
+ __slots__ = () # don't allocate __dict__
18
+
19
+ def __new__(cls):
20
+ raise NotImplementedError("%s is not instantiable" % cls)
21
+
22
+ def __repr__(self):
23
+ return self._description_
24
+
25
+
26
+ def stub_function(fn):
27
+ '''
28
+ A stub function to represent special functions that are meaningless
29
+ outside the context of a CUDA kernel
30
+ '''
31
+ @functools.wraps(fn)
32
+ def wrapped(*args, **kwargs):
33
+ raise NotImplementedError("%s cannot be called from host code" % fn)
34
+ return wrapped
35
+
36
+
37
+ #-------------------------------------------------------------------------------
38
+ # Thread and grid indices and dimensions
39
+
40
+
41
+ class Dim3(Stub):
42
+ '''A triple, (x, y, z)'''
43
+ _description_ = '<Dim3>'
44
+
45
+ @property
46
+ def x(self):
47
+ pass
48
+
49
+ @property
50
+ def y(self):
51
+ pass
52
+
53
+ @property
54
+ def z(self):
55
+ pass
56
+
57
+
58
+ class threadIdx(Dim3):
59
+ '''
60
+ The thread indices in the current thread block. Each index is an integer
61
+ spanning the range from 0 inclusive to the corresponding value of the
62
+ attribute in :attr:`numba.cuda.blockDim` exclusive.
63
+ '''
64
+ _description_ = '<threadIdx.{x,y,z}>'
65
+
66
+
67
+ class blockIdx(Dim3):
68
+ '''
69
+ The block indices in the grid of thread blocks. Each index is an integer
70
+ spanning the range from 0 inclusive to the corresponding value of the
71
+ attribute in :attr:`numba.cuda.gridDim` exclusive.
72
+ '''
73
+ _description_ = '<blockIdx.{x,y,z}>'
74
+
75
+
76
+ class blockDim(Dim3):
77
+ '''
78
+ The shape of a block of threads, as declared when instantiating the kernel.
79
+ This value is the same for all threads in a given kernel launch, even if
80
+ they belong to different blocks (i.e. each block is "full").
81
+ '''
82
+ _description_ = '<blockDim.{x,y,z}>'
83
+
84
+
85
+ class gridDim(Dim3):
86
+ '''
87
+ The shape of the grid of blocks. This value is the same for all threads in
88
+ a given kernel launch.
89
+ '''
90
+ _description_ = '<gridDim.{x,y,z}>'
91
+
92
+
93
+ class warpsize(Stub):
94
+ '''
95
+ The size of a warp. All architectures implemented to date have a warp size
96
+ of 32.
97
+ '''
98
+ _description_ = '<warpsize>'
99
+
100
+
101
+ class laneid(Stub):
102
+ '''
103
+ This thread's lane within a warp. Ranges from 0 to
104
+ :attr:`numba.cuda.warpsize` - 1.
105
+ '''
106
+ _description_ = '<laneid>'
107
+
108
+
109
+ #-------------------------------------------------------------------------------
110
+ # Array creation
111
+
112
+ class shared(Stub):
113
+ '''
114
+ Shared memory namespace
115
+ '''
116
+ _description_ = '<shared>'
117
+
118
+ @stub_function
119
+ def array(shape, dtype):
120
+ '''
121
+ Allocate a shared array of the given *shape* and *type*. *shape* is
122
+ either an integer or a tuple of integers representing the array's
123
+ dimensions. *type* is a :ref:`Numba type <numba-types>` of the
124
+ elements needing to be stored in the array.
125
+
126
+ The returned array-like object can be read and written to like any
127
+ normal device array (e.g. through indexing).
128
+ '''
129
+
130
+
131
+ class local(Stub):
132
+ '''
133
+ Local memory namespace
134
+ '''
135
+ _description_ = '<local>'
136
+
137
+ @stub_function
138
+ def array(shape, dtype):
139
+ '''
140
+ Allocate a local array of the given *shape* and *type*. The array is
141
+ private to the current thread, and resides in global memory. An
142
+ array-like object is returned which can be read and written to like any
143
+ standard array (e.g. through indexing).
144
+ '''
145
+
146
+
147
+ class const(Stub):
148
+ '''
149
+ Constant memory namespace
150
+ '''
151
+
152
+ @stub_function
153
+ def array_like(ndarray):
154
+ '''
155
+ Create a const array from *ndarry*. The resulting const array will have
156
+ the same shape, type, and values as *ndarray*.
157
+ '''
158
+
159
+
160
+ # -------------------------------------------------------------------------------
161
+ # warp level operations
162
+
163
+ class syncwarp(Stub):
164
+ '''
165
+ syncwarp(mask=0xFFFFFFFF)
166
+
167
+ Synchronizes a masked subset of threads in a warp.
168
+ '''
169
+ _description_ = '<warp_sync()>'
170
+
171
+
172
+ class shfl_sync_intrinsic(Stub):
173
+ '''
174
+ shfl_sync_intrinsic(mask, mode, value, mode_offset, clamp)
175
+
176
+ Nvvm intrinsic for shuffling data across a warp
177
+ docs.nvidia.com/cuda/nvvm-ir-spec/index.html#nvvm-intrin-warp-level-datamove
178
+ '''
179
+ _description_ = '<shfl_sync()>'
180
+
181
+
182
+ class vote_sync_intrinsic(Stub):
183
+ '''
184
+ vote_sync_intrinsic(mask, mode, predictate)
185
+
186
+ Nvvm intrinsic for performing a reduce and broadcast across a warp
187
+ docs.nvidia.com/cuda/nvvm-ir-spec/index.html#nvvm-intrin-warp-level-vote
188
+ '''
189
+ _description_ = '<vote_sync()>'
190
+
191
+
192
+ class match_any_sync(Stub):
193
+ '''
194
+ match_any_sync(mask, value)
195
+
196
+ Nvvm intrinsic for performing a compare and broadcast across a warp.
197
+ Returns a mask of threads that have same value as the given value from
198
+ within the masked warp.
199
+ '''
200
+ _description_ = '<match_any_sync()>'
201
+
202
+
203
+ class match_all_sync(Stub):
204
+ '''
205
+ match_all_sync(mask, value)
206
+
207
+ Nvvm intrinsic for performing a compare and broadcast across a warp.
208
+ Returns a tuple of (mask, pred), where mask is a mask of threads that have
209
+ same value as the given value from within the masked warp, if they
210
+ all have the same value, otherwise it is 0. Pred is a boolean of whether
211
+ or not all threads in the mask warp have the same warp.
212
+ '''
213
+ _description_ = '<match_all_sync()>'
214
+
215
+
216
+ class activemask(Stub):
217
+ '''
218
+ activemask()
219
+
220
+ Returns a 32-bit integer mask of all currently active threads in the
221
+ calling warp. The Nth bit is set if the Nth lane in the warp is active when
222
+ activemask() is called. Inactive threads are represented by 0 bits in the
223
+ returned mask. Threads which have exited the kernel are always marked as
224
+ inactive.
225
+ '''
226
+ _description_ = '<activemask()>'
227
+
228
+
229
+ class lanemask_lt(Stub):
230
+ '''
231
+ lanemask_lt()
232
+
233
+ Returns a 32-bit integer mask of all lanes (including inactive ones) with
234
+ ID less than the current lane.
235
+ '''
236
+ _description_ = '<lanemask_lt()>'
237
+
238
+
239
+ # -------------------------------------------------------------------------------
240
+ # memory fences
241
+
242
+ class threadfence_block(Stub):
243
+ '''
244
+ A memory fence at thread block level
245
+ '''
246
+ _description_ = '<threadfence_block()>'
247
+
248
+
249
+ class threadfence_system(Stub):
250
+ '''
251
+ A memory fence at system level: across devices
252
+ '''
253
+ _description_ = '<threadfence_system()>'
254
+
255
+
256
+ class threadfence(Stub):
257
+ '''
258
+ A memory fence at device level
259
+ '''
260
+ _description_ = '<threadfence()>'
261
+
262
+
263
+ #-------------------------------------------------------------------------------
264
+ # bit manipulation
265
+
266
+ class popc(Stub):
267
+ """
268
+ popc(x)
269
+
270
+ Returns the number of set bits in x.
271
+ """
272
+
273
+
274
+ class brev(Stub):
275
+ """
276
+ brev(x)
277
+
278
+ Returns the reverse of the bit pattern of x. For example, 0b10110110
279
+ becomes 0b01101101.
280
+ """
281
+
282
+
283
+ class clz(Stub):
284
+ """
285
+ clz(x)
286
+
287
+ Returns the number of leading zeros in z.
288
+ """
289
+
290
+
291
+ class ffs(Stub):
292
+ """
293
+ ffs(x)
294
+
295
+ Returns the position of the first (least significant) bit set to 1 in x,
296
+ where the least significant bit position is 1. ffs(0) returns 0.
297
+ """
298
+
299
+
300
+ #-------------------------------------------------------------------------------
301
+ # comparison and selection instructions
302
+
303
+ class selp(Stub):
304
+ """
305
+ selp(a, b, c)
306
+
307
+ Select between source operands, based on the value of the predicate source
308
+ operand.
309
+ """
310
+
311
+
312
+ #-------------------------------------------------------------------------------
313
+ # single / double precision arithmetic
314
+
315
+ class fma(Stub):
316
+ """
317
+ fma(a, b, c)
318
+
319
+ Perform the fused multiply-add operation.
320
+ """
321
+
322
+
323
+ class cbrt(Stub):
324
+ """"
325
+ cbrt(a)
326
+
327
+ Perform the cube root operation.
328
+ """
329
+
330
+
331
+ #-------------------------------------------------------------------------------
332
+ # atomic
333
+
334
+ class atomic(Stub):
335
+ """Namespace for atomic operations
336
+ """
337
+ _description_ = '<atomic>'
338
+
339
+ class add(Stub):
340
+ """add(ary, idx, val)
341
+
342
+ Perform atomic ``ary[idx] += val``. Supported on int32, float32, and
343
+ float64 operands only.
344
+
345
+ Returns the old value at the index location as if it is loaded
346
+ atomically.
347
+ """
348
+
349
+ class sub(Stub):
350
+ """sub(ary, idx, val)
351
+
352
+ Perform atomic ``ary[idx] -= val``. Supported on int32, float32, and
353
+ float64 operands only.
354
+
355
+ Returns the old value at the index location as if it is loaded
356
+ atomically.
357
+ """
358
+
359
+ class and_(Stub):
360
+ """and_(ary, idx, val)
361
+
362
+ Perform atomic ``ary[idx] &= val``. Supported on int32, int64, uint32
363
+ and uint64 operands only.
364
+
365
+ Returns the old value at the index location as if it is loaded
366
+ atomically.
367
+ """
368
+
369
+ class or_(Stub):
370
+ """or_(ary, idx, val)
371
+
372
+ Perform atomic ``ary[idx] |= val``. Supported on int32, int64, uint32
373
+ and uint64 operands only.
374
+
375
+ Returns the old value at the index location as if it is loaded
376
+ atomically.
377
+ """
378
+
379
+ class xor(Stub):
380
+ """xor(ary, idx, val)
381
+
382
+ Perform atomic ``ary[idx] ^= val``. Supported on int32, int64, uint32
383
+ and uint64 operands only.
384
+
385
+ Returns the old value at the index location as if it is loaded
386
+ atomically.
387
+ """
388
+
389
+ class inc(Stub):
390
+ """inc(ary, idx, val)
391
+
392
+ Perform atomic ``ary[idx] += 1`` up to val, then reset to 0. Supported
393
+ on uint32, and uint64 operands only.
394
+
395
+ Returns the old value at the index location as if it is loaded
396
+ atomically.
397
+ """
398
+
399
+ class dec(Stub):
400
+ """dec(ary, idx, val)
401
+
402
+ Performs::
403
+
404
+ ary[idx] = (value if (array[idx] == 0) or
405
+ (array[idx] > value) else array[idx] - 1)
406
+
407
+ Supported on uint32, and uint64 operands only.
408
+
409
+ Returns the old value at the index location as if it is loaded
410
+ atomically.
411
+ """
412
+
413
+ class exch(Stub):
414
+ """exch(ary, idx, val)
415
+
416
+ Perform atomic ``ary[idx] = val``. Supported on int32, int64, uint32 and
417
+ uint64 operands only.
418
+
419
+ Returns the old value at the index location as if it is loaded
420
+ atomically.
421
+ """
422
+
423
+ class max(Stub):
424
+ """max(ary, idx, val)
425
+
426
+ Perform atomic ``ary[idx] = max(ary[idx], val)``.
427
+
428
+ Supported on int32, int64, uint32, uint64, float32, float64 operands
429
+ only.
430
+
431
+ Returns the old value at the index location as if it is loaded
432
+ atomically.
433
+ """
434
+
435
+ class min(Stub):
436
+ """min(ary, idx, val)
437
+
438
+ Perform atomic ``ary[idx] = min(ary[idx], val)``.
439
+
440
+ Supported on int32, int64, uint32, uint64, float32, float64 operands
441
+ only.
442
+
443
+ Returns the old value at the index location as if it is loaded
444
+ atomically.
445
+ """
446
+
447
+ class nanmax(Stub):
448
+ """nanmax(ary, idx, val)
449
+
450
+ Perform atomic ``ary[idx] = max(ary[idx], val)``.
451
+
452
+ NOTE: NaN is treated as a missing value such that:
453
+ nanmax(NaN, n) == n, nanmax(n, NaN) == n
454
+
455
+ Supported on int32, int64, uint32, uint64, float32, float64 operands
456
+ only.
457
+
458
+ Returns the old value at the index location as if it is loaded
459
+ atomically.
460
+ """
461
+
462
+ class nanmin(Stub):
463
+ """nanmin(ary, idx, val)
464
+
465
+ Perform atomic ``ary[idx] = min(ary[idx], val)``.
466
+
467
+ NOTE: NaN is treated as a missing value, such that:
468
+ nanmin(NaN, n) == n, nanmin(n, NaN) == n
469
+
470
+ Supported on int32, int64, uint32, uint64, float32, float64 operands
471
+ only.
472
+
473
+ Returns the old value at the index location as if it is loaded
474
+ atomically.
475
+ """
476
+
477
+ class compare_and_swap(Stub):
478
+ """compare_and_swap(ary, old, val)
479
+
480
+ Conditionally assign ``val`` to the first element of an 1D array ``ary``
481
+ if the current value matches ``old``.
482
+
483
+ Supported on int32, int64, uint32, uint64 operands only.
484
+
485
+ Returns the old value as if it is loaded atomically.
486
+ """
487
+
488
+ class cas(Stub):
489
+ """cas(ary, idx, old, val)
490
+
491
+ Conditionally assign ``val`` to the element ``idx`` of an array
492
+ ``ary`` if the current value of ``ary[idx]`` matches ``old``.
493
+
494
+ Supported on int32, int64, uint32, uint64 operands only.
495
+
496
+ Returns the old value as if it is loaded atomically.
497
+ """
498
+
499
+
500
+ #-------------------------------------------------------------------------------
501
+ # timers
502
+
503
+ class nanosleep(Stub):
504
+ '''
505
+ nanosleep(ns)
506
+
507
+ Suspends the thread for a sleep duration approximately close to the delay
508
+ `ns`, specified in nanoseconds.
509
+ '''
510
+ _description_ = '<nansleep()>'
511
+
512
+ #-------------------------------------------------------------------------------
513
+ # Floating point 16
514
+
515
+
516
+ class fp16(Stub):
517
+ """Namespace for fp16 operations
518
+ """
519
+ _description_ = '<fp16>'
520
+
521
+ class hadd(Stub):
522
+ """hadd(a, b)
523
+
524
+ Perform fp16 addition, (a + b) in round to nearest mode. Supported
525
+ on fp16 operands only.
526
+
527
+ Returns the fp16 result of the addition.
528
+
529
+ """
530
+
531
+ class hsub(Stub):
532
+ """hsub(a, b)
533
+
534
+ Perform fp16 subtraction, (a - b) in round to nearest mode. Supported
535
+ on fp16 operands only.
536
+
537
+ Returns the fp16 result of the subtraction.
538
+
539
+ """
540
+
541
+ class hmul(Stub):
542
+ """hmul(a, b)
543
+
544
+ Perform fp16 multiplication, (a * b) in round to nearest mode. Supported
545
+ on fp16 operands only.
546
+
547
+ Returns the fp16 result of the multiplication.
548
+
549
+ """
550
+
551
+ class hdiv(Stub):
552
+ """hdiv(a, b)
553
+
554
+ Perform fp16 division, (a / b) in round to nearest mode. Supported
555
+ on fp16 operands only.
556
+
557
+ Returns the fp16 result of the division
558
+
559
+ """
560
+
561
+ class hfma(Stub):
562
+ """hfma(a, b, c)
563
+
564
+ Perform fp16 multiply and accumulate, (a * b) + c in round to nearest
565
+ mode. Supported on fp16 operands only.
566
+
567
+ Returns the fp16 result of the multiplication.
568
+
569
+ """
570
+
571
+ class hneg(Stub):
572
+ """hneg(a)
573
+
574
+ Perform fp16 negation, -(a). Supported on fp16 operands only.
575
+
576
+ Returns the fp16 result of the negation.
577
+
578
+ """
579
+
580
+ class habs(Stub):
581
+ """habs(a)
582
+
583
+ Perform fp16 absolute value, |a|. Supported on fp16 operands only.
584
+
585
+ Returns the fp16 result of the absolute value.
586
+
587
+ """
588
+
589
+ class hsin(Stub):
590
+ """hsin(a)
591
+
592
+ Calculate sine in round to nearest even mode. Supported on fp16
593
+ operands only.
594
+
595
+ Returns the sine result.
596
+
597
+ """
598
+
599
+ class hcos(Stub):
600
+ """hsin(a)
601
+
602
+ Calculate cosine in round to nearest even mode. Supported on fp16
603
+ operands only.
604
+
605
+ Returns the cosine result.
606
+
607
+ """
608
+
609
+ class hlog(Stub):
610
+ """hlog(a)
611
+
612
+ Calculate natural logarithm in round to nearest even mode. Supported
613
+ on fp16 operands only.
614
+
615
+ Returns the natural logarithm result.
616
+
617
+ """
618
+
619
+ class hlog10(Stub):
620
+ """hlog10(a)
621
+
622
+ Calculate logarithm base 10 in round to nearest even mode. Supported
623
+ on fp16 operands only.
624
+
625
+ Returns the logarithm base 10 result.
626
+
627
+ """
628
+
629
+ class hlog2(Stub):
630
+ """hlog2(a)
631
+
632
+ Calculate logarithm base 2 in round to nearest even mode. Supported
633
+ on fp16 operands only.
634
+
635
+ Returns the logarithm base 2 result.
636
+
637
+ """
638
+
639
+ class hexp(Stub):
640
+ """hexp(a)
641
+
642
+ Calculate natural exponential, exp(a), in round to nearest mode.
643
+ Supported on fp16 operands only.
644
+
645
+ Returns the natural exponential result.
646
+
647
+ """
648
+
649
+ class hexp10(Stub):
650
+ """hexp10(a)
651
+
652
+ Calculate exponential base 10 (10 ** a) in round to nearest mode.
653
+ Supported on fp16 operands only.
654
+
655
+ Returns the exponential base 10 result.
656
+
657
+ """
658
+
659
+ class hexp2(Stub):
660
+ """hexp2(a)
661
+
662
+ Calculate exponential base 2 (2 ** a) in round to nearest mode.
663
+ Supported on fp16 operands only.
664
+
665
+ Returns the exponential base 2 result.
666
+
667
+ """
668
+
669
+ class hfloor(Stub):
670
+ """hfloor(a)
671
+
672
+ Calculate the floor, the largest integer less than or equal to 'a'.
673
+ Supported on fp16 operands only.
674
+
675
+ Returns the floor result.
676
+
677
+ """
678
+
679
+ class hceil(Stub):
680
+ """hceil(a)
681
+
682
+ Calculate the ceil, the smallest integer greater than or equal to 'a'.
683
+ Supported on fp16 operands only.
684
+
685
+ Returns the ceil result.
686
+
687
+ """
688
+
689
+ class hsqrt(Stub):
690
+ """hsqrt(a)
691
+
692
+ Calculate the square root of the input argument in round to nearest
693
+ mode. Supported on fp16 operands only.
694
+
695
+ Returns the square root result.
696
+
697
+ """
698
+
699
+ class hrsqrt(Stub):
700
+ """hrsqrt(a)
701
+
702
+ Calculate the reciprocal square root of the input argument in round
703
+ to nearest even mode. Supported on fp16 operands only.
704
+
705
+ Returns the reciprocal square root result.
706
+
707
+ """
708
+
709
+ class hrcp(Stub):
710
+ """hrcp(a)
711
+
712
+ Calculate the reciprocal of the input argument in round to nearest
713
+ even mode. Supported on fp16 operands only.
714
+
715
+ Returns the reciprocal result.
716
+
717
+ """
718
+
719
+ class hrint(Stub):
720
+ """hrint(a)
721
+
722
+ Round the input argument to nearest integer value. Supported on fp16
723
+ operands only.
724
+
725
+ Returns the rounded result.
726
+
727
+ """
728
+
729
+ class htrunc(Stub):
730
+ """htrunc(a)
731
+
732
+ Truncate the input argument to its integer portion. Supported
733
+ on fp16 operands only.
734
+
735
+ Returns the truncated result.
736
+
737
+ """
738
+
739
+ class heq(Stub):
740
+ """heq(a, b)
741
+
742
+ Perform fp16 comparison, (a == b). Supported
743
+ on fp16 operands only.
744
+
745
+ Returns True if a and b are equal and False otherwise.
746
+
747
+ """
748
+
749
+ class hne(Stub):
750
+ """hne(a, b)
751
+
752
+ Perform fp16 comparison, (a != b). Supported
753
+ on fp16 operands only.
754
+
755
+ Returns True if a and b are not equal and False otherwise.
756
+
757
+ """
758
+
759
+ class hge(Stub):
760
+ """hge(a, b)
761
+
762
+ Perform fp16 comparison, (a >= b). Supported
763
+ on fp16 operands only.
764
+
765
+ Returns True if a is >= b and False otherwise.
766
+
767
+ """
768
+
769
+ class hgt(Stub):
770
+ """hgt(a, b)
771
+
772
+ Perform fp16 comparison, (a > b). Supported
773
+ on fp16 operands only.
774
+
775
+ Returns True if a is > b and False otherwise.
776
+
777
+ """
778
+
779
+ class hle(Stub):
780
+ """hle(a, b)
781
+
782
+ Perform fp16 comparison, (a <= b). Supported
783
+ on fp16 operands only.
784
+
785
+ Returns True if a is <= b and False otherwise.
786
+
787
+ """
788
+
789
+ class hlt(Stub):
790
+ """hlt(a, b)
791
+
792
+ Perform fp16 comparison, (a < b). Supported
793
+ on fp16 operands only.
794
+
795
+ Returns True if a is < b and False otherwise.
796
+
797
+ """
798
+
799
+ class hmax(Stub):
800
+ """hmax(a, b)
801
+
802
+ Perform fp16 maximum operation, max(a,b) Supported
803
+ on fp16 operands only.
804
+
805
+ Returns a if a is greater than b, returns b otherwise.
806
+
807
+ """
808
+
809
+ class hmin(Stub):
810
+ """hmin(a, b)
811
+
812
+ Perform fp16 minimum operation, min(a,b). Supported
813
+ on fp16 operands only.
814
+
815
+ Returns a if a is less than b, returns b otherwise.
816
+
817
+ """
818
+
819
+
820
+ #-------------------------------------------------------------------------------
821
+ # vector types
822
+
823
+ def make_vector_type_stubs():
824
+ """Make user facing objects for vector types"""
825
+ vector_type_stubs = []
826
+ vector_type_prefix = (
827
+ "int8",
828
+ "int16",
829
+ "int32",
830
+ "int64",
831
+ "uint8",
832
+ "uint16",
833
+ "uint32",
834
+ "uint64",
835
+ "float32",
836
+ "float64"
837
+ )
838
+ vector_type_element_counts = (1, 2, 3, 4)
839
+ vector_type_attribute_names = ("x", "y", "z", "w")
840
+
841
+ for prefix, nelem in itertools.product(
842
+ vector_type_prefix, vector_type_element_counts
843
+ ):
844
+ type_name = f"{prefix}x{nelem}"
845
+ attr_names = vector_type_attribute_names[:nelem]
846
+
847
+ vector_type_stub = type(
848
+ type_name, (Stub,),
849
+ {
850
+ **{attr: lambda self: None for attr in attr_names},
851
+ **{
852
+ "_description_": f"<{type_name}>",
853
+ "__signature__": Signature(parameters=[
854
+ Parameter(
855
+ name=attr_name, kind=Parameter.POSITIONAL_ONLY
856
+ ) for attr_name in attr_names[:nelem]
857
+ ]),
858
+ "__doc__": f"A stub for {type_name} to be used in "
859
+ "CUDA kernels."
860
+ },
861
+ **{"aliases": []}
862
+ }
863
+ )
864
+ vector_type_stubs.append(vector_type_stub)
865
+ return vector_type_stubs
866
+
867
+
868
+ def map_vector_type_stubs_to_alias(vector_type_stubs):
869
+ """For each of the stubs, create its aliases.
870
+
871
+ For example: float64x3 -> double3
872
+ """
873
+ # C-compatible type mapping, see:
874
+ # https://numpy.org/devdocs/reference/arrays.scalars.html#integer-types
875
+ base_type_to_alias = {
876
+ "char": f"int{np.dtype(np.byte).itemsize * 8}",
877
+ "short": f"int{np.dtype(np.short).itemsize * 8}",
878
+ "int": f"int{np.dtype(np.intc).itemsize * 8}",
879
+ "long": f"int{np.dtype(np.int_).itemsize * 8}",
880
+ "longlong": f"int{np.dtype(np.longlong).itemsize * 8}",
881
+ "uchar": f"uint{np.dtype(np.ubyte).itemsize * 8}",
882
+ "ushort": f"uint{np.dtype(np.ushort).itemsize * 8}",
883
+ "uint": f"uint{np.dtype(np.uintc).itemsize * 8}",
884
+ "ulong": f"uint{np.dtype(np.uint).itemsize * 8}",
885
+ "ulonglong": f"uint{np.dtype(np.ulonglong).itemsize * 8}",
886
+ "float": f"float{np.dtype(np.single).itemsize * 8}",
887
+ "double": f"float{np.dtype(np.double).itemsize * 8}"
888
+ }
889
+
890
+ base_type_to_vector_type = defaultdict(list)
891
+ for stub in vector_type_stubs:
892
+ base_type_to_vector_type[stub.__name__[:-2]].append(stub)
893
+
894
+ for alias, base_type in base_type_to_alias.items():
895
+ vector_type_stubs = base_type_to_vector_type[base_type]
896
+ for stub in vector_type_stubs:
897
+ nelem = stub.__name__[-1]
898
+ stub.aliases.append(f"{alias}{nelem}")
899
+
900
+
901
+ _vector_type_stubs = make_vector_type_stubs()
902
+ map_vector_type_stubs_to_alias(_vector_type_stubs)