gpustack-runtime 0.1.40.post1__py3-none-any.whl → 0.1.41.post1__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.
Files changed (66) hide show
  1. gpustack_runtime/__init__.py +1 -1
  2. gpustack_runtime/__main__.py +5 -3
  3. gpustack_runtime/_version.py +2 -2
  4. gpustack_runtime/_version_appendix.py +1 -1
  5. gpustack_runtime/cmds/__init__.py +5 -3
  6. gpustack_runtime/cmds/__types__.py +1 -1
  7. gpustack_runtime/cmds/deployer.py +140 -18
  8. gpustack_runtime/cmds/detector.py +1 -1
  9. gpustack_runtime/cmds/images.py +1 -1
  10. gpustack_runtime/deployer/__init__.py +28 -2
  11. gpustack_runtime/deployer/__patches__.py +1 -1
  12. gpustack_runtime/deployer/__types__.py +2 -1
  13. gpustack_runtime/deployer/__utils__.py +2 -2
  14. gpustack_runtime/deployer/cdi/__init__.py +86 -5
  15. gpustack_runtime/deployer/cdi/__types__.py +92 -29
  16. gpustack_runtime/deployer/cdi/__utils__.py +180 -0
  17. gpustack_runtime/deployer/cdi/amd.py +146 -0
  18. gpustack_runtime/deployer/cdi/ascend.py +164 -0
  19. gpustack_runtime/deployer/cdi/hygon.py +147 -0
  20. gpustack_runtime/deployer/cdi/iluvatar.py +136 -0
  21. gpustack_runtime/deployer/cdi/metax.py +148 -0
  22. gpustack_runtime/deployer/cdi/thead.py +57 -23
  23. gpustack_runtime/deployer/docker.py +9 -8
  24. gpustack_runtime/deployer/k8s/deviceplugin/__init__.py +325 -0
  25. gpustack_runtime/deployer/k8s/deviceplugin/__types__.py +131 -0
  26. gpustack_runtime/deployer/k8s/deviceplugin/plugin.py +590 -0
  27. gpustack_runtime/deployer/k8s/types/kubelet/deviceplugin/v1beta1/__init__.py +3 -0
  28. gpustack_runtime/deployer/k8s/types/kubelet/deviceplugin/v1beta1/api.proto +212 -0
  29. gpustack_runtime/deployer/k8s/types/kubelet/deviceplugin/v1beta1/api_pb2.py +86 -0
  30. gpustack_runtime/deployer/k8s/types/kubelet/deviceplugin/v1beta1/api_pb2.pyi +168 -0
  31. gpustack_runtime/deployer/k8s/types/kubelet/deviceplugin/v1beta1/api_pb2_grpc.py +358 -0
  32. gpustack_runtime/deployer/k8s/types/kubelet/deviceplugin/v1beta1/constants.py +34 -0
  33. gpustack_runtime/deployer/kuberentes.py +50 -4
  34. gpustack_runtime/deployer/podman.py +9 -8
  35. gpustack_runtime/detector/__init__.py +42 -5
  36. gpustack_runtime/detector/__types__.py +8 -24
  37. gpustack_runtime/detector/__utils__.py +46 -39
  38. gpustack_runtime/detector/amd.py +55 -66
  39. gpustack_runtime/detector/ascend.py +29 -41
  40. gpustack_runtime/detector/cambricon.py +3 -3
  41. gpustack_runtime/detector/hygon.py +21 -49
  42. gpustack_runtime/detector/iluvatar.py +44 -60
  43. gpustack_runtime/detector/metax.py +54 -37
  44. gpustack_runtime/detector/mthreads.py +74 -36
  45. gpustack_runtime/detector/nvidia.py +130 -93
  46. gpustack_runtime/detector/pyacl/__init__.py +1 -1
  47. gpustack_runtime/detector/pyamdgpu/__init__.py +1 -1
  48. gpustack_runtime/detector/pyamdsmi/__init__.py +1 -1
  49. gpustack_runtime/detector/pycuda/__init__.py +1 -1
  50. gpustack_runtime/detector/pydcmi/__init__.py +1 -1
  51. gpustack_runtime/detector/pyhsa/__init__.py +1 -1
  52. gpustack_runtime/detector/pymxsml/__init__.py +1553 -1
  53. gpustack_runtime/detector/pyrocmcore/__init__.py +1 -1
  54. gpustack_runtime/detector/pyrocmsmi/__init__.py +1 -1
  55. gpustack_runtime/detector/thead.py +41 -60
  56. gpustack_runtime/envs.py +106 -12
  57. gpustack_runtime/logging.py +6 -2
  58. {gpustack_runtime-0.1.40.post1.dist-info → gpustack_runtime-0.1.41.post1.dist-info}/METADATA +6 -1
  59. gpustack_runtime-0.1.41.post1.dist-info/RECORD +67 -0
  60. gpustack_runtime/detector/pymxsml/mxsml.py +0 -1580
  61. gpustack_runtime/detector/pymxsml/mxsml_extension.py +0 -816
  62. gpustack_runtime/detector/pymxsml/mxsml_mcm.py +0 -476
  63. gpustack_runtime-0.1.40.post1.dist-info/RECORD +0 -55
  64. {gpustack_runtime-0.1.40.post1.dist-info → gpustack_runtime-0.1.41.post1.dist-info}/WHEEL +0 -0
  65. {gpustack_runtime-0.1.40.post1.dist-info → gpustack_runtime-0.1.41.post1.dist-info}/entry_points.txt +0 -0
  66. {gpustack_runtime-0.1.40.post1.dist-info → gpustack_runtime-0.1.41.post1.dist-info}/licenses/LICENSE +0 -0
@@ -1 +1,1553 @@
1
- from .mxsml_mcm import *
1
+ from ctypes import *
2
+ from functools import wraps
3
+ import sys
4
+ import os
5
+ import string
6
+
7
+
8
+ ## enums ##
9
+ _mxSmlDeviceBrand_t = c_uint
10
+ MXSML_BRAND_UNKNOWN = 0
11
+ MXSML_BRAND_N = 1
12
+ MXSML_BRAND_C = 2
13
+ MXSML_BRAND_G = 3
14
+
15
+ _mxSmlDeviceVirtualizationMode_t = c_uint
16
+ MXSML_VIRTUALIZATION_MODE_NONE = 0 # Represents bare metal
17
+ MXSML_VIRTUALIZATION_MODE_PF = 1 # Physical function after virtualization
18
+ MXSML_VIRTUALIZATION_MODE_VF = 2 # Virtualized device
19
+
20
+ _mxSmlVersionUnit_t = c_uint
21
+ MXSML_VERSION_BIOS = 0
22
+ MXSML_VERSION_DRIVER = 1
23
+ MXSML_VERSION_SMP0 = 2
24
+ MXSML_VERSION_SMP1 = 3
25
+ MXSML_VERSION_CCX0 = 4
26
+ MXSML_VERSION_CCX1 = 5
27
+ MXSML_VERSION_CCX2 = 6
28
+ MXSML_VERSION_CCX3 = 7 # Only valid for N-class device
29
+
30
+ _mxSmlPmbusUnit_t = c_uint
31
+ MXSML_PMBUS_SOC = 0
32
+ MXSML_PMBUS_CORE = 1
33
+ MXSML_PMBUS_HBM = 2
34
+ MXSML_PMBUS_PCIE = 3
35
+ MXSML_PMBUS_HBM2 = 4
36
+
37
+ _mxSmlTemperatureSensors_t = c_uint
38
+ MXSML_TEMPERATURE_HOTSPOT = 0 # Chip max temperature
39
+ MXSML_TEMPERATURE_HOTLIMIT = 1 # Chip temperature limit
40
+ MXSML_TEMPERATURE_SOC = 2 # Power DrMOS soc
41
+ MXSML_TEMPERATURE_CORE = 3 # Power DrMOS core
42
+ MXSML_TEMPERATURE_CCX_DNOC = 4 # Deprecated. Do not use
43
+ MXSML_TEMPERATURE_CSC_FUSE = 5 # Deprecated. Do not use
44
+ MXSML_TEMPERATURE_CCX_DLA_VPUE1_ATH = 6 # Deprecated. Do not use
45
+ MXSML_TEMPERATURE_VPUE1 = 7 # Deprecated. Do not use
46
+ MXSML_TEMPERATURE_VPUE0 = 8 # Deprecated. Do not use
47
+ MXSML_TEMPERATURE_ATUL2 = 9 # Deprecated. Do not use
48
+ MXSML_TEMPERATURE_DLA1 = 10 # Chip, Valid for N-class device
49
+ MXSML_TEMPERATURE_DLA0 = 11 # Chip, Valid for N-class device
50
+ MXSML_TEMPERATURE_EMC0 = 12 # Air inlet, Valid for C-class device
51
+ MXSML_TEMPERATURE_EMC1 = 13 # Tdiode, Valid for C-class device
52
+ MXSML_TEMPERATURE_SGM = 14 # Air outlet, Valid for C-class device
53
+
54
+ _mxSmlRasIp_t = c_uint
55
+ MXSML_RAS_MC = 0
56
+ MXSML_RAS_PCIE = 1
57
+ MXSML_RAS_FUSE = 2
58
+ MXSML_RAS_G2D = 3
59
+ MXSML_RAS_INT = 4
60
+ MXSML_RAS_HAG = 5
61
+ MXSML_RAS_METALK = 6
62
+ MXSML_RAS_SMP0 = 7
63
+ MXSML_RAS_SMP1 = 8
64
+ MXSML_RAS_CCX0 = 9
65
+ MXSML_RAS_CCX1 = 10
66
+ MXSML_RAS_CCX2 = 11
67
+ MXSML_RAS_CCX3 = 12
68
+ MXSML_RAS_DLA0 = 13
69
+ MXSML_RAS_DLA1 = 14
70
+ MXSML_RAS_VPUE0 = 15
71
+ MXSML_RAS_VPUE1 = 16
72
+ MXSML_RAS_VPUD0 = 17
73
+ MXSML_RAS_VPUD1 = 18
74
+ MXSML_RAS_VPUD2 = 19
75
+ MXSML_RAS_VPUD3 = 20
76
+ MXSML_RAS_VPUD4 = 21
77
+ MXSML_RAS_VPUD5 = 22
78
+ MXSML_RAS_VPUD6 = 23
79
+ MXSML_RAS_VPUD7 = 24
80
+ MXSML_RAS_DMA0 = 25
81
+ MXSML_RAS_DMA2 = 26
82
+ MXSML_RAS_DMA2 = 27
83
+ MXSML_RAS_DMA3 = 28
84
+ MXSML_RAS_DMA4 = 29
85
+ MXSML_RAS_MCCTL0 = 30
86
+ MXSML_RAS_MCCTL1 = 31
87
+ MXSML_RAS_MCCTL2 = 32
88
+ MXSML_RAS_MCCTL3 = 33
89
+ MXSML_RAS_DHUB1 = 34
90
+ MXSML_RAS_DHUB2 = 35
91
+ MXSML_RAS_DHUB3 = 36
92
+ MXSML_RAS_DHUB4 = 37
93
+ MXSML_RAS_DHUB5 = 38
94
+ MXSML_RAS_DHUB6 = 39
95
+ MXSML_RAS_DHUB7 = 40
96
+ MXSML_RAS_ATH = 41
97
+ MXSML_RAS_ATUL20 = 42
98
+ MXSML_RAS_ATUL21 = 43
99
+ MXSML_RAS_XSC = 44
100
+ MXSML_RAS_CE = 45
101
+
102
+ _mxSmlDpmIp_t = c_uint
103
+ MXSML_DPM_DLA = 0 # Valid for N-class device
104
+ MXSML_DPM_XCORE = 1 # Valid for C-class device
105
+ MXSML_DPM_MC = 2
106
+ MXSML_DPM_SOC = 3
107
+ MXSML_DPM_DNOC = 4
108
+ MXSML_DPM_VPUE = 5
109
+ MXSML_DPM_VPUD = 6
110
+ MXSML_DPM_HBM = 7
111
+ MXSML_DPM_G2D = 8 # Valid for N-class device
112
+ MXSML_DPM_HBM_POWER = 9
113
+ MXSML_DPM_CCX = 10
114
+ MXSML_DPM_IP_GROUP = (
115
+ 11 # Valid for N-class device, group of soc, dnoc, vpue, vpud, ccx, g2d
116
+ )
117
+ MXSML_DPM_DMA = 12
118
+ MXSML_DPM_CSC = 13
119
+ MXSML_DPM_ETH = 14
120
+ MXSML_DPM_RESERVED = 15
121
+
122
+ _mxSmlPciPowerState_t = c_uint
123
+ MXSML_POWER_PCI_STATE_D0 = 0
124
+ MXSML_POWER_PCI_STATE_D3HOT = 1
125
+ MXSML_POWER_PCI_STATE_D3COLD = 2
126
+
127
+ _mxSmlClockIp_t = c_uint
128
+ MXSML_CLOCK_CSC = 0
129
+ MXSML_CLOCK_DLA = 1 # Valid for N-class device
130
+ MXSML_CLOCK_MC = 2 # Valid for N-class device
131
+ MXSML_CLOCK_MC0 = 3 # Valid for C-class device
132
+ MXSML_CLOCK_MC1 = 4 # Valid for C-class device
133
+ MXSML_CLOCK_VPUE = 5
134
+ MXSML_CLOCK_VPUD = 6
135
+ MXSML_CLOCK_SOC = 7
136
+ MXSML_CLOCK_DNOC = 8
137
+ MXSML_CLOCK_G2D = 9 # Valid for N-class device
138
+ MXSML_CLOCK_CCX = 10
139
+ MXSML_CLOCK_XCORE = 11 # Valid for C-class device
140
+
141
+ _mxSmlMetaXLinkType_t = c_uint
142
+ MXSML_METAXLINK_INPUT = 0
143
+ MXSML_METAXLINK_TARGET = 1
144
+
145
+ _mxSmlGpuTopologyLevel_t = c_uint
146
+ MXSML_TOPOLOGY_INTERNAL = 0
147
+ MXSML_TOPOLOGY_SINGLE = 1 # All devices that only need traverse a single PCIe switch
148
+ MXSML_TOPOLOGY_MULTIPLE = 2 # All devices that need not traverse a host bridge
149
+ MXSML_TOPOLOGY_HOSTBRIDGE = 3 # All devices that are connected to the same host bridge
150
+ MXSML_TOPOLOGY_NODE = 4 # All devices that are connected to the same NUMA node but possibly multiple host bridges
151
+ MXSML_TOPOLOGY_METAXLINK = 5 # All devices that are connected to the same MetaXLink
152
+ MXSML_TOPOLOGY_SYSTEM = 6 # All devices in the system
153
+ MXSML_TOPOLOGY_UNDEFINED = 7
154
+
155
+ _mxSmlUsageIp_t = c_uint
156
+ MXSML_USAGE_DLA = 0 # Only valid for N-class device
157
+ MXSML_USAGE_VPUE = 1
158
+ MXSML_USAGE_VPUD = 2
159
+ MXSML_USAGE_G2D = 3 # Only valid for N-class device
160
+ MXSML_USAGE_XCORE = 4 # Only valid for C-class device
161
+
162
+ _mxSmlFwIpName_t = c_uint
163
+ MXSML_FW_IPNAME_SMP0 = 0
164
+ MXSML_FW_IPNAME_SMP1 = 1
165
+ MXSML_FW_IPNAME_CCX0 = 2
166
+ MXSML_FW_IPNAME_CCX1 = 3
167
+ MXSML_FW_IPNAME_CCX2 = 4
168
+ MXSML_FW_IPNAME_CCX3 = 5
169
+ MXSML_FW_IPNAME_ALL = 6
170
+
171
+ _mxSmlLoglevel_t = c_uint
172
+ MXSML_LOGLEVEL_NONE = 0
173
+ MXSML_LOGLEVEL_FATAL = 1
174
+ MXSML_LOGLEVEL_ERROR = 2
175
+ MXSML_LOGLEVEL_WARN = 3
176
+ MXSML_LOGLEVEL_INFO = 4
177
+ MXSML_LOGLEVEL_DEBUG = 5
178
+ MXSML_LOGLEVEL_VERBOSE = 6
179
+ MXSML_LOGLEVEL_UNKNOWN = 7
180
+
181
+ _mxSmlPciGen_t = c_uint
182
+ MXSML_PCI_GEN_1 = 1
183
+ MXSML_PCI_GEN_2 = 2
184
+ MXSML_PCI_GEN_3 = 3
185
+ MXSML_PCI_GEN_4 = 4
186
+ MXSML_PCI_GEN_5 = 5
187
+
188
+ _mxsmlReturn_t = c_uint
189
+ MXSML_SUCCESS = 0
190
+ MXSML_ERROR_FAILURE = 1
191
+ MXSML_ERROR_NO_DEVICE = 2
192
+ MXSML_ERROR_OPERATION_NOT_SUPPORT = 3
193
+ MXSML_ERROR_SYSFS_ERROR = 4
194
+ MXSML_ERROR_SYSFS_WRITE_ERROR = 5
195
+ MXSML_ERROR_INVALID_DEVICE_ID = 6
196
+ MXSML_ERROR_INVALID_DID_ID = 7
197
+ MXSML_ERROR_PERMISSION_DENIED = 8
198
+ MXSML_ERROR_INVALID_INPUT = 9
199
+ MXSML_ERROR_INSUFFICIENT_SIZE = 10
200
+ MXSML_ERROR_RESERVED3 = 11
201
+ MXSML_ERROR_IO_CONTROL_FAILURE = 12
202
+ MXSML_ERROR_MMAP_FAILURE = 13
203
+ MXSML_ERROR_UN_MMAP_FAILURE = 14
204
+ MXSML_ERROR_INVALID_INPUT_FOR_MMAP = 15
205
+ MXSML_ERROR_RESERVED1 = 16
206
+ MXSML_ERROR_RESERVED2 = 17
207
+ MXSML_ERROR_TARGET_VF_NOT_FOUND = 18
208
+ MXSML_ERROR_INVALID_FREQUENCY = 19
209
+ MXSML_ERROR_FLR_NOT_READY = 20
210
+ MXSML_ERROR_OPEN_DEVICE_FILE_FAILURE = 21
211
+ MXSML_ERROR_CLOSE_DEVICE_FILE_FAILURE = 22
212
+ MXSML_ERROR_BUSY_DEVICE = 23
213
+ MXSML_ERROR_MMIO_NOT_ENOUGH = 24
214
+ MXSML_ERROR_GET_PCI_BRIDGE_FAILURE = 25
215
+ MXSML_ERROR_LOAD_DLL_FAILURE = 26
216
+
217
+ _mxSmlMetaXLinkState_t = c_uint
218
+ MXSML_MetaXLink_State_Enabled = 0
219
+ MXSML_MetaXLink_State_Smi_Disabled = 1
220
+ MXSML_MetaXLink_State_Vf_Disabled = 2
221
+ MXSML_MetaXLink_State_GpuNum_Disabled = 3
222
+ MXSML_MetaXLink_State_Training_Disabled = 4
223
+
224
+ _mxSmlMxlkPortState_t = c_uint
225
+ MXSML_Mxlk_Port_State_NoTraining = 0
226
+ MXSML_Mxlk_Port_State_Up = 1
227
+ MXSML_Mxlk_Port_State_Down_Optical_InPlace = 2
228
+ MXSML_Mxlk_Port_State_Down_Optical_OutPlace = 3
229
+ MXSML_Mxlk_Port_State_Down_Optical_NoUse = 4
230
+ MXSML_Mxlk_Port_State_NoUse = 5
231
+
232
+ _mxSmlPciEventType_t = c_uint
233
+ MXSML_Pci_Event_AER_UE = 0
234
+ MXSML_Pci_Event_AER_CE = 1
235
+ MXSML_Pci_Event_SYNFLD = 2
236
+ MXSML_Pci_Event_DBE = 3
237
+ MXSML_Pci_Event_MMIO = 4
238
+
239
+
240
+ # buffer size
241
+ MXSML_DEVICE_BDF_ID_SIZE = 32 # Guaranteed maximum possible size for BDF ID
242
+ MXSML_EEPROM_INFO_SIZE = 1024 # Guaranteed maximum possible size for Eeprom info
243
+ MXSML_VERSION_INFO_SIZE = 64 # Guaranteed maximum possible size for Version info
244
+ MXSML_VIRTUAL_DEVICE_SIZE = (
245
+ 128 # Guaranteed maximum possible size for virtual device ids
246
+ )
247
+ MXSML_DEVICE_UUID_SIZE = 96 # Guaranteed maximum possible size for UUID
248
+ MXSML_DEVICE_NAME_SIZE = 32 # Guaranteed maximum possible size for Device name
249
+ MXSML_CHIP_SERIAL_SIZE = 32 # Guaranteed maximum possible size for chip serial
250
+ MXSML_BOARD_SERIAL_SIZE = 32 # Guaranteed maximum possible size for board serial
251
+ MXSML_OPTICAL_MODULE_INFO_SIZE = (
252
+ 32 # Guaranteed maximum possible size for optical module info
253
+ )
254
+ MXSML_DEVICE_REAL_PATH_SIZE = (
255
+ 1024 # Guaranteed maximum possible size for device real path
256
+ )
257
+ MXSML_VBIOS_BIN_PATH_SIZE = 150 # Guaranteed maximum possible size for file path
258
+ DEVICE_UNAVAILABLE_REASON_SIZE = (
259
+ 64 # Guaranteed maximum possible size for device unavailable reason
260
+ )
261
+
262
+ MXSML_RAS_ERROR_REG_NUM = 128 # Number of RAS error counter register
263
+ MXSML_RAS_STATUS_REG_NUM = 128 # Number of RAS status register
264
+
265
+ MXSML_METAX_LINK_NUM = 7 # Number of C-class device MetaXLink
266
+
267
+ MXSML_PROCESS_NAME_SIZE = 64 # Maximum length showed process name
268
+ MXSML_MAX_GPU_NUM_USED_BY_PROCESS = (
269
+ 64 # Maximum stored GPU information used by a process
270
+ )
271
+
272
+ MXSML_MAX_SMP_NUM = 2 # The max num of smp
273
+ MXSML_MAX_CCX_NUM = 4 # The max num of ccx
274
+
275
+ MXSML_MIN_PCI_DELAY = 1 # Minimum pci delay, unit: ms
276
+ MXSML_MAX_PCI_DELAY = 10000 # Maximum pci delay, unit: ms
277
+
278
+ # Used for mxSmlInitWithFlags
279
+ MXSML_INIT_FLAG_NORMAL = 0 # the behavior is the same as mxsmlInit
280
+ MXSML_INIT_FLAG_REINIT = 1 # repeated initialization will reinit resources
281
+
282
+
283
+ ## MXSML Structure ##
284
+ class mxsmlFriendlyObject(object):
285
+ def __init__(self, dictionary):
286
+ for x in dictionary:
287
+ setattr(self, x, dictionary[x])
288
+
289
+ def __str__(self):
290
+ return self.__dict__.__str__()
291
+
292
+
293
+ def mxsmlStructToFriendlyObject(struct):
294
+ dictionary = {}
295
+ for field in struct._fields_:
296
+ key = field[0]
297
+ value = getattr(struct, key)
298
+ dictionary[key] = value.decode() if isinstance(value, bytes) else value
299
+ return mxsmlFriendlyObject(dictionary)
300
+
301
+
302
+ # pack the object so it can be passed to the MXSML library
303
+ def mxsmlFriendlyObjectToStruct(obj, model):
304
+ for field in model._fields_:
305
+ key = field[0]
306
+ value = obj.__dict__[key]
307
+ setattr(model, key, value.encode())
308
+ return model
309
+
310
+
311
+ class _MxsmlBaseStructure(Structure):
312
+ _format_ = {}
313
+ _default_format_ = "%s"
314
+
315
+ def __str__(self):
316
+ attrs = []
317
+ for field in self._fields_:
318
+ attr_name = field[0]
319
+ attr_value = getattr(self, attr_name)
320
+ fmt = self._default_format_
321
+ if attr_name in self._format_:
322
+ fmt = self._format_[attr_name]
323
+ attrs.append(("%s: " + fmt) % (attr_name, attr_value))
324
+ return self.__class__.__name__ + "(" + ", ".join(attrs) + ")"
325
+
326
+ def __getattribute__(self, name):
327
+ res = super().__getattribute__(name)
328
+ if isinstance(res, bytes):
329
+ return res.decode()
330
+ return res
331
+
332
+ def __setattr__(self, name, value):
333
+ if isinstance(value, str):
334
+ value = value.encode()
335
+ super().__setattr__(name, value)
336
+
337
+
338
+ class c_mxsmlDeviceInfo_t(_MxsmlBaseStructure):
339
+ _fields_ = [
340
+ ("deviceId", c_uint),
341
+ ("type", c_uint), # Do not use
342
+ ("bdfId", c_char * MXSML_DEVICE_BDF_ID_SIZE),
343
+ ("gpuId", c_uint),
344
+ ("nodeId", c_uint),
345
+ ("uuid", c_char * MXSML_DEVICE_UUID_SIZE),
346
+ ("brand", _mxSmlDeviceBrand_t),
347
+ ("mode", _mxSmlDeviceVirtualizationMode_t),
348
+ ("deviceName", c_char * MXSML_DEVICE_NAME_SIZE),
349
+ ]
350
+
351
+
352
+ class c_mxSmlVirtualDeviceIds_t(_MxsmlBaseStructure):
353
+ _fields_ = [
354
+ ("number", c_int),
355
+ ("deviceId", c_int * MXSML_VIRTUAL_DEVICE_SIZE),
356
+ ]
357
+
358
+
359
+ class c_mxSmlLimitedDeviceIds_t(c_mxSmlVirtualDeviceIds_t):
360
+ pass
361
+
362
+
363
+ class c_mxsmlMemoryInfo_t(_MxsmlBaseStructure):
364
+ _fields_ = [
365
+ ("visVramTotal", c_long),
366
+ ("visVramUse", c_long),
367
+ ("vramTotal", c_long),
368
+ ("vramUse", c_long),
369
+ ("xttTotal", c_long),
370
+ ("xttUse", c_long),
371
+ ]
372
+ _default_format_ = "%d KB"
373
+
374
+
375
+ class c_mxSmlPmbusInfo_t(_MxsmlBaseStructure):
376
+ _fields_ = [
377
+ ("voltage", c_uint),
378
+ ("current", c_uint),
379
+ ("power", c_uint),
380
+ ]
381
+ _format_ = {"voltage": "%d mV", "current": "%d mA", "power": "%d mW"}
382
+
383
+
384
+ class c_mxSmlBoardWayElectricInfo_t(_MxsmlBaseStructure):
385
+ _fields_ = [
386
+ ("voltage", c_uint),
387
+ ("current", c_uint),
388
+ ("power", c_uint),
389
+ ]
390
+ _format_ = {"voltage": "%d mV", "current": "%d mA", "power": "%d mW"}
391
+
392
+
393
+ class c_mxSmlMxcDpmPerfLevel_t(_MxsmlBaseStructure):
394
+ _fields_ = [
395
+ ("xcore", c_uint),
396
+ ("mc", c_uint),
397
+ ("soc", c_uint),
398
+ ("dnoc", c_uint),
399
+ ("vpue", c_uint),
400
+ ("vpud", c_uint),
401
+ ("ccx", c_uint),
402
+ ]
403
+
404
+
405
+ class c_mxSmlEepromInfo_t(_MxsmlBaseStructure):
406
+ _fields_ = [
407
+ ("content", c_char * MXSML_EEPROM_INFO_SIZE),
408
+ ]
409
+
410
+
411
+ class c_mxSmlRasErrorRegister_t(_MxsmlBaseStructure):
412
+ _fields_ = [
413
+ ("rasIp", _mxSmlRasIp_t),
414
+ ("registerIndex", c_uint),
415
+ ("rasErrorUe", c_int),
416
+ ("rasErrorCe", c_int),
417
+ ]
418
+
419
+
420
+ class c_mxSmlRasErrorData_t(_MxsmlBaseStructure):
421
+ _fields_ = [
422
+ ("rasErrorRegister", c_mxSmlRasErrorRegister_t * MXSML_RAS_ERROR_REG_NUM),
423
+ ("showRasErrorSize", c_uint),
424
+ ]
425
+
426
+
427
+ class c_mxSmlRasRegister_t(_MxsmlBaseStructure):
428
+ _fields_ = [
429
+ ("rasIp", _mxSmlRasIp_t),
430
+ ("registerIndex", c_uint),
431
+ ("registerData", c_int),
432
+ ]
433
+
434
+
435
+ class c_mxSmlRasStatusData_t(_MxsmlBaseStructure):
436
+ _fields_ = [
437
+ ("rasStatusRegister", c_mxSmlRasRegister_t * MXSML_RAS_STATUS_REG_NUM),
438
+ ("showRasStatusSize", c_uint),
439
+ ]
440
+
441
+
442
+ class c_mxSmlPcieInfo_t(_MxsmlBaseStructure):
443
+ _fields_ = [
444
+ ("speed", c_float),
445
+ ("width", c_uint),
446
+ ]
447
+ _format_ = {"speed": "%.1f GT/s", "width": "x%d"}
448
+
449
+
450
+ class c_mxSmlCodecStatus_t(_MxsmlBaseStructure):
451
+ _fields_ = [
452
+ ("encoder", c_int),
453
+ ("decoder", c_int),
454
+ ]
455
+
456
+
457
+ class c_mxSmlHbmBandWidth_t(_MxsmlBaseStructure):
458
+ _fields_ = [
459
+ ("hbmBandwidthReqTotal", c_int),
460
+ ("hbmBandwidthRespTotal", c_int),
461
+ ]
462
+ _default_format_ = "%d MBytes/s"
463
+
464
+
465
+ class c_mxSmlPcieThroughput_t(_MxsmlBaseStructure):
466
+ _fields_ = [
467
+ ("rx", c_int),
468
+ ("tx", c_int),
469
+ ]
470
+ _default_format_ = "%d MBytes/s"
471
+
472
+
473
+ class c_mxSmlDmaEngineBandwidth_t(_MxsmlBaseStructure):
474
+ _fields_ = [
475
+ ("readReqBandwidth", c_int),
476
+ ("readRespBandwidth", c_int),
477
+ ("writeReqBandwidth", c_int),
478
+ ("writeRespBandwidth", c_int),
479
+ ]
480
+ _default_format_ = "%d MBytes/s"
481
+
482
+
483
+ class c_mxSmlMetaXLinkBandwidth_t(_MxsmlBaseStructure):
484
+ _fields_ = [
485
+ ("requestBandwidth", c_int),
486
+ ("responseBandwidth", c_int),
487
+ ]
488
+ _default_format_ = "%d MBytes/s"
489
+
490
+
491
+ class c_mxSmlMetaXLinkRemoteInfo_t(_MxsmlBaseStructure):
492
+ _fields_ = [
493
+ ("deviceId", c_int),
494
+ ("bdfId", c_char * MXSML_DEVICE_BDF_ID_SIZE),
495
+ ]
496
+
497
+
498
+ class c_mxSmlMcmMetaXLinkRemoteInfo_t(_MxsmlBaseStructure):
499
+ _fields_ = [
500
+ ("deviceId", c_int),
501
+ ("bdfId", c_char * MXSML_DEVICE_BDF_ID_SIZE),
502
+ ("dieId", c_uint),
503
+ ]
504
+
505
+
506
+ class c_mxSmlProcessGpuInfo_t(_MxsmlBaseStructure):
507
+ _fields_ = [
508
+ ("bdfId", c_char * MXSML_DEVICE_BDF_ID_SIZE),
509
+ ("gpuId", c_uint),
510
+ ("gpuMemoryUsage", c_ulong),
511
+ ]
512
+
513
+
514
+ class c_mxSmlProcessInfo_t(_MxsmlBaseStructure):
515
+ _fields_ = [
516
+ ("processId", c_uint),
517
+ ("processName", c_char * MXSML_PROCESS_NAME_SIZE),
518
+ ("gpuNumber", c_uint),
519
+ ("processGpuInfo", c_mxSmlProcessGpuInfo_t * MXSML_MAX_GPU_NUM_USED_BY_PROCESS),
520
+ ]
521
+
522
+
523
+ class c_mxSmlProcessGpuInfo_v2_t(_MxsmlBaseStructure):
524
+ _fields_ = [
525
+ ("bdfId", c_char * MXSML_DEVICE_BDF_ID_SIZE),
526
+ ("gpuId", c_uint),
527
+ ("gpuMemoryUsage", c_ulong),
528
+ ("dieId", c_uint),
529
+ ]
530
+
531
+
532
+ class c_mxSmlProcessInfo_v2_t(_MxsmlBaseStructure):
533
+ _fields_ = [
534
+ ("processId", c_uint),
535
+ ("processName", c_char * MXSML_PROCESS_NAME_SIZE),
536
+ ("gpuNumber", c_uint),
537
+ (
538
+ "processGpuInfo",
539
+ c_mxSmlProcessGpuInfo_v2_t * MXSML_MAX_GPU_NUM_USED_BY_PROCESS,
540
+ ),
541
+ ]
542
+
543
+
544
+ class c_mxSmlFwLoglevel_t(_MxsmlBaseStructure):
545
+ _fields_ = [
546
+ ("smpCount", c_uint),
547
+ ("smp", _mxSmlLoglevel_t * MXSML_MAX_SMP_NUM),
548
+ ("ccxCount", c_uint),
549
+ ("ccx", _mxSmlLoglevel_t * MXSML_MAX_CCX_NUM),
550
+ ]
551
+
552
+
553
+ class c_mxSmlMetaXLinkInfo_t(_MxsmlBaseStructure):
554
+ _fields_ = [
555
+ ("speed", c_float * MXSML_METAX_LINK_NUM),
556
+ ("width", c_uint * MXSML_METAX_LINK_NUM),
557
+ ]
558
+
559
+
560
+ class c_mxSmlSingleMxlkInfo_t(_MxsmlBaseStructure):
561
+ _fields_ = [
562
+ ("speed", c_float),
563
+ ("width", c_uint),
564
+ ]
565
+
566
+
567
+ class c_mxSmlOpticalModuleStatus_t(_MxsmlBaseStructure):
568
+ _fields_ = [
569
+ ("temperature", c_int), # unit: degress 0.01C
570
+ ("voltage", c_uint), # unit: mV
571
+ ("moduleState", c_uint),
572
+ ("dataPathState", c_uint),
573
+ ("rxState", c_uint * 2), # 6 bytes total
574
+ ("version", c_uint * 2), # version[0]: major, version[1]: minor
575
+ ]
576
+ _format_ = {"voltage": "%d mV", "dataPathState": "0x%x"}
577
+
578
+
579
+ class c_mxSmlOpticalModuleInfo_t(_MxsmlBaseStructure):
580
+ _fields_ = [
581
+ ("name", c_char * MXSML_OPTICAL_MODULE_INFO_SIZE),
582
+ ("oui", c_uint * 3),
583
+ ("pn", c_char * MXSML_OPTICAL_MODULE_INFO_SIZE),
584
+ ("rev", c_char * MXSML_OPTICAL_MODULE_INFO_SIZE),
585
+ ("sn", c_char * MXSML_OPTICAL_MODULE_INFO_SIZE),
586
+ ]
587
+
588
+
589
+ class c_mxSmlVbiosUpgradeArg_t(_MxsmlBaseStructure):
590
+ _fields_ = [
591
+ ("timeLimit", c_uint),
592
+ ("vbiosBinPath", c_char * (MXSML_VBIOS_BIN_PATH_SIZE + 1)),
593
+ ("forceUpgrade", c_int),
594
+ ("ret", c_uint),
595
+ ("pfBar0Size", c_int),
596
+ ("vfBar0Size", c_int),
597
+ ]
598
+
599
+
600
+ class c_mxSmlPciEventInfo_t(_MxsmlBaseStructure):
601
+ _fields_ = [
602
+ ("bitNumber", c_int),
603
+ ("count", c_int),
604
+ ("firstTime", c_char * 20),
605
+ ("name", c_char * 64),
606
+ ]
607
+
608
+
609
+ class c_mxSmlDeviceUnavailableReasonInfo_t(_MxsmlBaseStructure):
610
+ _fields_ = [
611
+ ("unavailableCode", c_int),
612
+ ("unavailableReason", c_char * DEVICE_UNAVAILABLE_REASON_SIZE),
613
+ ]
614
+
615
+
616
+ class c_mxSmlEccErrorCount_t(_MxsmlBaseStructure):
617
+ _fields_ = [
618
+ ("sramCE", c_uint),
619
+ ("sramUE", c_uint),
620
+ ("dramCE", c_uint),
621
+ ("dramUE", c_uint),
622
+ ("retiredPage", c_uint),
623
+ ]
624
+
625
+
626
+ class c_mxSmlMetaXLinkTopo_t(_MxsmlBaseStructure):
627
+ _fields_ = [
628
+ ("topologyId", c_uint),
629
+ ("socketId", c_uint),
630
+ ("dieId", c_uint),
631
+ ]
632
+
633
+
634
+ ## MXSML Error ##
635
+ class MXSMLError(Exception):
636
+ _valClassMapping = dict()
637
+
638
+ def __new__(typ, value):
639
+ """
640
+ Maps value to a proper subclass of MXSMLError.
641
+ See _generateErrorSubclass function for more details
642
+ """
643
+ if typ == MXSMLError:
644
+ typ = MXSMLError._valClassMapping.get(value, typ)
645
+ obj = Exception.__new__(typ)
646
+ obj.value = value
647
+ return obj
648
+
649
+ def __str__(self):
650
+ try:
651
+ return str(mxSmlGetErrorString(self.value))
652
+ except MXSMLError:
653
+ return "MXSML Error with code: " + str(self.value)
654
+
655
+ def __eq__(self, other):
656
+ return self.value == other.value
657
+
658
+
659
+ def _generateErrorSubclass():
660
+ # Create execption subclass for each MXSML Error
661
+ def generate_new_func(val):
662
+ def new(typ):
663
+ obj = MXSMLError.__new__(typ, val)
664
+ return obj
665
+
666
+ return new
667
+
668
+ this_module = sys.modules[__name__]
669
+ mxsmlErrorsNames = [x for x in dir(this_module) if x.startswith("MXSML_ERROR_")]
670
+ for err_name in mxsmlErrorsNames:
671
+ class_name = "MXSMLError_" + string.capwords(
672
+ err_name.replace("MXSML_ERROR_", ""), "_"
673
+ ).replace("_", "")
674
+ err_val = getattr(this_module, err_name)
675
+ new_error_class = type(
676
+ class_name, (MXSMLError,), {"__new__": generate_new_func(err_val)}
677
+ )
678
+ new_error_class.__module__ = __name__
679
+ setattr(this_module, class_name, new_error_class)
680
+ MXSMLError._valClassMapping[err_val] = new_error_class
681
+
682
+
683
+ _generateErrorSubclass()
684
+
685
+ ## Lib loading ##
686
+ mxSmlLib = None
687
+
688
+
689
+ def get_mxSmlLib():
690
+ return mxSmlLib
691
+
692
+
693
+ def _mxsmlCheckReturn(ret):
694
+ if ret != MXSML_SUCCESS:
695
+ raise MXSMLError(ret)
696
+ return ret
697
+
698
+
699
+ ## Function access ##
700
+ _mxsmlFunctionPointerCache = {}
701
+
702
+
703
+ def _mxsmlGetFunctionPointer(name):
704
+ if name in _mxsmlFunctionPointerCache:
705
+ return _mxsmlFunctionPointerCache[name]
706
+
707
+ global mxSmlLib
708
+ if mxSmlLib == None:
709
+ raise MXSMLError(MXSML_ERROR_FAILURE)
710
+
711
+ _mxsmlFunctionPointerCache[name] = getattr(mxSmlLib, name)
712
+ return _mxsmlFunctionPointerCache[name]
713
+
714
+
715
+ ## string/bytes conversion for ease of use
716
+ def convertStrBytes(func):
717
+ @wraps(func)
718
+ def wrapper(*args, **kwargs):
719
+ # encoding a str returns bytes
720
+ args = [arg.encode() if isinstance(arg, str) else arg for arg in args]
721
+ res = func(*args, **kwargs)
722
+ if isinstance(res, bytes):
723
+ return res.decode()
724
+ return res
725
+
726
+ return wrapper
727
+
728
+
729
+ def _searchMxsmlLibrary():
730
+ for lib in [
731
+ "/opt/mxdriver/lib/libmxsml.so",
732
+ "/opt/maca/lib/libmxsml.so",
733
+ "/opt/mxn100/lib/libmxsml.so",
734
+ ]:
735
+ if os.path.isfile(lib):
736
+ return lib
737
+
738
+ libmxsml = "libmxsml.so"
739
+ for root, __, files in os.walk("/opt", followlinks=True):
740
+ if libmxsml in files:
741
+ return os.path.join(os.path.realpath(root), libmxsml)
742
+ return None
743
+
744
+
745
+ def _loadMxsmlLibrary():
746
+ "Load the library if it isn't loaded already"
747
+ global mxSmlLib
748
+ if mxSmlLib != None:
749
+ return
750
+
751
+ try:
752
+ path_libmxsml = _searchMxsmlLibrary()
753
+ if not path_libmxsml:
754
+ _mxsmlCheckReturn(MXSML_ERROR_LOAD_DLL_FAILURE)
755
+ else:
756
+ mxSmlLib = CDLL(path_libmxsml)
757
+ except OSError as ose:
758
+ _mxsmlCheckReturn(MXSML_ERROR_LOAD_DLL_FAILURE)
759
+ if mxSmlLib == None:
760
+ _mxsmlCheckReturn(MXSML_ERROR_LOAD_DLL_FAILURE)
761
+
762
+
763
+ ## function wrappers ##
764
+ def mxSmlInit():
765
+ _loadMxsmlLibrary()
766
+ fn = _mxsmlGetFunctionPointer("mxSmlInit")
767
+ ret = fn()
768
+ _mxsmlCheckReturn(ret)
769
+ return None
770
+
771
+
772
+ def mxSmlInitWithFlags(flags):
773
+ _loadMxsmlLibrary()
774
+ fn = _mxsmlGetFunctionPointer("mxSmlInitWithFlags")
775
+ ret = fn(flags)
776
+ _mxsmlCheckReturn(ret)
777
+ return None
778
+
779
+
780
+ @convertStrBytes
781
+ def mxSmlGetMacaVersion():
782
+ version = create_string_buffer(MXSML_VERSION_INFO_SIZE)
783
+ fn = _mxsmlGetFunctionPointer("mxSmlGetMacaVersion")
784
+ ret = fn(byref(version), byref(c_uint(MXSML_VERSION_INFO_SIZE)))
785
+ _mxsmlCheckReturn(ret)
786
+ return version.value
787
+
788
+
789
+ def mxSmlGetDeviceCount():
790
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceCount")
791
+ return fn()
792
+
793
+
794
+ def mxSmlGetPfDeviceCount():
795
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPfDeviceCount")
796
+ return fn()
797
+
798
+
799
+ def mxSmlGetDeviceInfo(device_id):
800
+ device_info = c_mxsmlDeviceInfo_t()
801
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceInfo")
802
+ ret = fn(c_uint(device_id), byref(device_info))
803
+ _mxsmlCheckReturn(ret)
804
+ return device_info
805
+
806
+
807
+ def mxSmlGetVirtualDevicesByPhysicalId(device_id):
808
+ devices = c_mxSmlVirtualDeviceIds_t()
809
+ fn = _mxsmlGetFunctionPointer("mxSmlGetVirtualDevicesByPhysicalId")
810
+ ret = fn(c_uint(device_id), byref(devices))
811
+ _mxsmlCheckReturn(ret)
812
+ return devices
813
+
814
+
815
+ def mxSmlGetAllLimitedDevices():
816
+ devices = c_mxSmlLimitedDeviceIds_t()
817
+ fn = _mxsmlGetFunctionPointer("mxSmlGetAllLimitedDevices")
818
+ ret = fn(byref(devices))
819
+ _mxsmlCheckReturn(ret)
820
+ return devices
821
+
822
+
823
+ def mxSmlGetLimitedDeviceInfo(device_id):
824
+ device_info = c_mxsmlDeviceInfo_t()
825
+ fn = _mxsmlGetFunctionPointer("mxSmlGetLimitedDeviceInfo")
826
+ ret = fn(c_uint(device_id), byref(device_info))
827
+ _mxsmlCheckReturn(ret)
828
+ return device_info
829
+
830
+
831
+ @convertStrBytes
832
+ def mxSmlGetDeviceVersion(device_id, version_unit):
833
+ version = create_string_buffer(MXSML_VERSION_INFO_SIZE)
834
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceVersion")
835
+ ret = fn(
836
+ c_uint(device_id),
837
+ _mxSmlVersionUnit_t(version_unit),
838
+ byref(version),
839
+ byref(c_uint(MXSML_VERSION_INFO_SIZE)),
840
+ )
841
+ _mxsmlCheckReturn(ret)
842
+ return version.value
843
+
844
+
845
+ @convertStrBytes
846
+ def mxSmlGetChipSerial(device_id):
847
+ serial = create_string_buffer(MXSML_CHIP_SERIAL_SIZE)
848
+ fn = _mxsmlGetFunctionPointer("mxSmlGetChipSerial")
849
+ ret = fn(c_uint(device_id), byref(serial), byref(c_uint(MXSML_CHIP_SERIAL_SIZE)))
850
+ _mxsmlCheckReturn(ret)
851
+ return serial.value
852
+
853
+
854
+ def mxSmlGetMemoryInfo(device_id):
855
+ memory_info = c_mxsmlMemoryInfo_t()
856
+ fn = _mxsmlGetFunctionPointer("mxSmlGetMemoryInfo")
857
+ ret = fn(c_uint(device_id), byref(memory_info))
858
+ _mxsmlCheckReturn(ret)
859
+ return memory_info
860
+
861
+
862
+ def mxSmlGetPmbusInfo(device_id, pmbus_unit):
863
+ pmbus_info = c_mxSmlPmbusInfo_t()
864
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPmbusInfo")
865
+ ret = fn(c_uint(device_id), _mxSmlPmbusUnit_t(pmbus_unit), byref(pmbus_info))
866
+ _mxsmlCheckReturn(ret)
867
+ return pmbus_info
868
+
869
+
870
+ def mxSmlGetTemperatureInfo(device_id, temperature_type):
871
+ temperature = c_int()
872
+ fn = _mxsmlGetFunctionPointer("mxSmlGetTemperatureInfo")
873
+ ret = fn(
874
+ c_uint(device_id),
875
+ _mxSmlTemperatureSensors_t(temperature_type),
876
+ byref(temperature),
877
+ )
878
+ _mxsmlCheckReturn(ret)
879
+ return temperature.value
880
+
881
+
882
+ def mxSmlGetBoardPowerInfo(device_id):
883
+ fn = _mxsmlGetFunctionPointer("mxSmlGetBoardPowerInfo")
884
+ size = c_uint(0)
885
+ ret = fn(c_uint(device_id), byref(size), (c_mxSmlBoardWayElectricInfo_t * 0)())
886
+
887
+ if ret == MXSML_ERROR_INSUFFICIENT_SIZE:
888
+ power_infos = (c_mxSmlBoardWayElectricInfo_t * size.value)()
889
+ ret = fn(c_uint(device_id), byref(size), byref(power_infos))
890
+ _mxsmlCheckReturn(ret)
891
+ return [info for info in power_infos]
892
+ else:
893
+ raise MXSMLError(ret)
894
+
895
+
896
+ def mxSmlGetDpmMaxPerfLevel(device_id):
897
+ dpm_level = c_mxSmlMxcDpmPerfLevel_t()
898
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDpmMaxPerfLevel")
899
+ ret = fn(c_uint(device_id), byref(dpm_level))
900
+ _mxsmlCheckReturn(ret)
901
+ return dpm_level
902
+
903
+
904
+ def mxSmlGetDpmIpMaxPerfLevel(device_id, dpm_ip):
905
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDpmIpMaxPerfLevel")
906
+ level = c_uint(0)
907
+ ret = fn(c_uint(device_id), _mxSmlDpmIp_t(dpm_ip), byref(level))
908
+ _mxsmlCheckReturn(ret)
909
+ return level.value
910
+
911
+
912
+ def mxSmlGetEepromInfo(device_id):
913
+ eeprom_info = c_mxSmlEepromInfo_t()
914
+ fn = _mxsmlGetFunctionPointer("mxSmlGetEepromInfo")
915
+ ret = fn(c_uint(device_id), byref(eeprom_info))
916
+ _mxsmlCheckReturn(ret)
917
+ return eeprom_info
918
+
919
+
920
+ @convertStrBytes
921
+ def mxSmlGetBoardSerial(device_id):
922
+ serial = create_string_buffer(MXSML_BOARD_SERIAL_SIZE)
923
+ fn = _mxsmlGetFunctionPointer("mxSmlGetBoardSerial")
924
+ ret = fn(c_uint(device_id), byref(serial), byref(c_uint(MXSML_BOARD_SERIAL_SIZE)))
925
+ _mxsmlCheckReturn(ret)
926
+ return serial.value
927
+
928
+
929
+ @convertStrBytes
930
+ def mxSmlGetPptableVersion(device_id):
931
+ version = create_string_buffer(MXSML_VERSION_INFO_SIZE)
932
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPptableVersion")
933
+ ret = fn(c_uint(device_id), c_uint(5), byref(version))
934
+ _mxsmlCheckReturn(ret)
935
+ return version.value
936
+
937
+
938
+ def mxSmlGetRasErrorData(device_id):
939
+ ras = c_mxSmlRasErrorData_t()
940
+ fn = _mxsmlGetFunctionPointer("mxSmlGetRasErrorData")
941
+ ret = fn(c_uint(device_id), byref(ras))
942
+ _mxsmlCheckReturn(ret)
943
+ return ras
944
+
945
+
946
+ def mxSmlGetRasStatusData(device_id):
947
+ ras = c_mxSmlRasStatusData_t()
948
+ fn = _mxsmlGetFunctionPointer("mxSmlGetRasStatusData")
949
+ ret = fn(c_uint(device_id), byref(ras))
950
+ _mxsmlCheckReturn(ret)
951
+ return ras
952
+
953
+
954
+ def mxSmlGetPcieInfo(device_id):
955
+ pcie_info = c_mxSmlPcieInfo_t()
956
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPcieInfo")
957
+ ret = fn(c_uint(device_id), byref(pcie_info))
958
+ _mxsmlCheckReturn(ret)
959
+ return pcie_info
960
+
961
+
962
+ def mxSmlGetPcieMaxLinkInfo(device_id):
963
+ pcie_info = c_mxSmlPcieInfo_t()
964
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPcieMaxLinkInfo")
965
+ ret = fn(c_uint(device_id), byref(pcie_info))
966
+ _mxsmlCheckReturn(ret)
967
+ return pcie_info
968
+
969
+
970
+ def mxSmlGetPowerStateInfo(device_id, dpm_ip):
971
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPowerStateInfo")
972
+ size = c_uint(0)
973
+ ret = fn(c_uint(device_id), _mxSmlDpmIp_t(dpm_ip), (c_int * 0)(), byref(size))
974
+
975
+ if ret == MXSML_ERROR_INSUFFICIENT_SIZE:
976
+ power_states = (c_int * size.value)()
977
+ ret = fn(
978
+ c_uint(device_id), _mxSmlDpmIp_t(dpm_ip), byref(power_states), byref(size)
979
+ )
980
+ _mxsmlCheckReturn(ret)
981
+ return [state for state in power_states]
982
+ else:
983
+ raise MXSMLError(ret)
984
+
985
+
986
+ def mxSmlGetPciPowerState(device_id):
987
+ state = _mxSmlPciPowerState_t()
988
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPciPowerState")
989
+ ret = fn(c_uint(device_id), byref(state))
990
+ _mxsmlCheckReturn(ret)
991
+ return state.value
992
+
993
+
994
+ def mxSmlGetCodecStatus(device_id):
995
+ status = c_mxSmlCodecStatus_t()
996
+ fn = _mxsmlGetFunctionPointer("mxSmlGetCodecStatus")
997
+ ret = fn(c_uint(device_id), byref(status))
998
+ _mxsmlCheckReturn(ret)
999
+ return status
1000
+
1001
+
1002
+ def mxSmlGetClocks(device_id, clock_ip):
1003
+ fn = _mxsmlGetFunctionPointer("mxSmlGetClocks")
1004
+ size = c_uint(1)
1005
+ clocks = (c_uint * 1)()
1006
+ ret = fn(c_uint(device_id), _mxSmlClockIp_t(clock_ip), byref(size), byref(clocks))
1007
+
1008
+ if ret == MXSML_SUCCESS:
1009
+ return [clock for clock in clocks]
1010
+
1011
+ elif ret == MXSML_ERROR_INSUFFICIENT_SIZE:
1012
+ clocks = (c_uint * size.value)()
1013
+ ret = fn(
1014
+ c_uint(device_id), _mxSmlClockIp_t(clock_ip), byref(size), byref(clocks)
1015
+ )
1016
+ _mxsmlCheckReturn(ret)
1017
+ return [clock for clock in clocks]
1018
+
1019
+ else:
1020
+ raise MXSMLError(ret)
1021
+
1022
+
1023
+ def mxSmlGetHbmBandWidth(device_id):
1024
+ bw = c_mxSmlHbmBandWidth_t()
1025
+ fn = _mxsmlGetFunctionPointer("mxSmlGetHbmBandWidth")
1026
+ ret = fn(c_uint(device_id), byref(bw))
1027
+ _mxsmlCheckReturn(ret)
1028
+ return bw
1029
+
1030
+
1031
+ def mxSmlGetPcieThroughput(device_id):
1032
+ through_put = c_mxSmlPcieThroughput_t()
1033
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPcieThroughput")
1034
+ ret = fn(c_uint(device_id), byref(through_put))
1035
+ _mxsmlCheckReturn(ret)
1036
+ return through_put
1037
+
1038
+
1039
+ def mxSmlGetDmaBandwidth(device_id):
1040
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDmaBandwidth")
1041
+ size = c_uint(10)
1042
+ ret = fn(c_uint(device_id), (c_mxSmlDmaEngineBandwidth_t * 10)(), byref(size))
1043
+
1044
+ if ret == MXSML_SUCCESS:
1045
+ bandwidths = (c_mxSmlDmaEngineBandwidth_t * size.value)()
1046
+ ret = fn(c_uint(device_id), byref(bandwidths), byref(size))
1047
+ _mxsmlCheckReturn(ret)
1048
+ return [bw for bw in bandwidths]
1049
+ else:
1050
+ raise MXSMLError(ret)
1051
+
1052
+
1053
+ def mxSmlGetMetaXLinkBandwidth(device_id, mxlk_type):
1054
+ size = c_uint(MXSML_METAX_LINK_NUM)
1055
+ entry = []
1056
+ bw = (c_mxSmlMetaXLinkBandwidth_t * MXSML_METAX_LINK_NUM)(*entry)
1057
+ fn = _mxsmlGetFunctionPointer("mxSmlGetMetaXLinkBandwidth")
1058
+ ret = fn(
1059
+ c_uint(device_id), _mxSmlMetaXLinkType_t(mxlk_type), byref(size), byref(bw)
1060
+ )
1061
+ _mxsmlCheckReturn(ret)
1062
+ return bw
1063
+
1064
+
1065
+ def mxSmlGetMetaXLinkRemoteInfo(device_id, link_id):
1066
+ remote = c_mxSmlMetaXLinkRemoteInfo_t()
1067
+ fn = _mxsmlGetFunctionPointer("mxSmlGetMetaXLinkRemoteInfo")
1068
+ ret = fn(c_uint(device_id), c_uint(link_id), byref(remote))
1069
+ _mxsmlCheckReturn(ret)
1070
+ return remote
1071
+
1072
+
1073
+ def mxSmlGetNumberOfProcess():
1074
+ proc_number = c_uint()
1075
+ fn = _mxsmlGetFunctionPointer("mxSmlGetNumberOfProcess")
1076
+ ret = fn(byref(proc_number))
1077
+ _mxsmlCheckReturn(ret)
1078
+ return proc_number.value
1079
+
1080
+
1081
+ def mxSmlGetProcessInfo(process_number):
1082
+ entry = []
1083
+ processes = (c_mxSmlProcessInfo_t * process_number)(*entry)
1084
+ fn = _mxsmlGetFunctionPointer("mxSmlGetProcessInfo")
1085
+ ret = fn(process_number, byref(processes))
1086
+ _mxsmlCheckReturn(ret)
1087
+ return processes
1088
+
1089
+
1090
+ def mxSmlGetProcessInfo_v2(process_number):
1091
+ entry = []
1092
+ processes = (c_mxSmlProcessInfo_v2_t * process_number)(*entry)
1093
+ fn = _mxsmlGetFunctionPointer("mxSmlGetProcessInfo_v2")
1094
+ ret = fn(process_number, byref(processes))
1095
+ _mxsmlCheckReturn(ret)
1096
+ return processes
1097
+
1098
+
1099
+ def mxSmlGetSingleGpuProcess(device_id):
1100
+ number = c_uint(0)
1101
+ fn = _mxsmlGetFunctionPointer("mxSmlGetSingleGpuProcess")
1102
+ ret = fn(c_uint(device_id), byref(number), (c_mxSmlProcessInfo_t * 1)())
1103
+
1104
+ if ret == MXSML_SUCCESS:
1105
+ # oversize the array incase more processes are created
1106
+ number.value = number.value * 2 + 5
1107
+ processes = (c_mxSmlProcessInfo_t * number.value)()
1108
+ ret = fn(c_uint(device_id), byref(number), byref(processes))
1109
+ _mxsmlCheckReturn(ret)
1110
+
1111
+ process_array = []
1112
+ for i in range(number.value):
1113
+ process_array.append(mxsmlStructToFriendlyObject(processes[i]))
1114
+ return process_array
1115
+ else:
1116
+ # error case
1117
+ raise MXSMLError(ret)
1118
+
1119
+
1120
+ def mxSmlGetSingleGpuProcess_v2(device_id):
1121
+ number = c_uint(0)
1122
+ fn = _mxsmlGetFunctionPointer("mxSmlGetSingleGpuProcess_v2")
1123
+ ret = fn(c_uint(device_id), byref(number), (c_mxSmlProcessInfo_v2_t * 1)())
1124
+
1125
+ if ret == MXSML_SUCCESS:
1126
+ # oversize the array incase more processes are created
1127
+ number.value = number.value * 2 + 5
1128
+ processes = (c_mxSmlProcessInfo_v2_t * number.value)()
1129
+ ret = fn(c_uint(device_id), byref(number), byref(processes))
1130
+ _mxsmlCheckReturn(ret)
1131
+
1132
+ process_array = []
1133
+ for i in range(number.value):
1134
+ process_array.append(mxsmlStructToFriendlyObject(processes[i]))
1135
+ return process_array
1136
+ else:
1137
+ # error case
1138
+ raise MXSMLError(ret)
1139
+
1140
+
1141
+ def mxSmlGetDeviceTopology(device_src, device_dst):
1142
+ topo = _mxSmlGpuTopologyLevel_t()
1143
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceTopology")
1144
+ ret = fn(c_uint(device_src), c_uint(device_dst), byref(topo))
1145
+ _mxsmlCheckReturn(ret)
1146
+ return topo.value
1147
+
1148
+
1149
+ def mxSmlGetDeviceDistance(device_src, device_dst):
1150
+ distance = c_uint()
1151
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceDistance")
1152
+ ret = fn(c_uint(device_src), c_uint(device_dst), byref(distance))
1153
+ _mxsmlCheckReturn(ret)
1154
+ return distance.value
1155
+
1156
+
1157
+ def mxSmlGetCpuAffinity(device_id, cpu_set_size):
1158
+ entry = []
1159
+ cpu_set = (c_uint * cpu_set_size)(*entry)
1160
+ fn = _mxsmlGetFunctionPointer("mxSmlGetCpuAffinity")
1161
+ ret = fn(c_uint(device_id), c_uint(cpu_set_size), byref(cpu_set))
1162
+ _mxsmlCheckReturn(ret)
1163
+ return cpu_set
1164
+
1165
+
1166
+ def mxSmlGetNodeAffinity(device_id, node_set_size):
1167
+ entry = []
1168
+ node_set = (c_uint * node_set_size)(*entry)
1169
+ fn = _mxsmlGetFunctionPointer("mxSmlGetNodeAffinity")
1170
+ ret = fn(c_uint(device_id), c_uint(node_set_size), byref(node_set))
1171
+ _mxsmlCheckReturn(ret)
1172
+ return node_set
1173
+
1174
+
1175
+ def mxSmlGetPciDelay(device_id):
1176
+ delay = c_uint()
1177
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPciDelay")
1178
+ ret = fn(c_uint(device_id), byref(delay))
1179
+ _mxsmlCheckReturn(ret)
1180
+ return delay.value
1181
+
1182
+
1183
+ def mxSmlGetDpmIpClockInfo(device_id, dpm_ip):
1184
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDpmIpClockInfo")
1185
+ size = c_uint(0)
1186
+ ret = fn(c_uint(device_id), _mxSmlDpmIp_t(dpm_ip), (c_uint * 1)(), byref(size))
1187
+
1188
+ if ret == MXSML_ERROR_INSUFFICIENT_SIZE:
1189
+ clocks = (c_uint * size.value)()
1190
+ ret = fn(c_uint(device_id), _mxSmlDpmIp_t(dpm_ip), byref(clocks), byref(size))
1191
+ _mxsmlCheckReturn(ret)
1192
+ return [clk for clk in clocks]
1193
+ else:
1194
+ raise MXSMLError(ret)
1195
+
1196
+
1197
+ def mxSmlGetDpmIpVddInfo(device_id, dpm_ip):
1198
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDpmIpVddInfo")
1199
+ size = c_uint(0)
1200
+ ret = fn(c_uint(device_id), _mxSmlDpmIp_t(dpm_ip), (c_uint * 1)(), byref(size))
1201
+
1202
+ if ret == MXSML_ERROR_INSUFFICIENT_SIZE:
1203
+ vdds = (c_uint * size.value)()
1204
+ ret = fn(c_uint(device_id), _mxSmlDpmIp_t(dpm_ip), byref(vdds), byref(size))
1205
+ _mxsmlCheckReturn(ret)
1206
+ return [vdd for vdd in vdds]
1207
+ else:
1208
+ raise MXSMLError(ret)
1209
+
1210
+
1211
+ def mxSmlGetCurrentDpmIpPerfLevel(device_id, dpm_ip):
1212
+ level = c_uint()
1213
+ fn = _mxsmlGetFunctionPointer("mxSmlGetCurrentDpmIpPerfLevel")
1214
+ ret = fn(c_uint(device_id), _mxSmlDpmIp_t(dpm_ip), byref(level))
1215
+ _mxsmlCheckReturn(ret)
1216
+ return level.value
1217
+
1218
+
1219
+ def mxSmlGetDeviceIpUsage(device_id, usage_ip):
1220
+ usage = c_int()
1221
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceIpUsage")
1222
+ ret = fn(c_uint(device_id), _mxSmlUsageIp_t(usage_ip), byref(usage))
1223
+ _mxsmlCheckReturn(ret)
1224
+ return usage.value
1225
+
1226
+
1227
+ def mxSmlGetXcoreApUsage(device_id):
1228
+ fn = _mxsmlGetFunctionPointer("mxSmlGetXcoreApUsage")
1229
+ size = c_uint(0)
1230
+ dpc_num = c_uint(0)
1231
+ ret = fn(c_uint(device_id), (c_uint * 0)(), byref(size), byref(dpc_num))
1232
+
1233
+ if ret == MXSML_ERROR_INSUFFICIENT_SIZE:
1234
+ usage_array = (c_uint * size.value)()
1235
+ ret = fn(c_uint(device_id), byref(usage_array), byref(size), byref(dpc_num))
1236
+ _mxsmlCheckReturn(ret)
1237
+ idx_num = (size.value + dpc_num.value - 1) // dpc_num.value
1238
+ return [usage_array[i : i + idx_num] for i in range(0, size.value, idx_num)]
1239
+ else:
1240
+ raise MXSMLError(ret)
1241
+
1242
+
1243
+ def mxSmlGetApUsageToggle(device_id):
1244
+ toggle = c_uint()
1245
+ fn = _mxsmlGetFunctionPointer("mxSmlGetApUsageToggle")
1246
+ ret = fn(c_uint(device_id), byref(toggle))
1247
+ _mxsmlCheckReturn(ret)
1248
+ return toggle.value
1249
+
1250
+
1251
+ def mxSmlGetFwIpLoglevel(device_id, fw_ip):
1252
+ level = _mxSmlLoglevel_t()
1253
+ fn = _mxsmlGetFunctionPointer("mxSmlGetFwIpLoglevel")
1254
+ ret = fn(c_uint(device_id), _mxSmlFwIpName_t(fw_ip), byref(level))
1255
+ _mxsmlCheckReturn(ret)
1256
+ return level.value
1257
+
1258
+
1259
+ def mxSmlGetFwLoglevel(device_id):
1260
+ log_level = c_mxSmlFwLoglevel_t()
1261
+ fn = _mxsmlGetFunctionPointer("mxSmlGetFwLoglevel")
1262
+ ret = fn(c_uint(device_id), byref(log_level))
1263
+ _mxsmlCheckReturn(ret)
1264
+ return log_level
1265
+
1266
+
1267
+ def mxSmlGetEccState(device_id):
1268
+ state = c_uint()
1269
+ fn = _mxsmlGetFunctionPointer("mxSmlGetEccState")
1270
+ ret = fn(c_uint(device_id), byref(state))
1271
+ _mxsmlCheckReturn(ret)
1272
+ return state.value
1273
+
1274
+
1275
+ def mxSmlGetMetaXLinkInfo(device_id):
1276
+ mxlk_info = c_mxSmlMetaXLinkInfo_t()
1277
+ fn = _mxsmlGetFunctionPointer("mxSmlGetMetaXLinkInfo")
1278
+ ret = fn(c_uint(device_id), byref(mxlk_info))
1279
+ _mxsmlCheckReturn(ret)
1280
+ return mxlk_info
1281
+
1282
+
1283
+ def mxSmlGetSriovState(device_id):
1284
+ state = c_uint()
1285
+ fn = _mxsmlGetFunctionPointer("mxSmlGetSriovState")
1286
+ ret = fn(c_uint(device_id), byref(state))
1287
+ _mxsmlCheckReturn(ret)
1288
+ return state.value
1289
+
1290
+
1291
+ def mxSmlGetDeviceSlot(device_id):
1292
+ slot = c_uint()
1293
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceSlot")
1294
+ ret = fn(c_uint(device_id), byref(slot))
1295
+ _mxsmlCheckReturn(ret)
1296
+ return slot.value
1297
+
1298
+
1299
+ def mxSmlGetOpticalModuleStatus(device_id):
1300
+ fn = _mxsmlGetFunctionPointer("mxSmlGetOpticalModuleStatus")
1301
+ size = c_uint(0)
1302
+ ret = fn(c_uint(device_id), (c_mxSmlOpticalModuleStatus_t * 0)(), byref(size))
1303
+
1304
+ if ret == MXSML_ERROR_INSUFFICIENT_SIZE:
1305
+ status_array = (c_mxSmlOpticalModuleStatus_t * size.value)()
1306
+ ret = fn(c_uint(device_id), byref(status_array), byref(size))
1307
+ _mxsmlCheckReturn(ret)
1308
+ return [status for status in status_array]
1309
+ else:
1310
+ raise MXSMLError(ret)
1311
+
1312
+
1313
+ def mxSmlGetOpticalModuleInfo(device_id):
1314
+ fn = _mxsmlGetFunctionPointer("mxSmlGetOpticalModuleInfo")
1315
+ size = c_uint(0)
1316
+ ret = fn(c_uint(device_id), (c_mxSmlOpticalModuleInfo_t * 0)(), byref(size))
1317
+
1318
+ if ret == MXSML_ERROR_INSUFFICIENT_SIZE:
1319
+ infos = (c_mxSmlOpticalModuleInfo_t * size.value)()
1320
+ ret = fn(c_uint(device_id), byref(infos), byref(size))
1321
+ _mxsmlCheckReturn(ret)
1322
+ return [info for info in infos]
1323
+ else:
1324
+ raise MXSMLError(ret)
1325
+
1326
+
1327
+ @convertStrBytes
1328
+ def mxSmlGetDeviceRealPath(device_id):
1329
+ real_path = create_string_buffer(MXSML_DEVICE_REAL_PATH_SIZE)
1330
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceRealPath")
1331
+ ret = fn(
1332
+ c_uint(device_id), byref(real_path), byref(c_uint(MXSML_DEVICE_REAL_PATH_SIZE))
1333
+ )
1334
+ _mxsmlCheckReturn(ret)
1335
+ return real_path.value
1336
+
1337
+
1338
+ def mxSmlGetCurrentClocksThrottleReason(device_id):
1339
+ reason = c_ulonglong()
1340
+ fn = _mxsmlGetFunctionPointer("mxSmlGetCurrentClocksThrottleReason")
1341
+ ret = fn(c_uint(device_id), byref(reason))
1342
+ _mxsmlCheckReturn(ret)
1343
+ return reason.value
1344
+
1345
+
1346
+ def mxSmlGetBoardPowerLimit(device_id):
1347
+ limit = c_uint()
1348
+ fn = _mxsmlGetFunctionPointer("mxSmlGetBoardPowerLimit")
1349
+ ret = fn(c_uint(device_id), byref(limit))
1350
+ _mxsmlCheckReturn(ret)
1351
+ return limit.value
1352
+
1353
+
1354
+ def mxSmlSetDpmIpMaxPerfLevel(device_id, dpm_ip, level):
1355
+ fn = _mxsmlGetFunctionPointer("mxSmlSetDpmIpMaxPerfLevel")
1356
+ ret = fn(c_uint(device_id), _mxSmlDpmIp_t(dpm_ip), c_uint(level))
1357
+ _mxsmlCheckReturn(ret)
1358
+ return ret
1359
+
1360
+
1361
+ @convertStrBytes
1362
+ def mxSmlDumpVbios(device_id, time_limit, bin_path):
1363
+ fn = _mxsmlGetFunctionPointer("mxSmlDumpVbios")
1364
+ fw_ret = c_uint()
1365
+ b_bin_path = c_char_p(bin_path)
1366
+ ret = fn(c_uint(device_id), c_uint(time_limit), b_bin_path, byref(fw_ret))
1367
+ _mxsmlCheckReturn(ret)
1368
+ return ret
1369
+
1370
+
1371
+ @convertStrBytes
1372
+ def mxSmlVbiosUpgrade(device_id, time_limit, bin_path):
1373
+ # Will take effect after reboot
1374
+ upgrade_arg = c_mxSmlVbiosUpgradeArg_t()
1375
+ upgrade_arg.timeLimit = c_uint(time_limit)
1376
+ upgrade_arg.vbiosBinPath = bin_path
1377
+ upgrade_arg.forceUpgrade = c_int(0)
1378
+ fn = _mxsmlGetFunctionPointer("mxSmlVbiosUpgrade")
1379
+ ret = fn(c_uint(device_id), byref(upgrade_arg))
1380
+ _mxsmlCheckReturn(ret)
1381
+ return ret
1382
+
1383
+
1384
+ def mxSmlFunctionLevelReset(device_id):
1385
+ fn = _mxsmlGetFunctionPointer("mxSmlFunctionLevelReset")
1386
+ ret = fn(c_uint(device_id))
1387
+ _mxsmlCheckReturn(ret)
1388
+ return ret
1389
+
1390
+
1391
+ def mxSmlFunctionLevelResetVfFromPf(device_id):
1392
+ fn = _mxsmlGetFunctionPointer("mxSmlFunctionLevelResetVfFromPf")
1393
+ ret = fn(c_uint(device_id))
1394
+ _mxsmlCheckReturn(ret)
1395
+ return ret
1396
+
1397
+
1398
+ def mxSmlSetUnlockKey(device_id, key):
1399
+ b_key = c_char_p(key.encode("utf-8"))
1400
+ fn = _mxsmlGetFunctionPointer("mxSmlSetUnlockKey")
1401
+ ret = fn(c_uint(device_id), b_key)
1402
+ _mxsmlCheckReturn(ret)
1403
+ return ret
1404
+
1405
+
1406
+ def mxSmlSetCpuAffinity(device_id):
1407
+ fn = _mxsmlGetFunctionPointer("mxSmlSetCpuAffinity")
1408
+ ret = fn(c_uint(device_id))
1409
+ _mxsmlCheckReturn(ret)
1410
+ return ret
1411
+
1412
+
1413
+ def mxSmlClearCpuAffinity(device_id):
1414
+ fn = _mxsmlGetFunctionPointer("mxSmlClearCpuAffinity")
1415
+ ret = fn(c_uint(device_id))
1416
+ _mxsmlCheckReturn(ret)
1417
+ return ret
1418
+
1419
+
1420
+ def mxSmlReset(device_id):
1421
+ fn = _mxsmlGetFunctionPointer("mxSmlReset")
1422
+ ret = fn(c_uint(device_id))
1423
+ _mxsmlCheckReturn(ret)
1424
+ return ret
1425
+
1426
+
1427
+ def mxSmlSetPciSpeed(device_id, pci_gen):
1428
+ # Will take effect after reboot
1429
+ fn = _mxsmlGetFunctionPointer("mxSmlSetPciSpeed")
1430
+ ret = fn(c_uint(device_id), _mxSmlPciGen_t(pci_gen))
1431
+ _mxsmlCheckReturn(ret)
1432
+ return ret
1433
+
1434
+
1435
+ def mxSmlSetPciDelay(device_id, delay):
1436
+ fn = _mxsmlGetFunctionPointer("mxSmlSetPciDelay")
1437
+ ret = fn(c_uint(device_id), c_uint(delay))
1438
+ _mxsmlCheckReturn(ret)
1439
+ return ret
1440
+
1441
+
1442
+ def mxSmlSetFwLoglevel(device_id, fw_ip, level):
1443
+ fn = _mxsmlGetFunctionPointer("mxSmlSetFwLoglevel")
1444
+ ret = fn(c_uint(device_id), _mxSmlFwIpName_t(fw_ip), _mxSmlLoglevel_t(level))
1445
+ _mxsmlCheckReturn(ret)
1446
+ return ret
1447
+
1448
+
1449
+ def mxSmlSetApUsageToggle(device_id, toggle):
1450
+ fn = _mxsmlGetFunctionPointer("mxSmlSetApUsageToggle")
1451
+ ret = fn(c_uint(device_id), c_uint(toggle))
1452
+ _mxsmlCheckReturn(ret)
1453
+ return ret
1454
+
1455
+
1456
+ def mxSmlSetEccState(device_id, state):
1457
+ # Will take effect after reboot
1458
+ fn = _mxsmlGetFunctionPointer("mxSmlSetEccState")
1459
+ ret = fn(c_uint(device_id), c_uint(state))
1460
+ _mxsmlCheckReturn(ret)
1461
+ return ret
1462
+
1463
+
1464
+ def mxSmlGetMetaXLinkState(device_id):
1465
+ fn = _mxsmlGetFunctionPointer("mxSmlGetMetaXLinkState")
1466
+ mxlkStateCode = _mxSmlMetaXLinkState_t()
1467
+ entry = []
1468
+ mxlk_state = (c_char * 128)(*entry)
1469
+ size = c_uint(128)
1470
+ ret = fn(c_uint(device_id), byref(mxlkStateCode), byref(mxlk_state), byref(size))
1471
+ _mxsmlCheckReturn(ret)
1472
+ return ret
1473
+
1474
+
1475
+ def mxSmlGetMetaXLinkPortState(device_id):
1476
+ fn = _mxsmlGetFunctionPointer("mxSmlGetMetaXLinkPortState")
1477
+ entry = []
1478
+ mxlk_port_state = (_mxSmlMxlkPortState_t * 7)(*entry)
1479
+ size = c_uint(7)
1480
+ ret = fn(c_uint(device_id), byref(mxlk_port_state), byref(size))
1481
+ _mxsmlCheckReturn(ret)
1482
+ return mxlk_port_state
1483
+
1484
+
1485
+ def mxSmlGetPciMmioState(device_id):
1486
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPciMmioState")
1487
+ state = c_uint()
1488
+ ret = fn(c_uint(device_id), byref(state))
1489
+ _mxsmlCheckReturn(ret)
1490
+ return state.value
1491
+
1492
+
1493
+ def mxSmlGetPciEventInfo(device_id, event_type):
1494
+ fn = _mxsmlGetFunctionPointer("mxSmlGetPciEventInfo")
1495
+ entry = []
1496
+ event_infos = (c_mxSmlPciEventInfo_t * 2)(*entry)
1497
+ size = c_uint(2)
1498
+ ret = fn(
1499
+ c_uint(device_id),
1500
+ _mxSmlPciEventType_t(event_type),
1501
+ byref(event_infos),
1502
+ byref(size),
1503
+ )
1504
+ _mxsmlCheckReturn(ret)
1505
+ return event_infos
1506
+
1507
+
1508
+ def mxSmlGetDeviceIsaVersion(device_id):
1509
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceIsaVersion")
1510
+ isaVersion = c_int(0)
1511
+ ret = fn(c_uint(device_id), byref(isaVersion))
1512
+ _mxsmlCheckReturn(ret)
1513
+ return isaVersion.value
1514
+
1515
+
1516
+ def mxSmlGetDeviceUnavailableReason(device_id):
1517
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceUnavailableReason")
1518
+ reason = c_mxSmlDeviceUnavailableReasonInfo_t()
1519
+ ret = fn(c_uint(device_id), byref(reason))
1520
+ _mxsmlCheckReturn(ret)
1521
+ return reason
1522
+
1523
+
1524
+ def mxSmlGetTotalEccErrors(device_id):
1525
+ fn = _mxsmlGetFunctionPointer("mxSmlGetTotalEccErrors")
1526
+ eccCounts = c_mxSmlEccErrorCount_t()
1527
+ ret = fn(c_uint(device_id), byref(eccCounts))
1528
+ _mxsmlCheckReturn(ret)
1529
+ return mxsmlStructToFriendlyObject(eccCounts)
1530
+
1531
+
1532
+ def mxSmlGetMetaXLinkTopo(device_id):
1533
+ fn = _mxsmlGetFunctionPointer("mxSmlGetMetaXLinkTopo")
1534
+ topoInfo = c_mxSmlMetaXLinkTopo_t()
1535
+ ret = fn(c_uint(device_id), byref(topoInfo))
1536
+ _mxsmlCheckReturn(ret)
1537
+ return mxsmlStructToFriendlyObject(topoInfo)
1538
+
1539
+
1540
+ @convertStrBytes
1541
+ def mxSmlGetErrorString(result):
1542
+ fn = _mxsmlGetFunctionPointer("mxSmlGetErrorString")
1543
+ fn.restype = c_char_p # otherwise return is an int
1544
+ ret = fn(_mxsmlReturn_t(result))
1545
+ return ret
1546
+
1547
+
1548
+ def mxSmlGetDeviceDieId(device_id):
1549
+ fn = _mxsmlGetFunctionPointer("mxSmlGetDeviceDieId")
1550
+ die_id = c_uint()
1551
+ ret = fn(c_uint(device_id), byref(die_id))
1552
+ _mxsmlCheckReturn(ret)
1553
+ return die_id.value