nvmath-python 0.5.0__cp313-cp313-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.
- nvmath/__init__.pxd +0 -0
- nvmath/__init__.py +37 -0
- nvmath/_internal/__init__.py +0 -0
- nvmath/_internal/layout.py +58 -0
- nvmath/_utils.py +363 -0
- nvmath/bindings/__init__.pxd +0 -0
- nvmath/bindings/__init__.py +44 -0
- nvmath/bindings/_internal/__init__.pxd +0 -0
- nvmath/bindings/_internal/__init__.py +0 -0
- nvmath/bindings/_internal/cublas.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cublas.pxd +518 -0
- nvmath/bindings/_internal/cublasLt.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cublasLt.pxd +54 -0
- nvmath/bindings/_internal/cudss.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cudss.pxd +44 -0
- nvmath/bindings/_internal/cufft.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cufft.pxd +69 -0
- nvmath/bindings/_internal/cufftMp.pxd +77 -0
- nvmath/bindings/_internal/curand.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/curand.pxd +42 -0
- nvmath/bindings/_internal/cusolver.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cusolver.pxd +15 -0
- nvmath/bindings/_internal/cusolverDn.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cusolverDn.pxd +386 -0
- nvmath/bindings/_internal/cusparse.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cusparse.pxd +270 -0
- nvmath/bindings/_internal/mathdx.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/mathdx.pxd +79 -0
- nvmath/bindings/_internal/nvshmem.pxd +29 -0
- nvmath/bindings/_internal/utils.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/utils.pxd +186 -0
- nvmath/bindings/cublas.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cublas.pxd +545 -0
- nvmath/bindings/cublas.pyi +18 -0
- nvmath/bindings/cublasLt.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cublasLt.pxd +99 -0
- nvmath/bindings/cudss.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cudss.pxd +83 -0
- nvmath/bindings/cudss.pyi +249 -0
- nvmath/bindings/cufft.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cufft.pxd +114 -0
- nvmath/bindings/cufftMp.pxd +124 -0
- nvmath/bindings/curand.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/curand.pxd +71 -0
- nvmath/bindings/cusolver.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cusolver.pxd +60 -0
- nvmath/bindings/cusolverDn.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cusolverDn.pxd +410 -0
- nvmath/bindings/cusparse.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cusparse.pxd +329 -0
- nvmath/bindings/cycublas.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycublas.pxd +657 -0
- nvmath/bindings/cycublasLt.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycublasLt.pxd +1010 -0
- nvmath/bindings/cycudss.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycudss.pxd +191 -0
- nvmath/bindings/cycufft.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycufft.pxd +320 -0
- nvmath/bindings/cycufftMp.pxd +333 -0
- nvmath/bindings/cycurand.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycurand.pxd +146 -0
- nvmath/bindings/cycusolver.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycusolver.pxd +143 -0
- nvmath/bindings/cycusolverDn.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycusolverDn.pxd +414 -0
- nvmath/bindings/cycusparse.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycusparse.pxd +476 -0
- nvmath/bindings/cymathdx.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cymathdx.pxd +363 -0
- nvmath/bindings/cynvshmem.pxd +126 -0
- nvmath/bindings/mathdx.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/mathdx.pxd +131 -0
- nvmath/bindings/mathdx.pyi +686 -0
- nvmath/bindings/nvpl/__init__.pxd +0 -0
- nvmath/bindings/nvpl/__init__.py +11 -0
- nvmath/bindings/nvpl/_internal/__init__.pxd +0 -0
- nvmath/bindings/nvpl/_internal/__init__.py +0 -0
- nvmath/bindings/nvpl/_internal/fft.pxd +36 -0
- nvmath/bindings/nvpl/cyfft.pxd +87 -0
- nvmath/bindings/nvpl/fft.pxd +100 -0
- nvmath/bindings/nvshmem.pxd +54 -0
- nvmath/device/__init__.py +23 -0
- nvmath/device/_deprecated.py +33 -0
- nvmath/device/caching.py +51 -0
- nvmath/device/common.py +131 -0
- nvmath/device/common_backend.py +125 -0
- nvmath/device/common_cuda.py +156 -0
- nvmath/device/common_mathdx.py +97 -0
- nvmath/device/common_numba.py +159 -0
- nvmath/device/common_opaque_tensor.py +128 -0
- nvmath/device/cublasdx.py +1085 -0
- nvmath/device/cublasdx_backend.py +552 -0
- nvmath/device/cublasdx_numba.py +528 -0
- nvmath/device/cufftdx.py +551 -0
- nvmath/device/cufftdx_backend.py +194 -0
- nvmath/device/cufftdx_numba.py +123 -0
- nvmath/device/curand_kernel.py +9147 -0
- nvmath/device/nvrtc.py +95 -0
- nvmath/device/patch.py +35 -0
- nvmath/device/random.py +417 -0
- nvmath/device/random_helpers.py +23 -0
- nvmath/device/random_states.py +189 -0
- nvmath/device/types.py +11 -0
- nvmath/device/vector_types_numba.py +203 -0
- nvmath/distributed/__init__.py +117 -0
- nvmath/distributed/_internal/__init__.py +0 -0
- nvmath/distributed/_internal/nvshmem.py +243 -0
- nvmath/distributed/_internal/tensor_ifc_cupy.py +111 -0
- nvmath/distributed/_internal/tensor_ifc_numpy.py +53 -0
- nvmath/distributed/_internal/tensor_ifc_torch.py +108 -0
- nvmath/distributed/_internal/tensor_wrapper.py +59 -0
- nvmath/distributed/_utils.py +152 -0
- nvmath/distributed/fft/__init__.py +6 -0
- nvmath/distributed/fft/_configuration.py +86 -0
- nvmath/distributed/fft/fft.py +1737 -0
- nvmath/distributed/reshape/__init__.py +6 -0
- nvmath/distributed/reshape/_configuration.py +39 -0
- nvmath/distributed/reshape/reshape.py +1249 -0
- nvmath/fft/__init__.py +7 -0
- nvmath/fft/_configuration.py +208 -0
- nvmath/fft/_exec_utils.py +116 -0
- nvmath/fft/_helpers.py +260 -0
- nvmath/fft/fft.py +2346 -0
- nvmath/internal/__init__.py +5 -0
- nvmath/internal/enum_utils.py +142 -0
- nvmath/internal/formatters.py +87 -0
- nvmath/internal/mem_limit.py +51 -0
- nvmath/internal/package_ifc.py +119 -0
- nvmath/internal/package_ifc_cuda.py +43 -0
- nvmath/internal/package_ifc_cupy.py +49 -0
- nvmath/internal/package_ifc_torch.py +31 -0
- nvmath/internal/package_wrapper.py +14 -0
- nvmath/internal/tensor_ifc.py +143 -0
- nvmath/internal/tensor_ifc_cupy.py +185 -0
- nvmath/internal/tensor_ifc_numpy.py +157 -0
- nvmath/internal/tensor_ifc_torch.py +115 -0
- nvmath/internal/tensor_wrapper.py +160 -0
- nvmath/internal/typemaps.py +154 -0
- nvmath/internal/utils.py +634 -0
- nvmath/linalg/__init__.py +11 -0
- nvmath/linalg/_internal/__init__.py +3 -0
- nvmath/linalg/_internal/algo_cap_ifc.py +86 -0
- nvmath/linalg/_internal/algo_config_ifc.py +87 -0
- nvmath/linalg/_internal/enum_to_tuples.py +64 -0
- nvmath/linalg/_internal/epilog_protocol.py +738 -0
- nvmath/linalg/_internal/matmul_desc_ifc.py +72 -0
- nvmath/linalg/_internal/matmul_pref_ifc.py +65 -0
- nvmath/linalg/_internal/matrix_layout_ifc.py +59 -0
- nvmath/linalg/_internal/typemaps.py +135 -0
- nvmath/linalg/_internal/utils.py +96 -0
- nvmath/linalg/advanced/__init__.py +8 -0
- nvmath/linalg/advanced/_algorithmmod.py +142 -0
- nvmath/linalg/advanced/_configuration.py +320 -0
- nvmath/linalg/advanced/helpers/__init__.py +5 -0
- nvmath/linalg/advanced/helpers/matmul.py +173 -0
- nvmath/linalg/advanced/matmulmod.py +2855 -0
- nvmath/memory.py +266 -0
- nvmath/sparse/__init__.py +18 -0
- nvmath/sparse/_internal/__init__.py +21 -0
- nvmath/sparse/_internal/common_utils.py +81 -0
- nvmath/sparse/_internal/cudss_config_ifc.py +584 -0
- nvmath/sparse/_internal/cudss_data_ifc.py +291 -0
- nvmath/sparse/_internal/cudss_utils.py +398 -0
- nvmath/sparse/_internal/sparse_csr_ifc.py +154 -0
- nvmath/sparse/_internal/sparse_format_helpers.py +88 -0
- nvmath/sparse/_internal/sparse_tensor_ifc.py +80 -0
- nvmath/sparse/advanced/__init__.py +7 -0
- nvmath/sparse/advanced/_configuration.py +150 -0
- nvmath/sparse/advanced/direct_solver.py +1705 -0
- nvmath_python-0.5.0.dist-info/METADATA +122 -0
- nvmath_python-0.5.0.dist-info/RECORD +174 -0
- nvmath_python-0.5.0.dist-info/WHEEL +5 -0
- nvmath_python-0.5.0.dist-info/licenses/LICENSE +177 -0
- nvmath_python-0.5.0.dist-info/top_level.txt +1 -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,363 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import ctypes
|
|
6
|
+
from enum import IntEnum
|
|
7
|
+
import logging
|
|
8
|
+
import os
|
|
9
|
+
import re
|
|
10
|
+
import site
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# Note: This module should not depend on anything from the nvmath namespace!
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# The (subset of) compute types below are shared by cuStateVec and cuTensorNet
|
|
19
|
+
class ComputeType(IntEnum):
|
|
20
|
+
"""An enumeration of CUDA compute types."""
|
|
21
|
+
|
|
22
|
+
COMPUTE_DEFAULT = 0
|
|
23
|
+
COMPUTE_16F = 1 << 0
|
|
24
|
+
COMPUTE_32F = 1 << 2
|
|
25
|
+
COMPUTE_64F = 1 << 4
|
|
26
|
+
COMPUTE_8U = 1 << 6
|
|
27
|
+
COMPUTE_8I = 1 << 8
|
|
28
|
+
COMPUTE_32U = 1 << 7
|
|
29
|
+
COMPUTE_32I = 1 << 9
|
|
30
|
+
COMPUTE_16BF = 1 << 10
|
|
31
|
+
COMPUTE_TF32 = 1 << 12
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# TODO: use those exposed by CUDA Python instead, but before removing these
|
|
35
|
+
# duplicates, check if they are fixed to inherit IntEnum instead of Enum.
|
|
36
|
+
class CudaDataType(IntEnum):
|
|
37
|
+
"""An enumeration of `cudaDataType_t`."""
|
|
38
|
+
|
|
39
|
+
CUDA_R_16F = 2
|
|
40
|
+
CUDA_C_16F = 6
|
|
41
|
+
CUDA_R_16BF = 14
|
|
42
|
+
CUDA_C_16BF = 15
|
|
43
|
+
CUDA_R_32F = 0
|
|
44
|
+
CUDA_C_32F = 4
|
|
45
|
+
CUDA_R_64F = 1
|
|
46
|
+
CUDA_C_64F = 5
|
|
47
|
+
CUDA_R_4I = 16
|
|
48
|
+
CUDA_C_4I = 17
|
|
49
|
+
CUDA_R_4U = 18
|
|
50
|
+
CUDA_C_4U = 19
|
|
51
|
+
CUDA_R_8I = 3
|
|
52
|
+
CUDA_C_8I = 7
|
|
53
|
+
CUDA_R_8U = 8
|
|
54
|
+
CUDA_C_8U = 9
|
|
55
|
+
CUDA_R_16I = 20
|
|
56
|
+
CUDA_C_16I = 21
|
|
57
|
+
CUDA_R_16U = 22
|
|
58
|
+
CUDA_C_16U = 23
|
|
59
|
+
CUDA_R_32I = 10
|
|
60
|
+
CUDA_C_32I = 11
|
|
61
|
+
CUDA_R_32U = 12
|
|
62
|
+
CUDA_C_32U = 13
|
|
63
|
+
CUDA_R_64I = 24
|
|
64
|
+
CUDA_C_64I = 25
|
|
65
|
+
CUDA_R_64U = 26
|
|
66
|
+
CUDA_C_64U = 27
|
|
67
|
+
CUDA_R_8F_E4M3 = 28
|
|
68
|
+
CUDA_R_8F_E5M2 = 29
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class LibraryPropertyType(IntEnum):
|
|
72
|
+
"""An enumeration of library version information."""
|
|
73
|
+
|
|
74
|
+
MAJOR_VERSION = 0
|
|
75
|
+
MINOR_VERSION = 1
|
|
76
|
+
PATCH_LEVEL = 2
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
del IntEnum
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
PLATFORM_LINUX = sys.platform.startswith("linux")
|
|
83
|
+
PLATFORM_WIN = sys.platform.startswith("win32")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# TODO: unify all loading helpers into one
|
|
87
|
+
_nvrtc_obj: list[ctypes.CDLL] = []
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def force_loading_nvrtc(cu_ver):
|
|
91
|
+
# this logic should live in CUDA Python...
|
|
92
|
+
# TODO: remove this function once NVIDIA/cuda-python#62 is resolved
|
|
93
|
+
# This logic handles all cases - wheel, conda, and system installations
|
|
94
|
+
global _nvrtc_obj
|
|
95
|
+
if len(_nvrtc_obj) > 0:
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
cu_ver = cu_ver.split(".")
|
|
99
|
+
major = cu_ver[0]
|
|
100
|
+
if major == "11":
|
|
101
|
+
# CUDA 11.2+ supports minor ver compat
|
|
102
|
+
if PLATFORM_LINUX:
|
|
103
|
+
cu_ver = "11.2"
|
|
104
|
+
elif PLATFORM_WIN:
|
|
105
|
+
cu_ver = "112"
|
|
106
|
+
elif major == "12":
|
|
107
|
+
if PLATFORM_LINUX:
|
|
108
|
+
cu_ver = "12"
|
|
109
|
+
elif PLATFORM_WIN:
|
|
110
|
+
cu_ver = "120"
|
|
111
|
+
else:
|
|
112
|
+
raise NotImplementedError(f"CUDA {major} is not supported")
|
|
113
|
+
|
|
114
|
+
site_paths = [site.getusersitepackages()] + site.getsitepackages() + [None]
|
|
115
|
+
for sp in site_paths:
|
|
116
|
+
if PLATFORM_LINUX:
|
|
117
|
+
dso_dir = "lib"
|
|
118
|
+
dso_path = f"libnvrtc.so.{cu_ver}"
|
|
119
|
+
elif PLATFORM_WIN:
|
|
120
|
+
dso_dir = "bin"
|
|
121
|
+
dso_path = f"nvrtc64_{cu_ver}_0.dll"
|
|
122
|
+
else:
|
|
123
|
+
raise AssertionError()
|
|
124
|
+
|
|
125
|
+
if sp is not None:
|
|
126
|
+
dso_dir = os.path.join(sp, "nvidia", "cuda_nvrtc", dso_dir)
|
|
127
|
+
dso_path = os.path.join(dso_dir, dso_path)
|
|
128
|
+
try:
|
|
129
|
+
_nvrtc_obj.append(ctypes.CDLL(dso_path, mode=ctypes.RTLD_GLOBAL))
|
|
130
|
+
except OSError:
|
|
131
|
+
continue
|
|
132
|
+
else:
|
|
133
|
+
if PLATFORM_WIN:
|
|
134
|
+
import win32api
|
|
135
|
+
|
|
136
|
+
# This absolute path will always be correct regardless of the package source
|
|
137
|
+
nvrtc_path = win32api.GetModuleFileNameW(_nvrtc_obj[0]._handle)
|
|
138
|
+
dso_dir = os.path.dirname(nvrtc_path)
|
|
139
|
+
dso_path = os.path.join(dso_dir, [f for f in os.listdir(dso_dir) if re.match("^nvrtc-builtins.*.dll$", f)][0])
|
|
140
|
+
_nvrtc_obj.append(ctypes.CDLL(dso_path))
|
|
141
|
+
break
|
|
142
|
+
else:
|
|
143
|
+
raise RuntimeError(
|
|
144
|
+
f"NVRTC from CUDA {major} not found. Depending on how you install nvmath-python and other CUDA packages,\n"
|
|
145
|
+
f"you may need to perform one of the steps below:\n"
|
|
146
|
+
f" - pip install nvidia-cuda-nvrtc-cu{major}\n"
|
|
147
|
+
f" - conda install -c conda-forge cuda-nvrtc cuda-version={major}\n"
|
|
148
|
+
" - export LD_LIBRARY_PATH=/path/to/CUDA/Toolkit/lib64:$LD_LIBRARY_PATH"
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
# TODO: unify all loading helpers into one
|
|
153
|
+
_libmathdx_obj: list[ctypes.CDLL] = []
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def force_loading_libmathdx(cu_ver):
|
|
157
|
+
# this logic should live in CUDA Python...
|
|
158
|
+
# TODO: remove this function once NVIDIA/cuda-python#62 is resolved
|
|
159
|
+
# This logic handles all cases - wheel, conda, and system installations
|
|
160
|
+
global _libmathdx_obj
|
|
161
|
+
if len(_libmathdx_obj) > 0:
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
cu_ver = cu_ver.split(".")
|
|
165
|
+
major = cu_ver[0]
|
|
166
|
+
if major != "12":
|
|
167
|
+
raise NotImplementedError(f"CUDA {major} is not supported")
|
|
168
|
+
|
|
169
|
+
site_paths = [site.getusersitepackages()] + site.getsitepackages() + [None]
|
|
170
|
+
for sp in site_paths:
|
|
171
|
+
if PLATFORM_LINUX:
|
|
172
|
+
dso_dir = "lib"
|
|
173
|
+
dso_path = "libmathdx.so.0"
|
|
174
|
+
elif PLATFORM_WIN:
|
|
175
|
+
dso_dir = "bin"
|
|
176
|
+
dso_path = "libmathdx.dll"
|
|
177
|
+
else:
|
|
178
|
+
raise AssertionError("Unsupported Platform! Only Linux and Windows are supported.")
|
|
179
|
+
|
|
180
|
+
if sp is not None:
|
|
181
|
+
dso_dir = os.path.join(sp, "nvidia", f"cu{major}", dso_dir)
|
|
182
|
+
dso_path = os.path.join(dso_dir, dso_path)
|
|
183
|
+
try:
|
|
184
|
+
_libmathdx_obj.append(ctypes.CDLL(dso_path, mode=ctypes.RTLD_GLOBAL))
|
|
185
|
+
except OSError:
|
|
186
|
+
continue
|
|
187
|
+
else:
|
|
188
|
+
if PLATFORM_WIN:
|
|
189
|
+
# TODO: untested in context of libmathdx.
|
|
190
|
+
import win32api
|
|
191
|
+
|
|
192
|
+
# This absolute path will always be correct regardless of the package source
|
|
193
|
+
nvrtc_path = win32api.GetModuleFileNameW(_libmathdx_obj[0]._handle)
|
|
194
|
+
dso_dir = os.path.dirname(nvrtc_path)
|
|
195
|
+
dso_path = os.path.join(dso_dir, [f for f in os.listdir(dso_dir) if re.match("^nvrtc-builtins.*.dll$", f)][0])
|
|
196
|
+
_libmathdx_obj.append(ctypes.CDLL(dso_path))
|
|
197
|
+
break
|
|
198
|
+
else:
|
|
199
|
+
raise RuntimeError(
|
|
200
|
+
f"libmathdx not found. Depending on how you install nvmath-python and other CUDA packages,\n"
|
|
201
|
+
f"you may need to perform one of the steps below:\n"
|
|
202
|
+
f" - pip install nvidia-libmathdx-cu{major}\n"
|
|
203
|
+
f" - conda install -c conda-forge libmathdx cuda-version={major}"
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
from nvmath.bindings import mathdx
|
|
207
|
+
|
|
208
|
+
version = mathdx.get_version()
|
|
209
|
+
if version < 201 or version >= 300:
|
|
210
|
+
raise ValueError(f"libmathdx version must be >= 0.2.1 and < 0.3.0 ; got {version}")
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
# TODO: unify all loading helpers into one
|
|
214
|
+
_nvvm_obj: list[ctypes.CDLL] = []
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def force_loading_nvvm():
|
|
218
|
+
# this logic should live in CUDA Python...
|
|
219
|
+
# This logic handles all cases - wheel, conda, and system installations
|
|
220
|
+
global _nvvm_obj
|
|
221
|
+
if len(_nvvm_obj) > 0:
|
|
222
|
+
return
|
|
223
|
+
|
|
224
|
+
site_paths = [site.getusersitepackages()] + site.getsitepackages() + ["conda", None]
|
|
225
|
+
for sp in site_paths:
|
|
226
|
+
# The SONAME is taken based on public CTK 12.x releases
|
|
227
|
+
if PLATFORM_LINUX:
|
|
228
|
+
dso_dir = "lib64"
|
|
229
|
+
# Hack: libnvvm from Linux wheel does not have any soname (CUDAINST-3183)
|
|
230
|
+
dso_path = "libnvvm.so"
|
|
231
|
+
if sp == "conda" or sp is None:
|
|
232
|
+
dso_path += ".4"
|
|
233
|
+
elif PLATFORM_WIN:
|
|
234
|
+
dso_dir = "bin"
|
|
235
|
+
dso_path = "nvvm64_40_0.dll"
|
|
236
|
+
else:
|
|
237
|
+
raise AssertionError()
|
|
238
|
+
|
|
239
|
+
if sp == "conda" and "CONDA_PREFIX" in os.environ:
|
|
240
|
+
# nvvm is not under $CONDA_PREFIX/lib, so it's not in the default search path
|
|
241
|
+
if PLATFORM_LINUX:
|
|
242
|
+
dso_dir = os.path.join(os.environ["CONDA_PREFIX"], "nvvm", dso_dir)
|
|
243
|
+
elif PLATFORM_WIN:
|
|
244
|
+
dso_dir = os.path.join(os.environ["CONDA_PREFIX"], "Library", "nvvm", dso_dir)
|
|
245
|
+
dso_path = os.path.join(dso_dir, dso_path)
|
|
246
|
+
elif sp is not None:
|
|
247
|
+
dso_dir = os.path.join(sp, "nvidia", "cuda_nvcc", "nvvm", dso_dir)
|
|
248
|
+
dso_path = os.path.join(dso_dir, dso_path)
|
|
249
|
+
try:
|
|
250
|
+
_nvvm_obj.append(ctypes.CDLL(dso_path, mode=ctypes.RTLD_GLOBAL))
|
|
251
|
+
except OSError:
|
|
252
|
+
continue
|
|
253
|
+
else:
|
|
254
|
+
break
|
|
255
|
+
else:
|
|
256
|
+
raise RuntimeError(
|
|
257
|
+
"NVVM from CUDA 12 not found. Depending on how you install nvmath-python and other CUDA packages,\n"
|
|
258
|
+
"you may need to perform one of the steps below:\n"
|
|
259
|
+
" - pip install nvidia-cuda-nvcc-cu12\n"
|
|
260
|
+
" - conda install -c conda-forge cuda-nvvm cuda-version=12\n"
|
|
261
|
+
" - export LD_LIBRARY_PATH=/path/to/CUDA/Toolkit/nvvm/lib64:$LD_LIBRARY_PATH"
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
# TODO: unify all loading helpers into one
|
|
266
|
+
_libcudss_obj: list[ctypes.CDLL] = []
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def force_loading_cudss(cu_ver):
|
|
270
|
+
# this logic should live in CUDA Python...
|
|
271
|
+
global _libcudss_obj
|
|
272
|
+
if len(_libcudss_obj) > 0:
|
|
273
|
+
return
|
|
274
|
+
|
|
275
|
+
cu_ver = cu_ver.split(".")
|
|
276
|
+
major = cu_ver[0]
|
|
277
|
+
if major != "12":
|
|
278
|
+
raise NotImplementedError(f"CUDA {major} is not supported")
|
|
279
|
+
|
|
280
|
+
site_paths = [site.getusersitepackages()] + site.getsitepackages() + [None]
|
|
281
|
+
for sp in site_paths:
|
|
282
|
+
if PLATFORM_LINUX:
|
|
283
|
+
dso_dir = "lib"
|
|
284
|
+
dso_path = "libcudss.so.0"
|
|
285
|
+
elif PLATFORM_WIN:
|
|
286
|
+
dso_dir = "bin"
|
|
287
|
+
dso_path = "cudss64_0.dll"
|
|
288
|
+
else:
|
|
289
|
+
raise AssertionError("Unsupported Platform! Only Linux and Windows are supported.")
|
|
290
|
+
|
|
291
|
+
if sp is not None:
|
|
292
|
+
dso_dir = os.path.join(sp, "nvidia", f"cu{major}", dso_dir)
|
|
293
|
+
dso_path = os.path.join(dso_dir, dso_path)
|
|
294
|
+
try:
|
|
295
|
+
_libcudss_obj.append(ctypes.CDLL(dso_path, mode=ctypes.RTLD_GLOBAL))
|
|
296
|
+
logging.debug("Loaded %s", dso_path)
|
|
297
|
+
except OSError as e:
|
|
298
|
+
logging.debug("%s", e)
|
|
299
|
+
continue
|
|
300
|
+
else:
|
|
301
|
+
break
|
|
302
|
+
else:
|
|
303
|
+
raise RuntimeError(
|
|
304
|
+
f"libcudss not found. Depending on how you install nvmath-python and other CUDA packages,\n"
|
|
305
|
+
f"you may need to perform one of the steps below:\n"
|
|
306
|
+
f" - pip install nvidia-cudss-cu{major}\n"
|
|
307
|
+
f" - conda install -c conda-forge libcudss cuda-version={major}"
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def module_init_force_cupy_lib_load():
|
|
312
|
+
"""
|
|
313
|
+
Attempt to preload libraries at module import time.
|
|
314
|
+
Fail silently if preload fails.
|
|
315
|
+
"""
|
|
316
|
+
from nvmath.bindings import _internal
|
|
317
|
+
|
|
318
|
+
for lib in ("cublas", "cufft", "curand", "cusolverDn", "cusparse"):
|
|
319
|
+
try:
|
|
320
|
+
mod = getattr(_internal, lib)
|
|
321
|
+
mod._inspect_function_pointers()
|
|
322
|
+
except (_internal.utils.NotSupportedError, RuntimeError):
|
|
323
|
+
pass
|
|
324
|
+
for cu_ver in ("12", "11"):
|
|
325
|
+
try:
|
|
326
|
+
force_loading_nvrtc(cu_ver)
|
|
327
|
+
return
|
|
328
|
+
except RuntimeError:
|
|
329
|
+
pass
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def get_nvrtc_build_id():
|
|
333
|
+
from cuda.core.experimental import ObjectCode, Program, ProgramOptions
|
|
334
|
+
|
|
335
|
+
code = r"""
|
|
336
|
+
extern "C" __global__ void get_build_id(int* build_id) {
|
|
337
|
+
|
|
338
|
+
*build_id = __CUDACC_VER_BUILD__;
|
|
339
|
+
}
|
|
340
|
+
"""
|
|
341
|
+
|
|
342
|
+
prog = Program(code, "c++", ProgramOptions(std="c++17", minimal=True, arch="compute_75"))
|
|
343
|
+
obj = prog.compile("ptx")
|
|
344
|
+
assert isinstance(obj, ObjectCode)
|
|
345
|
+
|
|
346
|
+
pattern = re.compile(r"mov\.u32\s+%\w+,\s+(\d+)")
|
|
347
|
+
m = pattern.search(obj.code.decode())
|
|
348
|
+
assert m is not None
|
|
349
|
+
|
|
350
|
+
return int(m.group(1))
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def get_nvrtc_version():
|
|
354
|
+
"""
|
|
355
|
+
Returns the NVRTC version as a tuple of (major, minor, build).
|
|
356
|
+
"""
|
|
357
|
+
from cuda.bindings import nvrtc
|
|
358
|
+
|
|
359
|
+
err, major, minor = nvrtc.nvrtcVersion()
|
|
360
|
+
if err != nvrtc.nvrtcResult.NVRTC_SUCCESS:
|
|
361
|
+
raise RuntimeError(f"nvrtcVersion error: {err}")
|
|
362
|
+
build = get_nvrtc_build_id()
|
|
363
|
+
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
|
|
Binary file
|