accelerator.py Source File

accelerator.py Source File#

SDK qb Runtime Library: accelerator.py Source File
SDK qb Runtime Library v1.3
MCS001-EN
accelerator.py
Go to the documentation of this file.
1
4
5from typing import Sequence
6
7import numpy as np
8
9import qbruntime.qbruntime as _cQbRuntime
10from .pinned_memory import PinnedMemory
11
12
15
16
18 """@brief Represents an accelerator, i.e., an NPU, used for executing models."""
19
20 def __init__(self, dev_no: int = 0):
21 """
22 @brief Creates an Accelerator object for a specific device number.
23
24 The `dev_no` parameter represents the device number. For example, on Linux,
25 if an ARIES NPU is attached as `/dev/aries0`, the device number is `0`.
26
27 @param dev_no The device number to associate with the Accelerator.
28 """
29 self._accelerator = _cQbRuntime.Accelerator(dev_no)
30
32 self, shape: Sequence[int], dtype: np.dtype
33 ) -> PinnedMemory:
34 """
35 @brief Allocates an NPU-accessible pinned memory buffer.
36
37 The returned buffer can be used as input or output for zero-copy inference
38 via `Model.infer_pinned_memory`.
39
40 @note This is an experimental API and is only supported on Regulus hardware.
41
42 @param shape The shape of the buffer to allocate.
43 @param dtype The element type of the buffer. Must be `numpy.float32` or
44 `numpy.uint8`.
45 @return A PinnedMemory wrapping the allocated buffer.
46 """
48 [int(s) for s in shape], np.dtype(dtype)
49 )
50 return PinnedMemory(cobj)
51
52
53
Represents an accelerator, i.e., an NPU, used for executing models.
PinnedMemory allocate_pinned_memory(self, Sequence[int] shape, np.dtype dtype)
Allocates an NPU-accessible pinned memory buffer.
__init__(self, int dev_no=0)
Creates an Accelerator object for a specific device number.
An NPU-accessible pinned (physically contiguous) memory buffer.