1+ # This file was generated by stubgen-pyx v0.2.6 from cuda_core/cuda/core/_array.pyx
2+
3+ from __future__ import annotations
4+
5+ from enum import IntEnum
6+
7+ from cuda .bindings import cydriver
8+
9+
10+ class ArrayFormat (IntEnum ):
11+ """Element format for a :class:`CUDAArray` allocation.
12+
13+ Mirrors ``CUarray_format`` from the CUDA driver API.
14+ """
15+ UINT8 = cydriver .CU_AD_FORMAT_UNSIGNED_INT8
16+ UINT16 = cydriver .CU_AD_FORMAT_UNSIGNED_INT16
17+ UINT32 = cydriver .CU_AD_FORMAT_UNSIGNED_INT32
18+ INT8 = cydriver .CU_AD_FORMAT_SIGNED_INT8
19+ INT16 = cydriver .CU_AD_FORMAT_SIGNED_INT16
20+ INT32 = cydriver .CU_AD_FORMAT_SIGNED_INT32
21+ FLOAT16 = cydriver .CU_AD_FORMAT_HALF
22+ FLOAT32 = cydriver .CU_AD_FORMAT_FLOAT
23+
24+ class CUDAArray :
25+ """An opaque, hardware-laid-out GPU allocation for texture/surface access.
26+
27+ Distinct from :class:`Buffer`: a ``CUarray`` has no exposed device pointer
28+ and can only be accessed from kernels through a :class:`TextureObject` or
29+ :class:`SurfaceObject`. Its memory layout is chosen by the driver for 2D/3D
30+ spatial locality.
31+
32+ Construct via :meth:`from_descriptor`. Only plain 1D/2D/3D allocations are
33+ supported in this initial version; layered/cubemap/sparse variants will
34+ follow once their shape semantics are settled.
35+ """
36+
37+ def close (self ):
38+ """Destroy the underlying ``CUarray`` if owned by this object."""
39+
40+ def __init__ (self , * args , ** kwargs ):
41+ ...
42+
43+ @classmethod
44+ def from_descriptor (cls , * , shape , format , num_channels , surface_load_store = False ):
45+ """Allocate a new CUDA array.
46+
47+ Parameters
48+ ----------
49+ shape : tuple of int
50+ ``(width,)``, ``(width, height)``, or ``(width, height, depth)``
51+ in elements.
52+ format : ArrayFormat
53+ Element format.
54+ num_channels : int
55+ Channels per element. Must be 1, 2, or 4.
56+ surface_load_store : bool
57+ If True, allocate with ``CUDA_ARRAY3D_SURFACE_LDST`` so the array
58+ can be bound as a :class:`SurfaceObject` for kernel-side writes.
59+ Default False.
60+
61+ Returns
62+ -------
63+ CUDAArray
64+ """
65+
66+ @classmethod
67+ def _from_handle (cls , handle : int , owning : bool , * , device_id = None ):
68+ """Wrap an externally-allocated ``CUarray``.
69+
70+ Intended for graphics interop (``cuGraphicsSubResourceGetMappedArray``)
71+ where the array is owned by the graphics API. With ``owning=False``,
72+ :meth:`close` and ``__dealloc__`` will not free the handle. Shape,
73+ format, and channel count are queried from the driver.
74+ """
75+
76+ @property
77+ def handle (self ):
78+ """The underlying ``CUarray`` as an integer."""
79+
80+ @property
81+ def shape (self ):
82+ """Allocation shape, in elements."""
83+
84+ @property
85+ def format (self ):
86+ """The element :class:`ArrayFormat`."""
87+
88+ @property
89+ def num_channels (self ):
90+ """Channels per element (1, 2, or 4)."""
91+
92+ @property
93+ def element_size (self ):
94+ """Bytes per element (format size * channels)."""
95+
96+ @property
97+ def device (self ):
98+ """The :class:`Device` this array was allocated on."""
99+
100+ @property
101+ def is_surface_load_store (self ):
102+ """True if this array was created with ``CUDA_ARRAY3D_SURFACE_LDST``
103+ and can be bound as a :class:`SurfaceObject`."""
104+
105+ def _extent_bytes (self ):
106+ """Return (width_bytes, height, depth) for cuMemcpy3D, with height/depth
107+ normalized to >=1 for lower-rank arrays."""
108+
109+ def copy_from (self , src , * , stream ):
110+ """Copy a full-array's worth of data into this array.
111+
112+ Parameters
113+ ----------
114+ src : Buffer or buffer-protocol object
115+ Source data. Must contain at least ``self.size_bytes`` bytes
116+ of contiguous data.
117+ stream : Stream
118+ Stream to issue the copy on.
119+ """
120+
121+ def copy_to (self , dst , * , stream ):
122+ """Copy a full-array's worth of data out of this array.
123+
124+ Parameters
125+ ----------
126+ dst : Buffer or writable buffer-protocol object
127+ Destination. Must have at least ``self.size_bytes`` bytes of
128+ writable, contiguous space.
129+ stream : Stream
130+ Stream to issue the copy on.
131+ """
132+
133+ @property
134+ def size_bytes (self ):
135+ """Total bytes of array storage (``prod(shape) * element_size``)."""
136+
137+ def __dealloc__ (self ):
138+ ...
139+
140+ def __enter__ (self ):
141+ ...
142+
143+ def __exit__ (self , exc_type , exc , tb ):
144+ ...
145+
146+ def __repr__ (self ):
147+ ...
148+ _FORMAT_ELEM_SIZE = {int (ArrayFormat .UINT8 ): 1 , int (ArrayFormat .INT8 ): 1 , int (ArrayFormat .UINT16 ): 2 , int (ArrayFormat .INT16 ): 2 , int (ArrayFormat .FLOAT16 ): 2 , int (ArrayFormat .UINT32 ): 4 , int (ArrayFormat .INT32 ): 4 , int (ArrayFormat .FLOAT32 ): 4 }
0 commit comments