mbltml.py Source File

mbltml.py Source File#

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