nvmath-python 0.6.0__cp313-cp313-manylinux_2_28_x86_64.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 (224) hide show
  1. nvmath/__init__.pxd +0 -0
  2. nvmath/__init__.py +37 -0
  3. nvmath/_internal/__init__.py +0 -0
  4. nvmath/_internal/layout.py +58 -0
  5. nvmath/_utils.py +143 -0
  6. nvmath/bindings/__init__.pxd +0 -0
  7. nvmath/bindings/__init__.py +44 -0
  8. nvmath/bindings/_internal/__init__.pxd +0 -0
  9. nvmath/bindings/_internal/__init__.py +0 -0
  10. nvmath/bindings/_internal/cublas.cpython-313-x86_64-linux-gnu.so +0 -0
  11. nvmath/bindings/_internal/cublas.pxd +520 -0
  12. nvmath/bindings/_internal/cublasLt.cpython-313-x86_64-linux-gnu.so +0 -0
  13. nvmath/bindings/_internal/cublasLt.pxd +54 -0
  14. nvmath/bindings/_internal/cudss.cpython-313-x86_64-linux-gnu.so +0 -0
  15. nvmath/bindings/_internal/cudss.pxd +44 -0
  16. nvmath/bindings/_internal/cufft.cpython-313-x86_64-linux-gnu.so +0 -0
  17. nvmath/bindings/_internal/cufft.pxd +69 -0
  18. nvmath/bindings/_internal/cufftMp.cpython-313-x86_64-linux-gnu.so +0 -0
  19. nvmath/bindings/_internal/cufftMp.pxd +77 -0
  20. nvmath/bindings/_internal/curand.cpython-313-x86_64-linux-gnu.so +0 -0
  21. nvmath/bindings/_internal/curand.pxd +42 -0
  22. nvmath/bindings/_internal/cusolver.cpython-313-x86_64-linux-gnu.so +0 -0
  23. nvmath/bindings/_internal/cusolver.pxd +15 -0
  24. nvmath/bindings/_internal/cusolverDn.cpython-313-x86_64-linux-gnu.so +0 -0
  25. nvmath/bindings/_internal/cusolverDn.pxd +386 -0
  26. nvmath/bindings/_internal/cusparse.cpython-313-x86_64-linux-gnu.so +0 -0
  27. nvmath/bindings/_internal/cusparse.pxd +270 -0
  28. nvmath/bindings/_internal/mathdx.cpython-313-x86_64-linux-gnu.so +0 -0
  29. nvmath/bindings/_internal/mathdx.pxd +79 -0
  30. nvmath/bindings/_internal/nvshmem.cpython-313-x86_64-linux-gnu.so +0 -0
  31. nvmath/bindings/_internal/nvshmem.pxd +29 -0
  32. nvmath/bindings/_internal/utils.cpython-313-x86_64-linux-gnu.so +0 -0
  33. nvmath/bindings/_internal/utils.pxd +178 -0
  34. nvmath/bindings/_internal/utils.pyi +7 -0
  35. nvmath/bindings/cublas.cpython-313-x86_64-linux-gnu.so +0 -0
  36. nvmath/bindings/cublas.pxd +548 -0
  37. nvmath/bindings/cublas.pyi +712 -0
  38. nvmath/bindings/cublasLt.cpython-313-x86_64-linux-gnu.so +0 -0
  39. nvmath/bindings/cublasLt.pxd +100 -0
  40. nvmath/bindings/cublasLt.pyi +1242 -0
  41. nvmath/bindings/cudss.cpython-313-x86_64-linux-gnu.so +0 -0
  42. nvmath/bindings/cudss.pxd +83 -0
  43. nvmath/bindings/cudss.pyi +249 -0
  44. nvmath/bindings/cufft.cpython-313-x86_64-linux-gnu.so +0 -0
  45. nvmath/bindings/cufft.pxd +114 -0
  46. nvmath/bindings/cufft.pyi +235 -0
  47. nvmath/bindings/cufftMp.cpython-313-x86_64-linux-gnu.so +0 -0
  48. nvmath/bindings/cufftMp.pxd +124 -0
  49. nvmath/bindings/cufftMp.pyi +258 -0
  50. nvmath/bindings/curand.cpython-313-x86_64-linux-gnu.so +0 -0
  51. nvmath/bindings/curand.pxd +71 -0
  52. nvmath/bindings/curand.pyi +148 -0
  53. nvmath/bindings/cusolver.cpython-313-x86_64-linux-gnu.so +0 -0
  54. nvmath/bindings/cusolver.pxd +60 -0
  55. nvmath/bindings/cusolver.pyi +210 -0
  56. nvmath/bindings/cusolverDn.cpython-313-x86_64-linux-gnu.so +0 -0
  57. nvmath/bindings/cusolverDn.pxd +410 -0
  58. nvmath/bindings/cusolverDn.pyi +395 -0
  59. nvmath/bindings/cusparse.cpython-313-x86_64-linux-gnu.so +0 -0
  60. nvmath/bindings/cusparse.pxd +329 -0
  61. nvmath/bindings/cusparse.pyi +664 -0
  62. nvmath/bindings/cycublas.cpython-313-x86_64-linux-gnu.so +0 -0
  63. nvmath/bindings/cycublas.pxd +667 -0
  64. nvmath/bindings/cycublasLt.cpython-313-x86_64-linux-gnu.so +0 -0
  65. nvmath/bindings/cycublasLt.pxd +1020 -0
  66. nvmath/bindings/cycudss.cpython-313-x86_64-linux-gnu.so +0 -0
  67. nvmath/bindings/cycudss.pxd +191 -0
  68. nvmath/bindings/cycufft.cpython-313-x86_64-linux-gnu.so +0 -0
  69. nvmath/bindings/cycufft.pxd +320 -0
  70. nvmath/bindings/cycufftMp.cpython-313-x86_64-linux-gnu.so +0 -0
  71. nvmath/bindings/cycufftMp.pxd +333 -0
  72. nvmath/bindings/cycurand.cpython-313-x86_64-linux-gnu.so +0 -0
  73. nvmath/bindings/cycurand.pxd +146 -0
  74. nvmath/bindings/cycusolver.cpython-313-x86_64-linux-gnu.so +0 -0
  75. nvmath/bindings/cycusolver.pxd +143 -0
  76. nvmath/bindings/cycusolverDn.cpython-313-x86_64-linux-gnu.so +0 -0
  77. nvmath/bindings/cycusolverDn.pxd +414 -0
  78. nvmath/bindings/cycusparse.cpython-313-x86_64-linux-gnu.so +0 -0
  79. nvmath/bindings/cycusparse.pxd +476 -0
  80. nvmath/bindings/cymathdx.cpython-313-x86_64-linux-gnu.so +0 -0
  81. nvmath/bindings/cymathdx.pxd +362 -0
  82. nvmath/bindings/cynvshmem.cpython-313-x86_64-linux-gnu.so +0 -0
  83. nvmath/bindings/cynvshmem.pxd +126 -0
  84. nvmath/bindings/mathdx.cpython-313-x86_64-linux-gnu.so +0 -0
  85. nvmath/bindings/mathdx.pxd +131 -0
  86. nvmath/bindings/mathdx.pyi +682 -0
  87. nvmath/bindings/nvpl/__init__.pxd +0 -0
  88. nvmath/bindings/nvpl/__init__.py +11 -0
  89. nvmath/bindings/nvpl/_internal/__init__.pxd +0 -0
  90. nvmath/bindings/nvpl/_internal/__init__.py +0 -0
  91. nvmath/bindings/nvpl/_internal/fft.cpython-313-x86_64-linux-gnu.so +0 -0
  92. nvmath/bindings/nvpl/_internal/fft.pxd +36 -0
  93. nvmath/bindings/nvpl/cyfft.cpython-313-x86_64-linux-gnu.so +0 -0
  94. nvmath/bindings/nvpl/cyfft.pxd +87 -0
  95. nvmath/bindings/nvpl/fft.cpython-313-x86_64-linux-gnu.so +0 -0
  96. nvmath/bindings/nvpl/fft.pxd +100 -0
  97. nvmath/bindings/nvpl/fft.pyi +154 -0
  98. nvmath/bindings/nvshmem.cpython-313-x86_64-linux-gnu.so +0 -0
  99. nvmath/bindings/nvshmem.pxd +54 -0
  100. nvmath/bindings/nvshmem.pyi +131 -0
  101. nvmath/device/__init__.py +13 -0
  102. nvmath/device/_deprecated.py +33 -0
  103. nvmath/device/common.py +145 -0
  104. nvmath/device/common_backend.py +125 -0
  105. nvmath/device/common_cuda.py +156 -0
  106. nvmath/device/common_mathdx.py +100 -0
  107. nvmath/device/common_numba.py +159 -0
  108. nvmath/device/common_opaque_tensor.py +128 -0
  109. nvmath/device/cublasdx.py +1089 -0
  110. nvmath/device/cublasdx_backend.py +552 -0
  111. nvmath/device/cublasdx_numba.py +531 -0
  112. nvmath/device/cufftdx.py +555 -0
  113. nvmath/device/cufftdx_backend.py +194 -0
  114. nvmath/device/cufftdx_numba.py +123 -0
  115. nvmath/device/curand_kernel.py +9147 -0
  116. nvmath/device/random.py +437 -0
  117. nvmath/device/random_helpers.py +23 -0
  118. nvmath/device/random_states.py +189 -0
  119. nvmath/device/types.py +11 -0
  120. nvmath/device/vector_types_numba.py +203 -0
  121. nvmath/distributed/__init__.py +117 -0
  122. nvmath/distributed/_internal/__init__.py +0 -0
  123. nvmath/distributed/_internal/nvshmem.py +306 -0
  124. nvmath/distributed/_internal/tensor_ifc.py +60 -0
  125. nvmath/distributed/_internal/tensor_ifc_cupy.py +62 -0
  126. nvmath/distributed/_internal/tensor_ifc_host_device.py +165 -0
  127. nvmath/distributed/_internal/tensor_ifc_numpy.py +42 -0
  128. nvmath/distributed/_internal/tensor_ifc_torch.py +140 -0
  129. nvmath/distributed/_internal/tensor_wrapper.py +76 -0
  130. nvmath/distributed/_utils.py +168 -0
  131. nvmath/distributed/fft/__init__.py +6 -0
  132. nvmath/distributed/fft/_configuration.py +100 -0
  133. nvmath/distributed/fft/fft.py +2443 -0
  134. nvmath/distributed/reshape/__init__.py +6 -0
  135. nvmath/distributed/reshape/_configuration.py +39 -0
  136. nvmath/distributed/reshape/reshape.py +1259 -0
  137. nvmath/fft/__init__.py +7 -0
  138. nvmath/fft/_configuration.py +208 -0
  139. nvmath/fft/_exec_utils.py +114 -0
  140. nvmath/fft/_helpers.py +260 -0
  141. nvmath/fft/fft.py +2343 -0
  142. nvmath/internal/__init__.pxd +3 -0
  143. nvmath/internal/__init__.py +5 -0
  144. nvmath/internal/bindings.cpython-313-x86_64-linux-gnu.so +0 -0
  145. nvmath/internal/bindings.pxd +24 -0
  146. nvmath/internal/enum_utils.py +142 -0
  147. nvmath/internal/formatters.py +87 -0
  148. nvmath/internal/mem_limit.py +51 -0
  149. nvmath/internal/memory.cpython-313-x86_64-linux-gnu.so +0 -0
  150. nvmath/internal/memory.pxd +50 -0
  151. nvmath/internal/memory.pyi +53 -0
  152. nvmath/internal/ndbuffer/__init__.pxd +3 -0
  153. nvmath/internal/ndbuffer/__init__.py +7 -0
  154. nvmath/internal/ndbuffer/copy_kernel/args.h +34 -0
  155. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/array_view.h +52 -0
  156. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/elementwise.h +68 -0
  157. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/grid_indexer.h +69 -0
  158. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/transposed.h +240 -0
  159. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/type_utils.h +39 -0
  160. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/utils.h +132 -0
  161. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/vec.h +159 -0
  162. nvmath/internal/ndbuffer/copy_kernel/elementwise.h +53 -0
  163. nvmath/internal/ndbuffer/copy_kernel/transposed.h +58 -0
  164. nvmath/internal/ndbuffer/copy_kernel.cpython-313-x86_64-linux-gnu.so +0 -0
  165. nvmath/internal/ndbuffer/copy_kernel.pxd +9 -0
  166. nvmath/internal/ndbuffer/data_layout.cpython-313-x86_64-linux-gnu.so +0 -0
  167. nvmath/internal/ndbuffer/data_layout.pxd +72 -0
  168. nvmath/internal/ndbuffer/jit.cpython-313-x86_64-linux-gnu.so +0 -0
  169. nvmath/internal/ndbuffer/jit.pxd +11 -0
  170. nvmath/internal/ndbuffer/ndbuffer.cpython-313-x86_64-linux-gnu.so +0 -0
  171. nvmath/internal/ndbuffer/ndbuffer.pxd +36 -0
  172. nvmath/internal/ndbuffer/ndbuffer.pyi +35 -0
  173. nvmath/internal/ndbuffer/nvrtc_helper.py +84 -0
  174. nvmath/internal/ndbuffer/package_utils.cpython-313-x86_64-linux-gnu.so +0 -0
  175. nvmath/internal/ndbuffer/package_utils.pxd +11 -0
  176. nvmath/internal/ndbuffer/package_utils.pyi +29 -0
  177. nvmath/internal/package_ifc.py +119 -0
  178. nvmath/internal/package_ifc_cuda.py +37 -0
  179. nvmath/internal/package_ifc_cupy.py +49 -0
  180. nvmath/internal/package_ifc_torch.py +31 -0
  181. nvmath/internal/package_wrapper.py +14 -0
  182. nvmath/internal/tensor_ifc.py +155 -0
  183. nvmath/internal/tensor_ifc_cupy.py +210 -0
  184. nvmath/internal/tensor_ifc_ndbuffer.py +136 -0
  185. nvmath/internal/tensor_ifc_numpy.py +157 -0
  186. nvmath/internal/tensor_ifc_torch.py +122 -0
  187. nvmath/internal/tensor_wrapper.py +162 -0
  188. nvmath/internal/typemaps.py +155 -0
  189. nvmath/internal/utils.py +656 -0
  190. nvmath/linalg/__init__.py +11 -0
  191. nvmath/linalg/_internal/__init__.py +3 -0
  192. nvmath/linalg/_internal/algo_cap_ifc.py +86 -0
  193. nvmath/linalg/_internal/algo_config_ifc.py +87 -0
  194. nvmath/linalg/_internal/enum_to_tuples.py +64 -0
  195. nvmath/linalg/_internal/epilog_protocol.py +738 -0
  196. nvmath/linalg/_internal/matmul_desc_ifc.py +72 -0
  197. nvmath/linalg/_internal/matmul_pref_ifc.py +65 -0
  198. nvmath/linalg/_internal/matrix_layout_ifc.py +59 -0
  199. nvmath/linalg/_internal/typemaps.py +135 -0
  200. nvmath/linalg/_internal/utils.py +96 -0
  201. nvmath/linalg/advanced/__init__.py +8 -0
  202. nvmath/linalg/advanced/_algorithmmod.py +142 -0
  203. nvmath/linalg/advanced/_configuration.py +320 -0
  204. nvmath/linalg/advanced/helpers/__init__.py +5 -0
  205. nvmath/linalg/advanced/helpers/matmul.py +173 -0
  206. nvmath/linalg/advanced/matmulmod.py +2864 -0
  207. nvmath/memory.py +278 -0
  208. nvmath/sparse/__init__.py +9 -0
  209. nvmath/sparse/_internal/__init__.py +21 -0
  210. nvmath/sparse/_internal/common_utils.py +81 -0
  211. nvmath/sparse/_internal/cudss_config_ifc.py +584 -0
  212. nvmath/sparse/_internal/cudss_data_ifc.py +291 -0
  213. nvmath/sparse/_internal/cudss_utils.py +398 -0
  214. nvmath/sparse/_internal/sparse_csr_ifc.py +154 -0
  215. nvmath/sparse/_internal/sparse_format_helpers.py +88 -0
  216. nvmath/sparse/_internal/sparse_tensor_ifc.py +80 -0
  217. nvmath/sparse/advanced/__init__.py +7 -0
  218. nvmath/sparse/advanced/_configuration.py +150 -0
  219. nvmath/sparse/advanced/direct_solver.py +1703 -0
  220. nvmath_python-0.6.0.dist-info/METADATA +124 -0
  221. nvmath_python-0.6.0.dist-info/RECORD +224 -0
  222. nvmath_python-0.6.0.dist-info/WHEEL +5 -0
  223. nvmath_python-0.6.0.dist-info/licenses/LICENSE +177 -0
  224. nvmath_python-0.6.0.dist-info/top_level.txt +2 -0
nvmath/__init__.pxd ADDED
File without changes
nvmath/__init__.py ADDED
@@ -0,0 +1,37 @@
1
+ # Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ import importlib.metadata
6
+
7
+
8
+ # Attempt to preload libraries. Fail silently if preload fails.
9
+ def _force_lib_load():
10
+ from nvmath._utils import module_init_force_cupy_lib_load
11
+
12
+ module_init_force_cupy_lib_load()
13
+
14
+
15
+ _force_lib_load()
16
+
17
+ from nvmath import bindings # noqa: E402
18
+ from nvmath._utils import ComputeType # noqa: E402
19
+ from nvmath._utils import CudaDataType # noqa: E402
20
+ from nvmath._utils import LibraryPropertyType # noqa: E402
21
+
22
+ from nvmath import fft, linalg, sparse # noqa: E402
23
+ from nvmath.memory import BaseCUDAMemoryManager, MemoryPointer # noqa: E402
24
+
25
+ __all__ = [
26
+ "BaseCUDAMemoryManager",
27
+ "bindings",
28
+ "ComputeType",
29
+ "CudaDataType",
30
+ "fft",
31
+ "LibraryPropertyType",
32
+ "linalg",
33
+ "MemoryPointer",
34
+ "sparse",
35
+ ]
36
+
37
+ __version__ = importlib.metadata.version("nvmath-python")
File without changes
@@ -0,0 +1,58 @@
1
+ # Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ """
6
+ A collection of (internal use) helper functions for shape/stride
7
+ validation and manipulation.
8
+ """
9
+
10
+ from collections.abc import Sequence
11
+
12
+
13
+ def is_contiguous_layout(sorted_shape: Sequence[int], sorted_strides: Sequence[int]) -> bool:
14
+ return all(sorted_shape[s - 1] * sorted_strides[s - 1] == sorted_strides[s] for s in range(1, len(sorted_strides)))
15
+
16
+
17
+ def is_contiguous_in_memory(shape: Sequence[int], strides: Sequence[int]) -> bool:
18
+ """
19
+ Check if the provided (shape, strides) result in a contiguous memory layout.
20
+ """
21
+ sorted_strides, sorted_shape = zip(*sorted(zip(strides, shape, strict=True)), strict=True)
22
+ return is_contiguous_layout(sorted_shape, sorted_strides)
23
+
24
+
25
+ def is_contiguous_and_dense(shape: Sequence[int], strides: Sequence[int]) -> bool:
26
+ """
27
+ Check if the provided (shape, strides) result in a contiguous memory layout
28
+ with no extra stride in least strided dimension.
29
+ """
30
+ sorted_strides, sorted_shape = zip(*sorted(zip(strides, shape, strict=True)), strict=True)
31
+ if len(sorted_strides) > 0 and sorted_strides[0] != 1:
32
+ return False
33
+ return is_contiguous_layout(sorted_shape, sorted_strides)
34
+
35
+
36
+ def is_overlapping_layout(shape: Sequence[int], strides: Sequence[int]) -> bool:
37
+ """
38
+ For a tensor `t`, if `not is_overlapping_layout(t.shape, t.strides)`,
39
+ there are no two different valid nd-indices `idxs` such that
40
+ `t[idxs_0]` and `t[idxs_1]` map to the same offset in the memory.
41
+ Checks that the strides:
42
+ 1. are positive
43
+ 2. any n - 1 extents maximal offset is smaller than the stride
44
+ of the n-th extent.
45
+ The check should return False for contiguous
46
+ or contiguous and sliced tensors.
47
+ """
48
+ sorted_strides, sorted_shape = zip(*sorted(zip(strides, shape, strict=True)), strict=True)
49
+ cur_max_offset = 0
50
+ for s in range(1, len(sorted_strides)):
51
+ stride = sorted_strides[s - 1]
52
+ extent = sorted_shape[s - 1]
53
+ if stride <= 0:
54
+ return True
55
+ cur_max_offset += stride * (extent - 1)
56
+ if cur_max_offset >= sorted_strides[s]:
57
+ return True
58
+ return False
nvmath/_utils.py ADDED
@@ -0,0 +1,143 @@
1
+ # Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from enum import IntEnum
6
+ from functools import cache
7
+ import logging
8
+ import re
9
+ import sys
10
+ from cuda import pathfinder
11
+
12
+ logger = logging.getLogger()
13
+
14
+ #
15
+ # Note: This module should not depend on anything from the nvmath namespace!
16
+ #
17
+
18
+
19
+ # The (subset of) compute types below are shared by cuStateVec and cuTensorNet
20
+ class ComputeType(IntEnum):
21
+ """An enumeration of CUDA compute types."""
22
+
23
+ COMPUTE_DEFAULT = 0
24
+ COMPUTE_16F = 1 << 0
25
+ COMPUTE_32F = 1 << 2
26
+ COMPUTE_64F = 1 << 4
27
+ COMPUTE_8U = 1 << 6
28
+ COMPUTE_8I = 1 << 8
29
+ COMPUTE_32U = 1 << 7
30
+ COMPUTE_32I = 1 << 9
31
+ COMPUTE_16BF = 1 << 10
32
+ COMPUTE_TF32 = 1 << 12
33
+
34
+
35
+ # TODO: use those exposed by CUDA Python instead, but before removing these
36
+ # duplicates, check if they are fixed to inherit IntEnum instead of Enum.
37
+ class CudaDataType(IntEnum):
38
+ """An enumeration of `cudaDataType_t`."""
39
+
40
+ CUDA_R_16F = 2
41
+ CUDA_C_16F = 6
42
+ CUDA_R_16BF = 14
43
+ CUDA_C_16BF = 15
44
+ CUDA_R_32F = 0
45
+ CUDA_C_32F = 4
46
+ CUDA_R_64F = 1
47
+ CUDA_C_64F = 5
48
+ CUDA_R_4I = 16
49
+ CUDA_C_4I = 17
50
+ CUDA_R_4U = 18
51
+ CUDA_C_4U = 19
52
+ CUDA_R_8I = 3
53
+ CUDA_C_8I = 7
54
+ CUDA_R_8U = 8
55
+ CUDA_C_8U = 9
56
+ CUDA_R_16I = 20
57
+ CUDA_C_16I = 21
58
+ CUDA_R_16U = 22
59
+ CUDA_C_16U = 23
60
+ CUDA_R_32I = 10
61
+ CUDA_C_32I = 11
62
+ CUDA_R_32U = 12
63
+ CUDA_C_32U = 13
64
+ CUDA_R_64I = 24
65
+ CUDA_C_64I = 25
66
+ CUDA_R_64U = 26
67
+ CUDA_C_64U = 27
68
+ CUDA_R_8F_E4M3 = 28
69
+ CUDA_R_8F_E5M2 = 29
70
+
71
+
72
+ class LibraryPropertyType(IntEnum):
73
+ """An enumeration of library version information."""
74
+
75
+ MAJOR_VERSION = 0
76
+ MINOR_VERSION = 1
77
+ PATCH_LEVEL = 2
78
+
79
+
80
+ del IntEnum
81
+
82
+
83
+ PLATFORM_LINUX = sys.platform.startswith("linux")
84
+ PLATFORM_WIN = sys.platform.startswith("win32")
85
+
86
+
87
+ def module_init_force_cupy_lib_load():
88
+ """
89
+ Attempt to preload libraries at module import time. We want to do it before
90
+ cupy, since it does not know how to properly search for libraries:
91
+ https://github.com/cupy/cupy/issues/9127
92
+ Fail silently if preload fails.
93
+ """
94
+ from nvmath.bindings import _internal
95
+
96
+ for lib in ("cublas", "cufft", "curand", "cusolverDn", "cusparse"):
97
+ try:
98
+ mod = getattr(_internal, lib)
99
+ mod._inspect_function_pointers()
100
+ except (_internal.utils.NotSupportedError, RuntimeError):
101
+ pass
102
+
103
+ try:
104
+ pathfinder.load_nvidia_dynamic_lib("nvrtc")
105
+ except pathfinder.DynamicLibNotFoundError:
106
+ pass
107
+
108
+
109
+ @cache
110
+ def get_nvrtc_build_id(minimal=True) -> int:
111
+ from cuda.core.experimental import ObjectCode, Program, ProgramOptions
112
+
113
+ code = r"""
114
+ extern "C" __global__ void get_build_id(int* build_id) {
115
+
116
+ *build_id = __CUDACC_VER_BUILD__;
117
+ }
118
+ """
119
+
120
+ prog = Program(code, "c++", ProgramOptions(std="c++17", minimal=minimal, arch="compute_75"))
121
+ obj = prog.compile("ptx")
122
+ assert isinstance(obj, ObjectCode)
123
+
124
+ pattern = re.compile(r"mov\.u32\s+%\w+,\s+(\d+)")
125
+ m = pattern.search(obj.code.decode())
126
+ assert m is not None
127
+
128
+ return int(m.group(1))
129
+
130
+
131
+ @cache
132
+ def get_nvrtc_version() -> tuple[int, int, int]:
133
+ """
134
+ Returns the NVRTC version as a tuple of (major, minor, build).
135
+ """
136
+ from cuda.bindings import nvrtc
137
+
138
+ err, major, minor = nvrtc.nvrtcVersion()
139
+ if err != nvrtc.nvrtcResult.NVRTC_SUCCESS:
140
+ raise RuntimeError(f"nvrtcVersion error: {err}")
141
+ # minimal support was added in CUDA 12.0
142
+ build = get_nvrtc_build_id(minimal=major >= 12)
143
+ return major, minor, build
File without changes
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ # type: ignore
6
+
7
+ from nvmath.bindings import cublas
8
+ from nvmath.bindings import cudss
9
+ from nvmath.bindings import cufft
10
+ from nvmath.bindings import curand
11
+ from nvmath.bindings import cusolver
12
+ from nvmath.bindings import cusolverDn
13
+ from nvmath.bindings import cusparse
14
+
15
+ try:
16
+ # nvpl is Linux-only.
17
+ from nvmath.bindings import nvpl
18
+ except ImportError:
19
+ nvpl = None
20
+
21
+ try:
22
+ # cufftMp is Linux-only.
23
+ from nvmath.bindings import cufftMp
24
+ except ImportError:
25
+ cufftMp = None
26
+
27
+ try:
28
+ # nvshmem is Linux-only.
29
+ from nvmath.bindings import nvshmem
30
+ except ImportError:
31
+ nvshmem = None
32
+
33
+ __all__ = [
34
+ "cublas",
35
+ "cudss",
36
+ "cufft",
37
+ "cufftMp",
38
+ "curand",
39
+ "cusolver",
40
+ "cusolverDn",
41
+ "cusparse",
42
+ "nvpl",
43
+ "nvshmem",
44
+ ]
File without changes
File without changes