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,9 @@
|
|
|
1
|
+
# Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
cimport cython
|
|
6
|
+
from libc.stdint cimport intptr_t
|
|
7
|
+
from .data_layout cimport Layout
|
|
8
|
+
|
|
9
|
+
cdef int launch_copy_kernel(Layout dst, Layout src, intptr_t dst_ptr, intptr_t src_ptr, int device_id, intptr_t stream_ptr, object logger=*) except -1 nogil
|
|
Binary file
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
cimport cython
|
|
6
|
+
from libc.stdint cimport int64_t, uint32_t, intptr_t
|
|
7
|
+
from libcpp cimport vector
|
|
8
|
+
|
|
9
|
+
ctypedef int64_t extent_t
|
|
10
|
+
ctypedef int64_t stride_t
|
|
11
|
+
ctypedef int axis_t
|
|
12
|
+
|
|
13
|
+
ctypedef uint32_t axes_mask_t
|
|
14
|
+
|
|
15
|
+
ctypedef vector.vector[extent_t] shape_t
|
|
16
|
+
ctypedef vector.vector[stride_t] strides_t
|
|
17
|
+
ctypedef vector.vector[axis_t] axis_order_t
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
ctypedef fused vector_type:
|
|
21
|
+
shape_t
|
|
22
|
+
strides_t
|
|
23
|
+
axis_order_t
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
cdef enum OrderFlag:
|
|
27
|
+
C_ORDER = 0
|
|
28
|
+
F_ORDER = 1
|
|
29
|
+
CUSTOM_PERMUTATION = 2
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@cython.final
|
|
33
|
+
cdef class Layout:
|
|
34
|
+
cdef readonly shape_t shape
|
|
35
|
+
cdef readonly strides_t strides
|
|
36
|
+
cdef readonly int64_t volume
|
|
37
|
+
cdef readonly int ndim
|
|
38
|
+
cdef readonly int itemsize
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@cython.overflowcheck(True)
|
|
42
|
+
cdef inline int64_t size_in_bytes(Layout layout) except? -1 nogil:
|
|
43
|
+
return layout.volume * layout.itemsize
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
cdef int tuple2vec(vector_type &vec, object t) except -1
|
|
47
|
+
cdef int set_strides_tuple(Layout layout, object strides, bint strides_in_bytes) except -1
|
|
48
|
+
cdef int64_t set_strides_in_order(strides_t& strides, shape_t &shape, OrderFlag order_flag, axis_order_t *axis_order=*) except -1 nogil
|
|
49
|
+
cdef int64_t overflow_checked_volume(shape_t& shape) except? -1 nogil
|
|
50
|
+
cdef int zero_strides(strides_t& strides, int ndim) except -1 nogil
|
|
51
|
+
cdef int divide_strides(strides_t &strides, int ndim, int itemsize) except -1 nogil
|
|
52
|
+
cdef tuple get_strides_in_bytes_tuple(Layout layout)
|
|
53
|
+
cdef Layout create_layout_without_strides(object shape, int itemsize)
|
|
54
|
+
cdef Layout create_layout(object shape, object strides, int itemsize, bint strides_in_bytes)
|
|
55
|
+
cdef Layout copy_layout(Layout src)
|
|
56
|
+
cdef Layout empty_layout_with_dtype_like(Layout src)
|
|
57
|
+
cdef bint is_overlapping_layout(Layout sorted_layout) except -1 nogil
|
|
58
|
+
cdef bint is_overlapping_layout_in_order(Layout layout, axis_order_t& axis_order) except -1 nogil
|
|
59
|
+
cdef int64_t transpose_squeeze_zeros_ones_layout(Layout out_layout, Layout in_layout, axis_order_t& axis_order) except -1 nogil
|
|
60
|
+
cdef int transpose_layout(Layout layout, axis_order_t& axis_order) except -1 nogil
|
|
61
|
+
cdef bint is_c_contiguous_layout(Layout sorted_layout) except -1 nogil
|
|
62
|
+
cdef bint is_f_contiguous_layout(Layout sorted_layout) except -1 nogil
|
|
63
|
+
cdef bint is_contiguous_layout_in_order(Layout layout, axis_order_t& axis_order) except -1 nogil
|
|
64
|
+
cdef int squeeze_layouts_together(Layout layout_a, Layout layout_b, int ndim) except -1 nogil
|
|
65
|
+
cdef int squeeze_layout(shape_t& out_shape, strides_t& out_strides, Layout in_layout) except? -1 nogil
|
|
66
|
+
cdef bint split_strides(Layout new_layout, shape_t& old_shape, strides_t& old_strides) except -1 nogil
|
|
67
|
+
cdef int vectorize_together(Layout layout_a, intptr_t ptr_a, Layout layout_b, intptr_t ptr_b, int max_vec_size=*, int max_itemsize=*) except -1 nogil
|
|
68
|
+
cdef int get_axis_order(axis_order_t& axis_order, Layout layout) except -1 nogil
|
|
69
|
+
cdef axes_mask_t get_contiguous_axes_up_to_vol(int64_t &suffix_vol, axes_mask_t forbidden_axes, int64_t max_volume, Layout layout, int* axis_order=*) except? -1 nogil
|
|
70
|
+
cdef int parse_py_axis_order(OrderFlag& order_flag, axis_order_t& axis_order_vec, Layout other, object axis_order_arg) except -1
|
|
71
|
+
cdef bint is_c_or_f(OrderFlag& order_flag, shape_t& shape, strides_t& strides, int ndim) except -1 nogil
|
|
72
|
+
cdef bint is_c_or_f_layout(OrderFlag& order_flag, Layout layout) except -1 nogil
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import _cython_3_2_4
|
|
6
|
+
from _typeshed import Incomplete
|
|
7
|
+
|
|
8
|
+
__pyx_capi__: dict
|
|
9
|
+
__reduce_cython__: _cython_3_2_4.cython_function_or_method
|
|
10
|
+
__setstate_cython__: _cython_3_2_4.cython_function_or_method
|
|
11
|
+
__test__: dict
|
|
12
|
+
|
|
13
|
+
class Layout:
|
|
14
|
+
itemsize: Incomplete
|
|
15
|
+
ndim: Incomplete
|
|
16
|
+
shape: Incomplete
|
|
17
|
+
strides: Incomplete
|
|
18
|
+
volume: Incomplete
|
|
19
|
+
@classmethod
|
|
20
|
+
def __init__(cls, *args, **kwargs) -> None:
|
|
21
|
+
"""Create and return a new object. See help(type) for accurate signature."""
|
|
22
|
+
def __reduce__(self):
|
|
23
|
+
"""Layout.__reduce_cython__(self)"""
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from libc.stdint cimport intptr_t
|
|
6
|
+
|
|
7
|
+
cdef intptr_t get_kernel(str kernel_code, str kernel_name, int device_id, include_path, object logger=*) except? 0
|
|
Binary file
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
cimport cython
|
|
6
|
+
from libc.stdint cimport intptr_t
|
|
7
|
+
from .data_layout cimport Layout, axis_order_t, OrderFlag
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@cython.final
|
|
11
|
+
cdef class NDBuffer:
|
|
12
|
+
cdef Layout layout
|
|
13
|
+
cdef readonly object data
|
|
14
|
+
cdef int data_device_id
|
|
15
|
+
cdef int flags
|
|
16
|
+
cdef readonly intptr_t data_ptr
|
|
17
|
+
cdef readonly str dtype_name
|
|
18
|
+
|
|
19
|
+
# possibly lazy evaluated properties
|
|
20
|
+
# accessible publicly in python
|
|
21
|
+
cdef prop_strides
|
|
22
|
+
cdef prop_shape
|
|
23
|
+
cdef prop_device
|
|
24
|
+
cdef prop_device_id
|
|
25
|
+
cdef prop_strides_in_bytes
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
cdef NDBuffer _no_data_dense_like(NDBuffer other, axis_order_t* axis_order_vec, OrderFlag order_flag)
|
|
29
|
+
cdef NDBuffer _no_data_like(NDBuffer other, bint copy_data)
|
|
30
|
+
cdef int _set_flags(NDBuffer ndbuffer, bint is_wrapping_tensor=*) except -1 nogil
|
|
31
|
+
|
|
32
|
+
cpdef NDBuffer wrap_external(data, intptr_t ptr, str dtype_name, object shape, object strides, int device_id, int itemsize, bint strides_in_bytes=*)
|
|
33
|
+
cpdef NDBuffer empty(object shape, int device_id, str dtype_name, int itemsize, object axis_order=*, object strides=*, object host_memory_pool=*, object device_memory_pool=*, object stream=*, bint strides_in_bytes=*, object logger=*)
|
|
34
|
+
cpdef NDBuffer empty_like(NDBuffer other, object axis_order=*, object device_id=*, object stream=*, object host_memory_pool=*, object device_memory_pool=*, object logger=*)
|
|
35
|
+
cpdef int copy_into(NDBuffer dst, NDBuffer src, object stream, object host_memory_pool=*, object device_memory_pool=*, object logger=*) except -1
|
|
36
|
+
cpdef NDBuffer reshaped_view(NDBuffer other, object shape, object logger=*)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import _cython_3_2_4
|
|
6
|
+
from _typeshed import Incomplete
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
CPU_DEVICE_ID: int
|
|
10
|
+
__pyx_capi__: dict
|
|
11
|
+
__test__: dict
|
|
12
|
+
copy_into: _cython_3_2_4.cython_function_or_method
|
|
13
|
+
empty: _cython_3_2_4.cython_function_or_method
|
|
14
|
+
empty_like: _cython_3_2_4.cython_function_or_method
|
|
15
|
+
reshaped_view: _cython_3_2_4.cython_function_or_method
|
|
16
|
+
wrap_external: _cython_3_2_4.cython_function_or_method
|
|
17
|
+
|
|
18
|
+
class NDBuffer:
|
|
19
|
+
data: Incomplete
|
|
20
|
+
data_ptr: Incomplete
|
|
21
|
+
device: Incomplete
|
|
22
|
+
device_id: Incomplete
|
|
23
|
+
dtype_name: Incomplete
|
|
24
|
+
itemsize: Incomplete
|
|
25
|
+
ndim: Incomplete
|
|
26
|
+
shape: Incomplete
|
|
27
|
+
size: Incomplete
|
|
28
|
+
size_in_bytes: Incomplete
|
|
29
|
+
strides: Incomplete
|
|
30
|
+
strides_in_bytes: Incomplete
|
|
31
|
+
@classmethod
|
|
32
|
+
def __init__(cls, *args, **kwargs) -> None:
|
|
33
|
+
"""Create and return a new object. See help(type) for accurate signature."""
|
|
34
|
+
def cf_order(self) -> Any:
|
|
35
|
+
"""NDBuffer.cf_order(self)"""
|
|
36
|
+
def __reduce__(self):
|
|
37
|
+
"""NDBuffer.__reduce_cython__(self)"""
|
|
38
|
+
def __reduce_cython__(self) -> Any:
|
|
39
|
+
"""NDBuffer.__reduce_cython__(self)"""
|
|
40
|
+
def __setstate_cython__(self, __pyx_state) -> Any:
|
|
41
|
+
"""NDBuffer.__setstate_cython__(self, __pyx_state)"""
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from .ndbuffer cimport NDBuffer
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
cpdef NDBuffer empty_numpy_like(NDBuffer other, object axis_order=*)
|
|
9
|
+
cpdef NDBuffer wrap_numpy_array(object array)
|
|
10
|
+
cpdef NDBuffer wrap_cupy_array(object array)
|
|
11
|
+
cpdef str is_c_or_f(object shape, object strides)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import _cython_3_2_4
|
|
6
|
+
|
|
7
|
+
__pyx_capi__: dict
|
|
8
|
+
__test__: dict
|
|
9
|
+
empty_numpy_like: _cython_3_2_4.cython_function_or_method
|
|
10
|
+
is_c_or_f: _cython_3_2_4.cython_function_or_method
|
|
11
|
+
wrap_cupy_array: _cython_3_2_4.cython_function_or_method
|
|
12
|
+
wrap_numpy_array: _cython_3_2_4.cython_function_or_method
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
An abstract interface to certain package-provided operations.
|
|
7
|
+
|
|
8
|
+
Even though cuda.core does not have the concept of a "current stream" or a "stream context",
|
|
9
|
+
we promise to honor third-party CUDA stream contexts if they match the input operand's
|
|
10
|
+
package. The interface class defined in this module wraps around those stream concepts to
|
|
11
|
+
make them uniform.
|
|
12
|
+
|
|
13
|
+
The strategy is to use cuda.core everywhere internally except for context managers which
|
|
14
|
+
will need to wrap back around to the external implementation.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
__all__ = ["Package", "StreamHolder"]
|
|
18
|
+
|
|
19
|
+
from abc import ABC, abstractmethod
|
|
20
|
+
from collections.abc import Hashable
|
|
21
|
+
from contextlib import AbstractContextManager
|
|
22
|
+
from dataclasses import dataclass
|
|
23
|
+
from typing import Generic, Protocol, TypeVar
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
from cuda.core import Stream
|
|
27
|
+
except ImportError:
|
|
28
|
+
from cuda.core.experimental import Stream
|
|
29
|
+
|
|
30
|
+
from ._device_utils import get_device
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class AnyStream(Hashable, Protocol):
|
|
34
|
+
"""Any supported Stream object such as a Stream from cuda.core, CuPy, or PyTorch."""
|
|
35
|
+
|
|
36
|
+
# This empty protocol class is just a placeholder to make type checking more helpful.
|
|
37
|
+
# Since the class is empty, it doesn't assume anything is true about the implementation
|
|
38
|
+
# classes.
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
A generic type for the third-party Stream which a given Package implementation wraps
|
|
44
|
+
around.
|
|
45
|
+
"""
|
|
46
|
+
S = TypeVar("S")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class _cuda_core_stream_holder:
|
|
50
|
+
"""
|
|
51
|
+
Dummy class implementing ``__cuda_stream__`` protocol for ``cuda.core.Stream``.
|
|
52
|
+
|
|
53
|
+
Calling ``cuda.core.Device.create_stream(_cuda_core_stream_holder(handle, external))``
|
|
54
|
+
is similar to ``Stream.from_handle(handle)``, but additionally makes sure
|
|
55
|
+
to extend the ``external`` reference lifetime as long as the created
|
|
56
|
+
``cuda.core.Stream`` object is alive.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def __init__(self, handle: int, external: S):
|
|
60
|
+
self.handle = handle
|
|
61
|
+
self.external = external
|
|
62
|
+
|
|
63
|
+
def __cuda_stream__(self):
|
|
64
|
+
return (0, self.handle)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class Package(ABC, Generic[S]):
|
|
68
|
+
@staticmethod
|
|
69
|
+
@abstractmethod
|
|
70
|
+
def get_current_stream(device_id: int) -> S:
|
|
71
|
+
"""
|
|
72
|
+
Obtain the current stream on the device.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
device_id: The id (ordinal) of the device.
|
|
76
|
+
"""
|
|
77
|
+
raise NotImplementedError
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
@abstractmethod
|
|
81
|
+
def to_stream_pointer(stream: S) -> int:
|
|
82
|
+
"""
|
|
83
|
+
Obtain the stream pointer.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
stream: The stream object.
|
|
87
|
+
"""
|
|
88
|
+
raise NotImplementedError
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
@abstractmethod
|
|
92
|
+
def to_stream_context(stream: S) -> AbstractContextManager[S]:
|
|
93
|
+
"""
|
|
94
|
+
Create a context manager from the stream.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
stream: The stream object.
|
|
98
|
+
"""
|
|
99
|
+
raise NotImplementedError
|
|
100
|
+
|
|
101
|
+
@staticmethod
|
|
102
|
+
@abstractmethod
|
|
103
|
+
def create_external_stream(device_id: int, stream_ptr: int) -> S:
|
|
104
|
+
"""
|
|
105
|
+
Wrap a stream pointer into an external stream object.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
device_id: The id (ordinal) of the device.
|
|
109
|
+
stream: The stream pointer (int) to be wrapped.
|
|
110
|
+
"""
|
|
111
|
+
raise NotImplementedError
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def create_stream(cls, external: S, device_id: int) -> Stream:
|
|
115
|
+
"""
|
|
116
|
+
Wrap an external Stream object into a cuda.core.Stream.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
external: The external Stream object.
|
|
120
|
+
"""
|
|
121
|
+
# use get_device to ensure the initial set_current is called
|
|
122
|
+
device = get_device(device_id)
|
|
123
|
+
# the stream holder ensures we tie the external reference to the
|
|
124
|
+
# cuda.core stream object, extending its lifetime.
|
|
125
|
+
holder = _cuda_core_stream_holder(cls.to_stream_pointer(external), external)
|
|
126
|
+
return device.create_stream(holder)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@dataclass
|
|
130
|
+
class StreamHolder(Generic[S]):
|
|
131
|
+
"""A data class for easing CUDA stream manipulation.
|
|
132
|
+
|
|
133
|
+
Attributes:
|
|
134
|
+
ctx: A context manager for using the specified stream.
|
|
135
|
+
device_id (int): The device ID where the encapsulated stream locates.
|
|
136
|
+
external: A foreign object that holds the stream alive.
|
|
137
|
+
obj: The cuda.core Stream object wrapping external.
|
|
138
|
+
package (str): The name of the package to which the external stream belongs.
|
|
139
|
+
ptr (int): The address of the underlying ``cudaStream_t`` object.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
ctx: AbstractContextManager[S]
|
|
143
|
+
device_id: int
|
|
144
|
+
external: S
|
|
145
|
+
obj: Stream
|
|
146
|
+
package: str
|
|
147
|
+
ptr: int
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Interface to cuda.core operations.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__all__ = ["CUDAPackage"]
|
|
10
|
+
|
|
11
|
+
import contextlib
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
from cuda.core import Stream
|
|
15
|
+
except ImportError:
|
|
16
|
+
from cuda.core.experimental import Stream
|
|
17
|
+
|
|
18
|
+
from ._device_utils import get_device
|
|
19
|
+
from .package_ifc import Package
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class CUDAPackage(Package[Stream]):
|
|
23
|
+
@staticmethod
|
|
24
|
+
def get_current_stream(device_id: int):
|
|
25
|
+
# Use get_device to ensure the cuda.core
|
|
26
|
+
# device has been initialized.
|
|
27
|
+
# In cuda.core 0.5.0, Stream.__hash__ requires context
|
|
28
|
+
# to be set.
|
|
29
|
+
# See https://github.com/NVIDIA/cuda-python/issues/1480
|
|
30
|
+
# TODO(ktokarski): Once we drop support for cuda.core 0.5.0,
|
|
31
|
+
# we can remove this precaution.
|
|
32
|
+
device = get_device(device_id)
|
|
33
|
+
return device.default_stream
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def to_stream_pointer(stream: Stream) -> int: # type: ignore[override]
|
|
37
|
+
return int(stream.handle)
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def to_stream_context(stream: Stream): # type: ignore[override]
|
|
41
|
+
return contextlib.nullcontext(stream)
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def create_external_stream(device_id: int, stream_ptr: int) -> Stream:
|
|
45
|
+
return Stream.from_handle(stream_ptr)
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def create_stream(cls, external: Stream, device_id: int) -> Stream: # type: ignore[override]
|
|
49
|
+
return external
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Interface to CuPy operations.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__all__ = ["CupyPackage"]
|
|
10
|
+
|
|
11
|
+
import cupy as cp
|
|
12
|
+
|
|
13
|
+
from . import utils
|
|
14
|
+
from .package_ifc import Package
|
|
15
|
+
|
|
16
|
+
# Using the functional API is faster than setting a device context
|
|
17
|
+
if int(cp.__version__.split(".")[0]) >= 13:
|
|
18
|
+
_get_current_stream = cp.cuda.get_current_stream
|
|
19
|
+
else:
|
|
20
|
+
|
|
21
|
+
def _get_current_stream(device_id: int):
|
|
22
|
+
with utils.device_ctx(device_id):
|
|
23
|
+
stream = cp.cuda.get_current_stream()
|
|
24
|
+
return stream
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# Monkey patch older versions of CuPy, so that Streams are hashable
|
|
28
|
+
# NOTE: We choose not to patch the BaseStream/_BaseStream class because of name change
|
|
29
|
+
if int(cp.__version__.split(".")[0]) < 11:
|
|
30
|
+
cp.cuda.Stream.__hash__ = lambda self: hash(self.ptr)
|
|
31
|
+
cp.cuda.ExternalStream.__hash__ = lambda self: hash(self.ptr)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class CupyPackage(Package[cp.cuda.Stream]):
|
|
35
|
+
@staticmethod
|
|
36
|
+
def get_current_stream(device_id: int):
|
|
37
|
+
return _get_current_stream(device_id)
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def to_stream_pointer(stream: cp.cuda.Stream) -> int:
|
|
41
|
+
return stream.ptr
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def to_stream_context(stream: cp.cuda.Stream):
|
|
45
|
+
return stream
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
def create_external_stream(device_id: int, stream_ptr: int) -> cp.cuda.ExternalStream:
|
|
49
|
+
return cp.cuda.ExternalStream(stream_ptr)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Interface to Torch operations.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__all__ = ["TorchPackage"]
|
|
10
|
+
|
|
11
|
+
import torch
|
|
12
|
+
|
|
13
|
+
from .package_ifc import Package
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TorchPackage(Package[torch.cuda.Stream]):
|
|
17
|
+
@staticmethod
|
|
18
|
+
def get_current_stream(device_id: int) -> torch.cuda.Stream:
|
|
19
|
+
return torch.cuda.current_stream(device=device_id)
|
|
20
|
+
|
|
21
|
+
@staticmethod
|
|
22
|
+
def to_stream_pointer(stream: torch.cuda.Stream) -> int: # type: ignore[override]
|
|
23
|
+
return stream.cuda_stream
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def to_stream_context(stream: torch.cuda.Stream) -> torch.cuda.StreamContext: # type: ignore[override]
|
|
27
|
+
return torch.cuda.stream(stream)
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def create_external_stream(device_id: int, stream_ptr: int):
|
|
31
|
+
return torch.cuda.ExternalStream(stream_ptr, device=device_id)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Create map from package names to package interface objects.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__all__ = ["PACKAGE", "AnyStream", "StreamHolder"]
|
|
10
|
+
|
|
11
|
+
from .package_ifc import AnyStream, Package, StreamHolder
|
|
12
|
+
from .package_ifc_cuda import CUDAPackage
|
|
13
|
+
|
|
14
|
+
PACKAGE: dict[str, type[Package]] = {"cuda": CUDAPackage}
|