mbltml.py Source File

mbltml.py Source File#

mbltml: mbltml.py Source File
mbltml v1.5
mbltml — KR
mbltml.py
Go to the documentation of this file.
1
4
5import os
6import glob
7import platform
8from ctypes import *
9from pathlib import Path
10from typing import List
11
12
15
16
17MBLTML_DRIVER_VERSION_BUFFER_SIZE = 80
18
19MBLTML_ON_DEVICE_DRIVER_VERSION_BUFFER_SIZE = 80
20
21MBLTML_FIRMWARE_VERSION_BUFFER_SIZE = 80
22
23MBLTML_NODE_NAME_BUFFER_SIZE = 80
24
25MBLTML_PCIE_SLOT_BUFFER_SIZE = 80
26
27
31mbltmlDriverType_t = c_uint
32MBLTML_DRIVER_ERROR = 0x0
33MBLTML_DRIVER_ARIES = 0x1
34MBLTML_DRIVER_REGULUS = 0x2
35MBLTML_DRIVER_REGULUS_USB = 0x4
36
37
38mbltmlTargetDeviceType_t = c_uint
39MBLTML_TARGET_DEVICE_ARIES_RA = 0x00000001
40MBLTML_TARGET_DEVICE_REGULUS_RA = 0x00000002
41MBLTML_TARGET_DEVICE_ARIES_RB = 0x00000003
42MBLTML_TARGET_DEVICE_REGULUS_RB = 0x00000004
43MBLTML_TARGET_DEVICE_REGULUS_RA_USB = 0x00000005
44MBLTML_TARGET_DEVICE_REGULUS_RB_USB = 0x00000006
45MBLTML_TARGET_DEVICE_ERROR = 0x7FFFFFFF
46
47
50mbltmlStatusCode_t = c_uint
51MBLTML_SUCCESS = 0
52MBLTML_DRIVER_NOT_FOUND = 2
53MBLTML_INVALID_ARGUMENT = 3
54MBLTML_UNINITIALIZED = 1
55MBLTML_NOT_SUPPORTED = 4
56MBLTML_INSUFFICIENT_LENGTH = 5
57MBLTML_DEVICE_NOT_FOUND = 6
58
59
63mbltmlExtraPmicId_t = c_uint
64MBLTML_EXTRA_PMIC_ID_NPU = 0
65MBLTML_EXTRA_PMIC_ID_DDR = 1
66MBLTML_EXTRA_PMIC_ID_PMIC = 2
67MBLTML_EXTRA_PMIC_ID_GOLDFINGER = 3
68
69
70mbltmlCluster_t = c_uint
71MBLTML_CLUSTER_0 = 0x00010000
72MBLTML_CLUSTER_1 = 0x00020000
73MBLTML_CLUSTER_ERROR = 0x7FFF0000
74
75
76mbltmlCore_t = c_uint
77MBLTML_CORE_0 = 1
78MBLTML_CORE_1 = 2
79MBLTML_CORE_2 = 3
80MBLTML_CORE_3 = 4
81MBLTML_CORE_GLOBAL = 0x0000FFFE
82MBLTML_CORE_ERROR = 0x0000FFFF
83
84
85# Classes
86class mbltmlCoreId_t(Structure):
87 """@brief Composite identifier of an NPU core (cluster + core).
88
89 @var cluster Cluster to which the core belongs (mbltmlCluster_t).
90 @var core Core within the cluster (mbltmlCore_t).
91 """
92
93 cluster: mbltmlCluster_t
94 core: mbltmlCore_t
95 _fields_ = [
96 ("cluster", mbltmlCluster_t),
97 ("core", mbltmlCore_t),
98 ]
99
100 def __repr__(self):
101 d = {"cluster": self.cluster, "core": self.core}
102 return "{}({})".format(
103 self.__class__.__name__,
104 ", ".join("{}={}".format(k, v) for k, v in d.items()),
105 )
106
107
108class mbltmlCoreInfo_t(Structure):
109 """@brief Per-core usage record returned by mbltmlGetCoreInfos().
110
111 Utilization for the core can be computed as @c npu_time / @c interval
112 when @c interval is non-zero.
113
114 @var core_id Identifier of the core (mbltmlCoreId_t).
115 @var npu_time Accumulated NPU active time on the core, in microseconds.
116 @var interval Sampling interval covered by @c npu_time, in microseconds.
117 """
118
119 core_id: mbltmlCoreId_t
120 npu_time: c_int64
121 interval: c_int64
122 _fields_ = [
123 ("core_id", mbltmlCoreId_t),
124 ("npu_time", c_int64),
125 ("interval", c_int64),
126 ]
127
128 def __repr__(self):
129 d = {
130 "core_id": self.core_id,
131 "npu_time": self.npu_time,
132 "interval": self.interval,
133 }
134 return "{}({})".format(
135 self.__class__.__name__,
136 ", ".join("{}={}".format(k, v) for k, v in d.items()),
137 )
138
139
140class mbltmlProcessInfo_t(Structure):
141 """@brief Per-process usage record returned by mbltmlGetProcessInfos().
142
143 Utilization for the process can be computed as
144 @c total_npu_time_us / @c total_interval_us when @c total_interval_us
145 is non-zero.
146
147 @var pid Process ID.
148 @var counts Number of NPU samples attributed to the process.
149 @var npu_memory_usage Device memory currently used by the process, in bytes.
150 @var total_interval_us Total sampling interval, in microseconds.
151 @var total_npu_time_us Total NPU active time used by the process, in microseconds.
152 """
153
154 pid: c_int
155 counts: c_int
156 npu_memory_usage: c_int64
157 total_interval_us: c_int64
158 total_npu_time_us: c_int64
159 _fields_ = [
160 ("pid", c_int),
161 ("counts", c_int),
162 ("npu_memory_usage", c_int64),
163 ("total_interval_us", c_int64),
164 ("total_npu_time_us", c_int64),
165 ]
166
167 def __repr__(self):
168 d = {
169 "pid": self.pid,
170 "counts": self.counts,
171 "npu_memory_usage": self.npu_memory_usage,
172 "total_interval_us": self.total_interval_us,
173 "total_npu_time_us": self.total_npu_time_us,
174 }
175 return "{}({})".format(
176 self.__class__.__name__,
177 ", ".join("{}={}".format(k, v) for k, v in d.items()),
178 )
179
180
181_clib = None
182
183
184def _loadLibrary() -> None:
185 global _clib
186 if _clib != None:
187 return
188 lib_fname = "mbltml.dll" if platform.system() == "Windows" else f"libmbltml.so*"
189 pattern = os.path.join(Path(__file__).resolve().parent, lib_fname)
190 candidates = glob.glob(pattern)
191 if not candidates:
192 raise FileNotFoundError(f"No library matching {pattern}")
193 candidates.sort(key=len, reverse=True)
194 _clib = CDLL(str(candidates[0]))
195
196 _clib.mbltmlInit.argtypes = []
197 _clib.mbltmlInit.restype = mbltmlStatusCode_t
198 _clib.mbltmlShutdown.argtypes = []
199 _clib.mbltmlShutdown.restype = mbltmlStatusCode_t
200 _clib.mbltmlGetDeviceCount.argtypes = [POINTER(c_uint)]
201 _clib.mbltmlGetDeviceCount.restype = mbltmlStatusCode_t
202 _clib.mbltmlGetTargetDeviceCount.argtypes = [
203 mbltmlTargetDeviceType_t,
204 POINTER(c_uint),
205 ]
206 _clib.mbltmlGetTargetDeviceCount.restype = mbltmlStatusCode_t
207 _clib.mbltmlGetDriverVersion.argtypes = [mbltmlDriverType_t, POINTER(c_char), c_int]
208 _clib.mbltmlGetDriverVersion.restype = mbltmlStatusCode_t
209 _clib.mbltmlGetDriverRevision.argtypes = [mbltmlDriverType_t, POINTER(c_uint)]
210 _clib.mbltmlGetDriverRevision.restype = mbltmlStatusCode_t
211 _clib.mbltmlGetNodeName.argtypes = [
212 mbltmlTargetDeviceType_t,
213 c_int,
214 POINTER(c_char),
215 c_int,
216 ]
217 _clib.mbltmlGetNodeName.restype = mbltmlStatusCode_t
218 _clib.mbltmlGetDriverType.argtypes = [
219 mbltmlTargetDeviceType_t,
220 c_int,
221 POINTER(mbltmlDriverType_t),
222 ]
223 _clib.mbltmlGetDriverType.restype = mbltmlStatusCode_t
224 _clib.mbltmlGetOnDeviceDriverVersion.argtypes = [
225 mbltmlTargetDeviceType_t,
226 c_int,
227 POINTER(c_char),
228 c_uint,
229 ]
230 _clib.mbltmlGetOnDeviceDriverVersion.restype = mbltmlStatusCode_t
231 _clib.mbltmlGetOnDeviceDriverRevision.argtypes = [
232 mbltmlTargetDeviceType_t,
233 c_int,
234 POINTER(c_uint),
235 ]
236 _clib.mbltmlGetOnDeviceDriverRevision.restype = mbltmlStatusCode_t
237 _clib.mbltmlGetFirmwareVersion.argtypes = [
238 mbltmlTargetDeviceType_t,
239 c_int,
240 POINTER(c_char),
241 c_uint,
242 ]
243 _clib.mbltmlGetFirmwareVersion.restype = mbltmlStatusCode_t
244 _clib.mbltmlGetFirmwareRevision.argtypes = [
245 mbltmlTargetDeviceType_t,
246 c_int,
247 POINTER(c_uint),
248 ]
249 _clib.mbltmlGetFirmwareRevision.restype = mbltmlStatusCode_t
250 _clib.mbltmlGetFirmwareCRC.argtypes = [
251 mbltmlTargetDeviceType_t,
252 c_int,
253 POINTER(c_uint),
254 ]
255 _clib.mbltmlGetFirmwareCRC.restype = mbltmlStatusCode_t
256 _clib.mbltmlGetTemperature.argtypes = [
257 mbltmlTargetDeviceType_t,
258 c_int,
259 POINTER(c_int),
260 ]
261 _clib.mbltmlGetTemperature.restype = mbltmlStatusCode_t
262 _clib.mbltmlGetPcieSwitchTemperature.argtypes = [
263 mbltmlTargetDeviceType_t,
264 c_int,
265 POINTER(c_int),
266 ]
267 _clib.mbltmlGetPcieSwitchTemperature.restype = mbltmlStatusCode_t
268 _clib.mbltmlGetChipId.argtypes = [mbltmlTargetDeviceType_t, c_int, POINTER(c_int)]
269 _clib.mbltmlGetChipId.restype = mbltmlStatusCode_t
270 _clib.mbltmlGetSignalType.argtypes = [
271 mbltmlTargetDeviceType_t,
272 c_int,
273 POINTER(c_uint),
274 ]
275 _clib.mbltmlGetSignalType.restype = mbltmlStatusCode_t
276 _clib.mbltmlGetNPUClock.argtypes = [
277 mbltmlTargetDeviceType_t,
278 c_int,
279 POINTER(c_uint),
280 ]
281 _clib.mbltmlGetNPUClock.restype = mbltmlStatusCode_t
282 _clib.mbltmlGetBusClock.argtypes = [
283 mbltmlTargetDeviceType_t,
284 c_int,
285 POINTER(c_uint),
286 ]
287 _clib.mbltmlGetBusClock.restype = mbltmlStatusCode_t
288 _clib.mbltmlGetFanDuty.argtypes = [mbltmlTargetDeviceType_t, c_int, POINTER(c_int)]
289 _clib.mbltmlGetFanDuty.restype = mbltmlStatusCode_t
290 _clib.mbltmlGetVendorId.argtypes = [
291 mbltmlTargetDeviceType_t,
292 c_int,
293 POINTER(c_uint),
294 ]
295 _clib.mbltmlGetVendorId.restype = mbltmlStatusCode_t
296 _clib.mbltmlGetDeviceId.argtypes = [
297 mbltmlTargetDeviceType_t,
298 c_int,
299 POINTER(c_uint),
300 ]
301 _clib.mbltmlGetDeviceId.restype = mbltmlStatusCode_t
302 _clib.mbltmlGetSubVendorId.argtypes = [
303 mbltmlTargetDeviceType_t,
304 c_int,
305 POINTER(c_uint),
306 ]
307 _clib.mbltmlGetSubVendorId.restype = mbltmlStatusCode_t
308 _clib.mbltmlGetSubDeviceId.argtypes = [
309 mbltmlTargetDeviceType_t,
310 c_int,
311 POINTER(c_uint),
312 ]
313 _clib.mbltmlGetSubDeviceId.restype = mbltmlStatusCode_t
314 _clib.mbltmlGetPcieGen.argtypes = [mbltmlTargetDeviceType_t, c_int, POINTER(c_uint)]
315 _clib.mbltmlGetPcieGen.restype = mbltmlStatusCode_t
316 _clib.mbltmlGetPcieLanes.argtypes = [
317 mbltmlTargetDeviceType_t,
318 c_int,
319 POINTER(c_uint),
320 ]
321 _clib.mbltmlGetPcieLanes.restype = mbltmlStatusCode_t
322 _clib.mbltmlGetPcieRev.argtypes = [mbltmlTargetDeviceType_t, c_int, POINTER(c_uint)]
323 _clib.mbltmlGetPcieRev.restype = mbltmlStatusCode_t
324 _clib.mbltmlGetPcieClassCode.argtypes = [
325 mbltmlTargetDeviceType_t,
326 c_int,
327 POINTER(c_uint),
328 ]
329 _clib.mbltmlGetPcieClassCode.restype = mbltmlStatusCode_t
330 _clib.mbltmlGetPcieSlot.argtypes = [
331 mbltmlTargetDeviceType_t,
332 c_int,
333 POINTER(c_char),
334 c_uint,
335 ]
336 _clib.mbltmlGetPcieSlot.restype = mbltmlStatusCode_t
337 _clib.mbltmlGetTotalPower.argtypes = [
338 mbltmlTargetDeviceType_t,
339 c_int,
340 POINTER(c_double),
341 ]
342 _clib.mbltmlGetTotalPower.restype = mbltmlStatusCode_t
343 _clib.mbltmlGetTotalCurrent.argtypes = [
344 mbltmlTargetDeviceType_t,
345 c_int,
346 POINTER(c_double),
347 ]
348 _clib.mbltmlGetTotalCurrent.restype = mbltmlStatusCode_t
349 _clib.mbltmlGetTotalVoltage.argtypes = [
350 mbltmlTargetDeviceType_t,
351 c_int,
352 POINTER(c_double),
353 ]
354 _clib.mbltmlGetTotalVoltage.restype = mbltmlStatusCode_t
355 _clib.mbltmlGetExtraPmicPower.argtypes = [
356 mbltmlTargetDeviceType_t,
357 c_int,
358 POINTER(c_double),
359 ]
360 _clib.mbltmlGetExtraPmicPower.restype = mbltmlStatusCode_t
361 _clib.mbltmlGetExtraPmicCurrent.argtypes = [
362 mbltmlTargetDeviceType_t,
363 c_int,
364 POINTER(c_double),
365 ]
366 _clib.mbltmlGetExtraPmicCurrent.restype = mbltmlStatusCode_t
367 _clib.mbltmlGetExtraPmicVoltage.argtypes = [
368 mbltmlTargetDeviceType_t,
369 c_int,
370 POINTER(c_double),
371 ]
372 _clib.mbltmlGetExtraPmicVoltage.restype = mbltmlStatusCode_t
373 _clib.mbltmlGetExtraPmicId.argtypes = [
374 mbltmlTargetDeviceType_t,
375 c_int,
376 POINTER(mbltmlExtraPmicId_t),
377 ]
378 _clib.mbltmlGetExtraPmicId.restype = mbltmlStatusCode_t
379 _clib.mbltmlGetTotalUtilization.argtypes = [
380 mbltmlTargetDeviceType_t,
381 c_int,
382 POINTER(c_double),
383 ]
384 _clib.mbltmlGetTotalUtilization.restype = mbltmlStatusCode_t
385 _clib.mbltmlGetMemoryUsage.argtypes = [
386 mbltmlTargetDeviceType_t,
387 c_int,
388 POINTER(c_int64),
389 ]
390 _clib.mbltmlGetMemoryUsage.restype = mbltmlStatusCode_t
391 _clib.mbltmlGetMemoryTotal.argtypes = [
392 mbltmlTargetDeviceType_t,
393 c_int,
394 POINTER(c_int64),
395 ]
396 _clib.mbltmlGetMemoryTotal.restype = mbltmlStatusCode_t
397 _clib.mbltmlGetProcessInfos.argtypes = [
398 mbltmlTargetDeviceType_t,
399 c_int,
400 POINTER(mbltmlProcessInfo_t),
401 POINTER(c_uint),
402 ]
403 _clib.mbltmlGetProcessInfos.restype = mbltmlStatusCode_t
404 _clib.mbltmlGetCoreInfos.argtypes = [
405 mbltmlTargetDeviceType_t,
406 c_int,
407 POINTER(mbltmlCoreInfo_t),
408 POINTER(c_uint),
409 ]
410 _clib.mbltmlGetCoreInfos.restype = mbltmlStatusCode_t
411 _clib.mbltmlSetExtraPmicID.argtypes = [
412 mbltmlTargetDeviceType_t,
413 c_int,
414 mbltmlExtraPmicId_t,
415 ]
416 _clib.mbltmlSetExtraPmicID.restype = mbltmlStatusCode_t
417
418
419class MBLTMLError(Exception):
420 """@brief Base exception raised by the mbltml Python binding.
421
422 Wraps a non-success mbltmlStatusCode_t returned by the underlying C
423 library. Instantiating MBLTMLError with a known status code yields the
424 matching subclass (e.g., MBLTMLInvalidArgumentError).
425
426 @var code The mbltmlStatusCode_t value associated with this exception.
427 """
428
429 _code_to_class = {}
430 _errcode_to_string = {
431 MBLTML_DRIVER_NOT_FOUND: "Driver is not found",
432 MBLTML_INVALID_ARGUMENT: "Invalid Argument",
433 MBLTML_UNINITIALIZED: "Uninitilized mbltml.",
434 MBLTML_NOT_SUPPORTED: "Unspported Function for Target Device",
435 MBLTML_INSUFFICIENT_LENGTH: "Insufficient Length",
436 MBLTML_DEVICE_NOT_FOUND: "Device is not found",
437 }
438
439 def __new__(cls, code: mbltmlStatusCode_t):
440 if cls is MBLTMLError and code in MBLTMLError._code_to_class:
441 cls = MBLTMLError._code_to_class[code]
442 obj = Exception.__new__(cls)
443 obj.code = code
444 return obj
445
446 def __str__(self):
447 return MBLTMLError._errcode_to_string[self.code]
448
449 def __eq__(self, other):
450 return self.code == other.code
451
452
453class MBLTMLDriverNotFoundError(MBLTMLError):
454 """@brief Raised when the required driver cannot be located.
455
456 Wraps MBLTML_DRIVER_NOT_FOUND.
457 """
458
459 pass
460
461
462class MBLTMLInvalidArgumentError(MBLTMLError):
463 """@brief Raised when one or more arguments are invalid.
464
465 Wraps MBLTML_INVALID_ARGUMENT. Typical causes include a NULL pointer or
466 a @c dev_no that is out of range of the target device type's device count.
467 """
468
469 pass
470
471
472class MBLTMLUninitializedError(MBLTMLError):
473 """@brief Raised when an API is called before initialization.
474
475 Wraps MBLTML_UNINITIALIZED. Call mbltmlInit() first.
476 """
477
478 pass
479
480
481class MBLTMLNotSupportedError(MBLTMLError):
482 """@brief Raised when the feature is not supported on the target device.
483
484 Wraps MBLTML_NOT_SUPPORTED.
485 """
486
487 pass
488
489
491 """@brief Raised when the output buffer is too small to hold the result.
492
493 Wraps MBLTML_INSUFFICIENT_LENGTH.
494 """
495
496 pass
497
498
499class MBLTMLDeviceNotFoundError(MBLTMLError):
500 """@brief Raised when the requested device cannot be located.
501
502 Wraps MBLTML_DEVICE_NOT_FOUND.
503 """
504
505 pass
506
507
508MBLTMLError._code_to_class = {
509 MBLTML_DRIVER_NOT_FOUND: MBLTMLDriverNotFoundError,
510 MBLTML_INVALID_ARGUMENT: MBLTMLInvalidArgumentError,
511 MBLTML_UNINITIALIZED: MBLTMLUninitializedError,
512 MBLTML_NOT_SUPPORTED: MBLTMLNotSupportedError,
513 MBLTML_INSUFFICIENT_LENGTH: MBLTMLInsufficientLengthError,
514 MBLTML_DEVICE_NOT_FOUND: MBLTMLDeviceNotFoundError,
515}
516
517
518def _mbltmlThrowError(ret: mbltmlStatusCode_t) -> None:
519 if ret != MBLTML_SUCCESS:
520 raise MBLTMLError(ret)
521
522
523# Function calls
524def mbltmlInit() -> None:
525 """@brief Initialize the mbltml library.
526
527 @throws MBLTMLError on failure.
528 """
529 _loadLibrary()
530 ret = _clib.mbltmlInit()
531 _mbltmlThrowError(ret)
532
533
534def mbltmlShutdown() -> None:
535 """@brief Release all resources held by the mbltml library.
536
537 After this call, any further API usage requires re-initialization via
538 mbltmlInit().
539
540 @throws MBLTMLError on failure.
541 """
542 _loadLibrary()
543 ret = _clib.mbltmlShutdown()
544 _mbltmlThrowError(ret)
545
546
547def mbltmlGetDeviceCount() -> int:
548 """@brief Get the total number of devices detected by the library.
549
550 @note Supported on all driver types.
551
552 This returns the number of all detected devices regardless of their target
553 device type, including devices whose target device type could not be
554 identified.
555
556 @attention Do not confuse this with mbltmlGetTargetDeviceCount(). Since
557 unidentified devices are not addressable by any (target_device_type,
558 dev_no) pair, this count may exceed the sum over every
559 mbltmlTargetDeviceType_t.
560
561 @return The number of devices detected.
562 @throws MBLTMLError on failure.
563 """
564 _loadLibrary()
565 value = c_uint()
566 ret = _clib.mbltmlGetDeviceCount(byref(value))
567 _mbltmlThrowError(ret)
568 return value.value
569
570
571def mbltmlGetTargetDeviceCount(target_device_type: mbltmlTargetDeviceType_t) -> int:
572 """@brief Get the number of detected devices of a specific target device type.
573
574 @note Supported on all driver types.
575
576 @param target_device_type Target device type whose device count is queried.
577 @return The number of devices of @p target_device_type detected, or 0 if
578 none is detected.
579 @throws MBLTMLError on failure.
580 """
581 _loadLibrary()
582 value = c_uint()
583 ret = _clib.mbltmlGetTargetDeviceCount(target_device_type, byref(value))
584 _mbltmlThrowError(ret)
585 return value.value
586
587
588def mbltmlGetDriverVersion(driver_type: mbltmlDriverType_t) -> str:
589 """@brief Get the driver version string for a specific driver.
590
591 @note Supported on all driver types.
592
593 @param driver_type Driver type whose driver version is queried.
594 @return The driver version string.
595 @throws MBLTMLError on failure.
596 """
597 _loadLibrary()
598 buf = create_string_buffer(MBLTML_DRIVER_VERSION_BUFFER_SIZE)
599 ret = _clib.mbltmlGetDriverVersion(
600 driver_type, buf, MBLTML_DRIVER_VERSION_BUFFER_SIZE
601 )
602 _mbltmlThrowError(ret)
603 return buf.value.decode()
604
605
606def mbltmlGetDriverRevision(driver_type: mbltmlDriverType_t) -> int:
607 """@brief Get the driver revision number for a specific driver.
608
609 @note Supported on all driver types.
610
611 @param driver_type Driver type whose driver revision is queried.
612 @return The driver revision number.
613 @throws MBLTMLError on failure.
614 """
615 _loadLibrary()
616 value = c_uint()
617 ret = _clib.mbltmlGetDriverRevision(driver_type, byref(value))
618 _mbltmlThrowError(ret)
619 return value.value
620
621
622def mbltmlGetNodeName(target_device_type: mbltmlTargetDeviceType_t, dev_no: int) -> str:
623 """@brief Get the node name of a device.
624
625 @note Supported on all driver types.
626
627 @param target_device_type Target device type of the device.
628 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
629 @return The node name string.
630 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
631 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
632 @throws MBLTMLError on other failures.
633 """
634 _loadLibrary()
635 buf = create_string_buffer(MBLTML_NODE_NAME_BUFFER_SIZE)
636 ret = _clib.mbltmlGetNodeName(
637 target_device_type, dev_no, buf, MBLTML_NODE_NAME_BUFFER_SIZE
638 )
639 _mbltmlThrowError(ret)
640 return buf.value.decode()
641
642
644 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
645) -> mbltmlDriverType_t:
646 """@brief Get the driver type of a device.
647
648 @note Supported on all driver types.
649
650 @param target_device_type Target device type of the device.
651 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
652 @return The mbltmlDriverType_t of the device.
653 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
654 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
655 @throws MBLTMLError on other failures.
656 """
657 _loadLibrary()
658 value = c_uint()
659 ret = _clib.mbltmlGetDriverType(target_device_type, dev_no, byref(value))
660 _mbltmlThrowError(ret)
661 return value.value
662
663
665 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
666) -> str:
667 """@brief Get the on-device driver version string of a device.
668
669 @note Supported on MBLTML_DRIVER_REGULUS_USB only.
670
671 @param target_device_type Target device type of the device.
672 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
673 @return The on-device driver version string.
674 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
675 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
676 @throws MBLTMLError on other failures.
677 """
678 _loadLibrary()
679 buf = create_string_buffer(MBLTML_ON_DEVICE_DRIVER_VERSION_BUFFER_SIZE)
680 ret = _clib.mbltmlGetOnDeviceDriverVersion(
681 target_device_type, dev_no, buf, MBLTML_ON_DEVICE_DRIVER_VERSION_BUFFER_SIZE
682 )
683 _mbltmlThrowError(ret)
684 return buf.value.decode()
685
686
688 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
689) -> int:
690 """@brief Get the on-device driver revision number of a device.
691
692 @note Supported on MBLTML_DRIVER_REGULUS_USB only.
693
694 @param target_device_type Target device type of the device.
695 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
696 @return The on-device driver revision.
697 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
698 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
699 @throws MBLTMLError on other failures.
700 """
701 _loadLibrary()
702 value = c_uint()
703 ret = _clib.mbltmlGetOnDeviceDriverRevision(
704 target_device_type, dev_no, byref(value)
705 )
706 _mbltmlThrowError(ret)
707 return value.value
708
709
711 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
712) -> str:
713 """@brief Get the firmware version string of a device.
714
715 @note Supported on MBLTML_DRIVER_ARIES only.
716
717 @param target_device_type Target device type of the device.
718 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
719 @return The firmware version string.
720 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
721 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
722 @throws MBLTMLError on other failures.
723 """
724 _loadLibrary()
725 buf = create_string_buffer(MBLTML_FIRMWARE_VERSION_BUFFER_SIZE)
726 ret = _clib.mbltmlGetFirmwareVersion(
727 target_device_type, dev_no, buf, MBLTML_FIRMWARE_VERSION_BUFFER_SIZE
728 )
729 _mbltmlThrowError(ret)
730 return buf.value.decode()
731
732
734 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
735) -> int:
736 """@brief Get the firmware revision number of a device.
737
738 @note Supported on MBLTML_DRIVER_ARIES only.
739
740 @param target_device_type Target device type of the device.
741 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
742 @return The firmware revision.
743 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
744 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
745 @throws MBLTMLError on other failures.
746 """
747 _loadLibrary()
748 value = c_uint()
749 ret = _clib.mbltmlGetFirmwareRevision(target_device_type, dev_no, byref(value))
750 _mbltmlThrowError(ret)
751 return value.value
752
753
755 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
756) -> int:
757 """@brief Get the CRC of the currently-loaded firmware image.
758
759 @note Supported on MBLTML_DRIVER_ARIES only.
760
761 @param target_device_type Target device type of the device.
762 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
763 @return The firmware CRC.
764 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
765 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
766 @throws MBLTMLError on other failures.
767 """
768 _loadLibrary()
769 value = c_uint()
770 ret = _clib.mbltmlGetFirmwareCRC(target_device_type, dev_no, byref(value))
771 _mbltmlThrowError(ret)
772 return value.value
773
774
776 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
777) -> int:
778 """@brief Get the current die temperature of a device.
779
780 @note Supported on all driver types.
781
782 @param target_device_type Target device type of the device.
783 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
784 @return The temperature reading.
785 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
786 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
787 @throws MBLTMLError on other failures.
788 """
789 _loadLibrary()
790 value = c_int()
791 ret = _clib.mbltmlGetTemperature(target_device_type, dev_no, byref(value))
792 _mbltmlThrowError(ret)
793 return value.value
794
795
797 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
798) -> int:
799 """@brief Get the current temperature of the PCIe switch of a device.
800
801 @note Supported on MBLTML_DRIVER_ARIES only.
802 @note A valid reading is available only on the first aries-rb node of an MLA400 board. Any other ARIES device reports 0.
803 @note Requires ARIES firmware v1.2.5 or later. Earlier firmware reports 0.
804
805 @param target_device_type Target device type of the device.
806 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
807 @return The temperature reading.
808 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
809 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
810 @throws MBLTMLError on other failures.
811 """
812 _loadLibrary()
813 value = c_int()
814 ret = _clib.mbltmlGetPcieSwitchTemperature(target_device_type, dev_no, byref(value))
815 _mbltmlThrowError(ret)
816 return value.value
817
818
819def mbltmlGetChipId(target_device_type: mbltmlTargetDeviceType_t, dev_no: int) -> int:
820 """@brief Get the chip ID of a device.
821
822 @note Supported on MBLTML_DRIVER_ARIES only.
823 @note Requires ARIES firmware v1.2.5 or later. Earlier firmware reports 0.
824
825 @param target_device_type Target device type of the device.
826 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
827 @return The chip ID.
828 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
829 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
830 @throws MBLTMLError on other failures.
831 """
832 _loadLibrary()
833 value = c_int()
834 ret = _clib.mbltmlGetChipId(target_device_type, dev_no, byref(value))
835 _mbltmlThrowError(ret)
836 return value.value
837
838
840 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
841) -> int:
842 """@brief Get the current signal-type indicator reported by the device.
843
844 @note Supported on all driver types.
845
846 @param target_device_type Target device type of the device.
847 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
848 @return The signal-type value.
849 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
850 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
851 @throws MBLTMLError on other failures.
852 """
853 _loadLibrary()
854 value = c_uint()
855 ret = _clib.mbltmlGetSignalType(target_device_type, dev_no, byref(value))
856 _mbltmlThrowError(ret)
857 return value.value
858
859
860def mbltmlGetNPUClock(target_device_type: mbltmlTargetDeviceType_t, dev_no: int) -> int:
861 """@brief Get the current NPU clock frequency of a device.
862
863 @note Supported on all driver types.
864
865 @param target_device_type Target device type of the device.
866 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
867 @return The NPU clock value.
868 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
869 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
870 @throws MBLTMLError on other failures.
871 """
872 _loadLibrary()
873 value = c_uint()
874 ret = _clib.mbltmlGetNPUClock(target_device_type, dev_no, byref(value))
875 _mbltmlThrowError(ret)
876 return value.value
877
878
879def mbltmlGetBusClock(target_device_type: mbltmlTargetDeviceType_t, dev_no: int) -> int:
880 """@brief Get the current bus clock frequency of a device.
881
882 @note Supported on MBLTML_DRIVER_ARIES only.
883
884 @param target_device_type Target device type of the device.
885 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
886 @return The bus clock value.
887 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
888 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
889 @throws MBLTMLError on other failures.
890 """
891 _loadLibrary()
892 value = c_uint()
893 ret = _clib.mbltmlGetBusClock(target_device_type, dev_no, byref(value))
894 _mbltmlThrowError(ret)
895 return value.value
896
897
898def mbltmlGetFanDuty(target_device_type: mbltmlTargetDeviceType_t, dev_no: int) -> int:
899 """@brief Get the current cooling-fan duty cycle of a device.
900
901 @note Supported on MBLTML_DRIVER_ARIES only.
902
903 @param target_device_type Target device type of the device.
904 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
905 @return The fan duty value.
906 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
907 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
908 @throws MBLTMLError on other failures.
909 """
910 _loadLibrary()
911 value = c_int()
912 ret = _clib.mbltmlGetFanDuty(target_device_type, dev_no, byref(value))
913 _mbltmlThrowError(ret)
914 return value.value
915
916
917def mbltmlGetVendorId(target_device_type: mbltmlTargetDeviceType_t, dev_no: int) -> int:
918 """@brief Get the PCIe vendor ID of a device.
919
920 @note Supported on MBLTML_DRIVER_ARIES only.
921
922 @param target_device_type Target device type of the device.
923 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
924 @return The vendor ID.
925 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
926 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
927 @throws MBLTMLError on other failures.
928 """
929 _loadLibrary()
930 value = c_uint()
931 ret = _clib.mbltmlGetVendorId(target_device_type, dev_no, byref(value))
932 _mbltmlThrowError(ret)
933 return value.value
934
935
936def mbltmlGetDeviceId(target_device_type: mbltmlTargetDeviceType_t, dev_no: int) -> int:
937 """@brief Get the PCIe device ID of a device.
938
939 @note Supported on MBLTML_DRIVER_ARIES only.
940
941 @param target_device_type Target device type of the device.
942 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
943 @return The device ID.
944 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
945 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
946 @throws MBLTMLError on other failures.
947 """
948 _loadLibrary()
949 value = c_uint()
950 ret = _clib.mbltmlGetDeviceId(target_device_type, dev_no, byref(value))
951 _mbltmlThrowError(ret)
952 return value.value
953
954
956 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
957) -> int:
958 """@brief Get the PCIe subsystem vendor ID of a device.
959
960 @note Supported on MBLTML_DRIVER_ARIES only.
961
962 @param target_device_type Target device type of the device.
963 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
964 @return The subsystem vendor ID.
965 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
966 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
967 @throws MBLTMLError on other failures.
968 """
969 _loadLibrary()
970 value = c_uint()
971 ret = _clib.mbltmlGetSubVendorId(target_device_type, dev_no, byref(value))
972 _mbltmlThrowError(ret)
973 return value.value
974
975
977 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
978) -> int:
979 """@brief Get the PCIe subsystem device ID of a device.
980
981 @note Supported on MBLTML_DRIVER_ARIES only.
982
983 @param target_device_type Target device type of the device.
984 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
985 @return The subsystem device ID.
986 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
987 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
988 @throws MBLTMLError on other failures.
989 """
990 _loadLibrary()
991 value = c_uint()
992 ret = _clib.mbltmlGetSubDeviceId(target_device_type, dev_no, byref(value))
993 _mbltmlThrowError(ret)
994 return value.value
995
996
997def mbltmlGetPcieGen(target_device_type: mbltmlTargetDeviceType_t, dev_no: int) -> int:
998 """@brief Get the negotiated PCIe link generation of a device.
999
1000 @note Supported on MBLTML_DRIVER_ARIES only.
1001
1002 @param target_device_type Target device type of the device.
1003 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1004 @return The PCIe generation.
1005 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1006 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1007 @throws MBLTMLError on other failures.
1008 """
1009 _loadLibrary()
1010 value = c_uint()
1011 ret = _clib.mbltmlGetPcieGen(target_device_type, dev_no, byref(value))
1012 _mbltmlThrowError(ret)
1013 return value.value
1014
1015
1017 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1018) -> int:
1019 """@brief Get the negotiated PCIe link width (in lanes) of a device.
1020
1021 @note Supported on MBLTML_DRIVER_ARIES only.
1022
1023 @param target_device_type Target device type of the device.
1024 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1025 @return The lane count.
1026 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1027 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1028 @throws MBLTMLError on other failures.
1029 """
1030 _loadLibrary()
1031 value = c_uint()
1032 ret = _clib.mbltmlGetPcieLanes(target_device_type, dev_no, byref(value))
1033 _mbltmlThrowError(ret)
1034 return value.value
1035
1036
1037def mbltmlGetPcieRev(target_device_type: mbltmlTargetDeviceType_t, dev_no: int) -> int:
1038 """@brief Get the PCIe configuration-space revision ID of a device.
1039
1040 @note Supported on MBLTML_DRIVER_ARIES only.
1041
1042 @param target_device_type Target device type of the device.
1043 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1044 @return The revision value.
1045 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1046 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1047 @throws MBLTMLError on other failures.
1048 """
1049 _loadLibrary()
1050 value = c_uint()
1051 ret = _clib.mbltmlGetPcieRev(target_device_type, dev_no, byref(value))
1052 _mbltmlThrowError(ret)
1053 return value.value
1054
1055
1057 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1058) -> int:
1059 """@brief Get the PCIe configuration-space class code of a device.
1060
1061 @note Supported on MBLTML_DRIVER_ARIES only.
1062
1063 @param target_device_type Target device type of the device.
1064 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1065 @return The class code.
1066 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1067 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1068 @throws MBLTMLError on other failures.
1069 """
1070 _loadLibrary()
1071 value = c_uint()
1072 ret = _clib.mbltmlGetPcieClassCode(target_device_type, dev_no, byref(value))
1073 _mbltmlThrowError(ret)
1074 return value.value
1075
1076
1077def mbltmlGetPcieSlot(target_device_type: mbltmlTargetDeviceType_t, dev_no: int) -> str:
1078 """@brief Get the PCIe slot location of a device.
1079
1080 @note Supported on MBLTML_DRIVER_ARIES only.
1081
1082 @param target_device_type Target device type of the device.
1083 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1084 @return The slot location string, formatted either as an ACPI path (e.g. "0-1-2") or as a BDF address (e.g. "0000:01:00.0").
1085 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1086 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1087 @throws MBLTMLError on other failures.
1088 """
1089 _loadLibrary()
1090 buf = create_string_buffer(MBLTML_PCIE_SLOT_BUFFER_SIZE)
1091 ret = _clib.mbltmlGetPcieSlot(
1092 target_device_type, dev_no, buf, MBLTML_PCIE_SLOT_BUFFER_SIZE
1093 )
1094 _mbltmlThrowError(ret)
1095 return buf.value.decode()
1096
1097
1099 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1100) -> float:
1101 """@brief Get the total instantaneous power consumption of a device (W).
1102
1103 @note Supported on MBLTML_DRIVER_ARIES only.
1104
1105 @param target_device_type Target device type of the device.
1106 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1107 @return The power reading.
1108 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1109 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1110 @throws MBLTMLError on other failures.
1111 """
1112 _loadLibrary()
1113 value = c_double()
1114 ret = _clib.mbltmlGetTotalPower(target_device_type, dev_no, byref(value))
1115 _mbltmlThrowError(ret)
1116 return value.value
1117
1118
1120 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1121) -> float:
1122 """@brief Get the total instantaneous current draw of a device (A).
1123
1124 @note Supported on MBLTML_DRIVER_ARIES only.
1125
1126 @param target_device_type Target device type of the device.
1127 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1128 @return The current reading.
1129 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1130 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1131 @throws MBLTMLError on other failures.
1132 """
1133 _loadLibrary()
1134 value = c_double()
1135 ret = _clib.mbltmlGetTotalCurrent(target_device_type, dev_no, byref(value))
1136 _mbltmlThrowError(ret)
1137 return value.value
1138
1139
1141 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1142) -> float:
1143 """@brief Get the total instantaneous supply voltage of a device (V).
1144
1145 @note Supported on MBLTML_DRIVER_ARIES only.
1146
1147 @param target_device_type Target device type of the device.
1148 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1149 @return The voltage reading.
1150 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1151 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1152 @throws MBLTMLError on other failures.
1153 """
1154 _loadLibrary()
1155 value = c_double()
1156 ret = _clib.mbltmlGetTotalVoltage(target_device_type, dev_no, byref(value))
1157 _mbltmlThrowError(ret)
1158 return value.value
1159
1160
1162 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1163) -> float:
1164 """@brief Get the power consumption of the extra PMIC rail currently
1165 selected for the device (W).
1166
1167 @note Supported on MBLTML_DRIVER_ARIES only.
1168
1169 The selected rail is controlled by mbltmlSetExtraPmicID() and can be
1170 queried via mbltmlGetExtraPmicId().
1171
1172 The firmware refreshes this reading once per second. After changing the
1173 selected rail with mbltmlSetExtraPmicID(), allow up to 1 second for the
1174 new rail's value to be reported.
1175
1176 @param target_device_type Target device type of the device.
1177 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1178 @return The power reading.
1179 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1180 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1181 @throws MBLTMLError on other failures.
1182 """
1183 _loadLibrary()
1184 value = c_double()
1185 ret = _clib.mbltmlGetExtraPmicPower(target_device_type, dev_no, byref(value))
1186 _mbltmlThrowError(ret)
1187 return value.value
1188
1189
1191 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1192) -> float:
1193 """@brief Get the current of the extra PMIC rail currently selected
1194 for the device (A).
1195
1196 @note Supported on MBLTML_DRIVER_ARIES only.
1197
1198 The firmware refreshes this reading once per second. After changing the
1199 selected rail with mbltmlSetExtraPmicID(), allow up to 1 second for the
1200 new rail's value to be reported.
1201
1202 @param target_device_type Target device type of the device.
1203 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1204 @return The current reading.
1205 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1206 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1207 @throws MBLTMLError on other failures.
1208 """
1209 _loadLibrary()
1210 value = c_double()
1211 ret = _clib.mbltmlGetExtraPmicCurrent(target_device_type, dev_no, byref(value))
1212 _mbltmlThrowError(ret)
1213 return value.value
1214
1215
1217 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1218) -> float:
1219 """@brief Get the voltage of the extra PMIC rail currently selected
1220 for the device (V).
1221
1222 @note Supported on MBLTML_DRIVER_ARIES only.
1223
1224 The firmware refreshes this reading once per second. After changing the
1225 selected rail with mbltmlSetExtraPmicID(), allow up to 1 second for the
1226 new rail's value to be reported.
1227
1228 @param target_device_type Target device type of the device.
1229 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1230 @return The voltage reading.
1231 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1232 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1233 @throws MBLTMLError on other failures.
1234 """
1235 _loadLibrary()
1236 value = c_double()
1237 ret = _clib.mbltmlGetExtraPmicVoltage(target_device_type, dev_no, byref(value))
1238 _mbltmlThrowError(ret)
1239 return value.value
1240
1241
1243 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1244) -> mbltmlExtraPmicId_t:
1245 """@brief Get the extra PMIC rail currently selected for the device.
1246
1247 @note Supported on MBLTML_DRIVER_ARIES only.
1248
1249 @param target_device_type Target device type of the device.
1250 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1251 @return The selected mbltmlExtraPmicId_t value.
1252 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1253 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1254 @throws MBLTMLError on other failures.
1255 """
1256 _loadLibrary()
1257 value = c_uint()
1258 ret = _clib.mbltmlGetExtraPmicId(target_device_type, dev_no, byref(value))
1259 _mbltmlThrowError(ret)
1260 return value.value
1261
1262
1264 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1265) -> float:
1266 """@brief Get the overall NPU utilization of a device.
1267
1268 @note Supported on all driver types.
1269
1270 @param target_device_type Target device type of the device.
1271 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1272 @return The utilization value (typically a ratio in [0.0, 1.0] or a percentage).
1273 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1274 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1275 @throws MBLTMLError on other failures.
1276 """
1277 _loadLibrary()
1278 value = c_double()
1279 ret = _clib.mbltmlGetTotalUtilization(target_device_type, dev_no, byref(value))
1280 _mbltmlThrowError(ret)
1281 return value.value
1282
1283
1285 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1286) -> int:
1287 """@brief Get the amount of device memory currently in use.
1288
1289 @note Supported on all driver types.
1290
1291 @param target_device_type Target device type of the device.
1292 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1293 @return The in-use memory in bytes.
1294 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1295 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1296 @throws MBLTMLError on other failures.
1297 """
1298 _loadLibrary()
1299 value = c_int64()
1300 ret = _clib.mbltmlGetMemoryUsage(target_device_type, dev_no, byref(value))
1301 _mbltmlThrowError(ret)
1302 return value.value
1303
1304
1306 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1307) -> int:
1308 """@brief Get the total amount of device memory available.
1309
1310 @note Supported on all driver types.
1311
1312 @param target_device_type Target device type of the device.
1313 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1314 @return The total memory in bytes.
1315 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1316 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1317 @throws MBLTMLError on other failures.
1318 """
1319 _loadLibrary()
1320 value = c_int64()
1321 ret = _clib.mbltmlGetMemoryTotal(target_device_type, dev_no, byref(value))
1322 _mbltmlThrowError(ret)
1323 return value.value
1324
1325
1327 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1328) -> List[mbltmlProcessInfo_t]:
1329 """@brief Get per-process usage information for a device.
1330
1331 @note Supported on all driver types.
1332
1333 @param target_device_type Target device type of the device.
1334 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1335 @return List of mbltmlProcessInfo_t records; empty if no process is running.
1336 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1337 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1338 @throws MBLTMLError on other failures.
1339 """
1340 _loadLibrary()
1341 c_count = c_uint(0)
1342 ret = _clib.mbltmlGetProcessInfos(target_device_type, dev_no, None, byref(c_count))
1343 _mbltmlThrowError(ret)
1344 if c_count.value == 0: # No running process
1345 return []
1346 c_count.value = c_count.value * 2 # Padding to handle increased process number
1347 info_array = mbltmlProcessInfo_t * c_count.value
1348 infos = info_array()
1349 ret = _clib.mbltmlGetProcessInfos(target_device_type, dev_no, infos, byref(c_count))
1350 _mbltmlThrowError(ret)
1351 return [infos[i] for i in range(c_count.value)]
1352
1353
1355 target_device_type: mbltmlTargetDeviceType_t, dev_no: int
1356) -> List[mbltmlCoreInfo_t]:
1357 """@brief Get per-core usage information for a device.
1358
1359 @note Supported on all driver types.
1360
1361 @param target_device_type Target device type of the device.
1362 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1363 @return List of mbltmlCoreInfo_t records.
1364 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1365 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1366 @throws MBLTMLError on other failures.
1367 """
1368 _loadLibrary()
1369 c_count = c_uint(0)
1370 ret = _clib.mbltmlGetCoreInfos(target_device_type, dev_no, None, byref(c_count))
1371 _mbltmlThrowError(ret)
1372 if c_count.value == 0: # No core
1373 return []
1374 c_count.value = c_count.value
1375 info_array = mbltmlCoreInfo_t * c_count.value
1376 infos = info_array()
1377 ret = _clib.mbltmlGetCoreInfos(target_device_type, dev_no, infos, byref(c_count))
1378 _mbltmlThrowError(ret)
1379 return [infos[i] for i in range(c_count.value)]
1380
1381
1383 target_device_type: mbltmlTargetDeviceType_t,
1384 dev_no: int,
1385 pmic_id: mbltmlExtraPmicId_t,
1386) -> None:
1387 """@brief Select which extra PMIC rail subsequent mbltmlGetExtraPmic*() queries refer to.
1388
1389 @note Supported on aries-rb device (MBLTML_TARGET_DEVICE_ARIES_RB) only.
1390
1391 The underlying readings are refreshed by firmware once per second; allow
1392 up to 1 second after this call before mbltmlGetExtraPmicPower(),
1393 mbltmlGetExtraPmicCurrent() and mbltmlGetExtraPmicVoltage() reflect the
1394 newly selected rail.
1395
1396 @param target_device_type Target device type of the device.
1397 @param dev_no Device index within @p target_device_type. Device count is obtained via mbltmlGetTargetDeviceCount().
1398 @param pmic_id Identifier of the extra PMIC rail to select.
1399 @throws MBLTMLInvalidArgumentError if @p dev_no is out of range of the @p target_device_type device count.
1400 @throws MBLTMLDeviceNotFoundError if no device of @p target_device_type is detected.
1401 @throws MBLTMLError on other failures.
1402 """
1403 _loadLibrary()
1404 ret = _clib.mbltmlSetExtraPmicID(target_device_type, dev_no, pmic_id)
1405 _mbltmlThrowError(ret)
1406
1407
1408
Raised when the requested device cannot be located.
Definition mbltml.py:499
Raised when the required driver cannot be located.
Definition mbltml.py:453
Raised when the output buffer is too small to hold the result.
Definition mbltml.py:490
Raised when the feature is not supported on the target device.
Definition mbltml.py:481
Raised when an API is called before initialization.
Definition mbltml.py:472
None mbltmlShutdown()
Release all resources held by the mbltml library.
Definition mbltml.py:534
int mbltmlGetVendorId(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the PCIe vendor ID of a device.
Definition mbltml.py:917
int mbltmlGetFirmwareCRC(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the CRC of the currently-loaded firmware image.
Definition mbltml.py:756
List[mbltmlProcessInfo_t] mbltmlGetProcessInfos(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get per-process usage information for a device.
Definition mbltml.py:1328
int mbltmlGetTemperature(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the current die temperature of a device.
Definition mbltml.py:777
List[mbltmlCoreInfo_t] mbltmlGetCoreInfos(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get per-core usage information for a device.
Definition mbltml.py:1356
int mbltmlGetPcieGen(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the negotiated PCIe link generation of a device.
Definition mbltml.py:997
int mbltmlGetNPUClock(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the current NPU clock frequency of a device.
Definition mbltml.py:860
int mbltmlGetTargetDeviceCount(mbltmlTargetDeviceType_t target_device_type)
Get the number of detected devices of a specific target device type.
Definition mbltml.py:571
float mbltmlGetExtraPmicCurrent(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the current of the extra PMIC rail currently selected for the device (A).
Definition mbltml.py:1192
int mbltmlGetFanDuty(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the current cooling-fan duty cycle of a device.
Definition mbltml.py:898
int mbltmlGetChipId(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the chip ID of a device.
Definition mbltml.py:819
float mbltmlGetTotalUtilization(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the overall NPU utilization of a device.
Definition mbltml.py:1265
int mbltmlGetSubDeviceId(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the PCIe subsystem device ID of a device.
Definition mbltml.py:978
int mbltmlGetMemoryUsage(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the amount of device memory currently in use.
Definition mbltml.py:1286
int mbltmlGetFirmwareRevision(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the firmware revision number of a device.
Definition mbltml.py:735
int mbltmlGetPcieSwitchTemperature(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the current temperature of the PCIe switch of a device.
Definition mbltml.py:798
int mbltmlGetBusClock(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the current bus clock frequency of a device.
Definition mbltml.py:879
float mbltmlGetExtraPmicVoltage(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the voltage of the extra PMIC rail currently selected for the device (V).
Definition mbltml.py:1218
float mbltmlGetTotalCurrent(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the total instantaneous current draw of a device (A).
Definition mbltml.py:1121
float mbltmlGetTotalPower(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the total instantaneous power consumption of a device (W).
Definition mbltml.py:1100
mbltmlDriverType_t mbltmlGetDriverType(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the driver type of a device.
Definition mbltml.py:645
int mbltmlGetOnDeviceDriverRevision(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the on-device driver revision number of a device.
Definition mbltml.py:689
int mbltmlGetSignalType(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the current signal-type indicator reported by the device.
Definition mbltml.py:841
float mbltmlGetTotalVoltage(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the total instantaneous supply voltage of a device (V).
Definition mbltml.py:1142
str mbltmlGetDriverVersion(mbltmlDriverType_t driver_type)
Get the driver version string for a specific driver.
Definition mbltml.py:588
str mbltmlGetNodeName(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the node name of a device.
Definition mbltml.py:622
str mbltmlGetFirmwareVersion(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the firmware version string of a device.
Definition mbltml.py:712
str mbltmlGetOnDeviceDriverVersion(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the on-device driver version string of a device.
Definition mbltml.py:666
int mbltmlGetPcieRev(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the PCIe configuration-space revision ID of a device.
Definition mbltml.py:1037
int mbltmlGetSubVendorId(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the PCIe subsystem vendor ID of a device.
Definition mbltml.py:957
None mbltmlSetExtraPmicID(mbltmlTargetDeviceType_t target_device_type, int dev_no, mbltmlExtraPmicId_t pmic_id)
Select which extra PMIC rail subsequent mbltmlGetExtraPmic*() queries refer to.
Definition mbltml.py:1386
int mbltmlGetMemoryTotal(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the total amount of device memory available.
Definition mbltml.py:1307
mbltmlExtraPmicId_t mbltmlGetExtraPmicId(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the extra PMIC rail currently selected for the device.
Definition mbltml.py:1244
int mbltmlGetDeviceId(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the PCIe device ID of a device.
Definition mbltml.py:936
str mbltmlGetPcieSlot(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the PCIe slot location of a device.
Definition mbltml.py:1077
int mbltmlGetPcieLanes(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the negotiated PCIe link width (in lanes) of a device.
Definition mbltml.py:1018
int mbltmlGetDriverRevision(mbltmlDriverType_t driver_type)
Get the driver revision number for a specific driver.
Definition mbltml.py:606
int mbltmlGetDeviceCount()
Get the total number of devices detected by the library.
Definition mbltml.py:547
None mbltmlInit()
Initialize the mbltml library.
Definition mbltml.py:524
int mbltmlGetPcieClassCode(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the PCIe configuration-space class code of a device.
Definition mbltml.py:1058
float mbltmlGetExtraPmicPower(mbltmlTargetDeviceType_t target_device_type, int dev_no)
Get the power consumption of the extra PMIC rail currently selected for the device (W).
Definition mbltml.py:1163
Composite identifier of an NPU core (cluster + core).
Definition type.h:104
Per-core usage record returned by mbltmlGetCoreInfos().
Definition type.h:115
Per-process usage record returned by mbltmlGetProcessInfos().
Definition type.h:128