5from typing
import Sequence, overload
9import qbruntime.qbruntime
as _cQbRuntime
10from .pinned_memory
import PinnedMemory
19 @brief Represents an accelerator, i.e., an NPU, used for executing models.
21 @attention For the `regulus-usb` device family, do not unplug the USB device while
22 the runtime is running. Disconnecting a device that is in use may crash
23 the program or cause unexpected misbehavior.
27 def __init__(self, dev_no: int = 0): ...
30 def __init__(self, device_name: str =
"auto"): ...
33 def __init__(self, device_name: str =
"auto", dev_no: int = 0): ...
35 def __init__(self, device_name="auto", dev_no=0):
37 @brief Creates an Accelerator object for a specific target device and device number.
39 The @p device_name parameter selects target device to open; case-insensitive.
42 - `"aries"`, `"aries-rb"`
43 - `"regulus"`, `"regulus-usb"`
44 - `"regulus-ra"`, `"regulus-ra-usb"`
45 - `"regulus-rb"`, `"regulus-rb-usb"`
48 - `"auto"` resolves the target device automatically, but only when exactly one
49 supported kind of target device is present in the system.
50 - A base name (`"aries"`, `"regulus"`, `"regulus-usb"`, ...) is a shorthand
51 for every target device whose name begins with it (e.g. `"aries"` matches
52 `"aries-rb"`). It resolves to the concrete target device automatically, but
53 only when exactly one such matching target device is present.
55 The @p dev_no parameter is the device number. For example, on Linux an ARIES NPU
56 attached as `/dev/aries0` has device number `0`.
58 @param[in] device_name Device name to open (case-insensitive). See the list above.
59 @param[in] dev_no The device number to associate with the Accelerator.
61 @throws QbRuntimeError If @p device_name is unknown, if auto-resolution is ambiguous
62 (more than one candidate), or if no matching device exists.
64 @note Supported constructor forms:
65 - `Accelerator()`: auto-select the only attached NPU.
66 - `Accelerator(dev_no)`: auto-detect device, open target device `dev_no`.
67 - `Accelerator(device_name)`: open `device_name` at device 0.
68 - `Accelerator(device_name, dev_no)`: open `device_name` at device `dev_no`.
70 if isinstance(device_name, int):
71 dev_no, device_name = device_name,
"auto"
72 self.
_accelerator = _cQbRuntime.Accelerator(device_name, dev_no)
76 @brief Returns the resolved device name of this accelerator.
78 When created with a automatic resolve such as `"auto"`, `"aries"`,
79 this returns the real target device name that was resolved
80 (e.g. `"aries-rb"`, `"regulus-ra-usb"`).
82 @return The resolved device name.
87 self, shape: Sequence[int], dtype: np.dtype
90 @brief Allocates an NPU-accessible pinned memory buffer.
92 The returned buffer can be used as input or output for zero-copy inference
93 via `Model.infer_pinned_memory`.
95 @note This is an experimental API and is only supported on REGULUS device.
97 @param shape The shape of the buffer to allocate.
98 @param dtype The element type of the buffer. Must be `numpy.float32` or
100 @return A PinnedMemory wrapping the allocated buffer.
103 [int(s)
for s
in shape], np.dtype(dtype)
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.
str get_device_name(self)
Returns the resolved device name of this accelerator.
An NPU-accessible pinned (physically contiguous) memory buffer.