9from pathlib
import Path
10from typing
import List, Set
17MBLTML_DRIVER_VERSION_BUFFER_SIZE = 80
19MBLTML_FIRMWARE_VERSION_BUFFER_SIZE = 80
21MBLTML_NODE_NAME_BUFFER_SIZE = 80
27mbltmlDeviceType_t = c_uint
28MBLTML_DEVICE_ERROR = 0x0
29MBLTML_DEVICE_ARIES = 0x1
30MBLTML_DEVICE_REGULUS = 0x2
31MBLTML_DEVICE_REGULUS_USB = 0x4
34mbltmlHardwareVersion_t = c_uint
35MBLTML_HARDWARE_VERSION_ARIES = 0x00000001
36MBLTML_HARDWARE_VERSION_REGULUS = 0x00000002
37MBLTML_HARDWARE_VERSION_ARIES2 = 0x00000003
38MBLTML_HARDWARE_VERSION_REGULUS2 = 0x00000004
39MBLTML_HARDWARE_VERSION_ERROR = 0x7FFFFFFF
44mbltmlStatusCode_t = c_uint
46MBLTML_DRIVER_NOT_FOUND = 2
47MBLTML_INVALID_ARGUMENT = 3
48MBLTML_UNINITIALIZED = 1
49MBLTML_NOT_SUPPORTED = 4
50MBLTML_INSUFFICIENT_LENGTH = 5
56mbltmlExtraPmicId_t = c_uint
57MBLTML_EXTRA_PMIC_ID_NPU = 0
58MBLTML_EXTRA_PMIC_ID_DDR = 1
59MBLTML_EXTRA_PMIC_ID_PMIC = 2
60MBLTML_EXTRA_PMIC_ID_GOLDFINGER = 3
63mbltmlCluster_t = c_uint
64MBLTML_CLUSTER_0 = 0x00010000
65MBLTML_CLUSTER_1 = 0x00020000
66MBLTML_CLUSTER_ERROR = 0x7FFF0000
74MBLTML_CORE_GLOBAL = 0x0000FFFE
75MBLTML_CORE_ERROR = 0x0000FFFF
80 """@brief Composite identifier of an NPU core (cluster + core).
82 @var cluster Cluster to which the core belongs (mbltmlCluster_t).
83 @var core Core within the cluster (mbltmlCore_t).
86 cluster: mbltmlCluster_t
89 (
"cluster", mbltmlCluster_t),
90 (
"core", mbltmlCore_t),
94 d = {
"cluster": self.cluster,
"core": self.core}
95 return "{}({})".format(
96 self.__class__.__name__,
97 ", ".join(
"{}={}".format(k, v)
for k, v
in d.items()),
102 """@brief Per-core usage record returned by mbltmlGetCoreInfos().
104 Utilization for the core can be computed as @c npu_time / @c interval
105 when @c interval is non-zero.
107 @var core_id Identifier of the core (mbltmlCoreId_t).
108 @var npu_time Accumulated NPU active time on the core, in microseconds.
109 @var interval Sampling interval covered by @c npu_time, in microseconds.
112 core_id: mbltmlCoreId_t
116 (
"core_id", mbltmlCoreId_t),
117 (
"npu_time", c_int64),
118 (
"interval", c_int64),
123 "core_id": self.core_id,
124 "npu_time": self.npu_time,
125 "interval": self.interval,
127 return "{}({})".format(
128 self.__class__.__name__,
129 ", ".join(
"{}={}".format(k, v)
for k, v
in d.items()),
134 """@brief Per-process usage record returned by mbltmlGetProcessInfos().
136 Utilization for the process can be computed as
137 @c total_npu_time_us / @c total_interval_us when @c total_interval_us
141 @var counts Number of NPU samples attributed to the process.
142 @var npu_memory_usage Device memory currently used by the process, in bytes.
143 @var total_interval_us Total sampling interval, in microseconds.
144 @var total_npu_time_us Total NPU active time used by the process, in microseconds.
149 npu_memory_usage: c_int64
150 total_interval_us: c_int64
151 total_npu_time_us: c_int64
155 (
"npu_memory_usage", c_int64),
156 (
"total_interval_us", c_int64),
157 (
"total_npu_time_us", c_int64),
163 "counts": self.counts,
164 "npu_memory_usage": self.npu_memory_usage,
165 "total_interval_us": self.total_interval_us,
166 "total_npu_time_us": self.total_npu_time_us,
168 return "{}({})".format(
169 self.__class__.__name__,
170 ", ".join(
"{}={}".format(k, v)
for k, v
in d.items()),
177def _loadLibrary() -> None:
181 lib_fname =
"mbltml.dll" if platform.system() ==
"Windows" else f
"libmbltml.so*"
182 pattern = os.path.join(Path(__file__).resolve().parent, lib_fname)
183 candidates = glob.glob(pattern)
185 raise FileNotFoundError(f
"No library matching {pattern}")
186 candidates.sort(key=len, reverse=
True)
187 _clib = CDLL(str(candidates[0]))
189 _clib.mbltmlInit.argtypes = []
190 _clib.mbltmlInit.restype = mbltmlStatusCode_t
191 _clib.mbltmlInitDevices.argtypes = [mbltmlDeviceType_t]
192 _clib.mbltmlInitDevices.restype = mbltmlStatusCode_t
193 _clib.mbltmlShutdown.argtypes = []
194 _clib.mbltmlShutdown.restype = mbltmlStatusCode_t
195 _clib.mbltmlGetDeviceCount.argtypes = [POINTER(c_uint)]
196 _clib.mbltmlGetDeviceCount.restype = mbltmlStatusCode_t
197 _clib.mbltmlGetDriverVersion.argtypes = [mbltmlDeviceType_t, POINTER(c_char), c_int]
198 _clib.mbltmlGetDriverVersion.restype = mbltmlStatusCode_t
199 _clib.mbltmlGetDriverRevision.argtypes = [mbltmlDeviceType_t, POINTER(c_uint)]
200 _clib.mbltmlGetDriverRevision.restype = mbltmlStatusCode_t
201 _clib.mbltmlGetNodeName.argtypes = [c_int, POINTER(c_char), c_int]
202 _clib.mbltmlGetNodeName.restype = mbltmlStatusCode_t
203 _clib.mbltmlGetDeviceType.argtypes = [c_int, POINTER(mbltmlDeviceType_t)]
204 _clib.mbltmlGetDeviceType.restype = mbltmlStatusCode_t
205 _clib.mbltmlGetHardwareVersion.argtypes = [c_int, POINTER(mbltmlHardwareVersion_t)]
206 _clib.mbltmlGetHardwareVersion.restype = mbltmlStatusCode_t
207 _clib.mbltmlGetFirmwareVersion.argtypes = [c_int, POINTER(c_char), c_uint]
208 _clib.mbltmlGetFirmwareVersion.restype = mbltmlStatusCode_t
209 _clib.mbltmlGetFirmwareRevision.argtypes = [c_int, POINTER(c_uint)]
210 _clib.mbltmlGetFirmwareRevision.restype = mbltmlStatusCode_t
211 _clib.mbltmlGetFirmwareCRC.argtypes = [c_int, POINTER(c_uint)]
212 _clib.mbltmlGetFirmwareCRC.restype = mbltmlStatusCode_t
213 _clib.mbltmlGetTemperature.argtypes = [c_int, POINTER(c_int)]
214 _clib.mbltmlGetTemperature.restype = mbltmlStatusCode_t
215 _clib.mbltmlGetSignalType.argtypes = [c_int, POINTER(c_uint)]
216 _clib.mbltmlGetSignalType.restype = mbltmlStatusCode_t
217 _clib.mbltmlGetNPUClock.argtypes = [c_int, POINTER(c_uint)]
218 _clib.mbltmlGetNPUClock.restype = mbltmlStatusCode_t
219 _clib.mbltmlGetBusClock.argtypes = [c_int, POINTER(c_uint)]
220 _clib.mbltmlGetBusClock.restype = mbltmlStatusCode_t
221 _clib.mbltmlGetFanDuty.argtypes = [c_int, POINTER(c_int)]
222 _clib.mbltmlGetFanDuty.restype = mbltmlStatusCode_t
223 _clib.mbltmlGetVendorId.argtypes = [c_int, POINTER(c_uint)]
224 _clib.mbltmlGetVendorId.restype = mbltmlStatusCode_t
225 _clib.mbltmlGetDeviceId.argtypes = [c_int, POINTER(c_uint)]
226 _clib.mbltmlGetDeviceId.restype = mbltmlStatusCode_t
227 _clib.mbltmlGetSubVendorId.argtypes = [c_int, POINTER(c_uint)]
228 _clib.mbltmlGetSubVendorId.restype = mbltmlStatusCode_t
229 _clib.mbltmlGetSubDeviceId.argtypes = [c_int, POINTER(c_uint)]
230 _clib.mbltmlGetSubDeviceId.restype = mbltmlStatusCode_t
231 _clib.mbltmlGetPcieGen.argtypes = [c_int, POINTER(c_uint)]
232 _clib.mbltmlGetPcieGen.restype = mbltmlStatusCode_t
233 _clib.mbltmlGetPcieLanes.argtypes = [c_int, POINTER(c_uint)]
234 _clib.mbltmlGetPcieLanes.restype = mbltmlStatusCode_t
235 _clib.mbltmlGetPcieRev.argtypes = [c_int, POINTER(c_uint)]
236 _clib.mbltmlGetPcieRev.restype = mbltmlStatusCode_t
237 _clib.mbltmlGetPcieClassCode.argtypes = [c_int, POINTER(c_uint)]
238 _clib.mbltmlGetPcieClassCode.restype = mbltmlStatusCode_t
239 _clib.mbltmlGetTotalPower.argtypes = [c_int, POINTER(c_double)]
240 _clib.mbltmlGetTotalPower.restype = mbltmlStatusCode_t
241 _clib.mbltmlGetTotalCurrent.argtypes = [c_int, POINTER(c_double)]
242 _clib.mbltmlGetTotalCurrent.restype = mbltmlStatusCode_t
243 _clib.mbltmlGetTotalVoltage.argtypes = [c_int, POINTER(c_double)]
244 _clib.mbltmlGetTotalVoltage.restype = mbltmlStatusCode_t
245 _clib.mbltmlGetExtraPmicPower.argtypes = [c_int, POINTER(c_double)]
246 _clib.mbltmlGetExtraPmicPower.restype = mbltmlStatusCode_t
247 _clib.mbltmlGetExtraPmicCurrent.argtypes = [c_int, POINTER(c_double)]
248 _clib.mbltmlGetExtraPmicCurrent.restype = mbltmlStatusCode_t
249 _clib.mbltmlGetExtraPmicVoltage.argtypes = [c_int, POINTER(c_double)]
250 _clib.mbltmlGetExtraPmicVoltage.restype = mbltmlStatusCode_t
251 _clib.mbltmlGetExtraPmicId.argtypes = [c_int, POINTER(mbltmlExtraPmicId_t)]
252 _clib.mbltmlGetExtraPmicId.restype = mbltmlStatusCode_t
253 _clib.mbltmlGetTotalUtilization.argtypes = [c_int, POINTER(c_double)]
254 _clib.mbltmlGetTotalUtilization.restype = mbltmlStatusCode_t
255 _clib.mbltmlGetMemoryUsage.argtypes = [c_int, POINTER(c_int64)]
256 _clib.mbltmlGetMemoryUsage.restype = mbltmlStatusCode_t
257 _clib.mbltmlGetMemoryTotal.argtypes = [c_int, POINTER(c_int64)]
258 _clib.mbltmlGetMemoryTotal.restype = mbltmlStatusCode_t
259 _clib.mbltmlGetProcessInfos.argtypes = [
261 POINTER(mbltmlProcessInfo_t),
264 _clib.mbltmlGetProcessInfos.restype = mbltmlStatusCode_t
265 _clib.mbltmlGetCoreInfos.argtypes = [
267 POINTER(mbltmlCoreInfo_t),
270 _clib.mbltmlGetCoreInfos.restype = mbltmlStatusCode_t
271 _clib.mbltmlSetExtraPmicID.argtypes = [c_int, mbltmlExtraPmicId_t]
272 _clib.mbltmlSetExtraPmicID.restype = mbltmlStatusCode_t
275class MBLTMLError(Exception):
276 """@brief Base exception raised by the mbltml Python binding.
278 Wraps a non-success mbltmlStatusCode_t returned by the underlying C
279 library. Instantiating MBLTMLError with a known status code yields the
280 matching subclass (e.g., MBLTMLInvalidArgumentError).
282 @var code The mbltmlStatusCode_t value associated with this exception.
286 _errcode_to_string = {
287 MBLTML_DRIVER_NOT_FOUND:
"Driver is not found",
288 MBLTML_INVALID_ARGUMENT:
"Invalid Argument",
289 MBLTML_UNINITIALIZED:
"Uninitilized mbltml.",
290 MBLTML_NOT_SUPPORTED:
"Unspported Function for Target Device",
291 MBLTML_INSUFFICIENT_LENGTH:
"Insufficient Length",
294 def __new__(cls, code: mbltmlStatusCode_t):
295 if cls
is MBLTMLError
and code
in MBLTMLError._code_to_class:
296 cls = MBLTMLError._code_to_class[code]
297 obj = Exception.__new__(cls)
302 return MBLTMLError._errcode_to_string[self.code]
304 def __eq__(self, other):
305 return self.code == other.code
309 """@brief Raised when the required driver cannot be located.
311 Wraps MBLTML_DRIVER_NOT_FOUND.
317class MBLTMLInvalidArgumentError(MBLTMLError):
318 """@brief Raised when one or more arguments are invalid.
320 Wraps MBLTML_INVALID_ARGUMENT. Typical causes include a NULL pointer or
321 a @c dev_no that is out of range of the device count.
328 """@brief Raised when an API is called before initialization.
330 Wraps MBLTML_UNINITIALIZED. Call mbltmlInit() or mbltmlInitDevices() first.
337 """@brief Raised when the feature is not supported on the target device.
339 Wraps MBLTML_NOT_SUPPORTED.
346 """@brief Raised when the output buffer is too small to hold the result.
348 Wraps MBLTML_INSUFFICIENT_LENGTH.
354MBLTMLError._code_to_class = {
355 MBLTML_DRIVER_NOT_FOUND: MBLTMLDriverNotFoundError,
356 MBLTML_INVALID_ARGUMENT: MBLTMLInvalidArgumentError,
357 MBLTML_UNINITIALIZED: MBLTMLUninitializedError,
358 MBLTML_NOT_SUPPORTED: MBLTMLNotSupportedError,
359 MBLTML_INSUFFICIENT_LENGTH: MBLTMLInsufficientLengthError,
363def _mbltmlThrowError(ret: mbltmlStatusCode_t) ->
None:
364 if ret != MBLTML_SUCCESS:
365 raise MBLTMLError(ret)
370 """@brief Initialize the mbltml library for all supported device types.
372 Equivalent to calling mbltmlInitDevices() with every mbltmlDeviceType_t
373 enabled. Must be called (directly or via mbltmlInitDevices()) before any
376 @throws MBLTMLError on failure.
379 ret = _clib.mbltmlInit()
380 _mbltmlThrowError(ret)
384 """@brief Initialize the mbltml library for a selected set of device types.
386 @param device_types Set of mbltmlDeviceType_t values indicating which
387 device families to enumerate and monitor.
388 @throws MBLTMLError on failure.
392 for dt
in device_types:
393 all_device_types = all_device_types | dt
394 ret = _clib.mbltmlInitDevices(all_device_types)
395 _mbltmlThrowError(ret)
399 """@brief Release all resources held by the mbltml library.
401 After this call, any further API usage requires re-initialization via
402 mbltmlInit() or mbltmlInitDevices().
404 @throws MBLTMLError on failure.
407 ret = _clib.mbltmlShutdown()
408 _mbltmlThrowError(ret)
412 """@brief Get the total number of devices detected by the library.
414 @note Supported on all device types.
416 @return The number of devices detected.
417 @throws MBLTMLError on failure.
421 ret = _clib.mbltmlGetDeviceCount(byref(value))
422 _mbltmlThrowError(ret)
427 """@brief Get the driver version string for a specific device family.
429 @note Supported on all device types.
431 @param device_type Device family whose driver version is queried.
432 @return The driver version string.
433 @throws MBLTMLError on failure.
436 buf = create_string_buffer(MBLTML_DRIVER_VERSION_BUFFER_SIZE)
437 ret = _clib.mbltmlGetDriverVersion(
438 device_type, buf, MBLTML_DRIVER_VERSION_BUFFER_SIZE
440 _mbltmlThrowError(ret)
441 return buf.value.decode()
445 """@brief Get the driver revision number for a specific device family.
447 @note Supported on all device types.
449 @param device_type Device family whose driver revision is queried.
450 @return The driver revision number.
451 @throws MBLTMLError on failure.
455 ret = _clib.mbltmlGetDriverRevision(device_type, byref(value))
456 _mbltmlThrowError(ret)
461 """@brief Get the node name of a device.
463 @note Supported on all device types.
465 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
466 @return The node name string.
467 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
468 @throws MBLTMLError on other failures.
471 buf = create_string_buffer(MBLTML_NODE_NAME_BUFFER_SIZE)
472 ret = _clib.mbltmlGetNodeName(dev_no, buf, MBLTML_NODE_NAME_BUFFER_SIZE)
473 _mbltmlThrowError(ret)
474 return buf.value.decode()
478 """@brief Get the device family type of a device.
480 @note Supported on all device types.
482 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
483 @return The mbltmlDeviceType_t of the device.
484 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
485 @throws MBLTMLError on other failures.
489 ret = _clib.mbltmlGetDeviceType(dev_no, byref(value))
490 _mbltmlThrowError(ret)
495 """@brief Get the hardware version of a device.
497 @note Supported on all device types.
499 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
500 @return The mbltmlHardwareVersion_t of the device.
501 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
502 @throws MBLTMLError on other failures.
506 ret = _clib.mbltmlGetHardwareVersion(dev_no, byref(value))
507 _mbltmlThrowError(ret)
512 """@brief Get the firmware version string of a device.
514 @note Supported on all device types.
516 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
517 @return The firmware version string.
518 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
519 @throws MBLTMLError on other failures.
522 buf = create_string_buffer(MBLTML_FIRMWARE_VERSION_BUFFER_SIZE)
523 ret = _clib.mbltmlGetFirmwareVersion(
524 dev_no, buf, MBLTML_FIRMWARE_VERSION_BUFFER_SIZE
526 _mbltmlThrowError(ret)
527 return buf.value.decode()
531 """@brief Get the firmware revision number of a device.
533 @note Supported on all device types.
535 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
536 @return The firmware revision.
537 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
538 @throws MBLTMLError on other failures.
542 ret = _clib.mbltmlGetFirmwareRevision(dev_no, byref(value))
543 _mbltmlThrowError(ret)
548 """@brief Get the CRC of the currently-loaded firmware image.
550 @note Supported on MBLTML_DEVICE_ARIES only.
552 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
553 @return The firmware CRC.
554 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
555 @throws MBLTMLError on other failures.
559 ret = _clib.mbltmlGetFirmwareCRC(dev_no, byref(value))
560 _mbltmlThrowError(ret)
565 """@brief Get the current die temperature of a device.
567 @note Supported on all device types.
569 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
570 @return The temperature reading.
571 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
572 @throws MBLTMLError on other failures.
576 ret = _clib.mbltmlGetTemperature(dev_no, byref(value))
577 _mbltmlThrowError(ret)
582 """@brief Get the current signal-type indicator reported by the device.
584 @note Supported on all device types.
586 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
587 @return The signal-type value.
588 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
589 @throws MBLTMLError on other failures.
593 ret = _clib.mbltmlGetSignalType(dev_no, byref(value))
594 _mbltmlThrowError(ret)
599 """@brief Get the current NPU clock frequency of a device.
601 @note Supported on all device types.
603 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
604 @return The NPU clock value.
605 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
606 @throws MBLTMLError on other failures.
610 ret = _clib.mbltmlGetNPUClock(dev_no, byref(value))
611 _mbltmlThrowError(ret)
616 """@brief Get the current bus clock frequency of a device.
618 @note Supported on MBLTML_DEVICE_ARIES only.
620 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
621 @return The bus clock value.
622 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
623 @throws MBLTMLError on other failures.
627 ret = _clib.mbltmlGetBusClock(dev_no, byref(value))
628 _mbltmlThrowError(ret)
633 """@brief Get the current cooling-fan duty cycle of a device.
635 @note Supported on MBLTML_DEVICE_ARIES only.
637 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
638 @return The fan duty value.
639 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
640 @throws MBLTMLError on other failures.
644 ret = _clib.mbltmlGetFanDuty(dev_no, byref(value))
645 _mbltmlThrowError(ret)
650 """@brief Get the PCIe vendor ID of a device.
652 @note Supported on MBLTML_DEVICE_ARIES only.
654 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
655 @return The vendor ID.
656 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
657 @throws MBLTMLError on other failures.
661 ret = _clib.mbltmlGetVendorId(dev_no, byref(value))
662 _mbltmlThrowError(ret)
667 """@brief Get the PCIe device ID of a device.
669 @note Supported on MBLTML_DEVICE_ARIES only.
671 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
672 @return The device ID.
673 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
674 @throws MBLTMLError on other failures.
678 ret = _clib.mbltmlGetDeviceId(dev_no, byref(value))
679 _mbltmlThrowError(ret)
684 """@brief Get the PCIe subsystem vendor ID of a device.
686 @note Supported on MBLTML_DEVICE_ARIES only.
688 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
689 @return The subsystem vendor ID.
690 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
691 @throws MBLTMLError on other failures.
695 ret = _clib.mbltmlGetSubVendorId(dev_no, byref(value))
696 _mbltmlThrowError(ret)
701 """@brief Get the PCIe subsystem device ID of a device.
703 @note Supported on MBLTML_DEVICE_ARIES only.
705 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
706 @return The subsystem device ID.
707 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
708 @throws MBLTMLError on other failures.
712 ret = _clib.mbltmlGetSubDeviceId(dev_no, byref(value))
713 _mbltmlThrowError(ret)
718 """@brief Get the negotiated PCIe link generation of a device.
720 @note Supported on MBLTML_DEVICE_ARIES only.
722 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
723 @return The PCIe generation.
724 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
725 @throws MBLTMLError on other failures.
729 ret = _clib.mbltmlGetPcieGen(dev_no, byref(value))
730 _mbltmlThrowError(ret)
735 """@brief Get the negotiated PCIe link width (in lanes) of a device.
737 @note Supported on MBLTML_DEVICE_ARIES only.
739 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
740 @return The lane count.
741 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
742 @throws MBLTMLError on other failures.
746 ret = _clib.mbltmlGetPcieLanes(dev_no, byref(value))
747 _mbltmlThrowError(ret)
752 """@brief Get the PCIe configuration-space revision ID of a device.
754 @note Supported on MBLTML_DEVICE_ARIES only.
756 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
757 @return The revision value.
758 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
759 @throws MBLTMLError on other failures.
763 ret = _clib.mbltmlGetPcieRev(dev_no, byref(value))
764 _mbltmlThrowError(ret)
769 """@brief Get the PCIe configuration-space class code of a device.
771 @note Supported on MBLTML_DEVICE_ARIES only.
773 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
774 @return The class code.
775 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
776 @throws MBLTMLError on other failures.
780 ret = _clib.mbltmlGetPcieClassCode(dev_no, byref(value))
781 _mbltmlThrowError(ret)
786 """@brief Get the total instantaneous power consumption of a device (W).
788 @note Supported on MBLTML_DEVICE_ARIES only.
790 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
791 @return The power reading.
792 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
793 @throws MBLTMLError on other failures.
797 ret = _clib.mbltmlGetTotalPower(dev_no, byref(value))
798 _mbltmlThrowError(ret)
803 """@brief Get the total instantaneous current draw of a device (A).
805 @note Supported on MBLTML_DEVICE_ARIES only.
807 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
808 @return The current reading.
809 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
810 @throws MBLTMLError on other failures.
814 ret = _clib.mbltmlGetTotalCurrent(dev_no, byref(value))
815 _mbltmlThrowError(ret)
820 """@brief Get the total instantaneous supply voltage of a device (V).
822 @note Supported on MBLTML_DEVICE_ARIES only.
824 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
825 @return The voltage reading.
826 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
827 @throws MBLTMLError on other failures.
831 ret = _clib.mbltmlGetTotalVoltage(dev_no, byref(value))
832 _mbltmlThrowError(ret)
837 """@brief Get the power consumption of the extra PMIC rail currently
838 selected for the device (W).
840 @note Supported on MBLTML_DEVICE_ARIES only.
842 The selected rail is controlled by mbltmlSetExtraPmicID() and can be
843 queried via mbltmlGetExtraPmicId().
845 The firmware refreshes this reading once per second. After changing the
846 selected rail with mbltmlSetExtraPmicID(), allow up to 1 second for the
847 new rail's value to be reported.
849 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
850 @return The power 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.mbltmlGetExtraPmicPower(dev_no, byref(value))
857 _mbltmlThrowError(ret)
862 """@brief Get the current of the extra PMIC rail currently selected
865 @note Supported on MBLTML_DEVICE_ARIES only.
867 The firmware refreshes this reading once per second. After changing the
868 selected rail with mbltmlSetExtraPmicID(), allow up to 1 second for the
869 new rail's value to be reported.
871 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
872 @return The current reading.
873 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
874 @throws MBLTMLError on other failures.
878 ret = _clib.mbltmlGetExtraPmicCurrent(dev_no, byref(value))
879 _mbltmlThrowError(ret)
884 """@brief Get the voltage of the extra PMIC rail currently selected
887 @note Supported on MBLTML_DEVICE_ARIES only.
889 The firmware refreshes this reading once per second. After changing the
890 selected rail with mbltmlSetExtraPmicID(), allow up to 1 second for the
891 new rail's value to be reported.
893 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
894 @return The voltage reading.
895 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
896 @throws MBLTMLError on other failures.
900 ret = _clib.mbltmlGetExtraPmicVoltage(dev_no, byref(value))
901 _mbltmlThrowError(ret)
906 """@brief Get the extra PMIC rail currently selected for the device.
908 @note Supported on MBLTML_DEVICE_ARIES only.
910 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
911 @return The selected mbltmlExtraPmicId_t value.
912 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
913 @throws MBLTMLError on other failures.
917 ret = _clib.mbltmlGetExtraPmicId(dev_no, byref(value))
918 _mbltmlThrowError(ret)
923 """@brief Get the overall NPU utilization of a device.
925 @note Supported on all device types.
927 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
928 @return The utilization value (typically a ratio in [0.0, 1.0] or a percentage).
929 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
930 @throws MBLTMLError on other failures.
934 ret = _clib.mbltmlGetTotalUtilization(dev_no, byref(value))
935 _mbltmlThrowError(ret)
940 """@brief Get the amount of device memory currently in use.
942 @note Supported on all device types.
944 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
945 @return The in-use memory in bytes.
946 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
947 @throws MBLTMLError on other failures.
951 ret = _clib.mbltmlGetMemoryUsage(dev_no, byref(value))
952 _mbltmlThrowError(ret)
957 """@brief Get the total amount of device memory available.
959 @note Supported on all device types.
961 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
962 @return The total memory in bytes.
963 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
964 @throws MBLTMLError on other failures.
968 ret = _clib.mbltmlGetMemoryTotal(dev_no, byref(value))
969 _mbltmlThrowError(ret)
974 """@brief Get per-process usage information for a device.
976 @note Supported on all device types.
978 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
979 @return List of mbltmlProcessInfo_t records; empty if no process is running.
980 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
981 @throws MBLTMLError on other failures.
985 ret = _clib.mbltmlGetProcessInfos(dev_no,
None, byref(c_count))
986 _mbltmlThrowError(ret)
987 if c_count.value == 0:
989 c_count.value = c_count.value * 2
990 info_array = mbltmlProcessInfo_t * c_count.value
992 ret = _clib.mbltmlGetProcessInfos(dev_no, infos, byref(c_count))
993 _mbltmlThrowError(ret)
994 return [infos[i]
for i
in range(c_count.value)]
998 """@brief Get per-core usage information for a device.
1000 @note Supported on all device types.
1002 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
1003 @return List of mbltmlCoreInfo_t records.
1004 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
1005 @throws MBLTMLError on other failures.
1009 ret = _clib.mbltmlGetCoreInfos(dev_no,
None, byref(c_count))
1010 _mbltmlThrowError(ret)
1011 if c_count.value == 0:
1013 c_count.value = c_count.value
1014 info_array = mbltmlCoreInfo_t * c_count.value
1015 infos = info_array()
1016 ret = _clib.mbltmlGetCoreInfos(dev_no, infos, byref(c_count))
1017 _mbltmlThrowError(ret)
1018 return [infos[i]
for i
in range(c_count.value)]
1022 """@brief Select which extra PMIC rail subsequent mbltmlGetExtraPmic*() queries refer to.
1024 @note Supported on Aries2 hardware (MBLTML_HARDWARE_VERSION_ARIES2) only.
1026 The underlying readings are refreshed by firmware once per second; allow
1027 up to 1 second after this call before mbltmlGetExtraPmicPower(),
1028 mbltmlGetExtraPmicCurrent() and mbltmlGetExtraPmicVoltage() reflect the
1029 newly selected rail.
1031 @param dev_no Device index. Total device count is obtained via mbltmlGetDeviceCount().
1032 @param pmic_id Identifier of the extra PMIC rail to select.
1033 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the device count.
1034 @throws MBLTMLError on other failures.
1037 ret = _clib.mbltmlSetExtraPmicID(dev_no, pmic_id)
1038 _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 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.
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().