9from pathlib
import Path
10from typing
import List, Set
17MBLTML_DRIVER_VERSION_BUFFER_SIZE = 80
19MBLTML_ON_DEVICE_DRIVER_VERSION_BUFFER_SIZE = 80
21MBLTML_FIRMWARE_VERSION_BUFFER_SIZE = 80
23MBLTML_NODE_NAME_BUFFER_SIZE = 80
29mbltmlDeviceType_t = c_uint
30MBLTML_DEVICE_ERROR = 0x0
31MBLTML_DEVICE_ARIES = 0x1
32MBLTML_DEVICE_REGULUS = 0x2
33MBLTML_DEVICE_REGULUS_USB = 0x4
36mbltmlHardwareVersion_t = c_uint
37MBLTML_HARDWARE_VERSION_ARIES_RA = 0x00000001
38MBLTML_HARDWARE_VERSION_REGULUS_RA = 0x00000002
39MBLTML_HARDWARE_VERSION_ARIES_RB = 0x00000003
40MBLTML_HARDWARE_VERSION_REGULUS_RB = 0x00000004
41MBLTML_HARDWARE_VERSION_ERROR = 0x7FFFFFFF
46mbltmlStatusCode_t = c_uint
48MBLTML_DRIVER_NOT_FOUND = 2
49MBLTML_INVALID_ARGUMENT = 3
50MBLTML_UNINITIALIZED = 1
51MBLTML_NOT_SUPPORTED = 4
52MBLTML_INSUFFICIENT_LENGTH = 5
58mbltmlExtraPmicId_t = c_uint
59MBLTML_EXTRA_PMIC_ID_NPU = 0
60MBLTML_EXTRA_PMIC_ID_DDR = 1
61MBLTML_EXTRA_PMIC_ID_PMIC = 2
62MBLTML_EXTRA_PMIC_ID_GOLDFINGER = 3
65mbltmlCluster_t = c_uint
66MBLTML_CLUSTER_0 = 0x00010000
67MBLTML_CLUSTER_1 = 0x00020000
68MBLTML_CLUSTER_ERROR = 0x7FFF0000
76MBLTML_CORE_GLOBAL = 0x0000FFFE
77MBLTML_CORE_ERROR = 0x0000FFFF
82 """@brief Composite identifier of an NPU core (cluster + core).
84 @var cluster Cluster to which the core belongs (mbltmlCluster_t).
85 @var core Core within the cluster (mbltmlCore_t).
88 cluster: mbltmlCluster_t
91 (
"cluster", mbltmlCluster_t),
92 (
"core", mbltmlCore_t),
96 d = {
"cluster": self.cluster,
"core": self.core}
97 return "{}({})".format(
98 self.__class__.__name__,
99 ", ".join(
"{}={}".format(k, v)
for k, v
in d.items()),
104 """@brief Per-core usage record returned by mbltmlGetCoreInfos().
106 Utilization for the core can be computed as @c npu_time / @c interval
107 when @c interval is non-zero.
109 @var core_id Identifier of the core (mbltmlCoreId_t).
110 @var npu_time Accumulated NPU active time on the core, in microseconds.
111 @var interval Sampling interval covered by @c npu_time, in microseconds.
114 core_id: mbltmlCoreId_t
118 (
"core_id", mbltmlCoreId_t),
119 (
"npu_time", c_int64),
120 (
"interval", c_int64),
125 "core_id": self.core_id,
126 "npu_time": self.npu_time,
127 "interval": self.interval,
129 return "{}({})".format(
130 self.__class__.__name__,
131 ", ".join(
"{}={}".format(k, v)
for k, v
in d.items()),
136 """@brief Per-process usage record returned by mbltmlGetProcessInfos().
138 Utilization for the process can be computed as
139 @c total_npu_time_us / @c total_interval_us when @c total_interval_us
143 @var counts Number of NPU samples attributed to the process.
144 @var npu_memory_usage Device memory currently used by the process, in bytes.
145 @var total_interval_us Total sampling interval, in microseconds.
146 @var total_npu_time_us Total NPU active time used by the process, in microseconds.
151 npu_memory_usage: c_int64
152 total_interval_us: c_int64
153 total_npu_time_us: c_int64
157 (
"npu_memory_usage", c_int64),
158 (
"total_interval_us", c_int64),
159 (
"total_npu_time_us", c_int64),
165 "counts": self.counts,
166 "npu_memory_usage": self.npu_memory_usage,
167 "total_interval_us": self.total_interval_us,
168 "total_npu_time_us": self.total_npu_time_us,
170 return "{}({})".format(
171 self.__class__.__name__,
172 ", ".join(
"{}={}".format(k, v)
for k, v
in d.items()),
179def _loadLibrary() -> None:
183 lib_fname =
"mbltml.dll" if platform.system() ==
"Windows" else f
"libmbltml.so*"
184 pattern = os.path.join(Path(__file__).resolve().parent, lib_fname)
185 candidates = glob.glob(pattern)
187 raise FileNotFoundError(f
"No library matching {pattern}")
188 candidates.sort(key=len, reverse=
True)
189 _clib = CDLL(str(candidates[0]))
191 _clib.mbltmlInit.argtypes = []
192 _clib.mbltmlInit.restype = mbltmlStatusCode_t
193 _clib.mbltmlInitDevices.argtypes = [mbltmlDeviceType_t]
194 _clib.mbltmlInitDevices.restype = mbltmlStatusCode_t
195 _clib.mbltmlShutdown.argtypes = []
196 _clib.mbltmlShutdown.restype = mbltmlStatusCode_t
197 _clib.mbltmlGetDeviceCount.argtypes = [POINTER(c_uint)]
198 _clib.mbltmlGetDeviceCount.restype = mbltmlStatusCode_t
199 _clib.mbltmlGetDriverVersion.argtypes = [mbltmlDeviceType_t, POINTER(c_char), c_int]
200 _clib.mbltmlGetDriverVersion.restype = mbltmlStatusCode_t
201 _clib.mbltmlGetDriverRevision.argtypes = [mbltmlDeviceType_t, POINTER(c_uint)]
202 _clib.mbltmlGetDriverRevision.restype = mbltmlStatusCode_t
203 _clib.mbltmlGetNodeName.argtypes = [c_int, POINTER(c_char), c_int]
204 _clib.mbltmlGetNodeName.restype = mbltmlStatusCode_t
205 _clib.mbltmlGetDeviceType.argtypes = [c_int, POINTER(mbltmlDeviceType_t)]
206 _clib.mbltmlGetDeviceType.restype = mbltmlStatusCode_t
207 _clib.mbltmlGetHardwareVersion.argtypes = [c_int, POINTER(mbltmlHardwareVersion_t)]
208 _clib.mbltmlGetHardwareVersion.restype = mbltmlStatusCode_t
209 _clib.mbltmlGetOnDeviceDriverVersion.argtypes = [c_int, POINTER(c_char), c_uint]
210 _clib.mbltmlGetOnDeviceDriverVersion.restype = mbltmlStatusCode_t
211 _clib.mbltmlGetOnDeviceDriverRevision.argtypes = [c_int, POINTER(c_uint)]
212 _clib.mbltmlGetOnDeviceDriverRevision.restype = mbltmlStatusCode_t
213 _clib.mbltmlGetFirmwareVersion.argtypes = [c_int, POINTER(c_char), c_uint]
214 _clib.mbltmlGetFirmwareVersion.restype = mbltmlStatusCode_t
215 _clib.mbltmlGetFirmwareRevision.argtypes = [c_int, POINTER(c_uint)]
216 _clib.mbltmlGetFirmwareRevision.restype = mbltmlStatusCode_t
217 _clib.mbltmlGetFirmwareCRC.argtypes = [c_int, POINTER(c_uint)]
218 _clib.mbltmlGetFirmwareCRC.restype = mbltmlStatusCode_t
219 _clib.mbltmlGetTemperature.argtypes = [c_int, POINTER(c_int)]
220 _clib.mbltmlGetTemperature.restype = mbltmlStatusCode_t
221 _clib.mbltmlGetSignalType.argtypes = [c_int, POINTER(c_uint)]
222 _clib.mbltmlGetSignalType.restype = mbltmlStatusCode_t
223 _clib.mbltmlGetNPUClock.argtypes = [c_int, POINTER(c_uint)]
224 _clib.mbltmlGetNPUClock.restype = mbltmlStatusCode_t
225 _clib.mbltmlGetBusClock.argtypes = [c_int, POINTER(c_uint)]
226 _clib.mbltmlGetBusClock.restype = mbltmlStatusCode_t
227 _clib.mbltmlGetFanDuty.argtypes = [c_int, POINTER(c_int)]
228 _clib.mbltmlGetFanDuty.restype = mbltmlStatusCode_t
229 _clib.mbltmlGetVendorId.argtypes = [c_int, POINTER(c_uint)]
230 _clib.mbltmlGetVendorId.restype = mbltmlStatusCode_t
231 _clib.mbltmlGetDeviceId.argtypes = [c_int, POINTER(c_uint)]
232 _clib.mbltmlGetDeviceId.restype = mbltmlStatusCode_t
233 _clib.mbltmlGetSubVendorId.argtypes = [c_int, POINTER(c_uint)]
234 _clib.mbltmlGetSubVendorId.restype = mbltmlStatusCode_t
235 _clib.mbltmlGetSubDeviceId.argtypes = [c_int, POINTER(c_uint)]
236 _clib.mbltmlGetSubDeviceId.restype = mbltmlStatusCode_t
237 _clib.mbltmlGetPcieGen.argtypes = [c_int, POINTER(c_uint)]
238 _clib.mbltmlGetPcieGen.restype = mbltmlStatusCode_t
239 _clib.mbltmlGetPcieLanes.argtypes = [c_int, POINTER(c_uint)]
240 _clib.mbltmlGetPcieLanes.restype = mbltmlStatusCode_t
241 _clib.mbltmlGetPcieRev.argtypes = [c_int, POINTER(c_uint)]
242 _clib.mbltmlGetPcieRev.restype = mbltmlStatusCode_t
243 _clib.mbltmlGetPcieClassCode.argtypes = [c_int, POINTER(c_uint)]
244 _clib.mbltmlGetPcieClassCode.restype = mbltmlStatusCode_t
245 _clib.mbltmlGetTotalPower.argtypes = [c_int, POINTER(c_double)]
246 _clib.mbltmlGetTotalPower.restype = mbltmlStatusCode_t
247 _clib.mbltmlGetTotalCurrent.argtypes = [c_int, POINTER(c_double)]
248 _clib.mbltmlGetTotalCurrent.restype = mbltmlStatusCode_t
249 _clib.mbltmlGetTotalVoltage.argtypes = [c_int, POINTER(c_double)]
250 _clib.mbltmlGetTotalVoltage.restype = mbltmlStatusCode_t
251 _clib.mbltmlGetExtraPmicPower.argtypes = [c_int, POINTER(c_double)]
252 _clib.mbltmlGetExtraPmicPower.restype = mbltmlStatusCode_t
253 _clib.mbltmlGetExtraPmicCurrent.argtypes = [c_int, POINTER(c_double)]
254 _clib.mbltmlGetExtraPmicCurrent.restype = mbltmlStatusCode_t
255 _clib.mbltmlGetExtraPmicVoltage.argtypes = [c_int, POINTER(c_double)]
256 _clib.mbltmlGetExtraPmicVoltage.restype = mbltmlStatusCode_t
257 _clib.mbltmlGetExtraPmicId.argtypes = [c_int, POINTER(mbltmlExtraPmicId_t)]
258 _clib.mbltmlGetExtraPmicId.restype = mbltmlStatusCode_t
259 _clib.mbltmlGetTotalUtilization.argtypes = [c_int, POINTER(c_double)]
260 _clib.mbltmlGetTotalUtilization.restype = mbltmlStatusCode_t
261 _clib.mbltmlGetMemoryUsage.argtypes = [c_int, POINTER(c_int64)]
262 _clib.mbltmlGetMemoryUsage.restype = mbltmlStatusCode_t
263 _clib.mbltmlGetMemoryTotal.argtypes = [c_int, POINTER(c_int64)]
264 _clib.mbltmlGetMemoryTotal.restype = mbltmlStatusCode_t
265 _clib.mbltmlGetProcessInfos.argtypes = [
267 POINTER(mbltmlProcessInfo_t),
270 _clib.mbltmlGetProcessInfos.restype = mbltmlStatusCode_t
271 _clib.mbltmlGetCoreInfos.argtypes = [
273 POINTER(mbltmlCoreInfo_t),
276 _clib.mbltmlGetCoreInfos.restype = mbltmlStatusCode_t
277 _clib.mbltmlSetExtraPmicID.argtypes = [c_int, mbltmlExtraPmicId_t]
278 _clib.mbltmlSetExtraPmicID.restype = mbltmlStatusCode_t
281class MBLTMLError(Exception):
282 """@brief Base exception raised by the mbltml Python binding.
284 Wraps a non-success mbltmlStatusCode_t returned by the underlying C
285 library. Instantiating MBLTMLError with a known status code yields the
286 matching subclass (e.g., MBLTMLInvalidArgumentError).
288 @var code The mbltmlStatusCode_t value associated with this exception.
292 _errcode_to_string = {
293 MBLTML_DRIVER_NOT_FOUND:
"Driver is not found",
294 MBLTML_INVALID_ARGUMENT:
"Invalid Argument",
295 MBLTML_UNINITIALIZED:
"Uninitilized mbltml.",
296 MBLTML_NOT_SUPPORTED:
"Unspported Function for Target Device",
297 MBLTML_INSUFFICIENT_LENGTH:
"Insufficient Length",
300 def __new__(cls, code: mbltmlStatusCode_t):
301 if cls
is MBLTMLError
and code
in MBLTMLError._code_to_class:
302 cls = MBLTMLError._code_to_class[code]
303 obj = Exception.__new__(cls)
308 return MBLTMLError._errcode_to_string[self.code]
310 def __eq__(self, other):
311 return self.code == other.code
315 """@brief Raised when the required driver cannot be located.
317 Wraps MBLTML_DRIVER_NOT_FOUND.
323class MBLTMLInvalidArgumentError(MBLTMLError):
324 """@brief Raised when one or more arguments are invalid.
326 Wraps MBLTML_INVALID_ARGUMENT. Typical causes include a NULL pointer or
327 a @c dev_no that is out of range of the device count.
334 """@brief Raised when an API is called before initialization.
336 Wraps MBLTML_UNINITIALIZED. Call mbltmlInit() or mbltmlInitDevices() first.
343 """@brief Raised when the feature is not supported on the target device.
345 Wraps MBLTML_NOT_SUPPORTED.
352 """@brief Raised when the output buffer is too small to hold the result.
354 Wraps MBLTML_INSUFFICIENT_LENGTH.
360MBLTMLError._code_to_class = {
361 MBLTML_DRIVER_NOT_FOUND: MBLTMLDriverNotFoundError,
362 MBLTML_INVALID_ARGUMENT: MBLTMLInvalidArgumentError,
363 MBLTML_UNINITIALIZED: MBLTMLUninitializedError,
364 MBLTML_NOT_SUPPORTED: MBLTMLNotSupportedError,
365 MBLTML_INSUFFICIENT_LENGTH: MBLTMLInsufficientLengthError,
369def _mbltmlThrowError(ret: mbltmlStatusCode_t) ->
None:
370 if ret != MBLTML_SUCCESS:
371 raise MBLTMLError(ret)
376 """@brief Initialize the mbltml library for all supported device types.
378 Equivalent to calling mbltmlInitDevices() with every mbltmlDeviceType_t
379 enabled. Must be called (directly or via mbltmlInitDevices()) before any
382 @throws MBLTMLError on failure.
385 ret = _clib.mbltmlInit()
386 _mbltmlThrowError(ret)
390 """@brief Initialize the mbltml library for a selected set of device types.
392 @param device_types Set of mbltmlDeviceType_t values indicating which
393 device families to enumerate and monitor.
394 @throws MBLTMLError on failure.
398 for dt
in device_types:
399 all_device_types = all_device_types | dt
400 ret = _clib.mbltmlInitDevices(all_device_types)
401 _mbltmlThrowError(ret)
405 """@brief Release all resources held by the mbltml library.
407 After this call, any further API usage requires re-initialization via
408 mbltmlInit() or mbltmlInitDevices().
410 @throws MBLTMLError on failure.
413 ret = _clib.mbltmlShutdown()
414 _mbltmlThrowError(ret)
418 """@brief Get the total number of devices detected by the library.
420 @note Supported on all device types.
422 @return The number of devices detected.
423 @throws MBLTMLError on failure.
427 ret = _clib.mbltmlGetDeviceCount(byref(value))
428 _mbltmlThrowError(ret)
433 """@brief Get the driver version string for a specific device family.
435 @note Supported on all device types.
437 @param device_type Device family whose driver version is queried.
438 @return The driver version string.
439 @throws MBLTMLError on failure.
442 buf = create_string_buffer(MBLTML_DRIVER_VERSION_BUFFER_SIZE)
443 ret = _clib.mbltmlGetDriverVersion(
444 device_type, buf, MBLTML_DRIVER_VERSION_BUFFER_SIZE
446 _mbltmlThrowError(ret)
447 return buf.value.decode()
451 """@brief Get the driver revision number for a specific device family.
453 @note Supported on all device types.
455 @param device_type Device family whose driver revision is queried.
456 @return The driver revision number.
457 @throws MBLTMLError on failure.
461 ret = _clib.mbltmlGetDriverRevision(device_type, byref(value))
462 _mbltmlThrowError(ret)
467 """@brief Get the node name of a device.
469 @note Supported on all device types.
471 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
472 @return The node name string.
473 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
474 @throws MBLTMLError on other failures.
477 buf = create_string_buffer(MBLTML_NODE_NAME_BUFFER_SIZE)
478 ret = _clib.mbltmlGetNodeName(dev_no, buf, MBLTML_NODE_NAME_BUFFER_SIZE)
479 _mbltmlThrowError(ret)
480 return buf.value.decode()
484 """@brief Get the device family type of a device.
486 @note Supported on all device types.
488 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
489 @return The mbltmlDeviceType_t of the device.
490 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
491 @throws MBLTMLError on other failures.
495 ret = _clib.mbltmlGetDeviceType(dev_no, byref(value))
496 _mbltmlThrowError(ret)
501 """@brief Get the hardware version of a device.
503 @note Supported on all device types.
505 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
506 @return The mbltmlHardwareVersion_t of the device.
507 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
508 @throws MBLTMLError on other failures.
512 ret = _clib.mbltmlGetHardwareVersion(dev_no, byref(value))
513 _mbltmlThrowError(ret)
518 """@brief Get the on-device driver version string of a device.
520 @note Supported on MBLTML_DEVICE_REGULUS_USB only.
522 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
523 @return The on-device driver version string.
524 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
525 @throws MBLTMLError on other failures.
528 buf = create_string_buffer(MBLTML_ON_DEVICE_DRIVER_VERSION_BUFFER_SIZE)
529 ret = _clib.mbltmlGetOnDeviceDriverVersion(
530 dev_no, buf, MBLTML_ON_DEVICE_DRIVER_VERSION_BUFFER_SIZE
532 _mbltmlThrowError(ret)
533 return buf.value.decode()
537 """@brief Get the on-device driver revision number of a device.
539 @note Supported on MBLTML_DEVICE_REGULUS_USB only.
541 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
542 @return The on-device driver revision.
543 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
544 @throws MBLTMLError on other failures.
548 ret = _clib.mbltmlGetOnDeviceDriverRevision(dev_no, byref(value))
549 _mbltmlThrowError(ret)
554 """@brief Get the firmware version string of a device.
556 @note Supported on MBLTML_DEVICE_ARIES only.
558 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
559 @return The firmware version string.
560 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
561 @throws MBLTMLError on other failures.
564 buf = create_string_buffer(MBLTML_FIRMWARE_VERSION_BUFFER_SIZE)
565 ret = _clib.mbltmlGetFirmwareVersion(
566 dev_no, buf, MBLTML_FIRMWARE_VERSION_BUFFER_SIZE
568 _mbltmlThrowError(ret)
569 return buf.value.decode()
573 """@brief Get the firmware revision number of a device.
575 @note Supported on MBLTML_DEVICE_ARIES only.
577 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
578 @return The firmware revision.
579 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
580 @throws MBLTMLError on other failures.
584 ret = _clib.mbltmlGetFirmwareRevision(dev_no, byref(value))
585 _mbltmlThrowError(ret)
590 """@brief Get the CRC of the currently-loaded firmware image.
592 @note Supported on MBLTML_DEVICE_ARIES only.
594 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
595 @return The firmware CRC.
596 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
597 @throws MBLTMLError on other failures.
601 ret = _clib.mbltmlGetFirmwareCRC(dev_no, byref(value))
602 _mbltmlThrowError(ret)
607 """@brief Get the current die temperature of a device.
609 @note Supported on all device types.
611 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
612 @return The temperature reading.
613 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
614 @throws MBLTMLError on other failures.
618 ret = _clib.mbltmlGetTemperature(dev_no, byref(value))
619 _mbltmlThrowError(ret)
624 """@brief Get the current signal-type indicator reported by the device.
626 @note Supported on all device types.
628 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
629 @return The signal-type value.
630 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
631 @throws MBLTMLError on other failures.
635 ret = _clib.mbltmlGetSignalType(dev_no, byref(value))
636 _mbltmlThrowError(ret)
641 """@brief Get the current NPU clock frequency of a device.
643 @note Supported on all device types.
645 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
646 @return The NPU clock value.
647 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
648 @throws MBLTMLError on other failures.
652 ret = _clib.mbltmlGetNPUClock(dev_no, byref(value))
653 _mbltmlThrowError(ret)
658 """@brief Get the current bus clock frequency of a device.
660 @note Supported on MBLTML_DEVICE_ARIES only.
662 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
663 @return The bus clock value.
664 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
665 @throws MBLTMLError on other failures.
669 ret = _clib.mbltmlGetBusClock(dev_no, byref(value))
670 _mbltmlThrowError(ret)
675 """@brief Get the current cooling-fan duty cycle of a device.
677 @note Supported on MBLTML_DEVICE_ARIES only.
679 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
680 @return The fan duty value.
681 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
682 @throws MBLTMLError on other failures.
686 ret = _clib.mbltmlGetFanDuty(dev_no, byref(value))
687 _mbltmlThrowError(ret)
692 """@brief Get the PCIe vendor ID of a device.
694 @note Supported on MBLTML_DEVICE_ARIES only.
696 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
697 @return The vendor ID.
698 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
699 @throws MBLTMLError on other failures.
703 ret = _clib.mbltmlGetVendorId(dev_no, byref(value))
704 _mbltmlThrowError(ret)
709 """@brief Get the PCIe device ID of a device.
711 @note Supported on MBLTML_DEVICE_ARIES only.
713 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
714 @return The device ID.
715 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
716 @throws MBLTMLError on other failures.
720 ret = _clib.mbltmlGetDeviceId(dev_no, byref(value))
721 _mbltmlThrowError(ret)
726 """@brief Get the PCIe subsystem vendor ID of a device.
728 @note Supported on MBLTML_DEVICE_ARIES only.
730 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
731 @return The subsystem vendor ID.
732 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
733 @throws MBLTMLError on other failures.
737 ret = _clib.mbltmlGetSubVendorId(dev_no, byref(value))
738 _mbltmlThrowError(ret)
743 """@brief Get the PCIe subsystem device ID of a device.
745 @note Supported on MBLTML_DEVICE_ARIES only.
747 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
748 @return The subsystem device ID.
749 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
750 @throws MBLTMLError on other failures.
754 ret = _clib.mbltmlGetSubDeviceId(dev_no, byref(value))
755 _mbltmlThrowError(ret)
760 """@brief Get the negotiated PCIe link generation of a device.
762 @note Supported on MBLTML_DEVICE_ARIES only.
764 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
765 @return The PCIe generation.
766 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
767 @throws MBLTMLError on other failures.
771 ret = _clib.mbltmlGetPcieGen(dev_no, byref(value))
772 _mbltmlThrowError(ret)
777 """@brief Get the negotiated PCIe link width (in lanes) of a device.
779 @note Supported on MBLTML_DEVICE_ARIES only.
781 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
782 @return The lane count.
783 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
784 @throws MBLTMLError on other failures.
788 ret = _clib.mbltmlGetPcieLanes(dev_no, byref(value))
789 _mbltmlThrowError(ret)
794 """@brief Get the PCIe configuration-space revision ID of a device.
796 @note Supported on MBLTML_DEVICE_ARIES only.
798 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
799 @return The revision value.
800 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
801 @throws MBLTMLError on other failures.
805 ret = _clib.mbltmlGetPcieRev(dev_no, byref(value))
806 _mbltmlThrowError(ret)
811 """@brief Get the PCIe configuration-space class code of a device.
813 @note Supported on MBLTML_DEVICE_ARIES only.
815 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
816 @return The class code.
817 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
818 @throws MBLTMLError on other failures.
822 ret = _clib.mbltmlGetPcieClassCode(dev_no, byref(value))
823 _mbltmlThrowError(ret)
828 """@brief Get the total instantaneous power consumption of a device (W).
830 @note Supported on MBLTML_DEVICE_ARIES only.
832 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
833 @return The power reading.
834 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
835 @throws MBLTMLError on other failures.
839 ret = _clib.mbltmlGetTotalPower(dev_no, byref(value))
840 _mbltmlThrowError(ret)
845 """@brief Get the total instantaneous current draw of a device (A).
847 @note Supported on MBLTML_DEVICE_ARIES only.
849 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
850 @return The current reading.
851 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
852 @throws MBLTMLError on other failures.
856 ret = _clib.mbltmlGetTotalCurrent(dev_no, byref(value))
857 _mbltmlThrowError(ret)
862 """@brief Get the total instantaneous supply voltage of a device (V).
864 @note Supported on MBLTML_DEVICE_ARIES only.
866 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
867 @return The voltage reading.
868 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
869 @throws MBLTMLError on other failures.
873 ret = _clib.mbltmlGetTotalVoltage(dev_no, byref(value))
874 _mbltmlThrowError(ret)
879 """@brief Get the power consumption of the extra PMIC rail currently
880 selected for the device (W).
882 @note Supported on MBLTML_DEVICE_ARIES only.
884 The selected rail is controlled by mbltmlSetExtraPmicID() and can be
885 queried via mbltmlGetExtraPmicId().
887 The firmware refreshes this reading once per second. After changing the
888 selected rail with mbltmlSetExtraPmicID(), allow up to 1 second for the
889 new rail's value to be reported.
891 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
892 @return The power reading.
893 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
894 @throws MBLTMLError on other failures.
898 ret = _clib.mbltmlGetExtraPmicPower(dev_no, byref(value))
899 _mbltmlThrowError(ret)
904 """@brief Get the current of the extra PMIC rail currently selected
907 @note Supported on MBLTML_DEVICE_ARIES only.
909 The firmware refreshes this reading once per second. After changing the
910 selected rail with mbltmlSetExtraPmicID(), allow up to 1 second for the
911 new rail's value to be reported.
913 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
914 @return The current reading.
915 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
916 @throws MBLTMLError on other failures.
920 ret = _clib.mbltmlGetExtraPmicCurrent(dev_no, byref(value))
921 _mbltmlThrowError(ret)
926 """@brief Get the voltage of the extra PMIC rail currently selected
929 @note Supported on MBLTML_DEVICE_ARIES only.
931 The firmware refreshes this reading once per second. After changing the
932 selected rail with mbltmlSetExtraPmicID(), allow up to 1 second for the
933 new rail's value to be reported.
935 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
936 @return The voltage reading.
937 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
938 @throws MBLTMLError on other failures.
942 ret = _clib.mbltmlGetExtraPmicVoltage(dev_no, byref(value))
943 _mbltmlThrowError(ret)
948 """@brief Get the extra PMIC rail currently selected for the device.
950 @note Supported on MBLTML_DEVICE_ARIES only.
952 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
953 @return The selected mbltmlExtraPmicId_t value.
954 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
955 @throws MBLTMLError on other failures.
959 ret = _clib.mbltmlGetExtraPmicId(dev_no, byref(value))
960 _mbltmlThrowError(ret)
965 """@brief Get the overall NPU utilization of a device.
967 @note Supported on all device types.
969 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
970 @return The utilization value (typically a ratio in [0.0, 1.0] or a percentage).
971 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
972 @throws MBLTMLError on other failures.
976 ret = _clib.mbltmlGetTotalUtilization(dev_no, byref(value))
977 _mbltmlThrowError(ret)
982 """@brief Get the amount of device memory currently in use.
984 @note Supported on all device types.
986 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
987 @return The in-use memory in bytes.
988 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
989 @throws MBLTMLError on other failures.
993 ret = _clib.mbltmlGetMemoryUsage(dev_no, byref(value))
994 _mbltmlThrowError(ret)
999 """@brief Get the total amount of device memory available.
1001 @note Supported on all device types.
1003 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
1004 @return The total memory in bytes.
1005 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
1006 @throws MBLTMLError on other failures.
1010 ret = _clib.mbltmlGetMemoryTotal(dev_no, byref(value))
1011 _mbltmlThrowError(ret)
1016 """@brief Get per-process usage information for a device.
1018 @note Supported on all device types.
1020 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
1021 @return List of mbltmlProcessInfo_t records; empty if no process is running.
1022 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
1023 @throws MBLTMLError on other failures.
1027 ret = _clib.mbltmlGetProcessInfos(dev_no,
None, byref(c_count))
1028 _mbltmlThrowError(ret)
1029 if c_count.value == 0:
1031 c_count.value = c_count.value * 2
1032 info_array = mbltmlProcessInfo_t * c_count.value
1033 infos = info_array()
1034 ret = _clib.mbltmlGetProcessInfos(dev_no, infos, byref(c_count))
1035 _mbltmlThrowError(ret)
1036 return [infos[i]
for i
in range(c_count.value)]
1040 """@brief Get per-core usage information for a device.
1042 @note Supported on all device types.
1044 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
1045 @return List of mbltmlCoreInfo_t records.
1046 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
1047 @throws MBLTMLError on other failures.
1051 ret = _clib.mbltmlGetCoreInfos(dev_no,
None, byref(c_count))
1052 _mbltmlThrowError(ret)
1053 if c_count.value == 0:
1055 c_count.value = c_count.value
1056 info_array = mbltmlCoreInfo_t * c_count.value
1057 infos = info_array()
1058 ret = _clib.mbltmlGetCoreInfos(dev_no, infos, byref(c_count))
1059 _mbltmlThrowError(ret)
1060 return [infos[i]
for i
in range(c_count.value)]
1064 """@brief Select which extra PMIC rail subsequent mbltmlGetExtraPmic*() queries refer to.
1066 @note Supported on aries-rb hardware (MBLTML_HARDWARE_VERSION_ARIES_RB) only.
1068 The underlying readings are refreshed by firmware once per second; allow
1069 up to 1 second after this call before mbltmlGetExtraPmicPower(),
1070 mbltmlGetExtraPmicCurrent() and mbltmlGetExtraPmicVoltage() reflect the
1071 newly selected rail.
1073 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
1074 @param pmic_id Identifier of the extra PMIC rail to select.
1075 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
1076 @throws MBLTMLError on other failures.
1079 ret = _clib.mbltmlSetExtraPmicID(dev_no, pmic_id)
1080 _mbltmlThrowError(ret)
Raised when the required driver cannot be located.
Raised when the output buffer is too small to hold the result.
Raised when the feature is not supported on the target device.
Raised when an API is called before initialization.
int mbltmlGetOnDeviceDriverRevision(int dev_no)
Get the on-device driver revision number of a device.
int mbltmlGetSubVendorId(int dev_no)
Get the PCIe subsystem vendor ID of a device.
None mbltmlShutdown()
Release all resources held by the mbltml library.
mbltmlHardwareVersion_t mbltmlGetHardwareVersion(int dev_no)
Get the hardware version of a device.
int mbltmlGetDeviceId(int dev_no)
Get the PCIe device ID of a device.
int mbltmlGetFanDuty(int dev_no)
Get the current cooling-fan duty cycle of a device.
int mbltmlGetPcieGen(int dev_no)
Get the negotiated PCIe link generation of a device.
int mbltmlGetPcieLanes(int dev_no)
Get the negotiated PCIe link width (in lanes) of a device.
float mbltmlGetExtraPmicVoltage(int dev_no)
Get the voltage of the extra PMIC rail currently selected for the device (V).
List[mbltmlCoreInfo_t] mbltmlGetCoreInfos(int dev_no)
Get per-core usage information for a device.
float mbltmlGetExtraPmicCurrent(int dev_no)
Get the current of the extra PMIC rail currently selected for the device (A).
None mbltmlSetExtraPmicID(int dev_no, mbltmlExtraPmicId_t pmic_id)
Select which extra PMIC rail subsequent mbltmlGetExtraPmic*() queries refer to.
None mbltmlInitDevices(Set[mbltmlDeviceType_t] device_types)
Initialize the mbltml library for a selected set of device types.
float mbltmlGetTotalPower(int dev_no)
Get the total instantaneous power consumption of a device (W).
int mbltmlGetFirmwareRevision(int dev_no)
Get the firmware revision number of a device.
str mbltmlGetNodeName(int dev_no)
Get the node name of a device.
int mbltmlGetFirmwareCRC(int dev_no)
Get the CRC of the currently-loaded firmware image.
str mbltmlGetFirmwareVersion(int dev_no)
Get the firmware version string of a device.
str mbltmlGetOnDeviceDriverVersion(int dev_no)
Get the on-device driver version string of a device.
float mbltmlGetTotalVoltage(int dev_no)
Get the total instantaneous supply voltage of a device (V).
int mbltmlGetMemoryUsage(int dev_no)
Get the amount of device memory currently in use.
int mbltmlGetSignalType(int dev_no)
Get the current signal-type indicator reported by the device.
int mbltmlGetSubDeviceId(int dev_no)
Get the PCIe subsystem device ID of a device.
mbltmlExtraPmicId_t mbltmlGetExtraPmicId(int dev_no)
Get the extra PMIC rail currently selected for the device.
int mbltmlGetPcieRev(int dev_no)
Get the PCIe configuration-space revision ID of a device.
int mbltmlGetPcieClassCode(int dev_no)
Get the PCIe configuration-space class code of a device.
str mbltmlGetDriverVersion(mbltmlDeviceType_t device_type)
Get the driver version string for a specific device family.
int mbltmlGetTemperature(int dev_no)
Get the current die temperature of a device.
List[mbltmlProcessInfo_t] mbltmlGetProcessInfos(int dev_no)
Get per-process usage information for a device.
mbltmlDeviceType_t mbltmlGetDeviceType(int dev_no)
Get the device family type of a device.
int mbltmlGetNPUClock(int dev_no)
Get the current NPU clock frequency of a device.
int mbltmlGetVendorId(int dev_no)
Get the PCIe vendor ID of a device.
float mbltmlGetTotalCurrent(int dev_no)
Get the total instantaneous current draw of a device (A).
int mbltmlGetDriverRevision(mbltmlDeviceType_t device_type)
Get the driver revision number for a specific device family.
int mbltmlGetBusClock(int dev_no)
Get the current bus clock frequency of a device.
float mbltmlGetTotalUtilization(int dev_no)
Get the overall NPU utilization of a device.
int mbltmlGetMemoryTotal(int dev_no)
Get the total amount of device memory available.
float mbltmlGetExtraPmicPower(int dev_no)
Get the power consumption of the extra PMIC rail currently selected for the device (W).
int mbltmlGetDeviceCount()
Get the total number of devices detected by the library.
None mbltmlInit()
Initialize the mbltml library for all supported device types.
Composite identifier of an NPU core (cluster + core).
Per-core usage record returned by mbltmlGetCoreInfos().
Per-process usage record returned by mbltmlGetProcessInfos().