5from typing
import Tuple, Union
9import qbruntime.qbruntime
as _cQbRuntime
11_Shape = Tuple[int, ...]
13__all__ = [
"PinnedMemory"]
21 """@brief An NPU-accessible pinned (physically contiguous) memory buffer.
23 A PinnedMemory wraps a buffer that is pinned in device memory so the NPU can
24 read from / write to it directly, enabling zero-copy inference via
25 `Model.infer_pinned_memory`. Instances are created through
26 `Accelerator.allocate_pinned_memory`, not constructed directly.
28 @note This is an experimental API and is only supported on Regulus hardware.
33 _pinned_memory: Union[
34 _cQbRuntime.PinnedMemoryFloat, _cQbRuntime.PinnedMemoryUint8
37 """@brief Internal constructor.
39 @param _pinned_memory The underlying C++ pinned-memory object. Use
40 `Accelerator.allocate_pinned_memory` to create instances.
46 self.
_array = np.asarray(_pinned_memory)
49 """@brief Reads element(s) from the pinned buffer via indexing.
51 Supports the same indexing as numpy (integers, slices, tuples, etc.),
52 e.g. `pm[0]`, `pm[1, 2]`, `pm[:10]`. The data is read directly from the
53 pinned buffer without an intermediate copy.
55 @param key The index or slice.
56 @return The selected element or a view into the pinned buffer.
61 """@brief Writes value(s) into the pinned buffer via indexing.
63 Writes directly into the pinned buffer, e.g. `pm[0] = 1.0`,
64 `pm[:10] = src`. This is the recommended way to fill an input buffer
65 before `Model.infer_pinned_memory`.
67 @param key The index or slice.
68 @param value The value(s) to write.
73 """@brief Returns the length of the buffer's first dimension."""
78 """@brief Returns the shape of the buffer."""
83 """@brief Returns the numpy dtype of the buffer's elements."""
88 """@brief Returns the size of the buffer in bytes."""
93 """@brief Returns whether the buffer is allocated and still usable."""
An NPU-accessible pinned (physically contiguous) memory buffer.
np.dtype dtype(self)
Returns the numpy dtype of the buffer's elements.
int __len__(self)
Returns the length of the buffer's first dimension.
int size(self)
Returns the size of the buffer in bytes.
__setitem__(self, key, value)
Writes value(s) into the pinned buffer via indexing.
bool is_available(self)
Returns whether the buffer is allocated and still usable.
__getitem__(self, key)
Reads element(s) from the pinned buffer via indexing.
_Shape shape(self)
Returns the shape of the buffer.
__init__(self, Union[_cQbRuntime.PinnedMemoryFloat, _cQbRuntime.PinnedMemoryUint8] _pinned_memory)
Internal constructor.