qbruntime.pinned_memory.PinnedMemory Class Reference

qbruntime.pinned_memory.PinnedMemory Class Reference#

SDK qb Runtime Library: qbruntime.pinned_memory.PinnedMemory Class Reference
SDK qb Runtime Library v1.3
MCS001-EN
qbruntime.pinned_memory.PinnedMemory Class Reference

An NPU-accessible pinned (physically contiguous) memory buffer. More...

Public Member Functions

 __init__ (self, Union[_cQbRuntime.PinnedMemoryFloat, _cQbRuntime.PinnedMemoryUint8] _pinned_memory)
 Internal constructor.
 __getitem__ (self, key)
 Reads element(s) from the pinned buffer via indexing.
 __setitem__ (self, key, value)
 Writes value(s) into the pinned buffer via indexing.
int __len__ (self)
 Returns the length of the buffer's first dimension.
_Shape shape (self)
 Returns the shape of the buffer.
np.dtype dtype (self)
 Returns the numpy dtype of the buffer's elements.
int size (self)
 Returns the size of the buffer in bytes.
bool is_available (self)
 Returns whether the buffer is allocated and still usable.

Protected Attributes

 _pinned_memory = _pinned_memory
 _array = np.asarray(_pinned_memory)

Detailed Description

An NPU-accessible pinned (physically contiguous) memory buffer.

A PinnedMemory wraps a buffer that is pinned in device memory so the NPU can read from / write to it directly, enabling zero-copy inference via Model.infer_pinned_memory. Instances are created through Accelerator.allocate_pinned_memory, not constructed directly.

Note
This is an experimental API and is only supported on Regulus hardware.

Definition at line 20 of file pinned_memory.py.

Constructor & Destructor Documentation

◆ __init__()

qbruntime.pinned_memory.PinnedMemory.__init__ ( self,
Union[ _cQbRuntime.PinnedMemoryFloat, _cQbRuntime.PinnedMemoryUint8 ] _pinned_memory )

Internal constructor.

Parameters
_pinned_memoryThe underlying C++ pinned-memory object. Use Accelerator.allocate_pinned_memory to create instances.

Definition at line 31 of file pinned_memory.py.

Member Function Documentation

◆ __getitem__()

qbruntime.pinned_memory.PinnedMemory.__getitem__ ( self,
key )

Reads element(s) from the pinned buffer via indexing.

Supports the same indexing as numpy (integers, slices, tuples, etc.), e.g. pm[0], pm[1, 2], pm[:10]. The data is read directly from the pinned buffer without an intermediate copy.

Parameters
keyThe index or slice.
Returns
The selected element or a view into the pinned buffer.

Definition at line 48 of file pinned_memory.py.

◆ __setitem__()

qbruntime.pinned_memory.PinnedMemory.__setitem__ ( self,
key,
value )

Writes value(s) into the pinned buffer via indexing.

Writes directly into the pinned buffer, e.g. pm[0] = 1.0, pm[:10] = src. This is the recommended way to fill an input buffer before Model.infer_pinned_memory.

Parameters
keyThe index or slice.
valueThe value(s) to write.

Definition at line 60 of file pinned_memory.py.

◆ __len__()

int qbruntime.pinned_memory.PinnedMemory.__len__ ( self)

Returns the length of the buffer's first dimension.

Definition at line 72 of file pinned_memory.py.

◆ shape()

_Shape qbruntime.pinned_memory.PinnedMemory.shape ( self)

Returns the shape of the buffer.

Definition at line 77 of file pinned_memory.py.

◆ dtype()

np.dtype qbruntime.pinned_memory.PinnedMemory.dtype ( self)

Returns the numpy dtype of the buffer's elements.

Definition at line 82 of file pinned_memory.py.

◆ size()

int qbruntime.pinned_memory.PinnedMemory.size ( self)

Returns the size of the buffer in bytes.

Definition at line 87 of file pinned_memory.py.

◆ is_available()

bool qbruntime.pinned_memory.PinnedMemory.is_available ( self)

Returns whether the buffer is allocated and still usable.

Definition at line 92 of file pinned_memory.py.

Member Data Documentation

◆ _pinned_memory

qbruntime.pinned_memory.PinnedMemory._pinned_memory = _pinned_memory
protected

Definition at line 42 of file pinned_memory.py.

◆ _array

qbruntime.pinned_memory.PinnedMemory._array = np.asarray(_pinned_memory)
protected

Definition at line 46 of file pinned_memory.py.


The documentation for this class was generated from the following file: