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,247 @@
1
+ # Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ """
6
+ Interface classes to encapsulate low-level calls to get or set configuration information.
7
+ """
8
+
9
+ __all__ = ["ContractionPlanPreference"]
10
+
11
+
12
+ import numpy as np
13
+
14
+ from nvmath.bindings import cutensor
15
+ from nvmath.internal import utils
16
+
17
+
18
+ class ContractionPlanPreference:
19
+ """
20
+ An interface to configure :meth:`nvmath.tensor.BinaryContraction.plan` and
21
+ :meth:`nvmath.tensor.TernaryContraction.plan`. The
22
+ current configuration can also be queried.
23
+ """
24
+
25
+ def __init__(self, contraction):
26
+ """
27
+ ctor for internal use only.
28
+ """
29
+ self._contraction = contraction
30
+ self._handle = self._contraction.handle
31
+
32
+ get_dtype = cutensor.get_plan_preference_attribute_dtype
33
+
34
+ self._autotune_mode = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.AUTOTUNE_MODE))
35
+ self._cache_mode = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.CACHE_MODE))
36
+ self._incremental_count = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.INCREMENTAL_COUNT))
37
+ self._algo = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.ALGO))
38
+ self._kernel_rank = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.KERNEL_RANK))
39
+ self._jit = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.JIT))
40
+
41
+ def _check_valid_contraction_wrapper(self, *args, **kwargs):
42
+ if not self._contraction.valid_state:
43
+ raise RuntimeError("The ContractionPlanPreference object cannot be used after its contraction object is free'd.")
44
+
45
+ @staticmethod
46
+ def _get_scalar_attribute(contraction, name, attribute):
47
+ """
48
+ name = cutensor PlanPreference enum for the attribute
49
+ attribute = numpy ndarray object into which the value is stored by cutensornet
50
+ """
51
+ assert contraction.plan_preference_ptr is not None, "Internal error"
52
+ cutensor.plan_preference_get_attribute(
53
+ contraction.handle, contraction.plan_preference_ptr, name, attribute.ctypes.data, attribute.dtype.itemsize
54
+ )
55
+
56
+ @staticmethod
57
+ def _set_scalar_attribute(contraction, name, attribute, value):
58
+ """
59
+ name = cutensor PlanPreference enum for the attribute
60
+ attribute = numpy ndarray object into which the value is stored
61
+ value = the value to set the the attribute to
62
+ """
63
+ assert contraction.plan_preference_ptr is not None, "Internal error"
64
+ attribute[0] = value
65
+ cutensor.plan_preference_set_attribute(
66
+ contraction.handle, contraction.plan_preference_ptr, name, attribute.ctypes.data, attribute.dtype.itemsize
67
+ )
68
+
69
+ @property
70
+ @utils.precondition(_check_valid_contraction_wrapper)
71
+ def autotune_mode(self):
72
+ """
73
+ Query the autotune mode. See the
74
+ `cuTensor documentation
75
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorautotunemode-t>`__
76
+ for more information.
77
+ """
78
+ ContractionPlanPreference._get_scalar_attribute(
79
+ self._contraction, cutensor.PlanPreferenceAttribute.AUTOTUNE_MODE, self._autotune_mode
80
+ )
81
+ return self._autotune_mode.item()
82
+
83
+ @autotune_mode.setter
84
+ @utils.precondition(_check_valid_contraction_wrapper)
85
+ def autotune_mode(self, autotune_mode):
86
+ """
87
+ Set the autotune mode. See the
88
+ `cuTensor documentation
89
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorautotunemode-t>`__
90
+ for more information.
91
+
92
+ Args:
93
+ autotune_mode: (nvmath.tensor.ContractionAutotuneMode) The autotune mode.
94
+
95
+ """
96
+ ContractionPlanPreference._set_scalar_attribute(
97
+ self._contraction, cutensor.PlanPreferenceAttribute.AUTOTUNE_MODE, self._autotune_mode, autotune_mode
98
+ )
99
+
100
+ @property
101
+ @utils.precondition(_check_valid_contraction_wrapper)
102
+ def cache_mode(self):
103
+ """
104
+ Query the cache mode. See the
105
+ `cuTensor documentation
106
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorcachemode-t>`__
107
+ for more information.
108
+ """
109
+ ContractionPlanPreference._get_scalar_attribute(
110
+ self._contraction, cutensor.PlanPreferenceAttribute.CACHE_MODE, self._cache_mode
111
+ )
112
+ return self._cache_mode.item()
113
+
114
+ @cache_mode.setter
115
+ @utils.precondition(_check_valid_contraction_wrapper)
116
+ def cache_mode(self, cache_mode):
117
+ """
118
+ Set the cache mode. See the
119
+ `cuTensor documentation
120
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorcachemode-t>`__
121
+ for more information.
122
+
123
+ Args:
124
+ cache_mode: (nvmath.tensor.ContractionCacheMode) The cache mode.
125
+
126
+ """
127
+ ContractionPlanPreference._set_scalar_attribute(
128
+ self._contraction, cutensor.PlanPreferenceAttribute.CACHE_MODE, self._cache_mode, cache_mode
129
+ )
130
+
131
+ @property
132
+ @utils.precondition(_check_valid_contraction_wrapper)
133
+ def incremental_count(self):
134
+ """
135
+ Query the incremental count. See the
136
+ `cuTensor documentation
137
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorincrementalcount-t>`__
138
+ for more information.
139
+ """
140
+ ContractionPlanPreference._get_scalar_attribute(
141
+ self._contraction, cutensor.PlanPreferenceAttribute.INCREMENTAL_COUNT, self._incremental_count
142
+ )
143
+ return self._incremental_count.item()
144
+
145
+ @incremental_count.setter
146
+ @utils.precondition(_check_valid_contraction_wrapper)
147
+ def incremental_count(self, incremental_count):
148
+ """
149
+ Set the incremental count. See the
150
+ `cuTensor documentation
151
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorincrementalcount-t>`__
152
+ for more information.
153
+
154
+ Args:
155
+ incremental_count: The incremental count.
156
+
157
+ """
158
+ ContractionPlanPreference._set_scalar_attribute(
159
+ self._contraction, cutensor.PlanPreferenceAttribute.INCREMENTAL_COUNT, self._incremental_count, incremental_count
160
+ )
161
+
162
+ @property
163
+ @utils.precondition(_check_valid_contraction_wrapper)
164
+ def algo(self):
165
+ """
166
+ Query the algo. See the
167
+ `cuTensor documentation
168
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensoralgo-t>`__
169
+ for more information.
170
+ """
171
+ ContractionPlanPreference._get_scalar_attribute(self._contraction, cutensor.PlanPreferenceAttribute.ALGO, self._algo)
172
+ return self._algo.item()
173
+
174
+ @algo.setter
175
+ @utils.precondition(_check_valid_contraction_wrapper)
176
+ def algo(self, algo):
177
+ """
178
+ Set the algo. See the
179
+ `cuTensor documentation
180
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensoralgo-t>`__
181
+ for more information.
182
+
183
+ Args:
184
+ algo: (nvmath.tensor.ContractionAlgo) The contraction algorithm.
185
+
186
+ """
187
+ ContractionPlanPreference._set_scalar_attribute(
188
+ self._contraction, cutensor.PlanPreferenceAttribute.ALGO, self._algo, algo
189
+ )
190
+
191
+ @property
192
+ @utils.precondition(_check_valid_contraction_wrapper)
193
+ def kernel_rank(self):
194
+ """
195
+ Query the kernel rank. See the
196
+ `cuTensor documentation
197
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorkernelrank-t>`__
198
+ for more information.
199
+ """
200
+ ContractionPlanPreference._get_scalar_attribute(
201
+ self._contraction, cutensor.PlanPreferenceAttribute.KERNEL_RANK, self._kernel_rank
202
+ )
203
+ return self._kernel_rank.item()
204
+
205
+ @kernel_rank.setter
206
+ @utils.precondition(_check_valid_contraction_wrapper)
207
+ def kernel_rank(self, kernel_rank):
208
+ """
209
+ Set the kernel rank. See the
210
+ `cuTensor documentation
211
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorkernelrank-t>`__
212
+ for more information.
213
+
214
+ Args:
215
+ kernel_rank: The kernel rank.
216
+
217
+ """
218
+ ContractionPlanPreference._set_scalar_attribute(
219
+ self._contraction, cutensor.PlanPreferenceAttribute.KERNEL_RANK, self._kernel_rank, kernel_rank
220
+ )
221
+
222
+ @property
223
+ @utils.precondition(_check_valid_contraction_wrapper)
224
+ def jit(self):
225
+ """
226
+ Query the jit compilation mode. See the
227
+ `cuTensor documentation
228
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorjit-t>`__
229
+ for more information.
230
+ """
231
+ ContractionPlanPreference._get_scalar_attribute(self._contraction, cutensor.PlanPreferenceAttribute.JIT, self._jit)
232
+ return self._jit.item()
233
+
234
+ @jit.setter
235
+ @utils.precondition(_check_valid_contraction_wrapper)
236
+ def jit(self, jit):
237
+ """
238
+ Set the jit compilation mode. See the
239
+ `cuTensor documentation
240
+ <https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorjit-t>`__
241
+ for more information.
242
+
243
+ Args:
244
+ jit: (nvmath.tensor.ContractionJitMode) The JIT compilation mode.
245
+
246
+ """
247
+ ContractionPlanPreference._set_scalar_attribute(self._contraction, cutensor.PlanPreferenceAttribute.JIT, self._jit, jit)
@@ -0,0 +1,162 @@
1
+ # Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ import weakref
6
+ from collections.abc import Sequence
7
+
8
+ from nvmath.bindings import cutensor
9
+ from nvmath.internal.tensor_ifc import TensorHolder
10
+ from nvmath.internal.typemaps import NAME_TO_DATA_TYPE
11
+
12
+ __all__ = [
13
+ "compute_pointer_alignment",
14
+ "compute_strides",
15
+ "TensorDescriptor",
16
+ ]
17
+
18
+ DEFAULT_ALIGNMENT_REQUIREMENT = 256
19
+
20
+
21
+ def compute_pointer_alignment(ptr: int) -> int:
22
+ """
23
+ Compute the pointer alignment for the given pointer.
24
+
25
+ Args:
26
+ ptr: Pointer address as integer
27
+
28
+ Returns:
29
+ The alignment value (256, 128, 64, 32, 16, 8, 4, 2, or 1)
30
+ """
31
+ return 256 if ptr == 0 else min(ptr & -ptr, 256)
32
+
33
+
34
+ def compute_strides(shape: Sequence[int], order: str = "C") -> Sequence[int]:
35
+ """
36
+ Compute the strides for the given shape and order.
37
+
38
+ Args:
39
+ shape: Shape of the tensor
40
+
41
+ Returns:
42
+ The strides
43
+ """
44
+ assert order in {"C", "F"}, f"Invalid order: {order}"
45
+ strides = [0] * len(shape)
46
+ stride = 1
47
+ if order == "C":
48
+ for axis in range(len(shape) - 1, -1, -1):
49
+ strides[axis] = stride
50
+ stride *= shape[axis]
51
+ elif order == "F":
52
+ for axis in range(len(shape)):
53
+ strides[axis] = stride
54
+ stride *= shape[axis]
55
+ else:
56
+ raise ValueError(f"Invalid order: {order}")
57
+ return strides
58
+
59
+
60
+ class TensorDescriptor:
61
+ """
62
+ A managed wrapper for cuTensor tensor descriptors with automatic resource cleanup.
63
+
64
+ This class wraps a cuTensor tensor descriptor (``cutensorTensorDescriptor_t``) and
65
+ automatically manages its lifetime. The underlying C descriptor is created on
66
+ initialization and automatically destroyed when this object is garbage collected.
67
+
68
+ Args:
69
+ handle: The cuTensor library handle.
70
+ extents: The extents (shape) of each mode of the tensor. Must have the same
71
+ length as ``strides``.
72
+ strides: The stride for each mode of the tensor, in elements of the base type.
73
+ Must have the same length as ``extents``.
74
+ dtype: The data type of the tensor as a string.
75
+ alignment: The alignment requirement in bytes for the base pointer that will
76
+ be used with this descriptor.
77
+
78
+ """
79
+
80
+ def __init__(
81
+ self,
82
+ handle: int,
83
+ extents: Sequence[int],
84
+ strides: Sequence[int],
85
+ dtype: str,
86
+ alignment: int,
87
+ ):
88
+ self._extents = extents
89
+ self._strides = strides
90
+ self._dtype = dtype
91
+ self._alignment = alignment
92
+ num_modes = len(extents)
93
+ assert num_modes == len(strides), "The number of modes and strides must be the same"
94
+ self._tensor_desc = cutensor.create_tensor_descriptor(
95
+ handle, num_modes, extents, strides, NAME_TO_DATA_TYPE[dtype], alignment
96
+ )
97
+ self._finalizer = weakref.finalize(self, cutensor.destroy_tensor_descriptor, self._tensor_desc)
98
+
99
+ @property
100
+ def ptr(self) -> int:
101
+ return self._tensor_desc
102
+
103
+ @property
104
+ def shape(self) -> Sequence[int]:
105
+ return self._extents
106
+
107
+ @property
108
+ def dtype(self) -> str:
109
+ return self._dtype
110
+
111
+ @property
112
+ def alignment(self) -> int:
113
+ return self._alignment
114
+
115
+ @property
116
+ def strides(self) -> Sequence[int]:
117
+ return self._strides
118
+
119
+ @classmethod
120
+ def from_tensor_holder(cls, handle: int, tensor: TensorHolder) -> "TensorDescriptor":
121
+ """
122
+ Create a TensorDescriptor from a TensorHolder.
123
+
124
+ Args:
125
+ handle: The cuTensor library handle.
126
+ tensor: The TensorHolder to create the descriptor from.
127
+
128
+ Returns:
129
+ A TensorDescriptor with properties derived from the TensorHolder.
130
+ """
131
+ return cls(
132
+ handle=handle,
133
+ extents=tensor.shape,
134
+ strides=tensor.strides,
135
+ dtype=tensor.dtype,
136
+ alignment=compute_pointer_alignment(tensor.data_ptr),
137
+ )
138
+
139
+ @classmethod
140
+ def from_shape_and_dtype(
141
+ cls, handle: int, shape: Sequence[int], dtype: str, order: str = "C", alignment: int = DEFAULT_ALIGNMENT_REQUIREMENT
142
+ ) -> "TensorDescriptor":
143
+ """
144
+ Create a TensorDescriptor for the given shape, data type, order, and alignment.
145
+
146
+ Args:
147
+ handle: The cuTensor library handle.
148
+ shape: The shape (extents) of the tensor.
149
+ dtype: The data type of the tensor as a string.
150
+ order: The memory layout order. Defaults to ``"C"``.
151
+ alignment: The alignment requirement in bytes. Defaults to 256.
152
+
153
+ Returns:
154
+ A TensorDescriptor with the specified properties.
155
+ """
156
+ return cls(
157
+ handle=handle,
158
+ extents=shape,
159
+ strides=compute_strides(shape, order),
160
+ dtype=dtype,
161
+ alignment=alignment,
162
+ )
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ # Defined in CPython:
6
+ # https://github.com/python/cpython/blob/26bc2cc06128890ac89492eca20e83abe0789c1c/Objects/unicodetype_db.h#L6311-L6349
7
+
8
+ __all__ = ["WHITESPACE_UNICODE"]
9
+
10
+ _WHITESPACE_UNICODE_INTS = [
11
+ 0x0009,
12
+ 0x000A,
13
+ 0x000B,
14
+ 0x000C,
15
+ 0x000D,
16
+ 0x001C,
17
+ 0x001D,
18
+ 0x001E,
19
+ 0x001F,
20
+ 0x0020,
21
+ 0x0085,
22
+ 0x00A0,
23
+ 0x1680,
24
+ 0x2000,
25
+ 0x2001,
26
+ 0x2002,
27
+ 0x2003,
28
+ 0x2004,
29
+ 0x2005,
30
+ 0x2006,
31
+ 0x2007,
32
+ 0x2008,
33
+ 0x2009,
34
+ 0x200A,
35
+ 0x2028,
36
+ 0x2029,
37
+ 0x202F,
38
+ 0x205F,
39
+ 0x3000,
40
+ ]
41
+
42
+
43
+ WHITESPACE_UNICODE = "".join(chr(s) for s in _WHITESPACE_UNICODE_INTS)