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,26 @@
1
+ # Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ """
6
+ Interface class to encapsulate low-level calls to get and set matrix layout attributes.
7
+ """
8
+
9
+ __all__ = ["MatrixLayoutInterface"]
10
+
11
+ from nvmath._internal.attribute_ifc_factory import make_cublas_attribute_interface
12
+ from nvmath.bindings import cublasLt as cublaslt
13
+
14
+ # Create a class, MatrixLayoutInterface, such that each enum member in
15
+ # MatrixLayoutAttribute is exposed as a lowercase property (getter + setter).
16
+ # For example, if the class instance is stored as ``layout_ifc``,
17
+ # then the enum member ``ROWS`` becomes the property
18
+ # ``layout_ifc.rows``.
19
+ MatrixLayoutInterface = make_cublas_attribute_interface(
20
+ class_module=__name__,
21
+ class_name="MatrixLayoutInterface",
22
+ attribute_enum=cublaslt.MatrixLayoutAttribute,
23
+ get_attribute_dtype_fn=cublaslt.get_matrix_layout_attribute_dtype,
24
+ get_attribute_fn=cublaslt.matrix_layout_get_attribute,
25
+ set_attribute_fn=cublaslt.matrix_layout_set_attribute,
26
+ )
@@ -0,0 +1,144 @@
1
+ # Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ """
6
+ Functions to link type names with CUBLAS compute types.
7
+ """
8
+
9
+ __all__ = [
10
+ "NAMES_TO_DEFAULT_SCALE_TYPE",
11
+ "NAMES_TO_DEFAULT_COMPUTE_TYPE",
12
+ "SUPPORTED_TYPES",
13
+ "COMPUTE_TYPE_TO_DEFAULT_SCALE_TYPE",
14
+ "SCALE_TYPE_TO_DEFAULT_COMPUTE_TYPE",
15
+ ]
16
+
17
+ from nvmath.bindings import cublas # type: ignore
18
+ from nvmath.internal.typemaps import cudaDataType
19
+
20
+
21
+ def create_default_scale_type_map():
22
+ """
23
+ Map the data type name to the corresponding CUDA data type that's appropriate for
24
+ default scale.
25
+ """
26
+
27
+ dt = cudaDataType
28
+
29
+ scale_type_map = {}
30
+ # FP4 scale types (https://docs.nvidia.com/cuda/cublas/index.html#id105)
31
+ scale_type_map["float4_e2m1fn_x2", "float4_e2m1fn_x2"] = dt.CUDA_R_32F
32
+ # FP8 scale types
33
+ scale_type_map["float8_e4m3fn", "float8_e5m2"] = dt.CUDA_R_32F
34
+ scale_type_map["float8_e5m2", "float8_e4m3fn"] = dt.CUDA_R_32F
35
+ scale_type_map["float8_e4m3fn", "float8_e4m3fn"] = dt.CUDA_R_32F
36
+ scale_type_map["bfloat16", "bfloat16"] = dt.CUDA_R_32F
37
+ scale_type_map["float16", "float16"] = dt.CUDA_R_32F
38
+ scale_type_map["float32", "float32"] = dt.CUDA_R_32F
39
+ scale_type_map["float64", "float64"] = dt.CUDA_R_64F
40
+ scale_type_map["complex32", "complex32"] = dt.CUDA_C_32F
41
+ scale_type_map["complex64", "complex64"] = dt.CUDA_C_32F
42
+ scale_type_map["complex128", "complex128"] = dt.CUDA_C_64F
43
+
44
+ return scale_type_map
45
+
46
+
47
+ def create_compute_type_to_scale_type_map(is_complex):
48
+ """
49
+ Map the compute type to the corresponding CUDA data type that's appropriate for
50
+ default scale.
51
+ """
52
+
53
+ dt = cudaDataType
54
+ ct = cublas.ComputeType
55
+
56
+ scale_type_map = {}
57
+ scale_type_map[ct.COMPUTE_16F] = dt.CUDA_R_16F
58
+ scale_type_map[ct.COMPUTE_16F_PEDANTIC] = dt.CUDA_R_16F
59
+
60
+ f32 = dt.CUDA_C_32F if is_complex else dt.CUDA_R_32F
61
+ f64 = dt.CUDA_C_64F if is_complex else dt.CUDA_R_64F
62
+
63
+ scale_type_map[ct.COMPUTE_32F] = f32
64
+ scale_type_map[ct.COMPUTE_32F_PEDANTIC] = f32
65
+ scale_type_map[ct.COMPUTE_32F_FAST_16F] = f32
66
+ scale_type_map[ct.COMPUTE_32F_FAST_16BF] = f32
67
+ scale_type_map[ct.COMPUTE_32F_FAST_TF32] = f32
68
+ scale_type_map[ct.COMPUTE_32F_EMULATED_16BFX9] = f32
69
+ scale_type_map[ct.COMPUTE_64F] = f64
70
+ scale_type_map[ct.COMPUTE_64F_PEDANTIC] = f64
71
+ scale_type_map[ct.COMPUTE_64F_EMULATED_FIXEDPOINT] = f64
72
+
73
+ return scale_type_map
74
+
75
+
76
+ def create_scale_type_to_compute_type_map():
77
+ """
78
+ Map the scale type to the corresponding compute type that's an appropriate default.
79
+ """
80
+
81
+ dt = cudaDataType
82
+ ct = cublas.ComputeType
83
+
84
+ compute_type_map = {}
85
+ compute_type_map[dt.CUDA_R_16F] = ct.COMPUTE_16F
86
+ compute_type_map[dt.CUDA_R_16BF] = ct.COMPUTE_32F
87
+ compute_type_map[dt.CUDA_R_32F] = ct.COMPUTE_32F
88
+ compute_type_map[dt.CUDA_C_32F] = ct.COMPUTE_32F
89
+ compute_type_map[dt.CUDA_R_64F] = ct.COMPUTE_64F
90
+ compute_type_map[dt.CUDA_C_64F] = ct.COMPUTE_64F
91
+ return compute_type_map
92
+
93
+
94
+ def create_compute_type_map():
95
+ """
96
+ Map the data type name to the corresponding CUDA data type that's appropriate for
97
+ default compute type.
98
+ """
99
+
100
+ ct = cublas.ComputeType
101
+
102
+ compute_type_map = {}
103
+ # FP4 compute types (https://docs.nvidia.com/cuda/cublas/index.html#id105)
104
+ compute_type_map["float4_e2m1fn_x2", "float4_e2m1fn_x2"] = ct.COMPUTE_32F
105
+ # FP8 compute types
106
+ compute_type_map["float8_e4m3fn", "float8_e5m2"] = ct.COMPUTE_32F
107
+ compute_type_map["float8_e5m2", "float8_e4m3fn"] = ct.COMPUTE_32F
108
+ compute_type_map["float8_e4m3fn", "float8_e4m3fn"] = ct.COMPUTE_32F
109
+ compute_type_map["bfloat16", "bfloat16"] = ct.COMPUTE_32F
110
+ compute_type_map["float16", "float16"] = ct.COMPUTE_32F
111
+ compute_type_map["float32", "float32"] = ct.COMPUTE_32F
112
+ compute_type_map["float64", "float64"] = ct.COMPUTE_64F
113
+ compute_type_map["complex32", "complex32"] = ct.COMPUTE_32F
114
+ compute_type_map["complex64", "complex64"] = ct.COMPUTE_32F
115
+ compute_type_map["complex128", "complex128"] = ct.COMPUTE_64F
116
+
117
+ return compute_type_map
118
+
119
+
120
+ CUBLAS_COMPUTE_TYPE_TO_NAME = {
121
+ cublas.ComputeType.COMPUTE_32F: ("float32", "complex64"),
122
+ cublas.ComputeType.COMPUTE_64F: ("float64", "complex128"),
123
+ }
124
+
125
+ NAMES_TO_DEFAULT_SCALE_TYPE = create_default_scale_type_map()
126
+ NAMES_TO_DEFAULT_COMPUTE_TYPE = create_compute_type_map()
127
+ COMPUTE_TYPE_TO_DEFAULT_SCALE_TYPE = {
128
+ "real": create_compute_type_to_scale_type_map(is_complex=False),
129
+ "complex": create_compute_type_to_scale_type_map(is_complex=True),
130
+ }
131
+ SCALE_TYPE_TO_DEFAULT_COMPUTE_TYPE = create_scale_type_to_compute_type_map()
132
+
133
+ SUPPORTED_TYPES = [
134
+ "float4_e2m1fn_x2", # FP4 (supported on SM 10.0+)
135
+ "float8_e4m3fn",
136
+ "float8_e5m2",
137
+ "bfloat16",
138
+ "float16",
139
+ "float32",
140
+ "float64",
141
+ "complex32",
142
+ "complex64",
143
+ "complex128",
144
+ ]
@@ -0,0 +1,134 @@
1
+ # Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ """
6
+ Utilities.
7
+ """
8
+
9
+ __all__ = [
10
+ "axis_order_in_memory",
11
+ "calculate_strides",
12
+ "check_batch_tileable",
13
+ "create_handle",
14
+ "destroy_handle",
15
+ "get_handle",
16
+ "pointer_aligned_to",
17
+ ]
18
+
19
+ import atexit
20
+ import typing
21
+
22
+ from nvmath.bindings import cublas
23
+ from nvmath.bindings import cublasLt as cublaslt
24
+ from nvmath.internal import utils
25
+
26
+ HANDLES: dict[str, dict[int, int]] = {
27
+ "cublas": {},
28
+ "cublaslt": {},
29
+ }
30
+
31
+
32
+ def create_handle(device_id: int, binding="cublaslt") -> int:
33
+ """
34
+ Currently for internal use only.
35
+ """
36
+ with utils.device_ctx(device_id):
37
+ match binding:
38
+ case "cublas":
39
+ handle = cublas.create()
40
+ case "cublaslt" | _:
41
+ handle = cublaslt.create()
42
+ return handle
43
+
44
+
45
+ def destroy_handle(handle: int, binding="cublaslt"):
46
+ """
47
+ Currently for internal use only.
48
+ """
49
+ match binding:
50
+ case "cublas":
51
+ cublas.destroy(handle)
52
+ case "cublaslt" | _:
53
+ cublaslt.destroy(handle)
54
+
55
+
56
+ @atexit.register
57
+ def _cleanup_handles():
58
+ """
59
+ Cleanup all cached handles on program exit.
60
+ """
61
+ for binding, device_handles in HANDLES.items():
62
+ for handle in device_handles.values():
63
+ destroy_handle(handle, binding=binding)
64
+ device_handles.clear()
65
+
66
+
67
+ def get_handle(device_id: int, binding="cublaslt") -> int:
68
+ """
69
+ Retrieve the cuBLAS[lt] library handle for the specified device. If one doesn't exist,
70
+ create, cache, and return the handle.
71
+
72
+ According to the docs for cublasLtHandle_t, any valid cublasHandle_t can be used in
73
+ place of cublasLtHandle_t with a simple cast, so we use the same handle for both APIs.
74
+
75
+ Handles are cached and automatically cleaned up on program exit via the atexit handler.
76
+ We expect to have exactly one handle per device / thread.
77
+ """
78
+ if device_id in HANDLES[binding]:
79
+ handle = HANDLES[binding][device_id]
80
+ else:
81
+ handle = create_handle(device_id, binding=binding)
82
+ HANDLES[binding][device_id] = handle
83
+ return handle
84
+
85
+
86
+ def pointer_aligned_to(address):
87
+ """
88
+ Return the number of bytes the address is aligned to.
89
+ """
90
+ return address & ~(address - 1)
91
+
92
+
93
+ def axis_order_in_memory(strides):
94
+ """
95
+ Compute the order in which the axes appear in memory.
96
+ """
97
+ if len(strides) == 0:
98
+ return ()
99
+
100
+ _, axis_order = zip(*sorted(zip(strides, range(len(strides)), strict=True)), strict=True)
101
+
102
+ return axis_order
103
+
104
+
105
+ def calculate_strides(shape: typing.Sequence[int], axis_order: typing.Sequence[int], min_stride: int = 1):
106
+ """
107
+ Calculate the strides for the provided shape and axis order.
108
+ """
109
+ assert len(axis_order) == len(shape), f"axis_order length ({len(axis_order)}) must equal shape length ({len(shape)})"
110
+ assert len(set(axis_order)) == len(axis_order), f"axis_order must not contain duplicates: {axis_order}"
111
+ assert set(axis_order) == set(range(len(shape))), f"axis_order must be permutation of range({len(shape)}): {axis_order}"
112
+
113
+ strides: list[None | int] = [None] * len(shape)
114
+
115
+ stride = min_stride
116
+ for axis in axis_order:
117
+ strides[axis] = stride
118
+ stride *= shape[axis]
119
+
120
+ return strides
121
+
122
+
123
+ def _contiguous_layout(sorted_shape, sorted_strides):
124
+ return all(sorted_shape[s - 1] * sorted_strides[s - 1] == sorted_strides[s] for s in range(1, len(sorted_strides)))
125
+
126
+
127
+ def check_batch_tileable(batch_shape, batch_strides):
128
+ """
129
+ Check if the matrix layout is tileable across the specified batch layout.
130
+ """
131
+ sorted_batch_strides, sorted_batch_shape = zip(
132
+ *sorted((batch_strides[a], batch_shape[a]) for a in range(len(batch_shape))), strict=True
133
+ )
134
+ return _contiguous_layout(sorted_batch_shape, sorted_batch_strides)
@@ -0,0 +1,8 @@
1
+ # Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from . import helpers as helpers # noqa: F403
6
+ from ._algorithmmod import * # noqa: F403
7
+ from ._configuration import * # noqa: F403
8
+ from .matmulmod import * # noqa: F403
@@ -0,0 +1,149 @@
1
+ # Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ """
6
+ An interface class to query algorithm capabilities and configure it.
7
+ """
8
+
9
+ __all__ = ["Algorithm"]
10
+
11
+ import dataclasses
12
+
13
+ from nvmath.bindings.cublasLt import MatmulHeuristicResult # type: ignore
14
+ from nvmath.linalg._internal.algo_cap_ifc import AlgoCapInterface
15
+ from nvmath.linalg._internal.algo_config_ifc import AlgoConfigInterface
16
+ from nvmath.linalg._internal.enum_to_tuples import (
17
+ CLUSTER_SHAPE_TO_ENUM,
18
+ ENUM_TO_CLUSTER_SHAPE,
19
+ ENUM_TO_MATMUL_STAGE,
20
+ ENUM_TO_MATMUL_TILE,
21
+ MATMUL_STAGE_TO_ENUM,
22
+ MATMUL_TILE_TO_ENUM,
23
+ )
24
+ from nvmath.linalg.advanced._configuration import AlgorithmCapabilities
25
+
26
+
27
+ class Algorithm:
28
+ """
29
+ An interface class to query algorithm capabilities and configure the algorithm.
30
+
31
+ Note that objects of this type should not be constructed directly by the user.
32
+ """
33
+
34
+ def __init__(self, algorithm: MatmulHeuristicResult) -> None:
35
+ assert isinstance(algorithm, MatmulHeuristicResult), "Internal error."
36
+ self.algorithm = algorithm
37
+ self.cap_ifc = AlgoCapInterface(algorithm)
38
+ self.config_ifc = AlgoConfigInterface(algorithm)
39
+
40
+ @property
41
+ def capabilities(self):
42
+ """
43
+ Return the capabilities of this algorithm as a
44
+ :class:`nvmath.linalg.advanced.AlgorithmCapabilities` dataclass.
45
+ """
46
+ names = [field.name for field in dataclasses.fields(AlgorithmCapabilities)]
47
+ _capabilities = {}
48
+ for name in names:
49
+ # Not all capabilities in the enum are supported in all CTK versions.
50
+ try:
51
+ _capabilities[name] = getattr(self.cap_ifc, name)
52
+ except:
53
+ pass
54
+ return AlgorithmCapabilities(**_capabilities)
55
+
56
+ @property
57
+ def algorithm_id(self) -> int:
58
+ "The ID of the algorithm (integer)."
59
+ return self.config_ifc.id
60
+
61
+ @property
62
+ def tile(self) -> tuple[int | str, ...] | str:
63
+ """A tuple representing the tile (see MatmulAlgoConfigAttribute.TILE_ID).
64
+ The value provided must be one of the `tile_ids` in the algorithm capabilities."""
65
+ return ENUM_TO_MATMUL_TILE[self.config_ifc.tile_id]
66
+
67
+ @tile.setter
68
+ def tile(self, tile: tuple[int | str, ...] | str) -> None:
69
+ self.config_ifc.tile_id = MATMUL_TILE_TO_ENUM[tile]
70
+
71
+ @property
72
+ def stages(self) -> tuple[int | str, ...] | str:
73
+ """A tuple representing the stages (see MatmulAlgoConfigAttribute.STAGES_ID).
74
+ The value provided must be one of the `stages_ids` in the algorithm capabilities."""
75
+ return ENUM_TO_MATMUL_STAGE[self.config_ifc.stages_id]
76
+
77
+ @stages.setter
78
+ def stages(self, stages: tuple[int | str, ...] | str) -> None:
79
+ self.config_ifc.stages_id = MATMUL_STAGE_TO_ENUM[stages]
80
+
81
+ @property
82
+ def split_k(self) -> int:
83
+ """The number of split-k steps (see MatmulAlgoConfigAttribute.SPLITK_NUM).
84
+
85
+ This can be set only if `splitk_support` is 1 in the algorithm capabilities."""
86
+ return self.config_ifc.splitk_num
87
+
88
+ @split_k.setter
89
+ def split_k(self, number: int) -> None:
90
+ self.config_ifc.splitk_num = number
91
+
92
+ @property
93
+ def reduction_scheme(self) -> int:
94
+ """The reduction scheme used (see MatmulAlgoConfigAttribute.REDUCTION_SCHEME).
95
+
96
+ The value provided must be consistent with the `reduction_scheme_mask` in the
97
+ algorithm capabilities."""
98
+ return self.config_ifc.reduction_scheme
99
+
100
+ @reduction_scheme.setter
101
+ def reduction_scheme(self, scheme_id: int) -> None:
102
+ self.config_ifc.reduction_scheme = scheme_id
103
+
104
+ @property
105
+ def cta_swizzling(self) -> bool:
106
+ """A flag indicating CTA swizzling (see MatmulAlgoConfigAttribute.CTA_SWIZZLING).
107
+
108
+ This can be set only if `cta_swizzling` is 1 in the algorithm capabilities."""
109
+ return self.config_ifc.cta_swizzling
110
+
111
+ @cta_swizzling.setter
112
+ def cta_swizzling(self, flag: bool) -> None:
113
+ self.config_ifc.cta_swizzling = flag
114
+
115
+ @property
116
+ def custom_option(self) -> int:
117
+ """A value indicating the custom option (see
118
+ MatmulAlgoConfigAttribute.CUSTOM_OPTION).
119
+
120
+ The value provided must be less than `custom_option_max` in the algorithm
121
+ capabilities."""
122
+ return self.config_ifc.custom_option
123
+
124
+ @custom_option.setter
125
+ def custom_option(self, value: int) -> None:
126
+ self.config_ifc.custom_option = value
127
+
128
+ @property
129
+ def inner_shape(self) -> int:
130
+ """A value indicating the inner shape (see
131
+ MatmulAlgoConfigAttribute.INNER_SHAPE_ID)."""
132
+ return self.config_ifc.inner_shape_id
133
+
134
+ @inner_shape.setter
135
+ def inner_shape(self, shape: int) -> None:
136
+ self.config_ifc.inner_shape_id = shape
137
+
138
+ @property
139
+ def cluster_shape(self) -> tuple[int | str, ...] | str:
140
+ """A tuple representing the cluster shape (see
141
+ MatmulAlgoConfigAttribute.CLUSTER_SHAPE_ID).
142
+
143
+ The value provided must be one of the `cluster_shape_ids` in the algorithm
144
+ capabilities."""
145
+ return ENUM_TO_CLUSTER_SHAPE[self.config_ifc.cluster_shape_id]
146
+
147
+ @cluster_shape.setter
148
+ def cluster_shape(self, shape: tuple[int | str, ...] | str) -> None:
149
+ self.config_ifc.cluster_shape_id = CLUSTER_SHAPE_TO_ENUM[shape]