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