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.
Files changed (309) hide show
  1. nvmath/__init__.pxd +0 -0
  2. nvmath/__init__.py +45 -0
  3. nvmath/_internal/__init__.py +0 -0
  4. nvmath/_internal/attribute_ifc_factory.py +330 -0
  5. nvmath/_internal/layout.py +70 -0
  6. nvmath/_internal/templates.py +383 -0
  7. nvmath/_utils.py +150 -0
  8. nvmath/bindings/__init__.py +51 -0
  9. nvmath/bindings/_internal/__init__.pxd +0 -0
  10. nvmath/bindings/_internal/__init__.py +0 -0
  11. nvmath/bindings/_internal/cublas.cp314-win_amd64.pyd +0 -0
  12. nvmath/bindings/_internal/cublas.pxd +530 -0
  13. nvmath/bindings/_internal/cublasLt.cp314-win_amd64.pyd +0 -0
  14. nvmath/bindings/_internal/cublasLt.pxd +59 -0
  15. nvmath/bindings/_internal/cublasMp.pxd +52 -0
  16. nvmath/bindings/_internal/cudss.cp314-win_amd64.pyd +0 -0
  17. nvmath/bindings/_internal/cudss.pxd +47 -0
  18. nvmath/bindings/_internal/cufft.cp314-win_amd64.pyd +0 -0
  19. nvmath/bindings/_internal/cufft.pxd +70 -0
  20. nvmath/bindings/_internal/cufftMp.pxd +77 -0
  21. nvmath/bindings/_internal/curand.cp314-win_amd64.pyd +0 -0
  22. nvmath/bindings/_internal/curand.pxd +42 -0
  23. nvmath/bindings/_internal/cusolver.cp314-win_amd64.pyd +0 -0
  24. nvmath/bindings/_internal/cusolver.pxd +15 -0
  25. nvmath/bindings/_internal/cusolverDn.cp314-win_amd64.pyd +0 -0
  26. nvmath/bindings/_internal/cusolverDn.pxd +406 -0
  27. nvmath/bindings/_internal/cusparse.cp314-win_amd64.pyd +0 -0
  28. nvmath/bindings/_internal/cusparse.pxd +277 -0
  29. nvmath/bindings/_internal/cusparseLt.cp314-win_amd64.pyd +0 -0
  30. nvmath/bindings/_internal/cusparseLt.pxd +48 -0
  31. nvmath/bindings/_internal/cutensor.cp314-win_amd64.pyd +0 -0
  32. nvmath/bindings/_internal/cutensor.pxd +58 -0
  33. nvmath/bindings/_internal/mathdx.cp314-win_amd64.pyd +0 -0
  34. nvmath/bindings/_internal/mathdx.pxd +116 -0
  35. nvmath/bindings/_internal/nvshmem.pxd +29 -0
  36. nvmath/bindings/_internal/utils.cp314-win_amd64.pyd +0 -0
  37. nvmath/bindings/_internal/utils.pxd +179 -0
  38. nvmath/bindings/_internal/utils.pyi +10 -0
  39. nvmath/bindings/cublas.cp314-win_amd64.pyd +0 -0
  40. nvmath/bindings/cublas.pxd +558 -0
  41. nvmath/bindings/cublas.pyi +746 -0
  42. nvmath/bindings/cublasLt.cp314-win_amd64.pyd +0 -0
  43. nvmath/bindings/cublasLt.pxd +109 -0
  44. nvmath/bindings/cublasLt.pyi +1337 -0
  45. nvmath/bindings/cublasMp.pxd +85 -0
  46. nvmath/bindings/cublasMp.pyi +219 -0
  47. nvmath/bindings/cudss.cp314-win_amd64.pyd +0 -0
  48. nvmath/bindings/cudss.pxd +86 -0
  49. nvmath/bindings/cudss.pyi +282 -0
  50. nvmath/bindings/cufft.cp314-win_amd64.pyd +0 -0
  51. nvmath/bindings/cufft.pxd +118 -0
  52. nvmath/bindings/cufft.pyi +241 -0
  53. nvmath/bindings/cufftMp.pxd +124 -0
  54. nvmath/bindings/cufftMp.pyi +260 -0
  55. nvmath/bindings/curand.cp314-win_amd64.pyd +0 -0
  56. nvmath/bindings/curand.pxd +71 -0
  57. nvmath/bindings/curand.pyi +159 -0
  58. nvmath/bindings/cusolver.cp314-win_amd64.pyd +0 -0
  59. nvmath/bindings/cusolver.pxd +62 -0
  60. nvmath/bindings/cusolver.pyi +242 -0
  61. nvmath/bindings/cusolverDn.cp314-win_amd64.pyd +0 -0
  62. nvmath/bindings/cusolverDn.pxd +430 -0
  63. nvmath/bindings/cusolverDn.pyi +416 -0
  64. nvmath/bindings/cusparse.cp314-win_amd64.pyd +0 -0
  65. nvmath/bindings/cusparse.pxd +338 -0
  66. nvmath/bindings/cusparse.pyi +659 -0
  67. nvmath/bindings/cusparseLt.cp314-win_amd64.pyd +0 -0
  68. nvmath/bindings/cusparseLt.pxd +99 -0
  69. nvmath/bindings/cusparseLt.pyi +198 -0
  70. nvmath/bindings/cutensor.cp314-win_amd64.pyd +0 -0
  71. nvmath/bindings/cutensor.pxd +98 -0
  72. nvmath/bindings/cutensor.pyi +294 -0
  73. nvmath/bindings/cycublas.cp314-win_amd64.pyd +0 -0
  74. nvmath/bindings/cycublas.pxd +684 -0
  75. nvmath/bindings/cycublasLt.cp314-win_amd64.pyd +0 -0
  76. nvmath/bindings/cycublasLt.pxd +1055 -0
  77. nvmath/bindings/cycublasMp.pxd +183 -0
  78. nvmath/bindings/cycudss.cp314-win_amd64.pyd +0 -0
  79. nvmath/bindings/cycudss.pxd +224 -0
  80. nvmath/bindings/cycufft.cp314-win_amd64.pyd +0 -0
  81. nvmath/bindings/cycufft.pxd +326 -0
  82. nvmath/bindings/cycufftMp.pxd +334 -0
  83. nvmath/bindings/cycurand.cp314-win_amd64.pyd +0 -0
  84. nvmath/bindings/cycurand.pxd +146 -0
  85. nvmath/bindings/cycusolver.cp314-win_amd64.pyd +0 -0
  86. nvmath/bindings/cycusolver.pxd +154 -0
  87. nvmath/bindings/cycusolverDn.cp314-win_amd64.pyd +0 -0
  88. nvmath/bindings/cycusolverDn.pxd +446 -0
  89. nvmath/bindings/cycusparse.cp314-win_amd64.pyd +0 -0
  90. nvmath/bindings/cycusparse.pxd +470 -0
  91. nvmath/bindings/cycusparseLt.cp314-win_amd64.pyd +0 -0
  92. nvmath/bindings/cycusparseLt.pxd +150 -0
  93. nvmath/bindings/cycutensor.cp314-win_amd64.pyd +0 -0
  94. nvmath/bindings/cycutensor.pxd +192 -0
  95. nvmath/bindings/cymathdx.cp314-win_amd64.pyd +0 -0
  96. nvmath/bindings/cymathdx.pxd +552 -0
  97. nvmath/bindings/cynvshmem.pxd +126 -0
  98. nvmath/bindings/mathdx.cp314-win_amd64.pyd +0 -0
  99. nvmath/bindings/mathdx.pxd +182 -0
  100. nvmath/bindings/mathdx.pyi +1244 -0
  101. nvmath/bindings/nvpl/__init__.pxd +0 -0
  102. nvmath/bindings/nvpl/__init__.py +13 -0
  103. nvmath/bindings/nvpl/_internal/__init__.pxd +0 -0
  104. nvmath/bindings/nvpl/_internal/__init__.py +0 -0
  105. nvmath/bindings/nvpl/_internal/blas.cp314-win_amd64.pyd +0 -0
  106. nvmath/bindings/nvpl/_internal/blas.pxd +125 -0
  107. nvmath/bindings/nvpl/_internal/fft.cp314-win_amd64.pyd +0 -0
  108. nvmath/bindings/nvpl/_internal/fft.pxd +36 -0
  109. nvmath/bindings/nvpl/blas.cp314-win_amd64.pyd +0 -0
  110. nvmath/bindings/nvpl/blas.pxd +85 -0
  111. nvmath/bindings/nvpl/blas.pyi +122 -0
  112. nvmath/bindings/nvpl/cyblas.cp314-win_amd64.pyd +0 -0
  113. nvmath/bindings/nvpl/cyblas.pxd +166 -0
  114. nvmath/bindings/nvpl/cyfft.cp314-win_amd64.pyd +0 -0
  115. nvmath/bindings/nvpl/cyfft.pxd +92 -0
  116. nvmath/bindings/nvpl/fft.cp314-win_amd64.pyd +0 -0
  117. nvmath/bindings/nvpl/fft.pxd +100 -0
  118. nvmath/bindings/nvpl/fft.pyi +100 -0
  119. nvmath/bindings/nvshmem.pxd +54 -0
  120. nvmath/bindings/nvshmem.pyi +179 -0
  121. nvmath/device/__init__.py +21 -0
  122. nvmath/device/_deprecated.py +33 -0
  123. nvmath/device/common.py +313 -0
  124. nvmath/device/common_backend.py +131 -0
  125. nvmath/device/common_cuda.py +201 -0
  126. nvmath/device/common_numba.py +310 -0
  127. nvmath/device/common_opaque_tensor.py +201 -0
  128. nvmath/device/cublasdx.py +1805 -0
  129. nvmath/device/cublasdx_backend.py +807 -0
  130. nvmath/device/cublasdx_numba.py +1612 -0
  131. nvmath/device/cufftdx.py +510 -0
  132. nvmath/device/cufftdx_backend.py +196 -0
  133. nvmath/device/cufftdx_numba.py +196 -0
  134. nvmath/device/curand_kernel.py +9147 -0
  135. nvmath/device/cusolverdx.py +2690 -0
  136. nvmath/device/cusolverdx_backend.py +440 -0
  137. nvmath/device/cusolverdx_numba.py +1624 -0
  138. nvmath/device/llvm_array.py +29 -0
  139. nvmath/device/random.py +445 -0
  140. nvmath/device/random_helpers.py +23 -0
  141. nvmath/device/random_states.py +187 -0
  142. nvmath/device/types.py +147 -0
  143. nvmath/device/vector_types_numba.py +203 -0
  144. nvmath/distributed/__init__.py +205 -0
  145. nvmath/distributed/_internal/__init__.py +0 -0
  146. nvmath/distributed/_internal/nvshmem.py +302 -0
  147. nvmath/distributed/_internal/tensor_ifc.py +67 -0
  148. nvmath/distributed/_internal/tensor_ifc_cupy.py +62 -0
  149. nvmath/distributed/_internal/tensor_ifc_host_device.py +165 -0
  150. nvmath/distributed/_internal/tensor_ifc_numpy.py +41 -0
  151. nvmath/distributed/_internal/tensor_ifc_torch.py +141 -0
  152. nvmath/distributed/_internal/tensor_wrapper.py +78 -0
  153. nvmath/distributed/_utils.py +167 -0
  154. nvmath/distributed/distribution.py +770 -0
  155. nvmath/distributed/fft/__init__.py +7 -0
  156. nvmath/distributed/fft/_configuration.py +79 -0
  157. nvmath/distributed/fft/fft.py +2801 -0
  158. nvmath/distributed/linalg/__init__.py +12 -0
  159. nvmath/distributed/linalg/_internal/__init__.py +3 -0
  160. nvmath/distributed/linalg/_internal/epilog_protocol.py +496 -0
  161. nvmath/distributed/linalg/_internal/matmul_desc_ifc.py +28 -0
  162. nvmath/distributed/linalg/advanced/__init__.py +8 -0
  163. nvmath/distributed/linalg/advanced/_configuration.py +166 -0
  164. nvmath/distributed/linalg/advanced/matmulmod.py +2908 -0
  165. nvmath/distributed/process_group.py +408 -0
  166. nvmath/distributed/reshape/__init__.py +6 -0
  167. nvmath/distributed/reshape/_configuration.py +39 -0
  168. nvmath/distributed/reshape/reshape.py +1256 -0
  169. nvmath/fft/__init__.py +7 -0
  170. nvmath/fft/_configuration.py +208 -0
  171. nvmath/fft/_exec_utils.py +109 -0
  172. nvmath/fft/_helpers.py +237 -0
  173. nvmath/fft/fft.py +2903 -0
  174. nvmath/internal/__init__.pxd +3 -0
  175. nvmath/internal/__init__.py +10 -0
  176. nvmath/internal/_bindings.cp314-win_amd64.pyd +0 -0
  177. nvmath/internal/_bindings.pxd +12 -0
  178. nvmath/internal/_device_utils.py +54 -0
  179. nvmath/internal/enum_utils.py +142 -0
  180. nvmath/internal/formatters.py +87 -0
  181. nvmath/internal/mem_limit.py +51 -0
  182. nvmath/internal/memory.cp314-win_amd64.pyd +0 -0
  183. nvmath/internal/memory.pxd +10 -0
  184. nvmath/internal/memory.pyi +46 -0
  185. nvmath/internal/ndbuffer/__init__.pxd +3 -0
  186. nvmath/internal/ndbuffer/__init__.py +7 -0
  187. nvmath/internal/ndbuffer/copy_kernel/args.h +34 -0
  188. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/array_view.h +52 -0
  189. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/elementwise.h +68 -0
  190. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/grid_indexer.h +69 -0
  191. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/transposed.h +240 -0
  192. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/type_utils.h +39 -0
  193. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/utils.h +132 -0
  194. nvmath/internal/ndbuffer/copy_kernel/copy_kernel_impl/vec.h +159 -0
  195. nvmath/internal/ndbuffer/copy_kernel/elementwise.h +53 -0
  196. nvmath/internal/ndbuffer/copy_kernel/transposed.h +58 -0
  197. nvmath/internal/ndbuffer/copy_kernel.cp314-win_amd64.pyd +0 -0
  198. nvmath/internal/ndbuffer/copy_kernel.pxd +9 -0
  199. nvmath/internal/ndbuffer/copy_kernel.pyi +9 -0
  200. nvmath/internal/ndbuffer/data_layout.cp314-win_amd64.pyd +0 -0
  201. nvmath/internal/ndbuffer/data_layout.pxd +72 -0
  202. nvmath/internal/ndbuffer/data_layout.pyi +23 -0
  203. nvmath/internal/ndbuffer/jit.cp314-win_amd64.pyd +0 -0
  204. nvmath/internal/ndbuffer/jit.pxd +7 -0
  205. nvmath/internal/ndbuffer/jit.pyi +6 -0
  206. nvmath/internal/ndbuffer/ndbuffer.cp314-win_amd64.pyd +0 -0
  207. nvmath/internal/ndbuffer/ndbuffer.pxd +36 -0
  208. nvmath/internal/ndbuffer/ndbuffer.pyi +41 -0
  209. nvmath/internal/ndbuffer/package_utils.cp314-win_amd64.pyd +0 -0
  210. nvmath/internal/ndbuffer/package_utils.pxd +11 -0
  211. nvmath/internal/ndbuffer/package_utils.pyi +12 -0
  212. nvmath/internal/package_ifc.py +147 -0
  213. nvmath/internal/package_ifc_cuda.py +49 -0
  214. nvmath/internal/package_ifc_cupy.py +49 -0
  215. nvmath/internal/package_ifc_torch.py +31 -0
  216. nvmath/internal/package_wrapper.py +14 -0
  217. nvmath/internal/tensor_ifc.py +194 -0
  218. nvmath/internal/tensor_ifc_cupy.py +241 -0
  219. nvmath/internal/tensor_ifc_ndbuffer.py +153 -0
  220. nvmath/internal/tensor_ifc_numpy.py +183 -0
  221. nvmath/internal/tensor_ifc_torch.py +176 -0
  222. nvmath/internal/tensor_wrapper.py +157 -0
  223. nvmath/internal/typemaps.py +162 -0
  224. nvmath/internal/utils.py +771 -0
  225. nvmath/linalg/__init__.py +46 -0
  226. nvmath/linalg/_internal/__init__.py +3 -0
  227. nvmath/linalg/_internal/algo_cap_ifc.py +82 -0
  228. nvmath/linalg/_internal/algo_config_ifc.py +43 -0
  229. nvmath/linalg/_internal/batch.py +217 -0
  230. nvmath/linalg/_internal/enum_to_tuples.py +64 -0
  231. nvmath/linalg/_internal/epilog_protocol.py +766 -0
  232. nvmath/linalg/_internal/layout.py +624 -0
  233. nvmath/linalg/_internal/matmul_desc_ifc.py +28 -0
  234. nvmath/linalg/_internal/matmul_pref_ifc.py +27 -0
  235. nvmath/linalg/_internal/matrix_layout_ifc.py +26 -0
  236. nvmath/linalg/_internal/typemaps.py +144 -0
  237. nvmath/linalg/_internal/utils.py +134 -0
  238. nvmath/linalg/advanced/__init__.py +8 -0
  239. nvmath/linalg/advanced/_algorithmmod.py +149 -0
  240. nvmath/linalg/advanced/_configuration.py +349 -0
  241. nvmath/linalg/advanced/helpers/__init__.py +5 -0
  242. nvmath/linalg/advanced/helpers/matmul.py +1348 -0
  243. nvmath/linalg/advanced/matmulmod.py +3937 -0
  244. nvmath/linalg/generic/__init__.py +43 -0
  245. nvmath/linalg/generic/_configuration/__init__.py +37 -0
  246. nvmath/linalg/generic/_configuration/layout.py +263 -0
  247. nvmath/linalg/generic/_configuration/match.py +609 -0
  248. nvmath/linalg/generic/_configuration/qualifiers.py +494 -0
  249. nvmath/linalg/generic/_configuration/wrap.py +217 -0
  250. nvmath/linalg/generic/_dtype.py +15 -0
  251. nvmath/linalg/generic/matmulmod.py +1060 -0
  252. nvmath/memory.py +282 -0
  253. nvmath/sparse/__init__.py +38 -0
  254. nvmath/sparse/_internal/__init__.py +21 -0
  255. nvmath/sparse/_internal/common_utils.py +144 -0
  256. nvmath/sparse/_internal/cudss_config_ifc.py +741 -0
  257. nvmath/sparse/_internal/cudss_data_ifc.py +399 -0
  258. nvmath/sparse/_internal/cudss_utils.py +445 -0
  259. nvmath/sparse/_internal/cusparse_utils.py +382 -0
  260. nvmath/sparse/_internal/sparse_bsc_ifc.py +300 -0
  261. nvmath/sparse/_internal/sparse_bsr_ifc.py +303 -0
  262. nvmath/sparse/_internal/sparse_coo_ifc.py +254 -0
  263. nvmath/sparse/_internal/sparse_csc_ifc.py +266 -0
  264. nvmath/sparse/_internal/sparse_csr_ifc.py +266 -0
  265. nvmath/sparse/_internal/sparse_dia_ifc.py +239 -0
  266. nvmath/sparse/_internal/sparse_format_helpers.py +601 -0
  267. nvmath/sparse/_internal/sparse_tensor_ifc.py +121 -0
  268. nvmath/sparse/_internal/sparse_ust_ifc.py +146 -0
  269. nvmath/sparse/_internal/utils.py +56 -0
  270. nvmath/sparse/advanced/__init__.py +7 -0
  271. nvmath/sparse/advanced/_configuration.py +230 -0
  272. nvmath/sparse/advanced/direct_solver.py +1884 -0
  273. nvmath/sparse/generic/__init__.py +7 -0
  274. nvmath/sparse/generic/_configuration.py +129 -0
  275. nvmath/sparse/generic/_helpers.py +137 -0
  276. nvmath/sparse/generic/_thunks.py +21 -0
  277. nvmath/sparse/generic/matmulmod.py +2426 -0
  278. nvmath/sparse/ust/__init__.py +7 -0
  279. nvmath/sparse/ust/_converters.py +378 -0
  280. nvmath/sparse/ust/_drawer.py +552 -0
  281. nvmath/sparse/ust/_emitter.py +553 -0
  282. nvmath/sparse/ust/_jit.py +212 -0
  283. nvmath/sparse/ust/_kernel.py +346 -0
  284. nvmath/sparse/ust/_semiring.py +71 -0
  285. nvmath/sparse/ust/_utils.py +102 -0
  286. nvmath/sparse/ust/interfaces/__init__.py +0 -0
  287. nvmath/sparse/ust/interfaces/torch_interface.py +476 -0
  288. nvmath/sparse/ust/semiring_ops.py +71 -0
  289. nvmath/sparse/ust/tensor.py +1027 -0
  290. nvmath/sparse/ust/tensor_drawer.py +552 -0
  291. nvmath/sparse/ust/tensor_emitter.py +558 -0
  292. nvmath/sparse/ust/tensor_format.py +935 -0
  293. nvmath/sparse/ust/tensor_jit.py +212 -0
  294. nvmath/sparse/ust/tensor_kernel.py +348 -0
  295. nvmath/sparse/ust/tensor_utils.py +380 -0
  296. nvmath/tensor/__init__.py +6 -0
  297. nvmath/tensor/_configuration.py +95 -0
  298. nvmath/tensor/_internal/__init__.py +3 -0
  299. nvmath/tensor/_internal/cutensor_config_ifc.py +247 -0
  300. nvmath/tensor/_internal/cutensor_utils.py +162 -0
  301. nvmath/tensor/_internal/data.py +43 -0
  302. nvmath/tensor/_internal/einsum_parser.py +444 -0
  303. nvmath/tensor/_internal/typemaps.py +96 -0
  304. nvmath/tensor/contract.py +1861 -0
  305. nvmath_python-0.9.0.dist-info/METADATA +127 -0
  306. nvmath_python-0.9.0.dist-info/RECORD +309 -0
  307. nvmath_python-0.9.0.dist-info/WHEEL +5 -0
  308. nvmath_python-0.9.0.dist-info/licenses/LICENSE +177 -0
  309. 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
@@ -0,0 +1,9 @@
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
+ get_include_path: _cython_3_2_4.cython_function_or_method
@@ -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)"""
@@ -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
@@ -0,0 +1,6 @@
1
+ # Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ __pyx_capi__: dict
6
+ __test__: dict
@@ -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)"""
@@ -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}