habana-pyhlml 1.10.0.494__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of habana-pyhlml might be problematic. Click here for more details.

pyhlml/main.py ADDED
@@ -0,0 +1,1063 @@
1
+ import ctypes
2
+
3
+ from sys import modules
4
+ from typing import Tuple
5
+
6
+ import pyhlml.hlml_types as hlml_t
7
+
8
+ from pyhlml.hlml_lib import LibHLML
9
+ from pyhlml.hlml_error import HLMLError, ErrorsAsClass
10
+
11
+ _hlmlOBJ = None
12
+
13
+ def _wrapperInit():
14
+ """ init module level object and error classes
15
+ Parameters: None
16
+ Returns: None
17
+ """
18
+ ErrorsAsClass()
19
+ setattr(modules[__name__], "_hlmlOBJ", LibHLML())
20
+
21
+ def check_return(ret):
22
+ """ Checks ret for any error.
23
+ Parameters:
24
+ ret - Symbol for checking if return was valid.
25
+ Returns:
26
+ ret - Symbol for current error status.
27
+ """
28
+ if (ret != hlml_t.HLML_RETURN.HLML_SUCCESS ):
29
+ raise HLMLError(ret)
30
+ return ret
31
+
32
+ def hlmlInit() -> None:
33
+ """ Must be called before any other api can be used
34
+ Parameters: None
35
+ Returns: None
36
+ """
37
+ _wrapperInit()
38
+ global _hlmlOBJ
39
+
40
+ fn = _hlmlOBJ.get_func_ptr("hlml_init")
41
+ ret = fn()
42
+
43
+ _hlmlOBJ.inc_ref()
44
+ check_return(ret)
45
+ return None
46
+
47
+ def hlmlInitWithFlags(flags=0) -> None:
48
+ """ Allows the user to call the init function with a flag.
49
+ Parameters:
50
+ flags (int) [ default=0 ] - only the default is supported
51
+ Returns: None
52
+ """
53
+ _wrapperInit()
54
+ global _hlmlOBJ
55
+
56
+ fn = _hlmlOBJ.get_func_ptr("hlml_init_with_flags")
57
+ ret = fn(flags)
58
+
59
+ _hlmlOBJ.inc_ref()
60
+ check_return(ret)
61
+ return None
62
+
63
+ def hlmlShutdown() -> None:
64
+ """ Shutdown should be called last.
65
+ Parameters: None
66
+ Returns: None
67
+ """
68
+ global _hlmlOBJ
69
+
70
+ fn = _hlmlOBJ.get_func_ptr("hlml_shutdown")
71
+ ret = fn()
72
+
73
+ for _ in range(_hlmlOBJ.ref_count):
74
+ _hlmlOBJ.dec_ref()
75
+ check_return(ret)
76
+ return None
77
+
78
+ def hlmlDeviceGetCount() -> int:
79
+ """ Returns the number of Habana devices in the system.
80
+ Parameters: None
81
+ Returns:
82
+ count (int) - Number of habana devices.
83
+ Ex. An HLS1-H would return 4
84
+ """
85
+ global _hlmlOBJ
86
+ count = ctypes.c_uint()
87
+
88
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_count")
89
+ ret = fn(ctypes.byref(count))
90
+
91
+ check_return(ret)
92
+ return count.value
93
+
94
+ def hlmlDeviceGetHandleByPCIBusID(pci_addr: str) -> hlml_t.HLML_DEVICE.TYPE:
95
+ """ Acquire the handle for a device, based on PCI Address
96
+ Parameters:
97
+ pci_addr (str) - The PCI Address of a habana device.
98
+ Returns:
99
+ device (HLML_DEVICE.TYPE) - The handle for the habana device.
100
+ """
101
+ global _hlmlOBJ
102
+
103
+ device = hlml_t.HLML_DEVICE.TYPE
104
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_handle_by_pci_bus_id")
105
+ ret = fn(str.encode(pci_addr), ctypes.byref(device))
106
+
107
+ check_return(ret)
108
+ return device
109
+
110
+ def hlmlDeviceGetHandleByIndex(index: int) -> hlml_t.HLML_DEVICE.TYPE:
111
+ """ Acquire device handle by index
112
+ Parameters:
113
+ index (int) - The index of a habana device.
114
+ Returns:
115
+ device (HLML_DEVICE.TYPE) - The handle for the habana device.
116
+ """
117
+ global _hlmlOBJ
118
+ device = hlml_t.HLML_DEVICE.TYPE
119
+
120
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_handle_by_index")
121
+ ret = fn(index, ctypes.byref(device))
122
+
123
+ check_return(ret)
124
+ return device
125
+
126
+ def hlmlDeviceGetHandleByUUID(uuid: str) -> hlml_t.HLML_DEVICE.TYPE:
127
+ """ Acquire device handle by UUID
128
+ Parameters:
129
+ uuid (str) - A Universal Unique ID for a habana device to access.
130
+ Returns:
131
+ device (HLML_DEVICE.TYPE) - The handle for the habana device.
132
+ """
133
+ global _hlmlOBJ
134
+ device = hlml_t.HLML_DEVICE.TYPE
135
+
136
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_handle_by_UUID")
137
+ ret = fn(str.encode(uuid), ctypes.byref(device))
138
+
139
+ check_return(ret)
140
+ return device
141
+
142
+ def hlmlDeviceGetName(device: hlml_t.HLML_DEVICE.TYPE) -> str:
143
+ """ Acquire name of device from handle
144
+ Parameters:
145
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
146
+ Returns:
147
+ name (str) - The name of the habana device.
148
+ """
149
+ global _hlmlOBJ
150
+ name = ctypes.create_string_buffer(hlml_t.HLML_DEFINE.HL_FIELD_MAX_SIZE)
151
+
152
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_name")
153
+ ret = fn(
154
+ device, ctypes.byref(name),
155
+ ctypes.c_uint(hlml_t.HLML_DEFINE.HL_FIELD_MAX_SIZE)
156
+ )
157
+
158
+ check_return(ret)
159
+ return name.value
160
+
161
+ def hlmlDeviceGetPCIInfo(device: hlml_t.HLML_DEVICE.TYPE) -> hlml_t.c_hlml_pci_info:
162
+ """ Get the PCI attributes of input device
163
+ Parameters:
164
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
165
+ Returns:
166
+ pci_info (c_hlml_pci_info) - The PCI attributes of the given device.
167
+ """
168
+ global _hlmlOBJ
169
+ pci_info = hlml_t.c_hlml_pci_info()
170
+
171
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_pci_info")
172
+ ret = fn(
173
+ device, ctypes.byref(pci_info),
174
+ ctypes.c_uint(hlml_t.HLML_DEFINE.HL_FIELD_MAX_SIZE)
175
+ )
176
+
177
+ check_return(ret)
178
+ return pci_info
179
+
180
+ def hlmlDeviceGetClockInfo(device: hlml_t.HLML_DEVICE.TYPE, clock_type=0 ) -> int:
181
+ """ Retrives the current speed of the selected clock (MHz)
182
+ Parameters:
183
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
184
+ clock_type ( 0-SOC ( GAUDI ) / 1-IC ( GOYA ) / 2-MME ( GOYA ) / 3-TPC ( GOYA ) )
185
+ Returns:
186
+ speed (int) - The clock speed of the selected clock in MHz.
187
+ """
188
+ global _hlmlOBJ
189
+ speed = ctypes.c_uint()
190
+
191
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_clock_info")
192
+ ret = fn(device, clock_type, ctypes.byref(speed))
193
+
194
+ check_return(ret)
195
+ return speed.value
196
+
197
+ def hlmlDeviceGetMaxClockInfo(device: hlml_t.HLML_DEVICE.TYPE, clock_type=0 ) -> int:
198
+ """ Retrives the maximum speed of the selected clock (MHz)
199
+ Parameters:
200
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
201
+ clock_type ( 0-SOC ( GAUDI ) / 1-IC ( GOYA ) / 2-MME ( GOYA ) / 3-TPC ( GOYA ) )
202
+ Returns:
203
+ speed (int) - The MAXIMUM clock speed of the selected clock in MHz.
204
+ """
205
+ global _hlmlOBJ
206
+ speed = ctypes.c_uint()
207
+
208
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_max_clock_info")
209
+ ret = fn(device, clock_type, ctypes.byref(speed))
210
+
211
+ check_return(ret)
212
+ return speed.value
213
+
214
+ def hlmlDeviceGetUtilizationRates(device: hlml_t.HLML_DEVICE.TYPE) -> int:
215
+ """ Returns utilization over the past second as a percentage
216
+ Parameters:
217
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
218
+ Returns:
219
+ hlml_util (int) - The utilization rate over the last second as a percentage.
220
+ """
221
+ global _hlmlOBJ
222
+ hlml_util = hlml_t.c_hlml_utilization()
223
+
224
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_utilization_rates")
225
+ ret = fn(device, ctypes.byref(hlml_util))
226
+
227
+ check_return(ret)
228
+ return hlml_util.aip
229
+
230
+ def hlmlDeviceGetMemoryInfo(device: hlml_t.HLML_DEVICE.TYPE) -> hlml_t.c_hlml_memory:
231
+ """ Returns the total, used, and free memory in bytes
232
+ Parameters:
233
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
234
+ Returns:
235
+ hlml_mem (c_hlml_memory) - The total memory and how much is used/free in bytes.
236
+ """
237
+ global _hlmlOBJ
238
+ hlml_mem = hlml_t.c_hlml_memory()
239
+
240
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_memory_info")
241
+ ret = fn(device, ctypes.byref(hlml_mem))
242
+
243
+ check_return(ret)
244
+ return hlml_mem
245
+
246
+ def hlmlDeviceGetTemperature(
247
+ device: hlml_t.HLML_DEVICE.TYPE, sensor_type: hlml_t.HLML_TEMP_SENS.TYPE) -> int:
248
+ """ Retrives the current temperature (celsius) of the selected sensor_type
249
+ Parameters:
250
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
251
+ sensor_types ( 0-AIP / 1-BOARD )
252
+ Returns:
253
+ temp (int) - The temperature recorded at the given sensor in celsius.
254
+ """
255
+ global _hlmlOBJ
256
+ temp = ctypes.c_uint()
257
+
258
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_temperature")
259
+ ret = fn(device, sensor_type, ctypes.byref(temp))
260
+
261
+ check_return(ret)
262
+ return temp.value
263
+
264
+ def hlmlDeviceGetTemperatureThreshold(device: hlml_t.HLML_DEVICE.TYPE, threshold_type: int) -> int:
265
+ """ Retrieves the known temperature (celsius) threshold of the requested type
266
+ Parameters:
267
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
268
+ threshold_type (0-shutdown / 1-slowdown / 2-memory / 3-gpu ) - Which threshold temp to check.
269
+ Returns:
270
+ temp (int) - The temperature the given threshold is set at in celsius.
271
+ """
272
+ global _hlmlOBJ
273
+ temp = ctypes.c_uint()
274
+
275
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_temperature_threshold")
276
+ ret = fn(device, threshold_type, ctypes.byref(temp))
277
+
278
+ check_return(ret)
279
+ return temp.value
280
+
281
+ def hlmlDeviceGetPersistenceMode(device: hlml_t.HLML_DEVICE.TYPE) -> hlml_t.HLML_ENABLE_STATE:
282
+ """ Retrieves the persistence mode of the device
283
+ Parameters:
284
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
285
+ Returns:
286
+ mode (int) - The persistence mode of the device.
287
+ """
288
+ global _hlmlOBJ
289
+ mode = ctypes.c_uint()
290
+
291
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_persistence_mode")
292
+ ret = fn(device, ctypes.byref(mode))
293
+
294
+ check_return(ret)
295
+ return mode.value
296
+
297
+ def hlmlDeviceGetPerformanceState(device: hlml_t.HLML_DEVICE.TYPE) -> hlml_t.HLML_P_STATES:
298
+ """ Retrieves the performance state of the device
299
+ Parameters:
300
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
301
+ Returns:
302
+ p_state (int) - The performance state of the device.
303
+ """
304
+ global _hlmlOBJ
305
+ p_state = ctypes.c_uint()
306
+
307
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_performance_state")
308
+ ret = fn(device, ctypes.byref(p_state))
309
+
310
+ check_return(ret)
311
+ return p_state.value
312
+
313
+ def hlmlDeviceGetPowerUsage(device: hlml_t.HLML_DEVICE.TYPE) -> int:
314
+ """ Retrieves power usage for the device in mW
315
+ Parameters:
316
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
317
+ Returns:
318
+ power (int) - The given device's power usage in mW.
319
+ """
320
+ global _hlmlOBJ
321
+ power = ctypes.c_uint()
322
+
323
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_power_usage")
324
+ ret = fn(device, ctypes.byref(power))
325
+
326
+ check_return(ret)
327
+ return power.value
328
+
329
+ def hlmlDeviceGetPowerManagementDefaultLimit(device: hlml_t.HLML_DEVICE.TYPE) -> int:
330
+ """ Retrieves default power management limit on this device in mW
331
+ Parameters:
332
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
333
+ Returns:
334
+ power (int) - The power limit on the device in mW.
335
+ """
336
+ global _hlmlOBJ
337
+ power = ctypes.c_uint()
338
+
339
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_power_management_default_limit")
340
+ ret = fn(device, ctypes.byref(power))
341
+
342
+ check_return(ret)
343
+ return power.value
344
+
345
+ def hlmlDeviceGetECCMode(device: hlml_t.HLML_DEVICE.TYPE) -> dict:
346
+ """ Retrieves the current and pending ECC modes of the device
347
+ Parameters:
348
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
349
+ Returns:
350
+ out (dict) - The current and pending ECC modes for the device.
351
+ """
352
+ global _hlmlOBJ
353
+ out = hlml_t.hlml_ecc_mode()
354
+ current = ctypes.c_uint()
355
+ pending = ctypes.c_uint()
356
+
357
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_ecc_mode")
358
+ ret = fn(device, ctypes.byref(current), ctypes.byref(pending))
359
+
360
+ check_return(ret)
361
+ setattr(out, "current", current)
362
+ setattr(out, "pending", pending)
363
+
364
+ return out
365
+
366
+ def hlmlDeviceGetTotalECCErrors(device: hlml_t.HLML_DEVICE.TYPE, error_type: hlml_t.HLML_MEMORY_ERROR.TYPE, counter_type: hlml_t.HLML_ECC_COUNTER) -> int:
367
+ """ Returns the number of ECC errors for a device. Number is from the last reset, or driver
368
+ reinstall. Currently only the number of corrected errors is supported.
369
+ Parameters:
370
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
371
+ error_type ( 0-CORRECTED / 1-UNCORRECTED ) - The type of errors to count.
372
+ counter_type ( 0-VOLATILE / 1-AGGREGATE ) - The type of counter to use.
373
+ Returns:
374
+ count (int) - The number of ECC errors for the device, specified by parameters.
375
+ """
376
+ global _hlmlOBJ
377
+ count = ctypes.c_longlong()
378
+
379
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_total_ecc_errors")
380
+ ret = fn(device, error_type, counter_type, ctypes.byref(count))
381
+
382
+ check_return(ret)
383
+ return count.value
384
+
385
+ def hlmlDeviceGetMemoryErrorCounter(device: hlml_t.HLML_DEVICE.TYPE, error_type: hlml_t.HLML_MEMORY_ERROR.TYPE, counter_type: hlml_t.HLML_ECC_COUNTER.TYPE, location: hlml_t.HLML_MEMORY_LOCATION.TYPE) -> int:
386
+ """ Returns the number of ECC errors for a device at a specified memory location.
387
+ Number is from the last reset, or driver reinstall. Currently only the number
388
+ of corrected errors is supported.
389
+ Parameters:
390
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
391
+ error_type ( 0-CORRECTED / 1-UNCORRECTED ) - The type of errors to count.
392
+ counter_type ( 0-VOLATILE / 1-AGGREGATE ) - The type of counter to use.
393
+ location ( 0-SRAM / 1-DRAM ) - The type of memory.
394
+ Returns:
395
+ count (int) - The number of ECC errors for the device, specified by parameters.
396
+ """
397
+ global _hlmlOBJ
398
+ ecc_count = ctypes.c_longlong()
399
+
400
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_memory_error_counter")
401
+ ret = fn(device, error_type, counter_type, location, ctypes.byref(ecc_count))
402
+
403
+ check_return(ret)
404
+ return ecc_count.value
405
+
406
+ def hlmlDeviceGetUUID(device: hlml_t.HLML_DEVICE.TYPE) -> str:
407
+ """ Returns the UUID of the device
408
+ Parameters:
409
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
410
+ Returns:
411
+ name (str) - The UUID for the given device.
412
+ """
413
+ global _hlmlOBJ
414
+ name_len = hlml_t.COMMON_DEFINE.VERSION_MAX_LEN
415
+ name = ctypes.create_string_buffer(name_len)
416
+
417
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_uuid")
418
+ ret = fn(device, ctypes.byref(name), name_len)
419
+
420
+ check_return(ret)
421
+ return name.value
422
+
423
+ def hlmlDeviceGetMinorNumber(device: hlml_t.HLML_DEVICE.TYPE) -> int:
424
+ """ Retrieves the minor number of the device ( maps to the device node file )
425
+ at /sys/class/habanalabs/hl[minor]
426
+ Parameters:
427
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
428
+ Returns:
429
+ number (int) - The minor number for the device.
430
+ """
431
+ global _hlmlOBJ
432
+ number = ctypes.c_uint()
433
+
434
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_minor_number")
435
+ ret = fn(device, ctypes.byref(number))
436
+
437
+ check_return(ret)
438
+ return number.value
439
+
440
+ def hlmlEventSetCreate() -> hlml_t.HLML_EVENT_SET.TYPE:
441
+ """ Create an empty set of events
442
+ Parameters: None.
443
+ Returns:
444
+ st (HLML_EVENT_SET) - An empty set of events.
445
+ """
446
+ global _hlmlOBJ
447
+ st = hlml_t.HLML_EVENT_SET.TYPE
448
+
449
+ fn = _hlmlOBJ.get_func_ptr("hlml_event_set_create")
450
+ ret = fn(ctypes.byref(st))
451
+
452
+ check_return(ret)
453
+ return st
454
+
455
+ def hlmlEventSetFree(st: hlml_t.HLML_EVENT_SET.TYPE) -> None:
456
+ """ Release a set of events
457
+ Parameters:
458
+ st (HLML_EVENT_SET) - The set of events to be released.
459
+ Returns: None.
460
+ """
461
+ global _hlmlOBJ
462
+
463
+ fn = _hlmlOBJ.get_func_ptr("hlml_event_set_free")
464
+ ret = fn(st)
465
+
466
+ check_return(ret)
467
+ return None
468
+
469
+ def hlmlDeviceRegisterEvents(
470
+ device: hlml_t.HLML_DEVICE.TYPE, event_types: int,
471
+ st: hlml_t.HLML_EVENT_SET.TYPE
472
+ ) -> None:
473
+ """ Start recording events on input device add events to input set
474
+ Parameters:
475
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
476
+ event_types ( 0-ECC_err / 1-Crit_err / 2-Clock_change ) - The type of events to start recording.
477
+ st (HLML_EVENT_SET) - The set of events to be released.
478
+ Returns: None.
479
+ """
480
+ global _hlmlOBJ
481
+
482
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_register_events")
483
+ ret = fn(device, event_types, st)
484
+
485
+ check_return(ret)
486
+ return None
487
+
488
+ def hlmlEventSetWait(st: hlml_t.HLML_EVENT_SET.TYPE, timeout: int) -> hlml_t.c_hlml_event_data:
489
+ """ Waits on events and delivers events.
490
+ If some events are ready to be delivered at the time of the call, function returns immediately.
491
+ If there are no events ready to be delivered, function sleeps until the event arrives but not longer than the specified timeout.
492
+ Parameters:
493
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
494
+ timeout (int) - The maximum time to wait for a new event.
495
+ Returns:
496
+ data (c_hlml_event_data) - The data from events ready to be delivered.
497
+ """
498
+ global _hlmlOBJ
499
+ data = hlml_t.c_hlml_event_data()
500
+
501
+ fn = _hlmlOBJ.get_func_ptr("hlml_event_set_wait")
502
+ ret = fn(st, ctypes.byref(data), timeout)
503
+
504
+ check_return(ret)
505
+ return data
506
+
507
+ def hlmlDeviceGetMACInfo(
508
+ device: hlml_t.HLML_DEVICE.TYPE, count=20, start=1) -> hlml_t.c_hlml_mac_info:
509
+ """ Get MAC addresses of device.
510
+ Parameters:
511
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
512
+ Count (int) - How many addresses to return.
513
+ Start (int) - The index to start at.
514
+ Returns:
515
+ mac (c_hlml_mac_info array of size count) - The MAC addresses of the device.
516
+ """
517
+ global _hlmlOBJ
518
+ mac = (hlml_t.c_hlml_mac_info * count)()
519
+ actual_info_count = ctypes.c_int()
520
+
521
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_mac_info")
522
+ ret = fn(device, ctypes.byref(mac), count, start, ctypes.byref(actual_info_count))
523
+
524
+ check_return(ret)
525
+ return mac
526
+
527
+ def hlmlDeviceERRInject(device: hlml_t.HLML_DEVICE.TYPE, err_type: int) -> None:
528
+ """ Inject error to test response
529
+ Parameters:
530
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
531
+ err_type ( 0-endless_cmd / 1-non_fatal / 2-fatal / 3-lose_heartbeat / 4-thermal) - The type of error to inject.
532
+ Returns: None.
533
+ """
534
+ global _hlmlOBJ
535
+
536
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_err_inject")
537
+ ret = fn(device, err_type)
538
+
539
+ check_return(ret)
540
+ return None
541
+
542
+ def hlmlDeviceGetHLRevision(device: hlml_t.HLML_DEVICE.TYPE) -> int:
543
+ """ Returns HL revision
544
+ Parameters:
545
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
546
+ Returns:
547
+ rev (int) - The HL revision
548
+ """
549
+ global _hlmlOBJ
550
+ rev = ctypes.c_int()
551
+
552
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_hl_revision")
553
+ ret = fn(device, ctypes.byref(rev))
554
+
555
+ check_return(ret)
556
+ return rev.value
557
+
558
+ def hlmlDeviceGetPCBInfo(device: hlml_t.HLML_DEVICE.TYPE) -> hlml_t.c_hlml_pcb_info:
559
+ """ Returns the PCB info
560
+ Parameters:
561
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
562
+ Returns:
563
+ pcb (c_hlml_pcb_info) - The info about the device's PCB.
564
+ """
565
+ global _hlmlOBJ
566
+ pcb = hlml_t.c_hlml_pcb_info()
567
+
568
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_pcb_info")
569
+ ret = fn(device, ctypes.byref(pcb))
570
+
571
+ check_return(ret)
572
+ return pcb
573
+
574
+ def hlmlDeviceGetSerial(device: hlml_t.HLML_DEVICE.TYPE) -> str:
575
+ """ Returns the unique board sn
576
+ Parameters:
577
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
578
+ Returns:
579
+ ser (str) - The serial number of the device.
580
+ """
581
+ global _hlmlOBJ
582
+ ser_len = hlml_t.HLML_DEFINE.HL_FIELD_MAX_SIZE
583
+ ser = ctypes.create_string_buffer(ser_len)
584
+
585
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_serial")
586
+ ret = fn(device, ctypes.byref(ser), ser_len)
587
+
588
+ check_return(ret)
589
+ return ser.value
590
+
591
+ def hlmlDeviceGetModuleID(device: hlml_t.HLML_DEVICE.TYPE) -> int:
592
+ """ Retrieves the module id configured on the device.
593
+ Parameters:
594
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
595
+ Returns:
596
+ module_id (int) - The module id configured on the device.
597
+ """
598
+ global _hlmlOBJ
599
+ module_id = ctypes.c_uint()
600
+
601
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_module_id")
602
+ ret = fn(device, ctypes.byref(module_id))
603
+
604
+ check_return(ret)
605
+ return module_id.value
606
+
607
+ def hlmlDeviceGetBoardID(device: hlml_t.HLML_DEVICE.TYPE) -> int:
608
+ """ Retrieves the device boardID ( 0 - 7 )
609
+ Parameters:
610
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
611
+ Returns:
612
+ brd (int) - The board id of which slot the device is in.
613
+ """
614
+ global _hlmlOBJ
615
+ brd = ctypes.c_uint()
616
+
617
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_board_id")
618
+ ret = fn(device, ctypes.byref(brd))
619
+
620
+ check_return(ret)
621
+ return brd.value
622
+
623
+ def hlmlDeviceGetPCIEThroughput(device: hlml_t.HLML_DEVICE.TYPE, counter_type: int) -> int:
624
+ """ Retrieve PCIe utilization information ( over 10ms interval )
625
+ counter_type ( 0-TX / 1-RX )
626
+ Parameters:
627
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
628
+ counter_type (int) -----------------------------------------------------------------------------
629
+ Returns:
630
+ throughput (int) - The throughput on the PCIE Transfer or Recieve Connection.
631
+ """
632
+ global _hlmlOBJ
633
+ pcie = ctypes.c_uint()
634
+
635
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_pcie_throughput")
636
+ ret = fn(device, counter_type, ctypes.byref(pcie))
637
+
638
+ check_return(ret)
639
+ return pcie.value
640
+
641
+ def hlmlDeviceGetPCIEReplayCounter(device: hlml_t.HLML_DEVICE.TYPE) -> int:
642
+ """ Retrieve the PCIe replay counter
643
+ Parameters:
644
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
645
+ Returns:
646
+ pcie (int) - The replay counter of the PCIE device.
647
+ """
648
+ global _hlmlOBJ
649
+ pcie = ctypes.c_uint()
650
+
651
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_pcie_replay_counter")
652
+ ret = fn(device, ctypes.byref(pcie))
653
+
654
+ check_return(ret)
655
+ return pcie.value
656
+
657
+ def hlmlDeviceGetCurrPCIELinkGeneration(device: hlml_t.HLML_DEVICE.TYPE) -> int:
658
+ """ Retrieve the current PCIe link generation
659
+ Parameters:
660
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
661
+ Returns:
662
+ link (int) - The generation of the device's PCIe link.
663
+ """
664
+ global _hlmlOBJ
665
+ link = ctypes.c_uint()
666
+
667
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_curr_pcie_link_generation")
668
+ ret = fn(device, ctypes.byref(link))
669
+
670
+ check_return(ret)
671
+ return link.value
672
+
673
+ def hlmlDeviceGetCurrPCIELinkWidth(device: hlml_t.HLML_DEVICE.TYPE) -> int:
674
+ """ Retrieve the current PCIe link width
675
+ Parameters:
676
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
677
+ Returns:
678
+ width (int) - The width or lanes of the PCIE connection.
679
+ """
680
+ global _hlmlOBJ
681
+ width = ctypes.c_uint()
682
+
683
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_curr_pcie_link_width")
684
+ ret = fn(device, ctypes.byref(width))
685
+
686
+ check_return(ret)
687
+ return width.value
688
+
689
+ def hlmlDeviceGetCurrentClocksThrottleReasons(device: hlml_t.HLML_DEVICE.TYPE) -> int:
690
+ """ Retrieves the current clocks reason for throttling
691
+ Parameters:
692
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
693
+ Returns:
694
+ reason (int) - A code for the reason for the current clock throttle.
695
+ """
696
+ global _hlmlOBJ
697
+ reason = ctypes.c_ulonglong()
698
+
699
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_current_clocks_throttle_reasons")
700
+ ret = fn(device, ctypes.byref(reason))
701
+
702
+ check_return(ret)
703
+ return reason.value
704
+
705
+ def hlmlDeviceGetTotalEnergyConsumption(device: hlml_t.HLML_DEVICE.TYPE) -> int:
706
+ """ Retrieves total energy consumption in mJ since the driver was last reloaded
707
+ Parameters:
708
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
709
+ Returns:
710
+ energy (int) - Total energy consumption of the habana device.
711
+ """
712
+ global _hlmlOBJ
713
+ energy = ctypes.c_ulonglong()
714
+
715
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_total_energy_consumption")
716
+ ret = fn(device, ctypes.byref(energy))
717
+
718
+ check_return(ret)
719
+ return energy.value
720
+
721
+ def hlmlDeviceGetMacAddrInfo(device: hlml_t.HLML_DEVICE.TYPE) -> Tuple[Tuple[int, int], Tuple[int, int]]:
722
+ """ Retrieves the masks for supported ports and external ports.
723
+ Parameters:
724
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
725
+ Returns:
726
+ (mask, ext_mask)
727
+ mask is a tuple of two ints containing bitmask for supported ports.
728
+ mask_ext is a tuple of two ints containing bitmask for external
729
+ ports within the supported ports.
730
+ """
731
+ global _hlmlOBJ
732
+ mask = (ctypes.c_uint64 * 2)()
733
+ ext_mask = (ctypes.c_uint64 * 2)()
734
+
735
+ fn = _hlmlOBJ.get_func_ptr("hlml_get_mac_addr_info")
736
+ ret = fn(device, ctypes.byref(mask), ctypes.byref(ext_mask))
737
+
738
+ check_return(ret)
739
+ return (mask[0], mask[1]), (ext_mask[0], ext_mask[1])
740
+
741
+ def hlmlDeviceNicGetLink(device: hlml_t.HLML_DEVICE.TYPE, port: int) -> bool:
742
+ """ Retrieves the NICs link status (up/down) for the requested port.
743
+ Parameters:
744
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
745
+ port - Port for which the status is requested.
746
+ Returns:
747
+ up (bool) - Status of the port, True if up and False if down.
748
+ """
749
+ global _hlmlOBJ
750
+ up = ctypes.c_bool()
751
+
752
+ fn = _hlmlOBJ.get_func_ptr("hlml_nic_get_link")
753
+ ret = fn(device, ctypes.c_uint32(port), ctypes.byref(up))
754
+
755
+ check_return(ret)
756
+ return up.value
757
+
758
+ def hlmlDeviceNicGetStatistics(device: hlml_t.HLML_DEVICE.TYPE, port: int, num_of_counts: int = None) -> hlml_t.c_hlml_nic_stats_info:
759
+ """ Retrieves the NICs statistics for the requested port.
760
+ Parameters:
761
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
762
+ port (int) - Port for which the stats is requested.
763
+ [optional] num_of_counts (int) - num of counts to allocate
764
+ Returns:
765
+ nic_stats_info (c_hlml_nic_stats_info) - The nic statistics
766
+ """
767
+ global _hlmlOBJ
768
+ nic_stats_info = hlml_t.c_hlml_nic_stats_info(port, num_of_counts)
769
+
770
+ fn = _hlmlOBJ.get_func_ptr("hlml_nic_get_statistics")
771
+ ret = fn(device, ctypes.byref(nic_stats_info))
772
+
773
+ check_return(ret)
774
+ return nic_stats_info
775
+
776
+ def hlmlGetHLMLVersion() -> str:
777
+ """ Returns version of hlml library.
778
+ Returns:
779
+ ver (str) - Version of hlml library.
780
+ """
781
+ global _hlmlOBJ
782
+ ver_len = hlml_t.COMMON_DEFINE.VERSION_MAX_LEN
783
+ version = ctypes.create_string_buffer(ver_len)
784
+
785
+ fn = _hlmlOBJ.get_func_ptr("hlml_get_hlml_version")
786
+ ret = fn(version, ctypes.c_uint(ver_len))
787
+
788
+ check_return(ret)
789
+ return version.value
790
+
791
+ def hlmlGetDriverVersion() -> str:
792
+ """ Return version of driver.
793
+ Returns:
794
+ ver (str) - Version of driver.
795
+ """
796
+ global _hlmlOBJ
797
+ ver_len = hlml_t.COMMON_DEFINE.VERSION_MAX_LEN
798
+ version = ctypes.create_string_buffer(ver_len)
799
+
800
+ fn = _hlmlOBJ.get_func_ptr("hlml_get_driver_version")
801
+ ret = fn(version, ctypes.c_uint(ver_len))
802
+
803
+ check_return(ret)
804
+ return version.value
805
+
806
+ def hlmlDeviceGetModelNumber(device: hlml_t.HLML_DEVICE.TYPE) -> str:
807
+ """ Returns model number.
808
+ Parameters:
809
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
810
+ Returns:
811
+ model (str) - model number (in string format).
812
+ """
813
+ global _hlmlOBJ
814
+ num_len = hlml_t.HLML_DEFINE.HL_FIELD_MAX_SIZE
815
+ num_str = ctypes.create_string_buffer(num_len)
816
+
817
+ fn = _hlmlOBJ.get_func_ptr("hlml_get_model_number")
818
+ ret = fn(device, num_str, ctypes.c_uint(num_len))
819
+
820
+ check_return(ret)
821
+ return num_str.value
822
+
823
+ def hlmlDeviceGetFirmwareFITVersion(device: hlml_t.HLML_DEVICE.TYPE) -> str:
824
+ """ Return firmware fit version.
825
+ Parameters:
826
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
827
+ Returns:
828
+ ver (str) - firmware fit version.
829
+ """
830
+ global _hlmlOBJ
831
+ ver_len = hlml_t.COMMON_DEFINE.VERSION_MAX_LEN
832
+ ver_str = ctypes.create_string_buffer(ver_len)
833
+
834
+ fn = _hlmlOBJ.get_func_ptr("hlml_get_firmware_fit_version")
835
+ ret = fn(device, ver_str, ctypes.c_uint(ver_len))
836
+
837
+ check_return(ret)
838
+ return ver_str.value
839
+
840
+ def hlmlDeviceGetFirmwareSPIVersion(device: hlml_t.HLML_DEVICE.TYPE) -> str:
841
+ """ Return firmware spi version.
842
+ Parameters:
843
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
844
+ Returns:
845
+ ver (str) - firmware spi version.
846
+ """
847
+ global _hlmlOBJ
848
+ ver_len = hlml_t.COMMON_DEFINE.VERSION_MAX_LEN
849
+ ver_str = ctypes.create_string_buffer(ver_len)
850
+
851
+ fn = _hlmlOBJ.get_func_ptr("hlml_get_firmware_spi_version")
852
+ ret = fn(device, ver_str, ctypes.c_uint(ver_len))
853
+
854
+ check_return(ret)
855
+ return ver_str.value
856
+
857
+ def hlmlDeviceGetFWBootVersion(device: hlml_t.HLML_DEVICE.TYPE) -> str:
858
+ """ Return fw boot version.
859
+ Parameters:
860
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
861
+ Returns:
862
+ ver (str) - fw boot version.
863
+ """
864
+ global _hlmlOBJ
865
+ ver_len = hlml_t.COMMON_DEFINE.VERSION_MAX_LEN
866
+ ver_str = ctypes.create_string_buffer(ver_len)
867
+
868
+ fn = _hlmlOBJ.get_func_ptr("hlml_get_fw_boot_version")
869
+ ret = fn(device, ver_str, ctypes.c_uint(ver_len))
870
+
871
+ check_return(ret)
872
+ return ver_str.value
873
+
874
+ def hlmlDeviceGetFWOSVersion(device: hlml_t.HLML_DEVICE.TYPE) -> str:
875
+ """ Return fw os version.
876
+ Parameters:
877
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
878
+ Returns:
879
+ ver (str) - fw os version.
880
+ """
881
+ global _hlmlOBJ
882
+ ver_len = hlml_t.COMMON_DEFINE.VERSION_MAX_LEN
883
+ ver_str = ctypes.create_string_buffer(ver_len)
884
+
885
+ fn = _hlmlOBJ.get_func_ptr("hlml_get_fw_os_version")
886
+ ret = fn(device, ver_str, ctypes.c_uint(ver_len))
887
+
888
+ check_return(ret)
889
+ return ver_str.value
890
+
891
+ def hlmlDeviceGetCPLDVersion(device: hlml_t.HLML_DEVICE.TYPE) -> str:
892
+ """ Return cpld version.
893
+ Parameters:
894
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
895
+ Returns:
896
+ ver (str) - cpld version.
897
+ """
898
+ global _hlmlOBJ
899
+ ver_len = hlml_t.COMMON_DEFINE.VERSION_MAX_LEN
900
+ ver_str = ctypes.create_string_buffer(ver_len)
901
+
902
+ fn = _hlmlOBJ.get_func_ptr("hlml_get_cpld_version")
903
+ ret = fn(device, ver_str, ctypes.c_uint(ver_len))
904
+
905
+ check_return(ret)
906
+ return ver_str.value
907
+
908
+ def hlmlDeviceClearCpuAffinity(device: hlml_t.HLML_DEVICE.TYPE) -> None:
909
+ """ Clears a devices Cpu affinity
910
+ Parameters:
911
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
912
+ Returns:
913
+ None.
914
+ """
915
+ global _hlmlOBJ
916
+
917
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_clear_cpu_affinity")
918
+ ret = fn(device)
919
+
920
+ check_return(ret)
921
+ return None
922
+
923
+ def hlmlDeviceGetCpuAffinity(device: hlml_t.HLML_DEVICE.TYPE, cpu_set_size: int):
924
+ """ Retrieves the CPU affinity set associated with a device.
925
+ Parameters:
926
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
927
+ cpu_set_size - The size of the cpu set.
928
+ Returns:
929
+ cpu_set (int) - The cpu set.
930
+ """
931
+ global _hlmlOBJ
932
+ cpu_set = (ctypes.c_ulong * cpu_set_size)()
933
+
934
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_cpu_affinity")
935
+ ret = fn(device, cpu_set_size, ctypes.byref(cpu_set))
936
+
937
+ check_return(ret)
938
+ return cpu_set
939
+
940
+ def hlmlDeviceGetCpuAffinityWithinScope(device: hlml_t.HLML_DEVICE.TYPE, cpu_set_size: int, scope: hlml_t.HLML_AFFINITY_SCOPE.TYPE):
941
+ """ Retrieves the CPU affinity set associated with a device.
942
+ Parameters:
943
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
944
+ cpu_set_size - The size of the cpu set.
945
+ scope - The affinity scope.
946
+ Returns:
947
+ cpu_set (int) - The cpu set.
948
+ """
949
+ global _hlmlOBJ
950
+ cpu_set = (ctypes.c_ulong * cpu_set_size)()
951
+
952
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_cpu_affinity_within_scope")
953
+ ret = fn(device, cpu_set_size, ctypes.byref(cpu_set), scope)
954
+
955
+ check_return(ret)
956
+ return cpu_set
957
+
958
+ def hlmlDeviceGetMemoryAffinity(device: hlml_t.HLML_DEVICE.TYPE, node_set_size: int, scope: hlml_t.HLML_AFFINITY_SCOPE.TYPE):
959
+ """ Retrieves the memory affinity set associated with a device.
960
+ Parameters:
961
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
962
+ node_set_size - The size of the node set.
963
+ scope - The affinity scope.
964
+ Returns:
965
+ node_set (int) - The node set.
966
+ """
967
+ global _hlmlOBJ
968
+ node_set = (ctypes.c_ulong * cpu_set_size)()
969
+
970
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_memory_affinity")
971
+ ret = fn(device, node_set_size, ctypes.byref(node_set), scope)
972
+
973
+ check_return(ret)
974
+ return node_set
975
+
976
+ def hlmlDeviceSetCpuAffinity(device: hlml_t.HLML_DEVICE.TYPE) -> None:
977
+ """ Sets the CPU affinity with a device.
978
+ Parameters:
979
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
980
+ Returns:
981
+ None.
982
+ """
983
+ global _hlmlOBJ
984
+
985
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_set_cpu_affinity")
986
+ ret = fn(device)
987
+
988
+ check_return(ret)
989
+ return None
990
+
991
+ def hlmlDeviceGetViolationStatus(device: hlml_t.HLML_DEVICE.TYPE, perf_policy: hlml_t.HLML_PERF_POLICY.TYPE) -> hlml_t.c_hlml_violation_time:
992
+ """ Gets the violation status of a device.
993
+ Parameters:
994
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
995
+ perf_policy_type (HLML_PERF_POLICY.TYPE) - The perf policy type (
996
+ 0=HLML_PERF_POLICY_POWER
997
+ 1=HLML_PERF_POLICY_THERMAL)
998
+ Returns:
999
+ violation_time (c_hlml_violation_time) - The violation status of the device.
1000
+ """
1001
+ global _hlmlOBJ
1002
+
1003
+ violation_time = hlml_t.c_hlml_violation_time()
1004
+
1005
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_violation_status")
1006
+ ret = fn(device, perf_policy, ctypes.byref(violation_time))
1007
+
1008
+ check_return(ret)
1009
+ return violation_time
1010
+
1011
+ def hlmlDeviceGetReplacedRowsCount(device: hlml_t.HLML_DEVICE.TYPE, cause: hlml_t.HLML_ROW_REPLACEMENT_CAUSE.TYPE) -> int:
1012
+ """ Returns the number of replaced rows.
1013
+ Parameters:
1014
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
1015
+ cause (HLML_ROW_REPLACEMENT_CAUSE.TYPE) - The replacement cause to query.
1016
+ Returns:
1017
+ row_count -> The number of replaced rows
1018
+ """
1019
+ global _hlmlOBJ
1020
+
1021
+ row_count = ctypes.c_uint()
1022
+
1023
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_replaced_rows")
1024
+ ret = fn(device, cause, ctypes.byref(row_count), None)
1025
+
1026
+ check_return(ret)
1027
+ return row_count.value
1028
+
1029
+ def hlmlDeviceGetReplacedRows(device: hlml_t.HLML_DEVICE.TYPE, cause: hlml_t.HLML_ROW_REPLACEMENT_CAUSE.TYPE, row_count: int):
1030
+ """ Returns an array of rows replaced by the given cause.
1031
+ Parameters:
1032
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
1033
+ cause (HLML_ROW_REPLACEMENT_CAUSE.TYPE) - The replacement cause to query.
1034
+ Returns:
1035
+ addresses - An array of hlml_t.c_hlml_row_address structures.
1036
+ """
1037
+ global _hlmlOBJ
1038
+
1039
+ c_row_count = ctypes.c_uint(row_count)
1040
+ addresses = (hlml_t.c_hlml_row_address * row_count)()
1041
+
1042
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_replaced_rows")
1043
+ ret = fn(device, cause, ctypes.byref(c_row_count), ctypes.byref(addresses))
1044
+
1045
+ check_return(ret)
1046
+ return addresses
1047
+
1048
+ def hlmlDeviceGetReplacedRowsPendingStatus(device: hlml_t.HLML_DEVICE.TYPE) -> int:
1049
+ """ Returns the pending status of replaced rows.
1050
+ Parameters:
1051
+ device (HLML_DEVICE.TYPE) - The handle for a habana device.
1052
+ Returns:
1053
+ is_pending - If there is pending row status.
1054
+ """
1055
+ global _hlmlOBJ
1056
+
1057
+ is_pending = ctypes.c_uint()
1058
+
1059
+ fn = _hlmlOBJ.get_func_ptr("hlml_device_get_replaced_rows_pending_status")
1060
+ ret = fn(device, ctypes.byref(is_pending))
1061
+
1062
+ check_return(ret)
1063
+ return is_pending.value