nvmath-python 0.9.0__cp314-cp314-win_amd64.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 (309) hide show
  1. nvmath/__init__.pxd +0 -0
  2. nvmath/__init__.py +45 -0
  3. nvmath/_internal/__init__.py +0 -0
  4. nvmath/_internal/attribute_ifc_factory.py +330 -0
  5. nvmath/_internal/layout.py +70 -0
  6. nvmath/_internal/templates.py +383 -0
  7. nvmath/_utils.py +150 -0
  8. nvmath/bindings/__init__.py +51 -0
  9. nvmath/bindings/_internal/__init__.pxd +0 -0
  10. nvmath/bindings/_internal/__init__.py +0 -0
  11. nvmath/bindings/_internal/cublas.cp314-win_amd64.pyd +0 -0
  12. nvmath/bindings/_internal/cublas.pxd +530 -0
  13. nvmath/bindings/_internal/cublasLt.cp314-win_amd64.pyd +0 -0
  14. nvmath/bindings/_internal/cublasLt.pxd +59 -0
  15. nvmath/bindings/_internal/cublasMp.pxd +52 -0
  16. nvmath/bindings/_internal/cudss.cp314-win_amd64.pyd +0 -0
  17. nvmath/bindings/_internal/cudss.pxd +47 -0
  18. nvmath/bindings/_internal/cufft.cp314-win_amd64.pyd +0 -0
  19. nvmath/bindings/_internal/cufft.pxd +70 -0
  20. nvmath/bindings/_internal/cufftMp.pxd +77 -0
  21. nvmath/bindings/_internal/curand.cp314-win_amd64.pyd +0 -0
  22. nvmath/bindings/_internal/curand.pxd +42 -0
  23. nvmath/bindings/_internal/cusolver.cp314-win_amd64.pyd +0 -0
  24. nvmath/bindings/_internal/cusolver.pxd +15 -0
  25. nvmath/bindings/_internal/cusolverDn.cp314-win_amd64.pyd +0 -0
  26. nvmath/bindings/_internal/cusolverDn.pxd +406 -0
  27. nvmath/bindings/_internal/cusparse.cp314-win_amd64.pyd +0 -0
  28. nvmath/bindings/_internal/cusparse.pxd +277 -0
  29. nvmath/bindings/_internal/cusparseLt.cp314-win_amd64.pyd +0 -0
  30. nvmath/bindings/_internal/cusparseLt.pxd +48 -0
  31. nvmath/bindings/_internal/cutensor.cp314-win_amd64.pyd +0 -0
  32. nvmath/bindings/_internal/cutensor.pxd +58 -0
  33. nvmath/bindings/_internal/mathdx.cp314-win_amd64.pyd +0 -0
  34. nvmath/bindings/_internal/mathdx.pxd +116 -0
  35. nvmath/bindings/_internal/nvshmem.pxd +29 -0
  36. nvmath/bindings/_internal/utils.cp314-win_amd64.pyd +0 -0
  37. nvmath/bindings/_internal/utils.pxd +179 -0
  38. nvmath/bindings/_internal/utils.pyi +10 -0
  39. nvmath/bindings/cublas.cp314-win_amd64.pyd +0 -0
  40. nvmath/bindings/cublas.pxd +558 -0
  41. nvmath/bindings/cublas.pyi +746 -0
  42. nvmath/bindings/cublasLt.cp314-win_amd64.pyd +0 -0
  43. nvmath/bindings/cublasLt.pxd +109 -0
  44. nvmath/bindings/cublasLt.pyi +1337 -0
  45. nvmath/bindings/cublasMp.pxd +85 -0
  46. nvmath/bindings/cublasMp.pyi +219 -0
  47. nvmath/bindings/cudss.cp314-win_amd64.pyd +0 -0
  48. nvmath/bindings/cudss.pxd +86 -0
  49. nvmath/bindings/cudss.pyi +282 -0
  50. nvmath/bindings/cufft.cp314-win_amd64.pyd +0 -0
  51. nvmath/bindings/cufft.pxd +118 -0
  52. nvmath/bindings/cufft.pyi +241 -0
  53. nvmath/bindings/cufftMp.pxd +124 -0
  54. nvmath/bindings/cufftMp.pyi +260 -0
  55. nvmath/bindings/curand.cp314-win_amd64.pyd +0 -0
  56. nvmath/bindings/curand.pxd +71 -0
  57. nvmath/bindings/curand.pyi +159 -0
  58. nvmath/bindings/cusolver.cp314-win_amd64.pyd +0 -0
  59. nvmath/bindings/cusolver.pxd +62 -0
  60. nvmath/bindings/cusolver.pyi +242 -0
  61. nvmath/bindings/cusolverDn.cp314-win_amd64.pyd +0 -0
  62. nvmath/bindings/cusolverDn.pxd +430 -0
  63. nvmath/bindings/cusolverDn.pyi +416 -0
  64. nvmath/bindings/cusparse.cp314-win_amd64.pyd +0 -0
  65. nvmath/bindings/cusparse.pxd +338 -0
  66. nvmath/bindings/cusparse.pyi +659 -0
  67. nvmath/bindings/cusparseLt.cp314-win_amd64.pyd +0 -0
  68. nvmath/bindings/cusparseLt.pxd +99 -0
  69. nvmath/bindings/cusparseLt.pyi +198 -0
  70. nvmath/bindings/cutensor.cp314-win_amd64.pyd +0 -0
  71. nvmath/bindings/cutensor.pxd +98 -0
  72. nvmath/bindings/cutensor.pyi +294 -0
  73. nvmath/bindings/cycublas.cp314-win_amd64.pyd +0 -0
  74. nvmath/bindings/cycublas.pxd +684 -0
  75. nvmath/bindings/cycublasLt.cp314-win_amd64.pyd +0 -0
  76. nvmath/bindings/cycublasLt.pxd +1055 -0
  77. nvmath/bindings/cycublasMp.pxd +183 -0
  78. nvmath/bindings/cycudss.cp314-win_amd64.pyd +0 -0
  79. nvmath/bindings/cycudss.pxd +224 -0
  80. nvmath/bindings/cycufft.cp314-win_amd64.pyd +0 -0
  81. nvmath/bindings/cycufft.pxd +326 -0
  82. nvmath/bindings/cycufftMp.pxd +334 -0
  83. nvmath/bindings/cycurand.cp314-win_amd64.pyd +0 -0
  84. nvmath/bindings/cycurand.pxd +146 -0
  85. nvmath/bindings/cycusolver.cp314-win_amd64.pyd +0 -0
  86. nvmath/bindings/cycusolver.pxd +154 -0
  87. nvmath/bindings/cycusolverDn.cp314-win_amd64.pyd +0 -0
  88. nvmath/bindings/cycusolverDn.pxd +446 -0
  89. nvmath/bindings/cycusparse.cp314-win_amd64.pyd +0 -0
  90. nvmath/bindings/cycusparse.pxd +470 -0
  91. nvmath/bindings/cycusparseLt.cp314-win_amd64.pyd +0 -0
  92. nvmath/bindings/cycusparseLt.pxd +150 -0
  93. nvmath/bindings/cycutensor.cp314-win_amd64.pyd +0 -0
  94. nvmath/bindings/cycutensor.pxd +192 -0
  95. nvmath/bindings/cymathdx.cp314-win_amd64.pyd +0 -0
  96. nvmath/bindings/cymathdx.pxd +552 -0
  97. nvmath/bindings/cynvshmem.pxd +126 -0
  98. nvmath/bindings/mathdx.cp314-win_amd64.pyd +0 -0
  99. nvmath/bindings/mathdx.pxd +182 -0
  100. nvmath/bindings/mathdx.pyi +1244 -0
  101. nvmath/bindings/nvpl/__init__.pxd +0 -0
  102. nvmath/bindings/nvpl/__init__.py +13 -0
  103. nvmath/bindings/nvpl/_internal/__init__.pxd +0 -0
  104. nvmath/bindings/nvpl/_internal/__init__.py +0 -0
  105. nvmath/bindings/nvpl/_internal/blas.cp314-win_amd64.pyd +0 -0
  106. nvmath/bindings/nvpl/_internal/blas.pxd +125 -0
  107. nvmath/bindings/nvpl/_internal/fft.cp314-win_amd64.pyd +0 -0
  108. nvmath/bindings/nvpl/_internal/fft.pxd +36 -0
  109. nvmath/bindings/nvpl/blas.cp314-win_amd64.pyd +0 -0
  110. nvmath/bindings/nvpl/blas.pxd +85 -0
  111. nvmath/bindings/nvpl/blas.pyi +122 -0
  112. nvmath/bindings/nvpl/cyblas.cp314-win_amd64.pyd +0 -0
  113. nvmath/bindings/nvpl/cyblas.pxd +166 -0
  114. nvmath/bindings/nvpl/cyfft.cp314-win_amd64.pyd +0 -0
  115. nvmath/bindings/nvpl/cyfft.pxd +92 -0
  116. nvmath/bindings/nvpl/fft.cp314-win_amd64.pyd +0 -0
  117. nvmath/bindings/nvpl/fft.pxd +100 -0
  118. nvmath/bindings/nvpl/fft.pyi +100 -0
  119. nvmath/bindings/nvshmem.pxd +54 -0
  120. nvmath/bindings/nvshmem.pyi +179 -0
  121. nvmath/device/__init__.py +21 -0
  122. nvmath/device/_deprecated.py +33 -0
  123. nvmath/device/common.py +313 -0
  124. nvmath/device/common_backend.py +131 -0
  125. nvmath/device/common_cuda.py +201 -0
  126. nvmath/device/common_numba.py +310 -0
  127. nvmath/device/common_opaque_tensor.py +201 -0
  128. nvmath/device/cublasdx.py +1805 -0
  129. nvmath/device/cublasdx_backend.py +807 -0
  130. nvmath/device/cublasdx_numba.py +1612 -0
  131. nvmath/device/cufftdx.py +510 -0
  132. nvmath/device/cufftdx_backend.py +196 -0
  133. nvmath/device/cufftdx_numba.py +196 -0
  134. nvmath/device/curand_kernel.py +9147 -0
  135. nvmath/device/cusolverdx.py +2690 -0
  136. nvmath/device/cusolverdx_backend.py +440 -0
  137. nvmath/device/cusolverdx_numba.py +1624 -0
  138. nvmath/device/llvm_array.py +29 -0
  139. nvmath/device/random.py +445 -0
  140. nvmath/device/random_helpers.py +23 -0
  141. nvmath/device/random_states.py +187 -0
  142. nvmath/device/types.py +147 -0
  143. nvmath/device/vector_types_numba.py +203 -0
  144. nvmath/distributed/__init__.py +205 -0
  145. nvmath/distributed/_internal/__init__.py +0 -0
  146. nvmath/distributed/_internal/nvshmem.py +302 -0
  147. nvmath/distributed/_internal/tensor_ifc.py +67 -0
  148. nvmath/distributed/_internal/tensor_ifc_cupy.py +62 -0
  149. nvmath/distributed/_internal/tensor_ifc_host_device.py +165 -0
  150. nvmath/distributed/_internal/tensor_ifc_numpy.py +41 -0
  151. nvmath/distributed/_internal/tensor_ifc_torch.py +141 -0
  152. nvmath/distributed/_internal/tensor_wrapper.py +78 -0
  153. nvmath/distributed/_utils.py +167 -0
  154. nvmath/distributed/distribution.py +770 -0
  155. nvmath/distributed/fft/__init__.py +7 -0
  156. nvmath/distributed/fft/_configuration.py +79 -0
  157. nvmath/distributed/fft/fft.py +2801 -0
  158. nvmath/distributed/linalg/__init__.py +12 -0
  159. nvmath/distributed/linalg/_internal/__init__.py +3 -0
  160. nvmath/distributed/linalg/_internal/epilog_protocol.py +496 -0
  161. nvmath/distributed/linalg/_internal/matmul_desc_ifc.py +28 -0
  162. nvmath/distributed/linalg/advanced/__init__.py +8 -0
  163. nvmath/distributed/linalg/advanced/_configuration.py +166 -0
  164. nvmath/distributed/linalg/advanced/matmulmod.py +2908 -0
  165. nvmath/distributed/process_group.py +408 -0
  166. nvmath/distributed/reshape/__init__.py +6 -0
  167. nvmath/distributed/reshape/_configuration.py +39 -0
  168. nvmath/distributed/reshape/reshape.py +1256 -0
  169. nvmath/fft/__init__.py +7 -0
  170. nvmath/fft/_configuration.py +208 -0
  171. nvmath/fft/_exec_utils.py +109 -0
  172. nvmath/fft/_helpers.py +237 -0
  173. nvmath/fft/fft.py +2903 -0
  174. nvmath/internal/__init__.pxd +3 -0
  175. nvmath/internal/__init__.py +10 -0
  176. nvmath/internal/_bindings.cp314-win_amd64.pyd +0 -0
  177. nvmath/internal/_bindings.pxd +12 -0
  178. nvmath/internal/_device_utils.py +54 -0
  179. nvmath/internal/enum_utils.py +142 -0
  180. nvmath/internal/formatters.py +87 -0
  181. nvmath/internal/mem_limit.py +51 -0
  182. nvmath/internal/memory.cp314-win_amd64.pyd +0 -0
  183. nvmath/internal/memory.pxd +10 -0
  184. nvmath/internal/memory.pyi +46 -0
  185. nvmath/internal/ndbuffer/__init__.pxd +3 -0
  186. nvmath/internal/ndbuffer/__init__.py +7 -0
  187. nvmath/internal/ndbuffer/copy_kernel/args.h +34 -0
  188. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/array_view.h +52 -0
  189. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/elementwise.h +68 -0
  190. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/grid_indexer.h +69 -0
  191. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/transposed.h +240 -0
  192. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/type_utils.h +39 -0
  193. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/utils.h +132 -0
  194. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/vec.h +159 -0
  195. nvmath/internal/ndbuffer/copy_kernel/elementwise.h +53 -0
  196. nvmath/internal/ndbuffer/copy_kernel/transposed.h +58 -0
  197. nvmath/internal/ndbuffer/copy_kernel.cp314-win_amd64.pyd +0 -0
  198. nvmath/internal/ndbuffer/copy_kernel.pxd +9 -0
  199. nvmath/internal/ndbuffer/copy_kernel.pyi +9 -0
  200. nvmath/internal/ndbuffer/data_layout.cp314-win_amd64.pyd +0 -0
  201. nvmath/internal/ndbuffer/data_layout.pxd +72 -0
  202. nvmath/internal/ndbuffer/data_layout.pyi +23 -0
  203. nvmath/internal/ndbuffer/jit.cp314-win_amd64.pyd +0 -0
  204. nvmath/internal/ndbuffer/jit.pxd +7 -0
  205. nvmath/internal/ndbuffer/jit.pyi +6 -0
  206. nvmath/internal/ndbuffer/ndbuffer.cp314-win_amd64.pyd +0 -0
  207. nvmath/internal/ndbuffer/ndbuffer.pxd +36 -0
  208. nvmath/internal/ndbuffer/ndbuffer.pyi +41 -0
  209. nvmath/internal/ndbuffer/package_utils.cp314-win_amd64.pyd +0 -0
  210. nvmath/internal/ndbuffer/package_utils.pxd +11 -0
  211. nvmath/internal/ndbuffer/package_utils.pyi +12 -0
  212. nvmath/internal/package_ifc.py +147 -0
  213. nvmath/internal/package_ifc_cuda.py +49 -0
  214. nvmath/internal/package_ifc_cupy.py +49 -0
  215. nvmath/internal/package_ifc_torch.py +31 -0
  216. nvmath/internal/package_wrapper.py +14 -0
  217. nvmath/internal/tensor_ifc.py +194 -0
  218. nvmath/internal/tensor_ifc_cupy.py +241 -0
  219. nvmath/internal/tensor_ifc_ndbuffer.py +153 -0
  220. nvmath/internal/tensor_ifc_numpy.py +183 -0
  221. nvmath/internal/tensor_ifc_torch.py +176 -0
  222. nvmath/internal/tensor_wrapper.py +157 -0
  223. nvmath/internal/typemaps.py +162 -0
  224. nvmath/internal/utils.py +771 -0
  225. nvmath/linalg/__init__.py +46 -0
  226. nvmath/linalg/_internal/__init__.py +3 -0
  227. nvmath/linalg/_internal/algo_cap_ifc.py +82 -0
  228. nvmath/linalg/_internal/algo_config_ifc.py +43 -0
  229. nvmath/linalg/_internal/batch.py +217 -0
  230. nvmath/linalg/_internal/enum_to_tuples.py +64 -0
  231. nvmath/linalg/_internal/epilog_protocol.py +766 -0
  232. nvmath/linalg/_internal/layout.py +624 -0
  233. nvmath/linalg/_internal/matmul_desc_ifc.py +28 -0
  234. nvmath/linalg/_internal/matmul_pref_ifc.py +27 -0
  235. nvmath/linalg/_internal/matrix_layout_ifc.py +26 -0
  236. nvmath/linalg/_internal/typemaps.py +144 -0
  237. nvmath/linalg/_internal/utils.py +134 -0
  238. nvmath/linalg/advanced/__init__.py +8 -0
  239. nvmath/linalg/advanced/_algorithmmod.py +149 -0
  240. nvmath/linalg/advanced/_configuration.py +349 -0
  241. nvmath/linalg/advanced/helpers/__init__.py +5 -0
  242. nvmath/linalg/advanced/helpers/matmul.py +1348 -0
  243. nvmath/linalg/advanced/matmulmod.py +3937 -0
  244. nvmath/linalg/generic/__init__.py +43 -0
  245. nvmath/linalg/generic/_configuration/__init__.py +37 -0
  246. nvmath/linalg/generic/_configuration/layout.py +263 -0
  247. nvmath/linalg/generic/_configuration/match.py +609 -0
  248. nvmath/linalg/generic/_configuration/qualifiers.py +494 -0
  249. nvmath/linalg/generic/_configuration/wrap.py +217 -0
  250. nvmath/linalg/generic/_dtype.py +15 -0
  251. nvmath/linalg/generic/matmulmod.py +1060 -0
  252. nvmath/memory.py +282 -0
  253. nvmath/sparse/__init__.py +38 -0
  254. nvmath/sparse/_internal/__init__.py +21 -0
  255. nvmath/sparse/_internal/common_utils.py +144 -0
  256. nvmath/sparse/_internal/cudss_config_ifc.py +741 -0
  257. nvmath/sparse/_internal/cudss_data_ifc.py +399 -0
  258. nvmath/sparse/_internal/cudss_utils.py +445 -0
  259. nvmath/sparse/_internal/cusparse_utils.py +382 -0
  260. nvmath/sparse/_internal/sparse_bsc_ifc.py +300 -0
  261. nvmath/sparse/_internal/sparse_bsr_ifc.py +303 -0
  262. nvmath/sparse/_internal/sparse_coo_ifc.py +254 -0
  263. nvmath/sparse/_internal/sparse_csc_ifc.py +266 -0
  264. nvmath/sparse/_internal/sparse_csr_ifc.py +266 -0
  265. nvmath/sparse/_internal/sparse_dia_ifc.py +239 -0
  266. nvmath/sparse/_internal/sparse_format_helpers.py +601 -0
  267. nvmath/sparse/_internal/sparse_tensor_ifc.py +121 -0
  268. nvmath/sparse/_internal/sparse_ust_ifc.py +146 -0
  269. nvmath/sparse/_internal/utils.py +56 -0
  270. nvmath/sparse/advanced/__init__.py +7 -0
  271. nvmath/sparse/advanced/_configuration.py +230 -0
  272. nvmath/sparse/advanced/direct_solver.py +1884 -0
  273. nvmath/sparse/generic/__init__.py +7 -0
  274. nvmath/sparse/generic/_configuration.py +129 -0
  275. nvmath/sparse/generic/_helpers.py +137 -0
  276. nvmath/sparse/generic/_thunks.py +21 -0
  277. nvmath/sparse/generic/matmulmod.py +2426 -0
  278. nvmath/sparse/ust/__init__.py +7 -0
  279. nvmath/sparse/ust/_converters.py +378 -0
  280. nvmath/sparse/ust/_drawer.py +552 -0
  281. nvmath/sparse/ust/_emitter.py +553 -0
  282. nvmath/sparse/ust/_jit.py +212 -0
  283. nvmath/sparse/ust/_kernel.py +346 -0
  284. nvmath/sparse/ust/_semiring.py +71 -0
  285. nvmath/sparse/ust/_utils.py +102 -0
  286. nvmath/sparse/ust/interfaces/__init__.py +0 -0
  287. nvmath/sparse/ust/interfaces/torch_interface.py +476 -0
  288. nvmath/sparse/ust/semiring_ops.py +71 -0
  289. nvmath/sparse/ust/tensor.py +1027 -0
  290. nvmath/sparse/ust/tensor_drawer.py +552 -0
  291. nvmath/sparse/ust/tensor_emitter.py +558 -0
  292. nvmath/sparse/ust/tensor_format.py +935 -0
  293. nvmath/sparse/ust/tensor_jit.py +212 -0
  294. nvmath/sparse/ust/tensor_kernel.py +348 -0
  295. nvmath/sparse/ust/tensor_utils.py +380 -0
  296. nvmath/tensor/__init__.py +6 -0
  297. nvmath/tensor/_configuration.py +95 -0
  298. nvmath/tensor/_internal/__init__.py +3 -0
  299. nvmath/tensor/_internal/cutensor_config_ifc.py +247 -0
  300. nvmath/tensor/_internal/cutensor_utils.py +162 -0
  301. nvmath/tensor/_internal/data.py +43 -0
  302. nvmath/tensor/_internal/einsum_parser.py +444 -0
  303. nvmath/tensor/_internal/typemaps.py +96 -0
  304. nvmath/tensor/contract.py +1861 -0
  305. nvmath_python-0.9.0.dist-info/METADATA +127 -0
  306. nvmath_python-0.9.0.dist-info/RECORD +309 -0
  307. nvmath_python-0.9.0.dist-info/WHEEL +5 -0
  308. nvmath_python-0.9.0.dist-info/licenses/LICENSE +177 -0
  309. nvmath_python-0.9.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,179 @@
1
+ # Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ import _cython_3_2_4
6
+ import enum
7
+ import numpy.dtypes
8
+ from _typeshed import Incomplete
9
+ from typing import Any, Callable, ClassVar
10
+
11
+ STATUS_FULL_MPG: int
12
+ STATUS_INVALID: int
13
+ STATUS_IS_BOOTSTRAPPED: int
14
+ STATUS_IS_INITIALIZED: int
15
+ STATUS_LIMITED_MPG: int
16
+ STATUS_NOT_INITIALIZED: int
17
+ TEAMS_MIN: int
18
+ TEAM_GPU_LEADERS: int
19
+ TEAM_GPU_LEADERS_INDEX: int
20
+ TEAM_INDEX_MAX: int
21
+ TEAM_INVALID: int
22
+ TEAM_NODE: int
23
+ TEAM_NODE_INDEX: int
24
+ TEAM_SAME_GPU: int
25
+ TEAM_SAME_GPU_INDEX: int
26
+ TEAM_SAME_MYPE_NODE: int
27
+ TEAM_SAME_MYPE_NODE_INDEX: int
28
+ TEAM_SHARED: int
29
+ TEAM_SHARED_INDEX: int
30
+ TEAM_WORLD: int
31
+ TEAM_WORLD_INDEX: int
32
+ __pyx_capi__: dict
33
+ __test__: dict
34
+ align: _cython_3_2_4.cython_function_or_method
35
+ barrier_all_on_stream: _cython_3_2_4.cython_function_or_method
36
+ calloc: _cython_3_2_4.cython_function_or_method
37
+ check_status: _cython_3_2_4.cython_function_or_method
38
+ free: _cython_3_2_4.cython_function_or_method
39
+ get_uniqueid: _cython_3_2_4.cython_function_or_method
40
+ hostlib_finalize: _cython_3_2_4.cython_function_or_method
41
+ hostlib_init_attr: _cython_3_2_4.cython_function_or_method
42
+ init_attr_dtype: numpy.dtypes.VoidDType
43
+ init_status: _cython_3_2_4.cython_function_or_method
44
+ int_p: _cython_3_2_4.cython_function_or_method
45
+ malloc: _cython_3_2_4.cython_function_or_method
46
+ my_pe: _cython_3_2_4.cython_function_or_method
47
+ n_pes: _cython_3_2_4.cython_function_or_method
48
+ ptr: _cython_3_2_4.cython_function_or_method
49
+ set_attr_uniqueid_args: _cython_3_2_4.cython_function_or_method
50
+ sync_all_on_stream: _cython_3_2_4.cython_function_or_method
51
+ team_my_pe: _cython_3_2_4.cython_function_or_method
52
+ uniqueid_dtype: numpy.dtypes.VoidDType
53
+
54
+ class Flags(enum.IntEnum):
55
+ """See `flags`."""
56
+ __new__: ClassVar[Callable] = ...
57
+ INIT_MAX: ClassVar[Flags] = ...
58
+ INIT_THREAD_PES: ClassVar[Flags] = ...
59
+ INIT_WITH_MPI_COMM: ClassVar[Flags] = ...
60
+ INIT_WITH_SHMEM: ClassVar[Flags] = ...
61
+ INIT_WITH_UNIQUEID: ClassVar[Flags] = ...
62
+ _generate_next_value_: ClassVar[Callable] = ...
63
+ _member_map_: ClassVar[dict] = ...
64
+ _member_names_: ClassVar[list] = ...
65
+ _member_type_: ClassVar[type[int]] = ...
66
+ _value2member_map_: ClassVar[dict] = ...
67
+
68
+ class InitAttr:
69
+ """InitAttr()"""
70
+ mpi_comm: Incomplete
71
+ ptr: Incomplete
72
+ version: Incomplete
73
+ def __init__(self) -> Any:
74
+ """Initialize self. See help(type(self)) for accurate signature."""
75
+ def __reduce__(self):
76
+ """InitAttr.__reduce_cython__(self)"""
77
+ def __reduce_cython__(self) -> Any:
78
+ """InitAttr.__reduce_cython__(self)"""
79
+ def __setstate_cython__(self, __pyx_state) -> Any:
80
+ """InitAttr.__setstate_cython__(self, __pyx_state)"""
81
+
82
+ class NvshmemError(Exception):
83
+ def __init__(self, status) -> Any:
84
+ """NvshmemError.__init__(self, status)"""
85
+ def __reduce__(self) -> Any:
86
+ """NvshmemError.__reduce__(self)"""
87
+
88
+ class Status(enum.IntEnum):
89
+ """See `nvshmemx_status`."""
90
+ __new__: ClassVar[Callable] = ...
91
+ ERROR_COLLECTIVE_LAUNCH_FAILED: ClassVar[Status] = ...
92
+ ERROR_GPU_NOT_SELECTED: ClassVar[Status] = ...
93
+ ERROR_INTERNAL: ClassVar[Status] = ...
94
+ ERROR_INVALID_VALUE: ClassVar[Status] = ...
95
+ ERROR_NOT_SUPPORTED: ClassVar[Status] = ...
96
+ ERROR_OUT_OF_MEMORY: ClassVar[Status] = ...
97
+ ERROR_SENTINEL: ClassVar[Status] = ...
98
+ ERROR_SYMMETRY: ClassVar[Status] = ...
99
+ SUCCESS: ClassVar[Status] = ...
100
+ _generate_next_value_: ClassVar[Callable] = ...
101
+ _member_map_: ClassVar[dict] = ...
102
+ _member_names_: ClassVar[list] = ...
103
+ _member_type_: ClassVar[type[int]] = ...
104
+ _value2member_map_: ClassVar[dict] = ...
105
+
106
+ class UniqueId(uniqueid):
107
+ @classmethod
108
+ def __init__(cls, *args, **kwargs) -> None:
109
+ """Create and return a new object. See help(type) for accurate signature."""
110
+ def __reduce__(self):
111
+ """UniqueId.__reduce_cython__(self)"""
112
+ def __reduce_cython__(self) -> Any:
113
+ """UniqueId.__reduce_cython__(self)"""
114
+ def __setstate_cython__(self, __pyx_state) -> Any:
115
+ """UniqueId.__setstate_cython__(self, __pyx_state)"""
116
+
117
+ class uniqueid:
118
+ """uniqueid(size=1)
119
+
120
+ Empty-initialize an array of `nvshmemx_uniqueid_v1`.
121
+
122
+ The resulting object is of length `size` and of dtype `uniqueid_dtype`.
123
+ If default-constructed, the instance represents a single struct.
124
+
125
+ Args:
126
+ size (int): number of structs, default=1.
127
+
128
+
129
+ .. seealso:: `nvshmemx_uniqueid_v1`"""
130
+ ptr: Incomplete
131
+ version: Incomplete
132
+ def __init__(self, size=...) -> Any:
133
+ """Initialize self. See help(type(self)) for accurate signature."""
134
+ @staticmethod
135
+ def from_data(data) -> Any:
136
+ """uniqueid.from_data(data)
137
+
138
+ Create an uniqueid instance wrapping the given NumPy array.
139
+
140
+ Args:
141
+ data (_numpy.ndarray): a 1D array of dtype `uniqueid_dtype` holding the data."""
142
+ @staticmethod
143
+ def from_ptr(intptr_tptr, size_tsize=..., boolreadonly=...) -> Any:
144
+ """uniqueid.from_ptr(intptr_t ptr, size_t size=1, bool readonly=False)
145
+
146
+ Create an uniqueid instance wrapping the given pointer.
147
+
148
+ Args:
149
+ ptr (intptr_t): pointer address as Python :class:`int` to the data.
150
+ size (int): number of structs, default=1.
151
+ readonly (bool): whether the data is read-only (to the user). default is `False`."""
152
+ def __delitem__(self, other) -> None:
153
+ """Delete self[key]."""
154
+ def __eq__(self, other: object) -> bool:
155
+ """Return self==value."""
156
+ def __ge__(self, other: object) -> bool:
157
+ """Return self>=value."""
158
+ def __getitem__(self, index):
159
+ """Return self[key]."""
160
+ def __gt__(self, other: object) -> bool:
161
+ """Return self>value."""
162
+ def __int__(self) -> int:
163
+ """int(self)"""
164
+ def __le__(self, other: object) -> bool:
165
+ """Return self<=value."""
166
+ def __len__(self) -> int:
167
+ """Return len(self)."""
168
+ def __lt__(self, other: object) -> bool:
169
+ """Return self<value."""
170
+ def __ne__(self, other: object) -> bool:
171
+ """Return self!=value."""
172
+ def __reduce__(self):
173
+ """uniqueid.__reduce_cython__(self)"""
174
+ def __reduce_cython__(self) -> Any:
175
+ """uniqueid.__reduce_cython__(self)"""
176
+ def __setitem__(self, index, object) -> None:
177
+ """Set self[key] to value."""
178
+ def __setstate_cython__(self, __pyx_state) -> Any:
179
+ """uniqueid.__setstate_cython__(self, __pyx_state)"""
@@ -0,0 +1,21 @@
1
+ # Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from .common import * # noqa: F403
6
+ from .common_cuda import * # noqa: F403
7
+ from .cublasdx import * # noqa: F403
8
+ from .cublasdx_backend import * # noqa: F403
9
+ from .cufftdx import * # noqa: F403
10
+ from .cusolverdx import * # noqa: F403
11
+ from .types import * # noqa: F403
12
+ from .vector_types_numba import * # noqa: F403
13
+
14
+ # isort: split
15
+
16
+ # register models in numba; must occur after imports above
17
+ from . import (
18
+ cublasdx_numba, # noqa: F401
19
+ cufftdx_numba, # noqa: F401
20
+ cusolverdx_numba, # noqa: F401
21
+ )
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ import functools
6
+ import sys
7
+ from warnings import warn
8
+
9
+
10
+ def _deprecated(
11
+ msg,
12
+ category: type[Warning] | None = DeprecationWarning,
13
+ stacklevel: int = 1,
14
+ ):
15
+ """Dropin replacement for @warnings.deprecated(...)"""
16
+
17
+ def decorator(func):
18
+ @functools.wraps(func)
19
+ def wrapper(*args, **kwargs):
20
+ warn(msg, category=category, stacklevel=stacklevel + 1)
21
+ return func(*args, **kwargs)
22
+
23
+ return wrapper
24
+
25
+ return decorator
26
+
27
+
28
+ deprecated = _deprecated
29
+
30
+ if (sys.version_info.major, sys.version_info.minor) >= (3, 13):
31
+ from warnings import deprecated as _warnings_deprecated # type: ignore
32
+
33
+ deprecated = _warnings_deprecated
@@ -0,0 +1,313 @@
1
+ # Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ import os
6
+ import tempfile
7
+ from abc import abstractmethod
8
+ from collections.abc import Sequence
9
+ from typing import Any
10
+
11
+ import numpy as np
12
+
13
+ from .common_cuda import MAX_SUPPORTED_CC, MIN_SUPPORTED_CC, CodeType, ComputeCapability, get_current_device_cc
14
+
15
+ __all__ = [
16
+ "make_tensor",
17
+ "make_fragment_like",
18
+ "OpaqueTensor",
19
+ "Layout",
20
+ "axpby",
21
+ "copy",
22
+ "copy_fragment",
23
+ "clear",
24
+ "copy_wait",
25
+ ]
26
+
27
+ SHARED_DEVICE_DOCSTRINGS = {
28
+ "compiler": "A string to specify the compiler for the device code, currently supports ``None`` (default) and ``'numba'``",
29
+ #
30
+ "precision": """\
31
+ The computation precision specified as a numpy float dtype, currently supports ``numpy.float16``, ``numpy.float32`` and
32
+ ``numpy.float64``.""".replace("\n", " "),
33
+ #
34
+ "code_type": "The target GPU code and compute-capability.",
35
+ "sm": "Target mathdx compute-capability.",
36
+ #
37
+ "execution": "A string specifying the execution method, can be ``'Block'`` or ``'Thread'``.",
38
+ }
39
+
40
+
41
+ # TODO: maybe pre-compile regular expression
42
+ def make_binary_tempfile(content, suffix: str) -> tempfile._TemporaryFileWrapper:
43
+ """Write `content` to a temporary file with the given `suffix`.
44
+
45
+ A closed file object returned; it is the user's responsibility to delete the file when
46
+ finished.
47
+
48
+ .. seealso:: :py:func:`delete_binary_tempfiles`
49
+
50
+ """
51
+ with tempfile.NamedTemporaryFile(mode="w+b", suffix=suffix, delete=False) as tmp:
52
+ tmp.write(content)
53
+ tmp.flush()
54
+ return tmp
55
+
56
+
57
+ def delete_binary_tempfiles(filenames: list[str]):
58
+ for name in filenames:
59
+ if os.path.isfile(name):
60
+ os.remove(name)
61
+
62
+
63
+ def check_in(name, value, coll, format="{name} must be in {coll_str} ; got {name} = {value}"):
64
+ if value not in coll:
65
+ coll_str = ", ".join(f'"{t}"' for t in coll)
66
+ msg = format.format(name=name, value=value, coll_str=coll_str)
67
+ raise ValueError(msg)
68
+
69
+
70
+ def check_not_in(name, value, coll, format="{name} must not be any of those value {coll_str} ; got {name} = {value}"):
71
+ if value in coll:
72
+ coll_str = ", ".join(f'"{t}"' for t in coll)
73
+ msg = format.format(name=name, value=value, coll_str=coll_str)
74
+ raise ValueError(msg)
75
+
76
+
77
+ def check_contains(set, key):
78
+ check_in("", key, set, "{arg} must be in {set}")
79
+
80
+
81
+ def parse_sm(sm: Any) -> ComputeCapability:
82
+ if sm is None:
83
+ sm = get_current_device_cc()
84
+ else:
85
+ if not isinstance(sm, ComputeCapability) and not isinstance(sm, int):
86
+ raise ValueError(f"sm should be a ComputeCapability or an int; got sm = {sm}")
87
+ if isinstance(sm, int):
88
+ sm = ComputeCapability(sm // 10, sm % 10)
89
+
90
+ return sm
91
+
92
+
93
+ def check_sm(sm, library_name: str, var_name: str = "sm"):
94
+ if not isinstance(sm, ComputeCapability):
95
+ raise ValueError(f"{var_name} should be an instance of ComputeCapability ; got {var_name} = {sm}")
96
+ if sm < MIN_SUPPORTED_CC:
97
+ raise RuntimeError(f"Minimal compute capability {MIN_SUPPORTED_CC} is required by {library_name}, got {sm}")
98
+ if sm > MAX_SUPPORTED_CC:
99
+ raise RuntimeError(f"The maximum compute capability currently supported by device APIs is {MAX_SUPPORTED_CC}, got {sm}")
100
+ if sm.minor < 0:
101
+ raise ValueError(f"{var_name}.minor must be >= 0 ; got {var_name}.minor = {sm.minor}")
102
+
103
+
104
+ def parse_code_type(code_type: Any) -> CodeType:
105
+ if not isinstance(code_type, Sequence) or len(code_type) != 2:
106
+ raise ValueError(f"code_type should be an instance of CodeType or a 2-tuple ; got code_type = {code_type}")
107
+
108
+ return CodeType(code_type[0], ComputeCapability(*code_type[1]))
109
+
110
+
111
+ def check_code_type(code_type, library_name):
112
+ if not isinstance(code_type, CodeType):
113
+ raise ValueError(f"code_type should be an instance of CodeType ; got code_type = {code_type}")
114
+ check_sm(code_type.cc, library_name, "code_type.cc")
115
+ check_in("code_type.kind", code_type.kind, ["lto"])
116
+
117
+
118
+ def pad_or_truncate(list, target_len):
119
+ return list[:target_len] + [0] * (target_len - len(list))
120
+
121
+
122
+ class Layout:
123
+ """
124
+ Layout for the :py:class:`nvmath.device.OpaqueTensor`.
125
+
126
+ .. note:: Do not create directly, use appropriate method from
127
+ :py:func:`nvmath.device.Matmul`. Refer to
128
+ :cublasdx_doc:`api/other_tensors.html#imported-tensor-utilities`
129
+ for guidance on which method to use.
130
+ """
131
+
132
+ def __init__(self):
133
+ raise RuntimeError("Layout should not be called directly.")
134
+
135
+ @property
136
+ @abstractmethod
137
+ def size(self) -> int:
138
+ """
139
+ Number of valid elements in a tensor. This is simply a product of all
140
+ shape dimensions.
141
+
142
+ Refer to the cuBLASDx documentation for more details on how to use this attribute:
143
+ :cublasdx_doc:`api/other_tensors.html#imported-tensor-utilities`
144
+ """
145
+ pass
146
+
147
+ @property
148
+ @abstractmethod
149
+ def cosize(self) -> int:
150
+ """
151
+ Returns a distance from last element of a tensor to its first element.
152
+ It describes how many elements does the argument layout span.
153
+
154
+ Refer to the cuBLASDx documentation for more details on how to use this attribute:
155
+ :cublasdx_doc:`api/other_tensors.html#imported-tensor-utilities`
156
+ """
157
+ pass
158
+
159
+ @property
160
+ @abstractmethod
161
+ def alignment(self) -> int:
162
+ """
163
+ Returns the required alignment (in bytes) for the tensor data buffer.
164
+
165
+ Refer to the cuBLASDx documentation for more details on how to use this attribute:
166
+ :cublasdx_doc:`api/other_tensors.html#imported-tensor-utilities`
167
+ """
168
+ pass
169
+
170
+
171
+ class OpaqueTensor:
172
+ """
173
+ Abstraction over the cuBLASDx tensor type (an alias of the CuTe tensor type).
174
+ The CuTe tensor layout is powerful and supports layouts not provided by NumPy,
175
+ so this a bridge to add this functionality to Python.
176
+
177
+ .. note:: Do not create directly, use :py:func:`nvmath.device.make_tensor`.
178
+
179
+ Refer to the cuBLASDx documentation for more details on how to use this class:
180
+ :cublasdx_doc:`api/other_tensors.html#tensors`
181
+ """
182
+
183
+ buffer: np.ndarray
184
+ layout: Layout
185
+ leading_dimension: int | None
186
+
187
+ def __init__(self, *args):
188
+ raise RuntimeError("OpaqueTensor should not be called directly outside of a numba.cuda.jit(...) kernel.")
189
+
190
+
191
+ def make_tensor(array: np.ndarray, layout: Layout) -> OpaqueTensor:
192
+ """
193
+ make_tensor is a helper function for creating
194
+ :py:class:`nvmath.device.OpaqueTensor` objects.
195
+
196
+ Args:
197
+ array (np.ndarray): The input array to be wrapped as an OpaqueTensor.
198
+ layout (Layout): The layout of the tensor, which describes how the data is
199
+ organized in memory.
200
+
201
+ Refer to the cuBLASDx documentation for more details on how to use this function:
202
+ :cublasdx_doc:`api/other_tensors.html#create-tensor-other-label`
203
+ """
204
+ raise RuntimeError("make_tensor should not be called directly outside of a numba.cuda.jit(...) kernel.")
205
+
206
+
207
+ def make_fragment_like(tensor: OpaqueTensor, dtype) -> OpaqueTensor:
208
+ """
209
+ make_fragment_like is a helper function for creating register fragments with
210
+ the same layout as input tensor, but different dtype.
211
+
212
+ Args:
213
+ tensor (OpaqueTensor): The input tensor to be used as a template for the fragment.
214
+ dtype: The data type of the fragment to be created.
215
+
216
+ Refer to the cuBLASDx documentation for more details on how to use this function:
217
+ :cublasdx_doc:`api/other_tensors.html#imported-tensor-utilities`
218
+ """
219
+ raise RuntimeError("make_fragment_like should not be called directly outside of a numba.cuda.jit(...) kernel.")
220
+
221
+
222
+ def axpby(alpha: float, x_tensor: OpaqueTensor, beta: float, y_tensor: OpaqueTensor) -> None:
223
+ """
224
+ AXPBY operation: y = alpha * x + beta * y
225
+
226
+ Args:
227
+ alpha (float): Scalar multiplier for x_tensor.
228
+ x_tensor (OpaqueTensor): Input tensor x.
229
+ beta (float): Scalar multiplier for y_tensor.
230
+ y_tensor (OpaqueTensor): Input/output tensor y, which will be updated
231
+ with the result.
232
+
233
+ Refer to the cuBLASDx documentation for more details on how to use this function:
234
+ :cublasdx_doc:`api/other_tensors.html#imported-tensor-utilities`
235
+ """
236
+ raise RuntimeError("axpby should not be called directly outside of a numba.cuda.jit(...) kernel.")
237
+
238
+
239
+ def copy(src: OpaqueTensor, dst: OpaqueTensor, alignment=None):
240
+ """
241
+ Copies data from the source tensor to the destination tensor.
242
+
243
+ Args:
244
+ src (OpaqueTensor): The source tensor to copy from.
245
+ dst (OpaqueTensor): The destination tensor to copy to.
246
+ alignment (int, optional): The alignment (in bytes) for the copy operation.
247
+
248
+ Refer to the cuBLASDx documentation for more details on how to use this function:
249
+ :cublasdx_doc:`api/other_tensors.html#cooperative-global-shared-copying`
250
+ """
251
+ raise RuntimeError("copy should not be called directly outside of a numba.cuda.jit(...) kernel.")
252
+
253
+
254
+ def copy_fragment(src: OpaqueTensor, dst: OpaqueTensor, alignment=None):
255
+ """
256
+ A bidirectional copying method to copy data between register fragments and
257
+ global memory tensors.
258
+
259
+ Args:
260
+ src (OpaqueTensor): The source tensor to copy from.
261
+ dst (OpaqueTensor): The destination tensor to copy to.
262
+ alignment (int, optional): The alignment (in bytes) for the copy operation.
263
+
264
+ Refer to the cuBLASDx documentation for more details on how to use this function:
265
+ :cublasdx_doc:`api/other_tensors.html#copying-registers-tensors`
266
+ """
267
+ raise RuntimeError("copy_fragment should not be called directly outside of a numba.cuda.jit(...) kernel.")
268
+
269
+
270
+ def clear(arr: OpaqueTensor):
271
+ """
272
+ Clears the contents of the given tensor by setting all elements to zero.
273
+
274
+ Args:
275
+ arr (OpaqueTensor): The tensor to be cleared.
276
+
277
+ Refer to the cuBLASDx documentation for more details on how to use this function:
278
+ :cublasdx_doc:`api/other_tensors.html#imported-tensor-utilities`
279
+ """
280
+ raise RuntimeError("clear should not be called directly outside of a numba.cuda.jit(...) kernel.")
281
+
282
+
283
+ def copy_wait():
284
+ """
285
+ Creates synchronization point. It has to be called after :py:func:`nvmath.device.copy`
286
+ to ensure that the copy operation has completed before any subsequent
287
+ operations are executed.
288
+
289
+ Refer to the cuBLASDx documentation for more details on how to use this function:
290
+ :cublasdx_doc:`api/other_tensors.html#cooperative-global-shared-copying`
291
+ """
292
+ raise RuntimeError("copy_wait should not be called directly outside of a numba.cuda.jit(...) kernel.")
293
+
294
+
295
+ def check_positive_integer_sequence(arg, arg_name, min_len, max_len):
296
+ if not isinstance(arg, Sequence):
297
+ raise ValueError(f'Parameter "{arg_name}" must be a sequence. Got: {type(arg).__name__}.')
298
+
299
+ for i, x in enumerate(arg):
300
+ if not isinstance(x, (int, np.integer)):
301
+ raise ValueError(
302
+ f'Parameter "{arg_name}" must be a sequence of positive integers. '
303
+ + f"Element {arg_name}[{i}] is {type(x).__name__}."
304
+ )
305
+ if x <= 0:
306
+ raise ValueError(f'Parameter "{arg_name}" values must be positive integers. Got {arg_name}[{i}] = {x}.')
307
+
308
+ if min_len == max_len:
309
+ if len(arg) != min_len:
310
+ raise ValueError(f'Parameter "{arg_name}" must be a sequence of length {min_len}. Got length: {len(arg)}.')
311
+ else:
312
+ if len(arg) > max_len or len(arg) < min_len:
313
+ raise ValueError(f'Parameter "{arg_name}" must define {min_len} to {max_len} values. Got {len(arg)} value(s).')
@@ -0,0 +1,131 @@
1
+ # Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ import weakref
6
+ from collections.abc import Callable
7
+
8
+ import numpy as np
9
+
10
+ from nvmath.bindings import mathdx
11
+ from nvmath.device.common_cuda import ComputeCapability, ISAVersion
12
+
13
+ from .types import complex32, complex64, complex128, half2, half4
14
+
15
+ MATHDX_TYPES_TO_NP = {
16
+ mathdx.CommondxValueType.R_16F: np.float16,
17
+ mathdx.CommondxValueType.R_16F2: half2,
18
+ mathdx.CommondxValueType.R_32F: np.float32,
19
+ mathdx.CommondxValueType.R_64F: np.float64,
20
+ mathdx.CommondxValueType.C_16F: complex32,
21
+ mathdx.CommondxValueType.C_16F2: half4,
22
+ mathdx.CommondxValueType.C_32F: complex64,
23
+ mathdx.CommondxValueType.C_64F: complex128,
24
+ mathdx.CommondxValueType.R_8I: np.int8,
25
+ mathdx.CommondxValueType.R_16I: np.int16,
26
+ mathdx.CommondxValueType.R_32I: np.int32,
27
+ mathdx.CommondxValueType.R_64I: np.int64,
28
+ mathdx.CommondxValueType.R_8UI: np.uint8,
29
+ mathdx.CommondxValueType.R_16UI: np.uint16,
30
+ mathdx.CommondxValueType.R_32UI: np.uint32,
31
+ mathdx.CommondxValueType.R_64UI: np.uint64,
32
+ }
33
+
34
+
35
+ NP_TYPES_TO_MATHDX_TYPES = {np_type: mathdx_type for mathdx_type, np_type in MATHDX_TYPES_TO_NP.items()}
36
+
37
+ NP_TYPES_TO_MATHDX_PRECISION = {
38
+ np.float16: mathdx.CommondxPrecision.F16,
39
+ np.float32: mathdx.CommondxPrecision.F32,
40
+ np.float64: mathdx.CommondxPrecision.F64,
41
+ np.int8: mathdx.CommondxPrecision.I8,
42
+ np.int16: mathdx.CommondxPrecision.I16,
43
+ np.int32: mathdx.CommondxPrecision.I32,
44
+ np.int64: mathdx.CommondxPrecision.I64,
45
+ np.uint8: mathdx.CommondxPrecision.UI8,
46
+ np.uint16: mathdx.CommondxPrecision.UI16,
47
+ np.uint32: mathdx.CommondxPrecision.UI32,
48
+ np.uint64: mathdx.CommondxPrecision.UI64,
49
+ }
50
+
51
+ EXECUTION_STR_TO_MATHDX = {
52
+ "Block": mathdx.CommondxExecution.BLOCK,
53
+ "Thread": mathdx.CommondxExecution.THREAD,
54
+ }
55
+
56
+ NVARG_GEN_OPT_LTO = "-gen-opt-lto"
57
+
58
+
59
+ class DescriptorWrapper:
60
+ """
61
+ A smart pointer to a descriptor.
62
+
63
+ Lives as long as we need the descriptor (due to lru cache usage). Once the
64
+ descriptor is no longer needed/cached, it will trigger proper resource
65
+ deallocation.
66
+ """
67
+
68
+ def __init__(self, descriptor, destructor):
69
+ self.descriptor = descriptor
70
+ self._destructor = destructor
71
+ if destructor is not None:
72
+ weakref.finalize(self, self._destructor, self.descriptor)
73
+
74
+
75
+ def get_lto(code_descriptor: int) -> bytes:
76
+ """Get lto binary from the mathdx common code descriptor."""
77
+ lto_size = mathdx.commondx_get_code_ltoir_size(code_descriptor)
78
+
79
+ lto_fn = bytearray(lto_size)
80
+ mathdx.commondx_get_code_ltoir(code_descriptor, lto_size, lto_fn)
81
+ return bytes(lto_fn)
82
+
83
+
84
+ def get_isa_version(code_descriptor: int) -> ISAVersion:
85
+ """Parse isa version from the mathdx common code descriptor."""
86
+ isa = mathdx.commondx_get_code_option_int64(code_descriptor, mathdx.CommondxOption.CODE_ISA)
87
+ return ISAVersion.from_integer(isa)
88
+
89
+
90
+ def build_get_int_traits(get_trait_int64s: Callable[[int, int, int, int], int]):
91
+ """Generate function that returns mathdx tuple of int traits."""
92
+
93
+ def get_int_traits(handle: int, trait_type: int, size: int) -> tuple:
94
+ int_buffer = np.zeros(size, np.int64)
95
+ get_trait_int64s(handle, trait_type, size, int_buffer.ctypes.data)
96
+ return tuple(map(int, int_buffer))
97
+
98
+ return get_int_traits
99
+
100
+
101
+ def build_get_str_trait(
102
+ get_trait_str_size: Callable[[int, int], int],
103
+ get_trait_str: Callable[[int, int, int, bytearray], bytearray],
104
+ ):
105
+ """Generate function that returns mathdx string trait."""
106
+
107
+ def get_str_trait(handle: int, trait_type: int) -> str:
108
+ symbol_size = get_trait_str_size(handle, trait_type)
109
+
110
+ symbol = bytearray(symbol_size)
111
+
112
+ get_trait_str(handle, trait_type, symbol_size, symbol)
113
+
114
+ # terminate trailing 0 (indicator of c-string end)
115
+ symbol_str = symbol[:-1].decode()
116
+
117
+ return symbol_str
118
+
119
+ return get_str_trait
120
+
121
+
122
+ def get_mathdx_sm(version: ComputeCapability) -> list:
123
+ sm = [version.integer]
124
+ if version.arch == "a":
125
+ sm.append(mathdx.CommondxArchModifier.ARCH_SPECIFIC)
126
+ return sm
127
+
128
+
129
+ def set_code_target_sm(code: int, version: ComputeCapability):
130
+ sm = get_mathdx_sm(version)
131
+ mathdx.commondx_set_code_option_int64s(code, mathdx.CommondxOption.TARGET_SM, len(sm), sm)