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,12 @@
1
+ # Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from nvmath.bindings.cublas import ComputeType # type: ignore
6
+
7
+ from . import advanced
8
+
9
+ __all__ = [
10
+ "advanced",
11
+ "ComputeType",
12
+ ]
@@ -0,0 +1,3 @@
1
+ # Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,496 @@
1
+ # Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ """Internal interface for epilog input handling."""
6
+
7
+ __all__ = [
8
+ "EPILOG_INPUT_HANDLERS_MAP",
9
+ "EPILOG_OUTPUT_HANDLERS_MAP",
10
+ "BiasHandler",
11
+ "BgradHandler",
12
+ "ReluAuxHandler",
13
+ "GeluAuxHandler",
14
+ "DGeluAuxHandler",
15
+ "EpilogInputHandler",
16
+ "EpilogOutputHandler",
17
+ ]
18
+
19
+ import math
20
+ from abc import abstractmethod
21
+ from typing import Protocol, runtime_checkable
22
+
23
+ from nvmath.bindings import cublasMp # type: ignore
24
+ from nvmath.internal import typemaps
25
+ from nvmath.linalg._internal.utils import axis_order_in_memory, calculate_strides, check_batch_tileable
26
+
27
+ Epilog = cublasMp.MatmulEpilogue
28
+
29
+
30
+ @runtime_checkable
31
+ class EpilogInputHandler(Protocol):
32
+ """
33
+ Protocol for epilog handler input validation and setting the appropriate MM descriptor
34
+ attributes.
35
+ """
36
+
37
+ @abstractmethod
38
+ def __init__(self, logger, mm_traits, enumerator, c_dtype_name, d_dtype_name, aux_dtype_name):
39
+ raise NotImplementedError
40
+
41
+ @property
42
+ @abstractmethod
43
+ def name(self):
44
+ """
45
+ The name of the epilog input that is handled (bias, ...).
46
+ """
47
+ raise NotImplementedError
48
+
49
+ @abstractmethod
50
+ def validate(self, epilog_input):
51
+ """
52
+ Validate the provided epilog input.
53
+
54
+ Args:
55
+ epilog_input: The epilog input to validate.
56
+
57
+ """
58
+ raise NotImplementedError
59
+
60
+ @abstractmethod
61
+ def update(self, mm_desc_ifc, epilog_input):
62
+ """
63
+ Update the provided epilog input.
64
+
65
+ Args:
66
+ mm_desc_ifc: The MM descriptor to update, provided as a MatmulDescInterface
67
+ object. epilog_input: The epilog input to validate.
68
+
69
+ """
70
+ raise NotImplementedError
71
+
72
+
73
+ @runtime_checkable
74
+ class EpilogOutputHandler(Protocol):
75
+ """
76
+ Protocol for epilog handler output validation and setting the appropriate MM descriptor
77
+ attributes.
78
+ """
79
+
80
+ @abstractmethod
81
+ def __init__(self, logger, mm_traits, enumerator, c_dtype_name, d_dtype_name, aux_dtype_name):
82
+ raise NotImplementedError
83
+
84
+ @property
85
+ @abstractmethod
86
+ def name(self):
87
+ """
88
+ The name of the epilog output that is handled (relu_aux, gelu_aux, bgrad, bragda,
89
+ bgradb, ...).
90
+ """
91
+ raise NotImplementedError
92
+
93
+ @abstractmethod
94
+ def attributes(self):
95
+ """
96
+ The shape, stride, and dtype name of the output tensor.
97
+ """
98
+ raise NotImplementedError
99
+
100
+ @abstractmethod
101
+ def update(self, mm_desc_ifc):
102
+ """
103
+ Update all the attributes for this epilog, except the pointer.
104
+
105
+ Args:
106
+ mm_desc_ifc: The MM descriptor to update, provided as a MatmulDescInterface
107
+ object.
108
+ """
109
+ raise NotImplementedError
110
+
111
+ @abstractmethod
112
+ def update_ptr(self, mm_desc_ifc, ptr):
113
+ """
114
+ Set the pointer for this epilog.
115
+
116
+ Args:
117
+ mm_desc_ifc: The MM descriptor to update, provided as a MatmulDescInterface
118
+ object.
119
+
120
+ ptr: The pointer to set.
121
+
122
+ """
123
+ raise NotImplementedError
124
+
125
+
126
+ class BiasHandler(EpilogInputHandler):
127
+ def __init__(self, logger, mm_traits, enumerator, c_dtype_name, d_dtype_name, aux_dtype_name):
128
+ self.logger = logger
129
+ self.mm_traits = mm_traits
130
+
131
+ assert enumerator in [
132
+ Epilog.BIAS,
133
+ Epilog.RELU_BIAS,
134
+ Epilog.RELU_AUX_BIAS,
135
+ Epilog.GELU_BIAS,
136
+ Epilog.GELU_AUX_BIAS,
137
+ ], "Internal error."
138
+ self.enumerator = enumerator
139
+
140
+ self.d_dtype_name = d_dtype_name
141
+
142
+ self._name = "bias"
143
+
144
+ @property
145
+ def name(self):
146
+ return self._name
147
+
148
+ def validate(self, bias_tensor):
149
+ # The bias_tensor must be of rank 1, or rank 2 with (M, 1).
150
+
151
+ bias_shape = list(bias_tensor.shape)
152
+ bias_strides = list(bias_tensor.strides)
153
+
154
+ mm_traits = self.mm_traits
155
+
156
+ # Determine the rank of bias_tensor input.
157
+ bias_batch_shape, bias_mm_shape = bias_shape[:-2], bias_shape[-2:]
158
+ bias_mm_strides = bias_strides[-2:]
159
+ if len(bias_mm_shape) == 1:
160
+ s, d = bias_mm_shape[0], bias_mm_strides[0]
161
+ bias_mm_shape += [1]
162
+ bias_mm_strides += [s * d]
163
+ self.logger.debug(f"The MM shape for the bias is {bias_mm_shape} with strides {bias_mm_strides}.")
164
+
165
+ Mb, Nb = bias_mm_shape
166
+ if Mb != mm_traits.d_layout.shape[0]:
167
+ raise ValueError(f"The M dimension of the bias vector ({Mb}) must match the local M dimension of A.")
168
+
169
+ if Nb != 1:
170
+ raise ValueError(f"The N dimension of the bias vector ({Nb}) must be equal to 1.")
171
+
172
+ # Check if the bias_tensor batch shape and axis order match that of the MM, and it's
173
+ # tileable.
174
+ if len(bias_batch_shape) > 0:
175
+ raise ValueError("Batched matmul is currently not supported.")
176
+
177
+ if bias_mm_strides[0] != 1:
178
+ raise ValueError(
179
+ f"The stride of the bias {bias_strides} must be 1 along the dimension {len(bias_strides) - 2}, "
180
+ f"which corresponds to the M dimension."
181
+ )
182
+
183
+ def update(self, mm_desc_ifc, bias_tensor):
184
+ # Set the bias pointer.
185
+ mm_desc_ifc.bias_pointer = bias_tensor.data_ptr
186
+ # Set the bias data type.
187
+ if bias_tensor.dtype != self.d_dtype_name:
188
+ mm_desc_ifc.bias_data_type = typemaps.NAME_TO_DATA_TYPE[bias_tensor.dtype]
189
+
190
+
191
+ def round_up(m, base):
192
+ return m + (base - m) % base
193
+
194
+
195
+ def relu_aux_mm_shape(m, n):
196
+ """
197
+ Return the RELU auxiliary bitmask matrix shape when stored as uint8 and M is padded to
198
+ 128-bit/16-byte multiples.
199
+ """
200
+ # Store bitflag mask using int8 dtype, padded to (128//8 ==) 16 bytes.
201
+ m = round_up(math.ceil(m / 8), base=16)
202
+ return m, n
203
+
204
+
205
+ def gelu_aux_mm_shape(m, n):
206
+ """
207
+ Return the GELU auxiliary matrix shape when M is padded to 8-byte multiples.
208
+ """
209
+ m = round_up(m, base=8)
210
+ return m, n
211
+
212
+
213
+ class ReluAuxHandler(EpilogOutputHandler):
214
+ def __init__(self, logger, mm_traits, enumerator, c_dtype_name, d_dtype_name, aux_dtype_name):
215
+ self.logger = logger
216
+ self.mm_traits = mm_traits
217
+
218
+ assert enumerator in [Epilog.RELU_AUX, Epilog.RELU_AUX_BIAS], "Internal error."
219
+ self.enumerator = enumerator
220
+
221
+ self._name = "relu_aux"
222
+
223
+ m, n = relu_aux_mm_shape(*mm_traits.d_layout.shape)
224
+ batch_len = len(mm_traits.batch_axis_order)
225
+
226
+ self.aux_shape = mm_traits.batch_shape + [m, n]
227
+ aux_axis_order = [batch_len, batch_len + 1] + list(mm_traits.batch_axis_order) # Column order for the bitmask.
228
+ self.aux_strides = calculate_strides(self.aux_shape, aux_axis_order)
229
+ if aux_dtype_name is not None:
230
+ raise ValueError("Custom type for auxiliary outputs is not supported for RELU epilogs.")
231
+ self.aux_dtype_name = "uint8"
232
+
233
+ # We store bitmask using int8 dtype but the values below are in number of elements.
234
+ self.aux_ld = m * 8 # should be consistent with order (currently COL).
235
+ self.aux_batch_offset = m * 8 * n
236
+
237
+ @property
238
+ def name(self):
239
+ return self._name
240
+
241
+ def attributes(self):
242
+ return self.aux_shape, self.aux_strides, self.aux_dtype_name
243
+
244
+ def update(self, mm_desc_ifc):
245
+ # Set the aux LD.
246
+ mm_desc_ifc.epilogue_aux_ld = self.aux_ld
247
+ # Set the pointer to 0x1 to bypass the cuBLAS check.
248
+ mm_desc_ifc.epilogue_aux_pointer = 0x1
249
+
250
+ def update_ptr(self, mm_desc_ifc, ptr):
251
+ # Set the aux pointer.
252
+ mm_desc_ifc.epilogue_aux_pointer = ptr
253
+
254
+
255
+ class GeluAuxHandler(EpilogOutputHandler):
256
+ def __init__(self, logger, mm_traits, enumerator, c_dtype_name, d_dtype_name, aux_dtype_name):
257
+ self.logger = logger
258
+ self.mm_traits = mm_traits
259
+
260
+ assert enumerator in [Epilog.GELU_AUX, Epilog.GELU_AUX_BIAS], "Internal error."
261
+ self.enumerator = enumerator
262
+
263
+ self.d_dtype_name = d_dtype_name
264
+
265
+ self._name = "gelu_aux"
266
+
267
+ m, n = gelu_aux_mm_shape(*mm_traits.d_layout.shape)
268
+ batch_len = len(mm_traits.batch_axis_order)
269
+
270
+ self.aux_shape = mm_traits.batch_shape + [m, n]
271
+ aux_axis_order = [batch_len, batch_len + 1] + list(mm_traits.batch_axis_order) # Column order for the GELU inputs.
272
+ self.aux_strides = calculate_strides(self.aux_shape, aux_axis_order)
273
+
274
+ if aux_dtype_name:
275
+ self.aux_dtype_name = aux_dtype_name
276
+ else:
277
+ self.aux_dtype_name = c_dtype_name if "float8" in d_dtype_name else d_dtype_name
278
+
279
+ self.aux_ld = m # should be consistent with order (currently COL).
280
+ self.aux_batch_offset = m * n
281
+
282
+ @property
283
+ def name(self):
284
+ return self._name
285
+
286
+ def attributes(self):
287
+ return self.aux_shape, self.aux_strides, self.aux_dtype_name
288
+
289
+ def update(self, mm_desc_ifc):
290
+ # Set the aux LD.
291
+ mm_desc_ifc.epilogue_aux_ld = self.aux_ld
292
+ # Set the pointer to 0x1 to bypass the cuBLAS check.
293
+ mm_desc_ifc.epilogue_aux_pointer = 0x1
294
+ if self.aux_dtype_name is not None:
295
+ mm_desc_ifc.epilogue_aux_data_type = typemaps.NAME_TO_DATA_TYPE[self.aux_dtype_name]
296
+
297
+ def update_ptr(self, mm_desc_ifc, ptr):
298
+ # Set the aux pointer.
299
+ mm_desc_ifc.epilogue_aux_pointer = ptr
300
+
301
+
302
+ class BgradHandler(EpilogOutputHandler):
303
+ def __init__(self, logger, mm_traits, enumerator, c_dtype_name, d_dtype_name, aux_dtype_name):
304
+ self.logger = logger
305
+ self.mm_traits = mm_traits
306
+
307
+ assert enumerator in [Epilog.DRELU_BGRAD, Epilog.DGELU_BGRAD, Epilog.BGRADA, Epilog.BGRADB], "Internal error."
308
+ self.enumerator = enumerator
309
+
310
+ self._name = enumerator.name.lower()
311
+
312
+ if aux_dtype_name is not None:
313
+ raise ValueError("Custom type for auxiliary outputs is not supported for BGRAD epilogs.")
314
+
315
+ # For BGRADB with BIAS_RESULT_SCHEME=FULL the cuBLASMp output is always replicated.
316
+ m = mm_traits.N if enumerator == Epilog.BGRADB else mm_traits.d_layout.shape[0]
317
+ batch_len = len(mm_traits.batch_axis_order)
318
+
319
+ self.bgrad_shape = shape = [m]
320
+ if mm_traits.batch_shape:
321
+ shape = shape + [1]
322
+ self.bgrad_shape = mm_traits.batch_shape + self.bgrad_shape + [1]
323
+
324
+ bgrad_axis_order = [batch_len + a for a in range(len(shape))] + list(mm_traits.batch_axis_order) # Column order.
325
+ self.bgrad_strides = calculate_strides(self.bgrad_shape, bgrad_axis_order)
326
+
327
+ self.d_dtype_name = d_dtype_name
328
+ self.bgrad_dtype_name = d_dtype_name
329
+ self.bgrad_batch_offset = m
330
+
331
+ @property
332
+ def name(self):
333
+ return self._name
334
+
335
+ def attributes(self):
336
+ return self.bgrad_shape, self.bgrad_strides, self.bgrad_dtype_name
337
+
338
+ def update(self, mm_desc_ifc):
339
+ # The bgrad data type is by default the data type of the result for all the cases we
340
+ # support.
341
+ assert self.bgrad_dtype_name == self.d_dtype_name, "Internal error."
342
+
343
+ def update_ptr(self, mm_desc_ifc, ptr):
344
+ # Set the bgrad pointer.
345
+ mm_desc_ifc.bias_pointer = ptr
346
+
347
+
348
+ class DGeluAuxHandler(EpilogInputHandler):
349
+ def __init__(self, logger, mm_traits, enumerator, c_dtype_name, d_dtype_name, aux_dtype_name):
350
+ self.logger = logger
351
+ self.mm_traits = mm_traits
352
+
353
+ assert enumerator in [Epilog.DGELU, Epilog.DGELU_BGRAD], "Internal error."
354
+ self.enumerator = enumerator
355
+
356
+ self.d_dtype_name = d_dtype_name
357
+
358
+ self.batch_offset = None
359
+
360
+ self._name = "gelu_aux"
361
+
362
+ # The GELU aux matrix shape, including padding.
363
+ self.mm_m, self.mm_n = gelu_aux_mm_shape(*mm_traits.d_layout.shape)
364
+
365
+ self.aux_ld = self.mm_m # should be consistent with order (currently COL).
366
+
367
+ # K=1 is not supported by cuBLAS
368
+ if mm_traits.K == 1:
369
+ raise ValueError("K=1 is not supported for DGELU epilogs")
370
+
371
+ @property
372
+ def name(self):
373
+ return self._name
374
+
375
+ def validate(self, gelu_aux_tensor):
376
+ # The gelu_aux_tensor must be of rank 2 or its batched version of the latter (...,
377
+ # M, N).
378
+ gelu_aux_shape = list(gelu_aux_tensor.shape)
379
+ gelu_aux_strides = list(gelu_aux_tensor.strides)
380
+
381
+ # The dtype must be the same as that of D.
382
+ if gelu_aux_tensor.dtype != self.d_dtype_name:
383
+ raise ValueError(
384
+ f"The dtype of the GELU auxiliary input for epilog {self.enumerator.name} must be '{self.d_dtype_name}'. "
385
+ f"The epilog input's dtype is '{gelu_aux_tensor.dtype}'."
386
+ )
387
+
388
+ mm_traits = self.mm_traits
389
+
390
+ # Determine the rank of gelu_aux_tensor input.
391
+ gelu_aux_batch_shape, gelu_aux_mm_shape = gelu_aux_shape[:-2], gelu_aux_shape[-2:]
392
+ gelu_aux_batch_strides, gelu_aux_mm_strides = gelu_aux_strides[:-2], gelu_aux_strides[-2:]
393
+
394
+ # The MM shape must match, the MM must be in col order, and the batch order must
395
+ # match.
396
+ Ma, Na = gelu_aux_mm_shape
397
+ if Ma != self.mm_m or Na != self.mm_n:
398
+ raise ValueError(
399
+ f"The auxiliary epilog input for epilog {self.enumerator.name} must have "
400
+ f"the MM shape (..., {self.mm_m}, {self.mm_n}). The epilog input's MM shape is (..., {Ma}, {Na})."
401
+ )
402
+
403
+ # Check if the gelu_aux_tensor batch shape and axis order match that of the MM, and
404
+ # it's tileable.
405
+ if len(gelu_aux_batch_shape) > 0:
406
+ if gelu_aux_batch_shape != mm_traits.batch_shape:
407
+ raise ValueError(
408
+ f"The batch dimensions of the GELU auxiliary input {gelu_aux_batch_shape} must match with that "
409
+ f"of the matrix multiplication definition {mm_traits.batch_shape}."
410
+ )
411
+
412
+ if (gelu_aux_batch_axis_order := axis_order_in_memory(gelu_aux_batch_strides)) != mm_traits.batch_axis_order:
413
+ raise ValueError(
414
+ f"The batch axis order of the GELU auxiliary input {gelu_aux_batch_axis_order} "
415
+ f"must match with that of the other operands {mm_traits.batch_axis_order}."
416
+ )
417
+
418
+ if not check_batch_tileable(gelu_aux_batch_shape, gelu_aux_batch_strides):
419
+ message = (
420
+ f"The batch layout for GELU auxiliary input corresponding to shape = {gelu_aux_batch_shape} and "
421
+ f"strides = {gelu_aux_batch_strides} is currently not supported because it is not tileable."
422
+ )
423
+ raise ValueError(message)
424
+
425
+ if gelu_aux_mm_strides[0] != 1:
426
+ raise ValueError(
427
+ f"The stride of the GELU auxiliary input {gelu_aux_strides} must be 1 "
428
+ f"along the dimension {len(gelu_aux_strides) - 2}, which corresponds to the M dimension."
429
+ )
430
+
431
+ self.batch_offset = min(gelu_aux_batch_strides) if gelu_aux_batch_strides else 0 # gelu_aux broadcast
432
+
433
+ if self.batch_offset > 0:
434
+ assert self.batch_offset >= self.mm_m * self.mm_n, "Tensor data must not overlap."
435
+
436
+ def update(self, mm_desc_ifc, gelu_aux_tensor):
437
+ # Set the epilog aux pointer.
438
+ mm_desc_ifc.epilogue_aux_pointer = gelu_aux_tensor.data_ptr
439
+ # Set the aux LD.
440
+ mm_desc_ifc.epilogue_aux_ld = self.aux_ld
441
+ # Set the gelu aux data type.
442
+ if gelu_aux_tensor.dtype != self.d_dtype_name:
443
+ mm_desc_ifc.epilogue_aux_data_type = typemaps.NAME_TO_DATA_TYPE[gelu_aux_tensor.dtype]
444
+
445
+
446
+ EPILOG_INPUT_HANDLERS_MAP: dict[cublasMp.MatmulEpilogue, list[type[EpilogInputHandler]]] = {
447
+ Epilog.ALLREDUCE: [],
448
+ Epilog.RELU: [],
449
+ Epilog.RELU_AUX: [],
450
+ Epilog.GELU: [],
451
+ Epilog.GELU_AUX: [],
452
+ Epilog.BIAS: [BiasHandler],
453
+ Epilog.RELU_BIAS: [BiasHandler],
454
+ Epilog.RELU_AUX_BIAS: [BiasHandler],
455
+ Epilog.GELU_BIAS: [BiasHandler],
456
+ Epilog.GELU_AUX_BIAS: [BiasHandler],
457
+ Epilog.DGELU: [DGeluAuxHandler],
458
+ Epilog.DGELU_BGRAD: [DGeluAuxHandler],
459
+ Epilog.BGRADA: [],
460
+ Epilog.BGRADB: [],
461
+ }
462
+
463
+ EPILOG_OUTPUT_HANDLERS_MAP: dict[cublasMp.MatmulEpilogue, list[type[EpilogOutputHandler]]] = {
464
+ Epilog.ALLREDUCE: [],
465
+ Epilog.RELU: [],
466
+ Epilog.RELU_AUX: [ReluAuxHandler],
467
+ Epilog.GELU: [],
468
+ Epilog.GELU_AUX: [GeluAuxHandler],
469
+ Epilog.BIAS: [],
470
+ Epilog.RELU_BIAS: [],
471
+ Epilog.RELU_AUX_BIAS: [ReluAuxHandler],
472
+ Epilog.GELU_BIAS: [],
473
+ Epilog.GELU_AUX_BIAS: [GeluAuxHandler],
474
+ Epilog.DGELU: [],
475
+ Epilog.DGELU_BGRAD: [BgradHandler],
476
+ Epilog.BGRADA: [BgradHandler],
477
+ Epilog.BGRADB: [BgradHandler],
478
+ }
479
+
480
+ EPILOG_MINIMUM_VERSIONS_MAP: dict[cublasMp.MatmulEpilogue | None, dict[str, int]] = {
481
+ None: {"cublasMp": 00000},
482
+ Epilog.ALLREDUCE: {"cublasMp": 800},
483
+ Epilog.RELU: {"cublasMp": 800},
484
+ Epilog.GELU: {"cublasMp": 800},
485
+ Epilog.BIAS: {"cublasMp": 800},
486
+ Epilog.RELU_AUX: {"cublasMp": 800},
487
+ Epilog.GELU_AUX: {"cublasMp": 800},
488
+ Epilog.RELU_BIAS: {"cublasMp": 800},
489
+ Epilog.RELU_AUX_BIAS: {"cublasMp": 800},
490
+ Epilog.GELU_BIAS: {"cublasMp": 800},
491
+ Epilog.GELU_AUX_BIAS: {"cublasMp": 800},
492
+ Epilog.DGELU: {"cublasMp": 800},
493
+ Epilog.BGRADA: {"cublasMp": 800},
494
+ Epilog.BGRADB: {"cublasMp": 800},
495
+ Epilog.DGELU_BGRAD: {"cublasMp": 800},
496
+ }
@@ -0,0 +1,28 @@
1
+ # Copyright (c) 2025-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 matmul descriptor attributes.
7
+ """
8
+
9
+ __all__ = ["MatmulDescInterface"]
10
+
11
+ from nvmath._internal.attribute_ifc_factory import make_cublas_attribute_interface
12
+ from nvmath.bindings import cublasMp # type: ignore
13
+
14
+ # Create a class, MatmulDescInterface, such that each enum member in
15
+ # MatmulDescriptorAttribute is exposed as a lowercase property (getter + setter)
16
+ # and a ``set_<attr>_unchecked`` method (setter without debug logging).
17
+ # For example, if the class instance is stored as ``desc_ifc``,
18
+ # then the enum member ``ALGO_TYPE`` becomes the property
19
+ # ``desc_ifc.algo_type``.
20
+ MatmulDescInterface = make_cublas_attribute_interface(
21
+ class_module=__name__,
22
+ class_name="MatmulDescInterface",
23
+ attribute_enum=cublasMp.MatmulDescriptorAttribute,
24
+ get_attribute_dtype_fn=cublasMp.get_matmul_descriptor_attribute_dtype,
25
+ get_attribute_fn=cublasMp.matmul_descriptor_get_attribute,
26
+ set_attribute_fn=cublasMp.matmul_descriptor_set_attribute,
27
+ with_unchecked=True, # Consistent with the non-distributed MatmulDescInterface.
28
+ )
@@ -0,0 +1,8 @@
1
+ # Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from nvmath.linalg.advanced import helpers as helpers # noqa: F403
6
+
7
+ from ._configuration import * # noqa: F403
8
+ from .matmulmod import * # noqa: F403