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.
- nvmath/__init__.pxd +0 -0
- nvmath/__init__.py +45 -0
- nvmath/_internal/__init__.py +0 -0
- nvmath/_internal/attribute_ifc_factory.py +330 -0
- nvmath/_internal/layout.py +70 -0
- nvmath/_internal/templates.py +383 -0
- nvmath/_utils.py +150 -0
- nvmath/bindings/__init__.py +51 -0
- nvmath/bindings/_internal/__init__.pxd +0 -0
- nvmath/bindings/_internal/__init__.py +0 -0
- nvmath/bindings/_internal/cublas.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cublas.pxd +530 -0
- nvmath/bindings/_internal/cublasLt.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cublasLt.pxd +59 -0
- nvmath/bindings/_internal/cublasMp.pxd +52 -0
- nvmath/bindings/_internal/cudss.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cudss.pxd +47 -0
- nvmath/bindings/_internal/cufft.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cufft.pxd +70 -0
- nvmath/bindings/_internal/cufftMp.pxd +77 -0
- nvmath/bindings/_internal/curand.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/curand.pxd +42 -0
- nvmath/bindings/_internal/cusolver.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cusolver.pxd +15 -0
- nvmath/bindings/_internal/cusolverDn.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cusolverDn.pxd +406 -0
- nvmath/bindings/_internal/cusparse.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cusparse.pxd +277 -0
- nvmath/bindings/_internal/cusparseLt.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cusparseLt.pxd +48 -0
- nvmath/bindings/_internal/cutensor.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cutensor.pxd +58 -0
- nvmath/bindings/_internal/mathdx.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/mathdx.pxd +116 -0
- nvmath/bindings/_internal/nvshmem.pxd +29 -0
- nvmath/bindings/_internal/utils.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/utils.pxd +179 -0
- nvmath/bindings/_internal/utils.pyi +10 -0
- nvmath/bindings/cublas.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cublas.pxd +558 -0
- nvmath/bindings/cublas.pyi +746 -0
- nvmath/bindings/cublasLt.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cublasLt.pxd +109 -0
- nvmath/bindings/cublasLt.pyi +1337 -0
- nvmath/bindings/cublasMp.pxd +85 -0
- nvmath/bindings/cublasMp.pyi +219 -0
- nvmath/bindings/cudss.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cudss.pxd +86 -0
- nvmath/bindings/cudss.pyi +282 -0
- nvmath/bindings/cufft.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cufft.pxd +118 -0
- nvmath/bindings/cufft.pyi +241 -0
- nvmath/bindings/cufftMp.pxd +124 -0
- nvmath/bindings/cufftMp.pyi +260 -0
- nvmath/bindings/curand.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/curand.pxd +71 -0
- nvmath/bindings/curand.pyi +159 -0
- nvmath/bindings/cusolver.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cusolver.pxd +62 -0
- nvmath/bindings/cusolver.pyi +242 -0
- nvmath/bindings/cusolverDn.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cusolverDn.pxd +430 -0
- nvmath/bindings/cusolverDn.pyi +416 -0
- nvmath/bindings/cusparse.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cusparse.pxd +338 -0
- nvmath/bindings/cusparse.pyi +659 -0
- nvmath/bindings/cusparseLt.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cusparseLt.pxd +99 -0
- nvmath/bindings/cusparseLt.pyi +198 -0
- nvmath/bindings/cutensor.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cutensor.pxd +98 -0
- nvmath/bindings/cutensor.pyi +294 -0
- nvmath/bindings/cycublas.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cycublas.pxd +684 -0
- nvmath/bindings/cycublasLt.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cycublasLt.pxd +1055 -0
- nvmath/bindings/cycublasMp.pxd +183 -0
- nvmath/bindings/cycudss.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cycudss.pxd +224 -0
- nvmath/bindings/cycufft.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cycufft.pxd +326 -0
- nvmath/bindings/cycufftMp.pxd +334 -0
- nvmath/bindings/cycurand.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cycurand.pxd +146 -0
- nvmath/bindings/cycusolver.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cycusolver.pxd +154 -0
- nvmath/bindings/cycusolverDn.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cycusolverDn.pxd +446 -0
- nvmath/bindings/cycusparse.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cycusparse.pxd +470 -0
- nvmath/bindings/cycusparseLt.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cycusparseLt.pxd +150 -0
- nvmath/bindings/cycutensor.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cycutensor.pxd +192 -0
- nvmath/bindings/cymathdx.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/cymathdx.pxd +552 -0
- nvmath/bindings/cynvshmem.pxd +126 -0
- nvmath/bindings/mathdx.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/mathdx.pxd +182 -0
- nvmath/bindings/mathdx.pyi +1244 -0
- nvmath/bindings/nvpl/__init__.pxd +0 -0
- nvmath/bindings/nvpl/__init__.py +13 -0
- nvmath/bindings/nvpl/_internal/__init__.pxd +0 -0
- nvmath/bindings/nvpl/_internal/__init__.py +0 -0
- nvmath/bindings/nvpl/_internal/blas.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/nvpl/_internal/blas.pxd +125 -0
- nvmath/bindings/nvpl/_internal/fft.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/nvpl/_internal/fft.pxd +36 -0
- nvmath/bindings/nvpl/blas.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/nvpl/blas.pxd +85 -0
- nvmath/bindings/nvpl/blas.pyi +122 -0
- nvmath/bindings/nvpl/cyblas.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/nvpl/cyblas.pxd +166 -0
- nvmath/bindings/nvpl/cyfft.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/nvpl/cyfft.pxd +92 -0
- nvmath/bindings/nvpl/fft.cp314-win_amd64.pyd +0 -0
- nvmath/bindings/nvpl/fft.pxd +100 -0
- nvmath/bindings/nvpl/fft.pyi +100 -0
- nvmath/bindings/nvshmem.pxd +54 -0
- nvmath/bindings/nvshmem.pyi +179 -0
- nvmath/device/__init__.py +21 -0
- nvmath/device/_deprecated.py +33 -0
- nvmath/device/common.py +313 -0
- nvmath/device/common_backend.py +131 -0
- nvmath/device/common_cuda.py +201 -0
- nvmath/device/common_numba.py +310 -0
- nvmath/device/common_opaque_tensor.py +201 -0
- nvmath/device/cublasdx.py +1805 -0
- nvmath/device/cublasdx_backend.py +807 -0
- nvmath/device/cublasdx_numba.py +1612 -0
- nvmath/device/cufftdx.py +510 -0
- nvmath/device/cufftdx_backend.py +196 -0
- nvmath/device/cufftdx_numba.py +196 -0
- nvmath/device/curand_kernel.py +9147 -0
- nvmath/device/cusolverdx.py +2690 -0
- nvmath/device/cusolverdx_backend.py +440 -0
- nvmath/device/cusolverdx_numba.py +1624 -0
- nvmath/device/llvm_array.py +29 -0
- nvmath/device/random.py +445 -0
- nvmath/device/random_helpers.py +23 -0
- nvmath/device/random_states.py +187 -0
- nvmath/device/types.py +147 -0
- nvmath/device/vector_types_numba.py +203 -0
- nvmath/distributed/__init__.py +205 -0
- nvmath/distributed/_internal/__init__.py +0 -0
- nvmath/distributed/_internal/nvshmem.py +302 -0
- nvmath/distributed/_internal/tensor_ifc.py +67 -0
- nvmath/distributed/_internal/tensor_ifc_cupy.py +62 -0
- nvmath/distributed/_internal/tensor_ifc_host_device.py +165 -0
- nvmath/distributed/_internal/tensor_ifc_numpy.py +41 -0
- nvmath/distributed/_internal/tensor_ifc_torch.py +141 -0
- nvmath/distributed/_internal/tensor_wrapper.py +78 -0
- nvmath/distributed/_utils.py +167 -0
- nvmath/distributed/distribution.py +770 -0
- nvmath/distributed/fft/__init__.py +7 -0
- nvmath/distributed/fft/_configuration.py +79 -0
- nvmath/distributed/fft/fft.py +2801 -0
- nvmath/distributed/linalg/__init__.py +12 -0
- nvmath/distributed/linalg/_internal/__init__.py +3 -0
- nvmath/distributed/linalg/_internal/epilog_protocol.py +496 -0
- nvmath/distributed/linalg/_internal/matmul_desc_ifc.py +28 -0
- nvmath/distributed/linalg/advanced/__init__.py +8 -0
- nvmath/distributed/linalg/advanced/_configuration.py +166 -0
- nvmath/distributed/linalg/advanced/matmulmod.py +2908 -0
- nvmath/distributed/process_group.py +408 -0
- nvmath/distributed/reshape/__init__.py +6 -0
- nvmath/distributed/reshape/_configuration.py +39 -0
- nvmath/distributed/reshape/reshape.py +1256 -0
- nvmath/fft/__init__.py +7 -0
- nvmath/fft/_configuration.py +208 -0
- nvmath/fft/_exec_utils.py +109 -0
- nvmath/fft/_helpers.py +237 -0
- nvmath/fft/fft.py +2903 -0
- nvmath/internal/__init__.pxd +3 -0
- nvmath/internal/__init__.py +10 -0
- nvmath/internal/_bindings.cp314-win_amd64.pyd +0 -0
- nvmath/internal/_bindings.pxd +12 -0
- nvmath/internal/_device_utils.py +54 -0
- nvmath/internal/enum_utils.py +142 -0
- nvmath/internal/formatters.py +87 -0
- nvmath/internal/mem_limit.py +51 -0
- nvmath/internal/memory.cp314-win_amd64.pyd +0 -0
- nvmath/internal/memory.pxd +10 -0
- nvmath/internal/memory.pyi +46 -0
- nvmath/internal/ndbuffer/__init__.pxd +3 -0
- nvmath/internal/ndbuffer/__init__.py +7 -0
- nvmath/internal/ndbuffer/copy_kernel/args.h +34 -0
- nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/array_view.h +52 -0
- nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/elementwise.h +68 -0
- nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/grid_indexer.h +69 -0
- nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/transposed.h +240 -0
- nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/type_utils.h +39 -0
- nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/utils.h +132 -0
- nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/vec.h +159 -0
- nvmath/internal/ndbuffer/copy_kernel/elementwise.h +53 -0
- nvmath/internal/ndbuffer/copy_kernel/transposed.h +58 -0
- nvmath/internal/ndbuffer/copy_kernel.cp314-win_amd64.pyd +0 -0
- nvmath/internal/ndbuffer/copy_kernel.pxd +9 -0
- nvmath/internal/ndbuffer/copy_kernel.pyi +9 -0
- nvmath/internal/ndbuffer/data_layout.cp314-win_amd64.pyd +0 -0
- nvmath/internal/ndbuffer/data_layout.pxd +72 -0
- nvmath/internal/ndbuffer/data_layout.pyi +23 -0
- nvmath/internal/ndbuffer/jit.cp314-win_amd64.pyd +0 -0
- nvmath/internal/ndbuffer/jit.pxd +7 -0
- nvmath/internal/ndbuffer/jit.pyi +6 -0
- nvmath/internal/ndbuffer/ndbuffer.cp314-win_amd64.pyd +0 -0
- nvmath/internal/ndbuffer/ndbuffer.pxd +36 -0
- nvmath/internal/ndbuffer/ndbuffer.pyi +41 -0
- nvmath/internal/ndbuffer/package_utils.cp314-win_amd64.pyd +0 -0
- nvmath/internal/ndbuffer/package_utils.pxd +11 -0
- nvmath/internal/ndbuffer/package_utils.pyi +12 -0
- nvmath/internal/package_ifc.py +147 -0
- nvmath/internal/package_ifc_cuda.py +49 -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 +194 -0
- nvmath/internal/tensor_ifc_cupy.py +241 -0
- nvmath/internal/tensor_ifc_ndbuffer.py +153 -0
- nvmath/internal/tensor_ifc_numpy.py +183 -0
- nvmath/internal/tensor_ifc_torch.py +176 -0
- nvmath/internal/tensor_wrapper.py +157 -0
- nvmath/internal/typemaps.py +162 -0
- nvmath/internal/utils.py +771 -0
- nvmath/linalg/__init__.py +46 -0
- nvmath/linalg/_internal/__init__.py +3 -0
- nvmath/linalg/_internal/algo_cap_ifc.py +82 -0
- nvmath/linalg/_internal/algo_config_ifc.py +43 -0
- nvmath/linalg/_internal/batch.py +217 -0
- nvmath/linalg/_internal/enum_to_tuples.py +64 -0
- nvmath/linalg/_internal/epilog_protocol.py +766 -0
- nvmath/linalg/_internal/layout.py +624 -0
- nvmath/linalg/_internal/matmul_desc_ifc.py +28 -0
- nvmath/linalg/_internal/matmul_pref_ifc.py +27 -0
- nvmath/linalg/_internal/matrix_layout_ifc.py +26 -0
- nvmath/linalg/_internal/typemaps.py +144 -0
- nvmath/linalg/_internal/utils.py +134 -0
- nvmath/linalg/advanced/__init__.py +8 -0
- nvmath/linalg/advanced/_algorithmmod.py +149 -0
- nvmath/linalg/advanced/_configuration.py +349 -0
- nvmath/linalg/advanced/helpers/__init__.py +5 -0
- nvmath/linalg/advanced/helpers/matmul.py +1348 -0
- nvmath/linalg/advanced/matmulmod.py +3937 -0
- nvmath/linalg/generic/__init__.py +43 -0
- nvmath/linalg/generic/_configuration/__init__.py +37 -0
- nvmath/linalg/generic/_configuration/layout.py +263 -0
- nvmath/linalg/generic/_configuration/match.py +609 -0
- nvmath/linalg/generic/_configuration/qualifiers.py +494 -0
- nvmath/linalg/generic/_configuration/wrap.py +217 -0
- nvmath/linalg/generic/_dtype.py +15 -0
- nvmath/linalg/generic/matmulmod.py +1060 -0
- nvmath/memory.py +282 -0
- nvmath/sparse/__init__.py +38 -0
- nvmath/sparse/_internal/__init__.py +21 -0
- nvmath/sparse/_internal/common_utils.py +144 -0
- nvmath/sparse/_internal/cudss_config_ifc.py +741 -0
- nvmath/sparse/_internal/cudss_data_ifc.py +399 -0
- nvmath/sparse/_internal/cudss_utils.py +445 -0
- nvmath/sparse/_internal/cusparse_utils.py +382 -0
- nvmath/sparse/_internal/sparse_bsc_ifc.py +300 -0
- nvmath/sparse/_internal/sparse_bsr_ifc.py +303 -0
- nvmath/sparse/_internal/sparse_coo_ifc.py +254 -0
- nvmath/sparse/_internal/sparse_csc_ifc.py +266 -0
- nvmath/sparse/_internal/sparse_csr_ifc.py +266 -0
- nvmath/sparse/_internal/sparse_dia_ifc.py +239 -0
- nvmath/sparse/_internal/sparse_format_helpers.py +601 -0
- nvmath/sparse/_internal/sparse_tensor_ifc.py +121 -0
- nvmath/sparse/_internal/sparse_ust_ifc.py +146 -0
- nvmath/sparse/_internal/utils.py +56 -0
- nvmath/sparse/advanced/__init__.py +7 -0
- nvmath/sparse/advanced/_configuration.py +230 -0
- nvmath/sparse/advanced/direct_solver.py +1884 -0
- nvmath/sparse/generic/__init__.py +7 -0
- nvmath/sparse/generic/_configuration.py +129 -0
- nvmath/sparse/generic/_helpers.py +137 -0
- nvmath/sparse/generic/_thunks.py +21 -0
- nvmath/sparse/generic/matmulmod.py +2426 -0
- nvmath/sparse/ust/__init__.py +7 -0
- nvmath/sparse/ust/_converters.py +378 -0
- nvmath/sparse/ust/_drawer.py +552 -0
- nvmath/sparse/ust/_emitter.py +553 -0
- nvmath/sparse/ust/_jit.py +212 -0
- nvmath/sparse/ust/_kernel.py +346 -0
- nvmath/sparse/ust/_semiring.py +71 -0
- nvmath/sparse/ust/_utils.py +102 -0
- nvmath/sparse/ust/interfaces/__init__.py +0 -0
- nvmath/sparse/ust/interfaces/torch_interface.py +476 -0
- nvmath/sparse/ust/semiring_ops.py +71 -0
- nvmath/sparse/ust/tensor.py +1027 -0
- nvmath/sparse/ust/tensor_drawer.py +552 -0
- nvmath/sparse/ust/tensor_emitter.py +558 -0
- nvmath/sparse/ust/tensor_format.py +935 -0
- nvmath/sparse/ust/tensor_jit.py +212 -0
- nvmath/sparse/ust/tensor_kernel.py +348 -0
- nvmath/sparse/ust/tensor_utils.py +380 -0
- nvmath/tensor/__init__.py +6 -0
- nvmath/tensor/_configuration.py +95 -0
- nvmath/tensor/_internal/__init__.py +3 -0
- nvmath/tensor/_internal/cutensor_config_ifc.py +247 -0
- nvmath/tensor/_internal/cutensor_utils.py +162 -0
- nvmath/tensor/_internal/data.py +43 -0
- nvmath/tensor/_internal/einsum_parser.py +444 -0
- nvmath/tensor/_internal/typemaps.py +96 -0
- nvmath/tensor/contract.py +1861 -0
- nvmath_python-0.9.0.dist-info/METADATA +127 -0
- nvmath_python-0.9.0.dist-info/RECORD +309 -0
- nvmath_python-0.9.0.dist-info/WHEEL +5 -0
- nvmath_python-0.9.0.dist-info/licenses/LICENSE +177 -0
- nvmath_python-0.9.0.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Interface classes to encapsulate low-level calls to get or set configuration information.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__all__ = ["ContractionPlanPreference"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
from nvmath.bindings import cutensor
|
|
15
|
+
from nvmath.internal import utils
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ContractionPlanPreference:
|
|
19
|
+
"""
|
|
20
|
+
An interface to configure :meth:`nvmath.tensor.BinaryContraction.plan` and
|
|
21
|
+
:meth:`nvmath.tensor.TernaryContraction.plan`. The
|
|
22
|
+
current configuration can also be queried.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, contraction):
|
|
26
|
+
"""
|
|
27
|
+
ctor for internal use only.
|
|
28
|
+
"""
|
|
29
|
+
self._contraction = contraction
|
|
30
|
+
self._handle = self._contraction.handle
|
|
31
|
+
|
|
32
|
+
get_dtype = cutensor.get_plan_preference_attribute_dtype
|
|
33
|
+
|
|
34
|
+
self._autotune_mode = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.AUTOTUNE_MODE))
|
|
35
|
+
self._cache_mode = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.CACHE_MODE))
|
|
36
|
+
self._incremental_count = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.INCREMENTAL_COUNT))
|
|
37
|
+
self._algo = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.ALGO))
|
|
38
|
+
self._kernel_rank = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.KERNEL_RANK))
|
|
39
|
+
self._jit = np.zeros((1,), dtype=get_dtype(cutensor.PlanPreferenceAttribute.JIT))
|
|
40
|
+
|
|
41
|
+
def _check_valid_contraction_wrapper(self, *args, **kwargs):
|
|
42
|
+
if not self._contraction.valid_state:
|
|
43
|
+
raise RuntimeError("The ContractionPlanPreference object cannot be used after its contraction object is free'd.")
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def _get_scalar_attribute(contraction, name, attribute):
|
|
47
|
+
"""
|
|
48
|
+
name = cutensor PlanPreference enum for the attribute
|
|
49
|
+
attribute = numpy ndarray object into which the value is stored by cutensornet
|
|
50
|
+
"""
|
|
51
|
+
assert contraction.plan_preference_ptr is not None, "Internal error"
|
|
52
|
+
cutensor.plan_preference_get_attribute(
|
|
53
|
+
contraction.handle, contraction.plan_preference_ptr, name, attribute.ctypes.data, attribute.dtype.itemsize
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
@staticmethod
|
|
57
|
+
def _set_scalar_attribute(contraction, name, attribute, value):
|
|
58
|
+
"""
|
|
59
|
+
name = cutensor PlanPreference enum for the attribute
|
|
60
|
+
attribute = numpy ndarray object into which the value is stored
|
|
61
|
+
value = the value to set the the attribute to
|
|
62
|
+
"""
|
|
63
|
+
assert contraction.plan_preference_ptr is not None, "Internal error"
|
|
64
|
+
attribute[0] = value
|
|
65
|
+
cutensor.plan_preference_set_attribute(
|
|
66
|
+
contraction.handle, contraction.plan_preference_ptr, name, attribute.ctypes.data, attribute.dtype.itemsize
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
71
|
+
def autotune_mode(self):
|
|
72
|
+
"""
|
|
73
|
+
Query the autotune mode. See the
|
|
74
|
+
`cuTensor documentation
|
|
75
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorautotunemode-t>`__
|
|
76
|
+
for more information.
|
|
77
|
+
"""
|
|
78
|
+
ContractionPlanPreference._get_scalar_attribute(
|
|
79
|
+
self._contraction, cutensor.PlanPreferenceAttribute.AUTOTUNE_MODE, self._autotune_mode
|
|
80
|
+
)
|
|
81
|
+
return self._autotune_mode.item()
|
|
82
|
+
|
|
83
|
+
@autotune_mode.setter
|
|
84
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
85
|
+
def autotune_mode(self, autotune_mode):
|
|
86
|
+
"""
|
|
87
|
+
Set the autotune mode. See the
|
|
88
|
+
`cuTensor documentation
|
|
89
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorautotunemode-t>`__
|
|
90
|
+
for more information.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
autotune_mode: (nvmath.tensor.ContractionAutotuneMode) The autotune mode.
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
ContractionPlanPreference._set_scalar_attribute(
|
|
97
|
+
self._contraction, cutensor.PlanPreferenceAttribute.AUTOTUNE_MODE, self._autotune_mode, autotune_mode
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
102
|
+
def cache_mode(self):
|
|
103
|
+
"""
|
|
104
|
+
Query the cache mode. See the
|
|
105
|
+
`cuTensor documentation
|
|
106
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorcachemode-t>`__
|
|
107
|
+
for more information.
|
|
108
|
+
"""
|
|
109
|
+
ContractionPlanPreference._get_scalar_attribute(
|
|
110
|
+
self._contraction, cutensor.PlanPreferenceAttribute.CACHE_MODE, self._cache_mode
|
|
111
|
+
)
|
|
112
|
+
return self._cache_mode.item()
|
|
113
|
+
|
|
114
|
+
@cache_mode.setter
|
|
115
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
116
|
+
def cache_mode(self, cache_mode):
|
|
117
|
+
"""
|
|
118
|
+
Set the cache mode. See the
|
|
119
|
+
`cuTensor documentation
|
|
120
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorcachemode-t>`__
|
|
121
|
+
for more information.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
cache_mode: (nvmath.tensor.ContractionCacheMode) The cache mode.
|
|
125
|
+
|
|
126
|
+
"""
|
|
127
|
+
ContractionPlanPreference._set_scalar_attribute(
|
|
128
|
+
self._contraction, cutensor.PlanPreferenceAttribute.CACHE_MODE, self._cache_mode, cache_mode
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
133
|
+
def incremental_count(self):
|
|
134
|
+
"""
|
|
135
|
+
Query the incremental count. See the
|
|
136
|
+
`cuTensor documentation
|
|
137
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorincrementalcount-t>`__
|
|
138
|
+
for more information.
|
|
139
|
+
"""
|
|
140
|
+
ContractionPlanPreference._get_scalar_attribute(
|
|
141
|
+
self._contraction, cutensor.PlanPreferenceAttribute.INCREMENTAL_COUNT, self._incremental_count
|
|
142
|
+
)
|
|
143
|
+
return self._incremental_count.item()
|
|
144
|
+
|
|
145
|
+
@incremental_count.setter
|
|
146
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
147
|
+
def incremental_count(self, incremental_count):
|
|
148
|
+
"""
|
|
149
|
+
Set the incremental count. See the
|
|
150
|
+
`cuTensor documentation
|
|
151
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorincrementalcount-t>`__
|
|
152
|
+
for more information.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
incremental_count: The incremental count.
|
|
156
|
+
|
|
157
|
+
"""
|
|
158
|
+
ContractionPlanPreference._set_scalar_attribute(
|
|
159
|
+
self._contraction, cutensor.PlanPreferenceAttribute.INCREMENTAL_COUNT, self._incremental_count, incremental_count
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
@property
|
|
163
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
164
|
+
def algo(self):
|
|
165
|
+
"""
|
|
166
|
+
Query the algo. See the
|
|
167
|
+
`cuTensor documentation
|
|
168
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensoralgo-t>`__
|
|
169
|
+
for more information.
|
|
170
|
+
"""
|
|
171
|
+
ContractionPlanPreference._get_scalar_attribute(self._contraction, cutensor.PlanPreferenceAttribute.ALGO, self._algo)
|
|
172
|
+
return self._algo.item()
|
|
173
|
+
|
|
174
|
+
@algo.setter
|
|
175
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
176
|
+
def algo(self, algo):
|
|
177
|
+
"""
|
|
178
|
+
Set the algo. See the
|
|
179
|
+
`cuTensor documentation
|
|
180
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensoralgo-t>`__
|
|
181
|
+
for more information.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
algo: (nvmath.tensor.ContractionAlgo) The contraction algorithm.
|
|
185
|
+
|
|
186
|
+
"""
|
|
187
|
+
ContractionPlanPreference._set_scalar_attribute(
|
|
188
|
+
self._contraction, cutensor.PlanPreferenceAttribute.ALGO, self._algo, algo
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
@property
|
|
192
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
193
|
+
def kernel_rank(self):
|
|
194
|
+
"""
|
|
195
|
+
Query the kernel rank. See the
|
|
196
|
+
`cuTensor documentation
|
|
197
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorkernelrank-t>`__
|
|
198
|
+
for more information.
|
|
199
|
+
"""
|
|
200
|
+
ContractionPlanPreference._get_scalar_attribute(
|
|
201
|
+
self._contraction, cutensor.PlanPreferenceAttribute.KERNEL_RANK, self._kernel_rank
|
|
202
|
+
)
|
|
203
|
+
return self._kernel_rank.item()
|
|
204
|
+
|
|
205
|
+
@kernel_rank.setter
|
|
206
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
207
|
+
def kernel_rank(self, kernel_rank):
|
|
208
|
+
"""
|
|
209
|
+
Set the kernel rank. See the
|
|
210
|
+
`cuTensor documentation
|
|
211
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorkernelrank-t>`__
|
|
212
|
+
for more information.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
kernel_rank: The kernel rank.
|
|
216
|
+
|
|
217
|
+
"""
|
|
218
|
+
ContractionPlanPreference._set_scalar_attribute(
|
|
219
|
+
self._contraction, cutensor.PlanPreferenceAttribute.KERNEL_RANK, self._kernel_rank, kernel_rank
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
@property
|
|
223
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
224
|
+
def jit(self):
|
|
225
|
+
"""
|
|
226
|
+
Query the jit compilation mode. See the
|
|
227
|
+
`cuTensor documentation
|
|
228
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorjit-t>`__
|
|
229
|
+
for more information.
|
|
230
|
+
"""
|
|
231
|
+
ContractionPlanPreference._get_scalar_attribute(self._contraction, cutensor.PlanPreferenceAttribute.JIT, self._jit)
|
|
232
|
+
return self._jit.item()
|
|
233
|
+
|
|
234
|
+
@jit.setter
|
|
235
|
+
@utils.precondition(_check_valid_contraction_wrapper)
|
|
236
|
+
def jit(self, jit):
|
|
237
|
+
"""
|
|
238
|
+
Set the jit compilation mode. See the
|
|
239
|
+
`cuTensor documentation
|
|
240
|
+
<https://docs.nvidia.com/cuda/cutensor/latest/api/types.html#cutensorjit-t>`__
|
|
241
|
+
for more information.
|
|
242
|
+
|
|
243
|
+
Args:
|
|
244
|
+
jit: (nvmath.tensor.ContractionJitMode) The JIT compilation mode.
|
|
245
|
+
|
|
246
|
+
"""
|
|
247
|
+
ContractionPlanPreference._set_scalar_attribute(self._contraction, cutensor.PlanPreferenceAttribute.JIT, self._jit, jit)
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import weakref
|
|
6
|
+
from collections.abc import Sequence
|
|
7
|
+
|
|
8
|
+
from nvmath.bindings import cutensor
|
|
9
|
+
from nvmath.internal.tensor_ifc import TensorHolder
|
|
10
|
+
from nvmath.internal.typemaps import NAME_TO_DATA_TYPE
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"compute_pointer_alignment",
|
|
14
|
+
"compute_strides",
|
|
15
|
+
"TensorDescriptor",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
DEFAULT_ALIGNMENT_REQUIREMENT = 256
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def compute_pointer_alignment(ptr: int) -> int:
|
|
22
|
+
"""
|
|
23
|
+
Compute the pointer alignment for the given pointer.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
ptr: Pointer address as integer
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
The alignment value (256, 128, 64, 32, 16, 8, 4, 2, or 1)
|
|
30
|
+
"""
|
|
31
|
+
return 256 if ptr == 0 else min(ptr & -ptr, 256)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def compute_strides(shape: Sequence[int], order: str = "C") -> Sequence[int]:
|
|
35
|
+
"""
|
|
36
|
+
Compute the strides for the given shape and order.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
shape: Shape of the tensor
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
The strides
|
|
43
|
+
"""
|
|
44
|
+
assert order in {"C", "F"}, f"Invalid order: {order}"
|
|
45
|
+
strides = [0] * len(shape)
|
|
46
|
+
stride = 1
|
|
47
|
+
if order == "C":
|
|
48
|
+
for axis in range(len(shape) - 1, -1, -1):
|
|
49
|
+
strides[axis] = stride
|
|
50
|
+
stride *= shape[axis]
|
|
51
|
+
elif order == "F":
|
|
52
|
+
for axis in range(len(shape)):
|
|
53
|
+
strides[axis] = stride
|
|
54
|
+
stride *= shape[axis]
|
|
55
|
+
else:
|
|
56
|
+
raise ValueError(f"Invalid order: {order}")
|
|
57
|
+
return strides
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class TensorDescriptor:
|
|
61
|
+
"""
|
|
62
|
+
A managed wrapper for cuTensor tensor descriptors with automatic resource cleanup.
|
|
63
|
+
|
|
64
|
+
This class wraps a cuTensor tensor descriptor (``cutensorTensorDescriptor_t``) and
|
|
65
|
+
automatically manages its lifetime. The underlying C descriptor is created on
|
|
66
|
+
initialization and automatically destroyed when this object is garbage collected.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
handle: The cuTensor library handle.
|
|
70
|
+
extents: The extents (shape) of each mode of the tensor. Must have the same
|
|
71
|
+
length as ``strides``.
|
|
72
|
+
strides: The stride for each mode of the tensor, in elements of the base type.
|
|
73
|
+
Must have the same length as ``extents``.
|
|
74
|
+
dtype: The data type of the tensor as a string.
|
|
75
|
+
alignment: The alignment requirement in bytes for the base pointer that will
|
|
76
|
+
be used with this descriptor.
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
def __init__(
|
|
81
|
+
self,
|
|
82
|
+
handle: int,
|
|
83
|
+
extents: Sequence[int],
|
|
84
|
+
strides: Sequence[int],
|
|
85
|
+
dtype: str,
|
|
86
|
+
alignment: int,
|
|
87
|
+
):
|
|
88
|
+
self._extents = extents
|
|
89
|
+
self._strides = strides
|
|
90
|
+
self._dtype = dtype
|
|
91
|
+
self._alignment = alignment
|
|
92
|
+
num_modes = len(extents)
|
|
93
|
+
assert num_modes == len(strides), "The number of modes and strides must be the same"
|
|
94
|
+
self._tensor_desc = cutensor.create_tensor_descriptor(
|
|
95
|
+
handle, num_modes, extents, strides, NAME_TO_DATA_TYPE[dtype], alignment
|
|
96
|
+
)
|
|
97
|
+
self._finalizer = weakref.finalize(self, cutensor.destroy_tensor_descriptor, self._tensor_desc)
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def ptr(self) -> int:
|
|
101
|
+
return self._tensor_desc
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def shape(self) -> Sequence[int]:
|
|
105
|
+
return self._extents
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def dtype(self) -> str:
|
|
109
|
+
return self._dtype
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def alignment(self) -> int:
|
|
113
|
+
return self._alignment
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def strides(self) -> Sequence[int]:
|
|
117
|
+
return self._strides
|
|
118
|
+
|
|
119
|
+
@classmethod
|
|
120
|
+
def from_tensor_holder(cls, handle: int, tensor: TensorHolder) -> "TensorDescriptor":
|
|
121
|
+
"""
|
|
122
|
+
Create a TensorDescriptor from a TensorHolder.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
handle: The cuTensor library handle.
|
|
126
|
+
tensor: The TensorHolder to create the descriptor from.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
A TensorDescriptor with properties derived from the TensorHolder.
|
|
130
|
+
"""
|
|
131
|
+
return cls(
|
|
132
|
+
handle=handle,
|
|
133
|
+
extents=tensor.shape,
|
|
134
|
+
strides=tensor.strides,
|
|
135
|
+
dtype=tensor.dtype,
|
|
136
|
+
alignment=compute_pointer_alignment(tensor.data_ptr),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
@classmethod
|
|
140
|
+
def from_shape_and_dtype(
|
|
141
|
+
cls, handle: int, shape: Sequence[int], dtype: str, order: str = "C", alignment: int = DEFAULT_ALIGNMENT_REQUIREMENT
|
|
142
|
+
) -> "TensorDescriptor":
|
|
143
|
+
"""
|
|
144
|
+
Create a TensorDescriptor for the given shape, data type, order, and alignment.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
handle: The cuTensor library handle.
|
|
148
|
+
shape: The shape (extents) of the tensor.
|
|
149
|
+
dtype: The data type of the tensor as a string.
|
|
150
|
+
order: The memory layout order. Defaults to ``"C"``.
|
|
151
|
+
alignment: The alignment requirement in bytes. Defaults to 256.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
A TensorDescriptor with the specified properties.
|
|
155
|
+
"""
|
|
156
|
+
return cls(
|
|
157
|
+
handle=handle,
|
|
158
|
+
extents=shape,
|
|
159
|
+
strides=compute_strides(shape, order),
|
|
160
|
+
dtype=dtype,
|
|
161
|
+
alignment=alignment,
|
|
162
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
# Defined in CPython:
|
|
6
|
+
# https://github.com/python/cpython/blob/26bc2cc06128890ac89492eca20e83abe0789c1c/Objects/unicodetype_db.h#L6311-L6349
|
|
7
|
+
|
|
8
|
+
__all__ = ["WHITESPACE_UNICODE"]
|
|
9
|
+
|
|
10
|
+
_WHITESPACE_UNICODE_INTS = [
|
|
11
|
+
0x0009,
|
|
12
|
+
0x000A,
|
|
13
|
+
0x000B,
|
|
14
|
+
0x000C,
|
|
15
|
+
0x000D,
|
|
16
|
+
0x001C,
|
|
17
|
+
0x001D,
|
|
18
|
+
0x001E,
|
|
19
|
+
0x001F,
|
|
20
|
+
0x0020,
|
|
21
|
+
0x0085,
|
|
22
|
+
0x00A0,
|
|
23
|
+
0x1680,
|
|
24
|
+
0x2000,
|
|
25
|
+
0x2001,
|
|
26
|
+
0x2002,
|
|
27
|
+
0x2003,
|
|
28
|
+
0x2004,
|
|
29
|
+
0x2005,
|
|
30
|
+
0x2006,
|
|
31
|
+
0x2007,
|
|
32
|
+
0x2008,
|
|
33
|
+
0x2009,
|
|
34
|
+
0x200A,
|
|
35
|
+
0x2028,
|
|
36
|
+
0x2029,
|
|
37
|
+
0x202F,
|
|
38
|
+
0x205F,
|
|
39
|
+
0x3000,
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
WHITESPACE_UNICODE = "".join(chr(s) for s in _WHITESPACE_UNICODE_INTS)
|