gpustack-runtime 0.1.39.post2__py3-none-any.whl → 0.1.40__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.
- gpustack_runtime/__main__.py +7 -3
- gpustack_runtime/_version.py +2 -2
- gpustack_runtime/_version_appendix.py +1 -1
- gpustack_runtime/cmds/__init__.py +2 -0
- gpustack_runtime/cmds/deployer.py +84 -2
- gpustack_runtime/cmds/images.py +2 -0
- gpustack_runtime/deployer/__init__.py +2 -0
- gpustack_runtime/deployer/__types__.py +52 -28
- gpustack_runtime/deployer/__utils__.py +99 -112
- gpustack_runtime/deployer/cdi/__init__.py +81 -0
- gpustack_runtime/deployer/cdi/__types__.py +667 -0
- gpustack_runtime/deployer/cdi/thead.py +103 -0
- gpustack_runtime/deployer/docker.py +42 -24
- gpustack_runtime/deployer/kuberentes.py +8 -4
- gpustack_runtime/deployer/podman.py +41 -23
- gpustack_runtime/detector/__init__.py +62 -3
- gpustack_runtime/detector/__types__.py +11 -0
- gpustack_runtime/detector/__utils__.py +23 -0
- gpustack_runtime/detector/amd.py +17 -9
- gpustack_runtime/detector/hygon.py +6 -1
- gpustack_runtime/detector/iluvatar.py +20 -5
- gpustack_runtime/detector/mthreads.py +8 -12
- gpustack_runtime/detector/nvidia.py +365 -168
- gpustack_runtime/detector/pyacl/__init__.py +9 -1
- gpustack_runtime/detector/pyamdgpu/__init__.py +8 -0
- gpustack_runtime/detector/pycuda/__init__.py +9 -1
- gpustack_runtime/detector/pydcmi/__init__.py +9 -2
- gpustack_runtime/detector/pyhgml/__init__.py +5879 -0
- gpustack_runtime/detector/pyhgml/libhgml.so +0 -0
- gpustack_runtime/detector/pyhgml/libuki.so +0 -0
- gpustack_runtime/detector/pyhsa/__init__.py +9 -0
- gpustack_runtime/detector/pyixml/__init__.py +89 -164
- gpustack_runtime/detector/pyrocmcore/__init__.py +42 -24
- gpustack_runtime/detector/pyrocmsmi/__init__.py +141 -138
- gpustack_runtime/detector/thead.py +733 -0
- gpustack_runtime/envs.py +128 -55
- {gpustack_runtime-0.1.39.post2.dist-info → gpustack_runtime-0.1.40.dist-info}/METADATA +4 -2
- gpustack_runtime-0.1.40.dist-info/RECORD +55 -0
- gpustack_runtime/detector/pymtml/__init__.py +0 -770
- gpustack_runtime-0.1.39.post2.dist-info/RECORD +0 -49
- {gpustack_runtime-0.1.39.post2.dist-info → gpustack_runtime-0.1.40.dist-info}/WHEEL +0 -0
- {gpustack_runtime-0.1.39.post2.dist-info → gpustack_runtime-0.1.40.dist-info}/entry_points.txt +0 -0
- {gpustack_runtime-0.1.39.post2.dist-info → gpustack_runtime-0.1.40.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,770 +0,0 @@
|
|
|
1
|
-
##
|
|
2
|
-
# Python bindings for the MTML library
|
|
3
|
-
##
|
|
4
|
-
from __future__ import annotations
|
|
5
|
-
|
|
6
|
-
import string
|
|
7
|
-
import sys
|
|
8
|
-
import threading
|
|
9
|
-
from ctypes import *
|
|
10
|
-
from functools import wraps
|
|
11
|
-
from typing import ClassVar
|
|
12
|
-
|
|
13
|
-
## C Type mappings ##
|
|
14
|
-
## Constants ##
|
|
15
|
-
MTML_LIBRARY_VERSION_BUFFER_SIZE = 32
|
|
16
|
-
MTML_DRIVER_VERSION_BUFFER_SIZE = 80
|
|
17
|
-
MTML_DEVICE_NAME_BUFFER_SIZE = 32
|
|
18
|
-
MTML_DEVICE_UUID_BUFFER_SIZE = 48
|
|
19
|
-
MTML_DEVICE_MTBIOS_VERSION_BUFFER_SIZE = 64
|
|
20
|
-
MTML_DEVICE_VBIOS_VERSION_BUFFER_SIZE = MTML_DEVICE_MTBIOS_VERSION_BUFFER_SIZE
|
|
21
|
-
MTML_DEVICE_PATH_BUFFER_SIZE = 64
|
|
22
|
-
MTML_DEVICE_PCI_SBDF_BUFFER_SIZE = 32
|
|
23
|
-
MTML_VIRT_TYPE_ID_BUFFER_SIZE = 16
|
|
24
|
-
MTML_VIRT_TYPE_CLASS_BUFFER_SIZE = 32
|
|
25
|
-
MTML_VIRT_TYPE_NAME_BUFFER_SIZE = 32
|
|
26
|
-
MTML_VIRT_TYPE_API_BUFFER_SIZE = 16
|
|
27
|
-
MTML_DEVICE_PCI_BUS_ID_FMT = "%08X:%02X:%02X.0"
|
|
28
|
-
MTML_LOG_FILE_PATH_BUFFER_SIZE = 200
|
|
29
|
-
MTML_MPC_PROFILE_NAME_BUFFER_SIZE = 32
|
|
30
|
-
MTML_MPC_CONF_NAME_BUFFER_SIZE = 32
|
|
31
|
-
MTML_MPC_CONF_MAX_PROF_NUM = 16
|
|
32
|
-
MTML_DEVICE_SLOT_NAME_BUFFER_SIZE = 32
|
|
33
|
-
MTML_MEMORY_VENDOR_BUFFER_SIZE = 64
|
|
34
|
-
MTML_DEVICE_SERIAL_NUMBER_BUFFER_SIZE = 64
|
|
35
|
-
|
|
36
|
-
## Enums ##
|
|
37
|
-
MTML_BRAND_MTT = 0
|
|
38
|
-
MTML_BRAND_UNKNOWN = 1
|
|
39
|
-
|
|
40
|
-
## Enums ##
|
|
41
|
-
MTML_DEVICE_NOT_SUPPORT_VIRTUALIZATION = 0
|
|
42
|
-
MTML_DEVICE_SUPPORT_VIRTUALIZATION = 1
|
|
43
|
-
|
|
44
|
-
## Enums ##
|
|
45
|
-
MTML_VIRT_ROLE_NONE = 0
|
|
46
|
-
MTML_VIRT_ROLE_HOST_VIRTDEVICE = 1
|
|
47
|
-
|
|
48
|
-
## Enums ##
|
|
49
|
-
MTML_MPC_TYPE_NONE = 0
|
|
50
|
-
MTML_MPC_TYPE_PARENT = 1
|
|
51
|
-
MTML_MPC_TYPE_INSTANCE = 2
|
|
52
|
-
|
|
53
|
-
## Enums ##
|
|
54
|
-
MTML_DEVICE_NOT_SUPPORT_MPC = 0
|
|
55
|
-
MTML_DEVICE_SUPPORT_MPC = 1
|
|
56
|
-
|
|
57
|
-
## Enums ##
|
|
58
|
-
MTML_DEVICE_NOT_SUPPORT_MTLINK = 0
|
|
59
|
-
MTML_DEVICE_SUPPORT_MTLINK = 1
|
|
60
|
-
|
|
61
|
-
## Enums ##
|
|
62
|
-
MTML_GPU_ENGINE_GEOMETRY = 0
|
|
63
|
-
MTML_GPU_ENGINE_2D = 1
|
|
64
|
-
MTML_GPU_ENGINE_3D = 2
|
|
65
|
-
MTML_GPU_ENGINE_COMPUTE = 3
|
|
66
|
-
|
|
67
|
-
## Enums ##
|
|
68
|
-
MTML_DEVICE_MPC_DISABLE = 0
|
|
69
|
-
MTML_DEVICE_MPC_ENABLE = 1
|
|
70
|
-
|
|
71
|
-
## Enums ##
|
|
72
|
-
MTML_TOPOLOGY_INTERNAL = 0
|
|
73
|
-
MTML_TOPOLOGY_SINGLE = 1
|
|
74
|
-
MTML_TOPOLOGY_MULTIPLE = 2
|
|
75
|
-
MTML_TOPOLOGY_HOSTBRIDGE = 3
|
|
76
|
-
MTML_TOPOLOGY_NODE = 4
|
|
77
|
-
MTML_TOPOLOGY_SYSTEM = 5
|
|
78
|
-
|
|
79
|
-
## Error Codes ##
|
|
80
|
-
MTML_SUCCESS = 0
|
|
81
|
-
MTML_ERROR_DRIVER_NOT_LOADED = 1
|
|
82
|
-
MTML_ERROR_DRIVER_FAILURE = 2
|
|
83
|
-
MTML_ERROR_INVALID_ARGUMENT = 3
|
|
84
|
-
MTML_ERROR_NOT_SUPPORTED = 4
|
|
85
|
-
MTML_ERROR_NO_PERMISSION = 5
|
|
86
|
-
MTML_ERROR_INSUFFICIENT_SIZE = 6
|
|
87
|
-
MTML_ERROR_NOT_FOUND = 7
|
|
88
|
-
MTML_ERROR_INSUFFICIENT_MEMORY = 8
|
|
89
|
-
MTML_ERROR_DRIVER_TOO_OLD = 9
|
|
90
|
-
MTML_ERROR_DRIVER_TOO_NEW = 10
|
|
91
|
-
MTML_ERROR_TIMEOUT = 11
|
|
92
|
-
MTML_ERROR_UNKNOWN = 999
|
|
93
|
-
MTML_ERROR_UNINITIALIZED = -99997
|
|
94
|
-
MTML_ERROR_FUNCTION_NOT_FOUND = -99998
|
|
95
|
-
MTML_ERROR_LIBRARY_NOT_FOUND = -99999
|
|
96
|
-
|
|
97
|
-
## Lib loading ##
|
|
98
|
-
mtmlLib = None
|
|
99
|
-
libLoadLock = threading.Lock()
|
|
100
|
-
_mtmlLib_refcount = (
|
|
101
|
-
0 # Incremented on each mtmlLibraryInit and decremented on mtmlLibraryShutdown
|
|
102
|
-
)
|
|
103
|
-
_mtmlLib = None # Hold the loaded library, release when refcount goes to 0
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
## Error Checking ##
|
|
107
|
-
class MTMLError(Exception):
|
|
108
|
-
_valClassMapping: ClassVar[dict] = {}
|
|
109
|
-
|
|
110
|
-
_errcode_to_string: ClassVar[dict] = {
|
|
111
|
-
MTML_ERROR_DRIVER_NOT_LOADED: "Driver Not Loaded",
|
|
112
|
-
MTML_ERROR_DRIVER_FAILURE: "Driver Failure",
|
|
113
|
-
MTML_ERROR_INVALID_ARGUMENT: "Invalid Argument",
|
|
114
|
-
MTML_ERROR_NOT_SUPPORTED: "Not Supported",
|
|
115
|
-
MTML_ERROR_NO_PERMISSION: "No Permission",
|
|
116
|
-
MTML_ERROR_INSUFFICIENT_SIZE: "Insufficient Size",
|
|
117
|
-
MTML_ERROR_NOT_FOUND: "Not Found",
|
|
118
|
-
MTML_ERROR_INSUFFICIENT_MEMORY: "Insufficient Memory",
|
|
119
|
-
MTML_ERROR_DRIVER_TOO_OLD: "Driver Too Old",
|
|
120
|
-
MTML_ERROR_DRIVER_TOO_NEW: "Driver too New",
|
|
121
|
-
MTML_ERROR_TIMEOUT: "Timeout",
|
|
122
|
-
MTML_ERROR_UNKNOWN: "Unknown Error",
|
|
123
|
-
MTML_ERROR_UNINITIALIZED: "Library Not Initialized",
|
|
124
|
-
MTML_ERROR_FUNCTION_NOT_FOUND: "Function Not Found",
|
|
125
|
-
MTML_ERROR_LIBRARY_NOT_FOUND: "Library Not Found",
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
def __new__(cls, value):
|
|
129
|
-
"""
|
|
130
|
-
Maps value to a proper subclass of MTMLError.
|
|
131
|
-
See _extractMTMLErrorsAsClasses function for more details.
|
|
132
|
-
"""
|
|
133
|
-
if cls == MTMLError:
|
|
134
|
-
cls = MTMLError._valClassMapping.get(value, cls)
|
|
135
|
-
obj = Exception.__new__(cls)
|
|
136
|
-
obj.value = value
|
|
137
|
-
return obj
|
|
138
|
-
|
|
139
|
-
def __str__(self):
|
|
140
|
-
try:
|
|
141
|
-
if self.value not in MTMLError._errcode_to_string:
|
|
142
|
-
MTMLError._errcode_to_string[self.value] = (
|
|
143
|
-
f"Unknown MTML Error {self.value}"
|
|
144
|
-
)
|
|
145
|
-
return MTMLError._errcode_to_string[self.value]
|
|
146
|
-
except MTMLError:
|
|
147
|
-
return f"MTML Error with code {self.value}"
|
|
148
|
-
|
|
149
|
-
def __eq__(self, other):
|
|
150
|
-
if isinstance(other, MTMLError):
|
|
151
|
-
return self.value == other.value
|
|
152
|
-
if isinstance(other, int):
|
|
153
|
-
return self.value == other
|
|
154
|
-
return False
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
def mtmlExceptionClass(mtmlErrorCode):
|
|
158
|
-
if mtmlErrorCode not in MTMLError._valClassMapping:
|
|
159
|
-
msg = f"MTML error code {mtmlErrorCode} is not valid"
|
|
160
|
-
raise ValueError(msg)
|
|
161
|
-
return MTMLError._valClassMapping[mtmlErrorCode]
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def _extractMTMLErrorsAsClasses():
|
|
165
|
-
"""
|
|
166
|
-
Generates a hierarchy of classes on top of MTMLError class.
|
|
167
|
-
|
|
168
|
-
Each MTML Error gets a new MTMLError subclass. This way try,except blocks can filter appropriate
|
|
169
|
-
exceptions more easily.
|
|
170
|
-
|
|
171
|
-
MTMLError is a parent class. Each MTML_ERROR_* gets it's own subclass.
|
|
172
|
-
e.g. MTML_ERROR_INVALID_ARGUMENT will be turned into MTMLError_InvalidArgument.
|
|
173
|
-
"""
|
|
174
|
-
this_module = sys.modules[__name__]
|
|
175
|
-
mtmlErrorsNames = [x for x in dir(this_module) if x.startswith("MTML_ERROR_")]
|
|
176
|
-
for err_name in mtmlErrorsNames:
|
|
177
|
-
# e.g. Turn MTML_ERROR_INVALID_ARGUMENT into MTMLError_InvalidArgument
|
|
178
|
-
class_name = "MTMLError_" + string.capwords(
|
|
179
|
-
err_name.replace("MTML_ERROR_", ""),
|
|
180
|
-
"_",
|
|
181
|
-
).replace("_", "")
|
|
182
|
-
err_val = getattr(this_module, err_name)
|
|
183
|
-
|
|
184
|
-
def gen_new(val):
|
|
185
|
-
def new(typ, *args):
|
|
186
|
-
obj = MTMLError.__new__(typ, val)
|
|
187
|
-
return obj
|
|
188
|
-
|
|
189
|
-
return new
|
|
190
|
-
|
|
191
|
-
new_error_class = type(class_name, (MTMLError,), {"__new__": gen_new(err_val)})
|
|
192
|
-
new_error_class.__module__ = __name__
|
|
193
|
-
setattr(this_module, class_name, new_error_class)
|
|
194
|
-
MTMLError._valClassMapping[err_val] = new_error_class
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
_extractMTMLErrorsAsClasses()
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
def _mtmlCheckReturn(ret):
|
|
201
|
-
if ret != MTML_SUCCESS:
|
|
202
|
-
raise MTMLError(ret)
|
|
203
|
-
return ret
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
## Function access ##
|
|
207
|
-
_mtmlGetFunctionPointer_cache = {}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
def _mtmlGetFunctionPointer(name):
|
|
211
|
-
global mtmlLib
|
|
212
|
-
|
|
213
|
-
if name in _mtmlGetFunctionPointer_cache:
|
|
214
|
-
return _mtmlGetFunctionPointer_cache[name]
|
|
215
|
-
|
|
216
|
-
libLoadLock.acquire()
|
|
217
|
-
try:
|
|
218
|
-
if mtmlLib is None:
|
|
219
|
-
raise MTMLError(MTML_ERROR_UNINITIALIZED)
|
|
220
|
-
try:
|
|
221
|
-
_mtmlGetFunctionPointer_cache[name] = getattr(mtmlLib, name)
|
|
222
|
-
return _mtmlGetFunctionPointer_cache[name]
|
|
223
|
-
except AttributeError:
|
|
224
|
-
raise MTMLError(MTML_ERROR_FUNCTION_NOT_FOUND)
|
|
225
|
-
finally:
|
|
226
|
-
libLoadLock.release()
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
## Alternative object
|
|
230
|
-
# Allows the object to be printed
|
|
231
|
-
# Allows mismatched types to be assigned
|
|
232
|
-
# - like None when the Structure variant requires c_uint
|
|
233
|
-
class mtmlFriendlyObject:
|
|
234
|
-
def __init__(self, dictionary):
|
|
235
|
-
for x in dictionary:
|
|
236
|
-
setattr(self, x, dictionary[x])
|
|
237
|
-
|
|
238
|
-
def __str__(self):
|
|
239
|
-
return self.__dict__.__str__()
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
def mtmlStructToFriendlyObject(struct):
|
|
243
|
-
d = {}
|
|
244
|
-
for x in struct._fields_:
|
|
245
|
-
key = x[0]
|
|
246
|
-
value = getattr(struct, key)
|
|
247
|
-
# only need to convert from bytes if bytes, no need to check python version.
|
|
248
|
-
d[key] = value.decode() if isinstance(value, bytes) else value
|
|
249
|
-
obj = mtmlFriendlyObject(d)
|
|
250
|
-
return obj
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
# pack the object so it can be passed to the MTML library
|
|
254
|
-
def mtmlFriendlyObjectToStruct(obj, model):
|
|
255
|
-
for x in model._fields_:
|
|
256
|
-
key = x[0]
|
|
257
|
-
value = obj.__dict__[key]
|
|
258
|
-
# any c_char_p in python3 needs to be bytes, default encoding works fine.
|
|
259
|
-
setattr(model, key, value.encode())
|
|
260
|
-
return model
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
## Structure definitions ##
|
|
264
|
-
class _PrintableStructure(Structure):
|
|
265
|
-
"""
|
|
266
|
-
Abstract class that produces nicer __str__ output than ctypes.Structure.
|
|
267
|
-
"""
|
|
268
|
-
|
|
269
|
-
_fmt_ = {}
|
|
270
|
-
|
|
271
|
-
def __str__(self):
|
|
272
|
-
result = []
|
|
273
|
-
for x in self._fields_:
|
|
274
|
-
key = x[0]
|
|
275
|
-
value = getattr(self, key)
|
|
276
|
-
fmt = "%s"
|
|
277
|
-
if key in self._fmt_:
|
|
278
|
-
fmt = self._fmt_[key]
|
|
279
|
-
elif "<default>" in self._fmt_:
|
|
280
|
-
fmt = self._fmt_["<default>"]
|
|
281
|
-
result.append(("%s: " + fmt) % (key, value))
|
|
282
|
-
return self.__class__.__name__ + "(" + ", ".join(result) + ")"
|
|
283
|
-
|
|
284
|
-
def __getattribute__(self, name):
|
|
285
|
-
res = super().__getattribute__(name)
|
|
286
|
-
if isinstance(res, bytes):
|
|
287
|
-
return res.decode()
|
|
288
|
-
return res
|
|
289
|
-
|
|
290
|
-
def __setattr__(self, name, value):
|
|
291
|
-
if isinstance(value, str):
|
|
292
|
-
value = value.encode()
|
|
293
|
-
super().__setattr__(name, value)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
## Device structures
|
|
297
|
-
class struct_c_MtmlDevice_t(Structure):
|
|
298
|
-
pass # opaque handle
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
c_MtmlDevice_t = POINTER(struct_c_MtmlDevice_t)
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
class struct_c_MtmlGpu_t(Structure):
|
|
305
|
-
pass # opaque handle
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
c_MtmlGpu_t = POINTER(struct_c_MtmlGpu_t)
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
class struct_c_MtmlLibrary_t(Structure):
|
|
312
|
-
pass # opaque handle
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
c_MtmlLibrary_t = POINTER(struct_c_MtmlLibrary_t)
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
class struct_c_MtmlMemory_t(Structure):
|
|
319
|
-
pass # opaque handle
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
c_MtmlMemory_t = POINTER(struct_c_MtmlMemory_t)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
class struct_c_MtmlSystem_t(Structure):
|
|
326
|
-
pass # opaque handle
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
c_MtmlSystem_t = POINTER(struct_c_MtmlSystem_t)
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
class struct_c_MtmlVpu_t(Structure):
|
|
333
|
-
pass # opaque handle
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
c_MtmlVpu_t = POINTER(struct_c_MtmlVpu_t)
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
class c_MtmlPciInfo_t(_PrintableStructure):
|
|
340
|
-
_fields_: ClassVar = [
|
|
341
|
-
("sbdf", c_char * MTML_DEVICE_PCI_SBDF_BUFFER_SIZE),
|
|
342
|
-
("segment", c_uint),
|
|
343
|
-
("bus", c_uint),
|
|
344
|
-
("device", c_uint),
|
|
345
|
-
("pciDeviceId", c_uint),
|
|
346
|
-
("pciSubsystemId", c_uint),
|
|
347
|
-
("busWidth", c_uint),
|
|
348
|
-
("pciMaxSpeed", c_float),
|
|
349
|
-
("pciCurSpeed", c_float),
|
|
350
|
-
("pciMaxWidth", c_uint),
|
|
351
|
-
("pciCurWidth", c_uint),
|
|
352
|
-
("pciMaxGen", c_uint),
|
|
353
|
-
("pciCurGen", c_uint),
|
|
354
|
-
("rsvd", c_int * 6),
|
|
355
|
-
]
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
class c_MtmlDeviceProperty_t(_PrintableStructure):
|
|
359
|
-
_fields_: ClassVar = [
|
|
360
|
-
("virtCap", c_uint), # 0 = no virt, 1 = virt supported
|
|
361
|
-
("virtRole", c_uint), # 0 = none, 1 = host virt device
|
|
362
|
-
("mpcCap", c_uint), # 0 = no mpc, 1 = mpc parent, 2 = mpc instance
|
|
363
|
-
("mpcType", c_uint), # 0 = no mpc, 1 = supported
|
|
364
|
-
("mtLinkCap", c_uint), # 0 = no mtlink, 1 = mtlink supported
|
|
365
|
-
("rsvd", c_uint),
|
|
366
|
-
("rsvd2", c_uint),
|
|
367
|
-
]
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
class c_MtmlVirtType_t(_PrintableStructure):
|
|
371
|
-
_fields_: ClassVar = [
|
|
372
|
-
("id", c_char * MTML_VIRT_TYPE_ID_BUFFER_SIZE),
|
|
373
|
-
("name", c_char * MTML_VIRT_TYPE_NAME_BUFFER_SIZE),
|
|
374
|
-
("api", c_char * MTML_VIRT_TYPE_API_BUFFER_SIZE),
|
|
375
|
-
("horizontalResolution", c_uint),
|
|
376
|
-
("verticalResolution", c_uint),
|
|
377
|
-
("frameBuffer", c_uint),
|
|
378
|
-
("maxEncodeNum", c_uint),
|
|
379
|
-
("maxDecodeNum", c_uint),
|
|
380
|
-
("maxInstances", c_uint),
|
|
381
|
-
("maxVirtualDisplay", c_uint),
|
|
382
|
-
("rsvd", c_int * 11),
|
|
383
|
-
]
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
## string/bytes conversion for ease of use
|
|
387
|
-
def convertStrBytes(func):
|
|
388
|
-
@wraps(func)
|
|
389
|
-
def wrapper(*args, **kwargs):
|
|
390
|
-
# encoding a str returns bytes in python 2 and 3
|
|
391
|
-
args = [arg.encode() if isinstance(arg, str) else arg for arg in args]
|
|
392
|
-
res = func(*args, **kwargs)
|
|
393
|
-
# In python 2, str and bytes are the same
|
|
394
|
-
# In python 3, str is unicode and should be decoded.
|
|
395
|
-
# Ctypes handles most conversions, this only effects c_char and char arrays.
|
|
396
|
-
if isinstance(res, bytes):
|
|
397
|
-
if isinstance(res, str):
|
|
398
|
-
return res
|
|
399
|
-
return res.decode()
|
|
400
|
-
return res
|
|
401
|
-
|
|
402
|
-
return wrapper
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
def _LoadMtmlLibrary():
|
|
406
|
-
global mtmlLib
|
|
407
|
-
if mtmlLib is None:
|
|
408
|
-
libLoadLock.acquire()
|
|
409
|
-
try:
|
|
410
|
-
if mtmlLib is None:
|
|
411
|
-
if sys.platform.startswith("win"):
|
|
412
|
-
# MTML is typically used on Linux, but for completeness,
|
|
413
|
-
# Windows support would require different path handling.
|
|
414
|
-
raise MTMLError(MTML_ERROR_LIBRARY_NOT_FOUND)
|
|
415
|
-
# Linux path
|
|
416
|
-
locs = [
|
|
417
|
-
"libmtml.so",
|
|
418
|
-
]
|
|
419
|
-
for loc in locs:
|
|
420
|
-
try:
|
|
421
|
-
mtmlLib = CDLL(loc)
|
|
422
|
-
break
|
|
423
|
-
except OSError:
|
|
424
|
-
pass
|
|
425
|
-
if mtmlLib is None:
|
|
426
|
-
raise MTMLError(MTML_ERROR_LIBRARY_NOT_FOUND)
|
|
427
|
-
finally:
|
|
428
|
-
libLoadLock.release()
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
## C function wrappers ##
|
|
432
|
-
def mtmlLibraryInit():
|
|
433
|
-
_LoadMtmlLibrary()
|
|
434
|
-
|
|
435
|
-
global _mtmlLib
|
|
436
|
-
global _mtmlLib_refcount
|
|
437
|
-
|
|
438
|
-
fn = _mtmlGetFunctionPointer("mtmlLibraryInit")
|
|
439
|
-
|
|
440
|
-
libLoadLock.acquire()
|
|
441
|
-
|
|
442
|
-
if _mtmlLib is None:
|
|
443
|
-
__mtmlLib = c_MtmlLibrary_t()
|
|
444
|
-
ret = fn(byref(__mtmlLib))
|
|
445
|
-
_mtmlCheckReturn(ret)
|
|
446
|
-
_mtmlLib = __mtmlLib
|
|
447
|
-
|
|
448
|
-
_mtmlLib_refcount += 1
|
|
449
|
-
libLoadLock.release()
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
def mtmlLibraryShutDown():
|
|
453
|
-
global _mtmlLib
|
|
454
|
-
global _mtmlLib_refcount
|
|
455
|
-
|
|
456
|
-
fn = _mtmlGetFunctionPointer("mtmlLibraryShutDown")
|
|
457
|
-
|
|
458
|
-
libLoadLock.acquire()
|
|
459
|
-
if _mtmlLib_refcount > 0:
|
|
460
|
-
_mtmlLib_refcount -= 1
|
|
461
|
-
if _mtmlLib_refcount == 0 and _mtmlLib is not None:
|
|
462
|
-
ret = fn(_mtmlLib)
|
|
463
|
-
_mtmlCheckReturn(ret)
|
|
464
|
-
_mtmlLib = None
|
|
465
|
-
libLoadLock.release()
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
@convertStrBytes
|
|
469
|
-
def mtmlLibraryGetVersion():
|
|
470
|
-
c_version = create_string_buffer(MTML_LIBRARY_VERSION_BUFFER_SIZE)
|
|
471
|
-
fn = _mtmlGetFunctionPointer("mtmlLibraryGetVersion")
|
|
472
|
-
ret = fn(_mtmlLib, c_version, MTML_LIBRARY_VERSION_BUFFER_SIZE)
|
|
473
|
-
_mtmlCheckReturn(ret)
|
|
474
|
-
return c_version.value
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
def mtmlLibraryInitSystem():
|
|
478
|
-
system = c_MtmlSystem_t()
|
|
479
|
-
fn = _mtmlGetFunctionPointer("mtmlLibraryInitSystem")
|
|
480
|
-
ret = fn(_mtmlLib, byref(system))
|
|
481
|
-
_mtmlCheckReturn(ret)
|
|
482
|
-
return system
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
def mtmlLibraryFreeSystem(system):
|
|
486
|
-
fn = _mtmlGetFunctionPointer("mtmlLibraryFreeSystem")
|
|
487
|
-
ret = fn(_mtmlLib, system)
|
|
488
|
-
_mtmlCheckReturn(ret)
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
def mtmlLibraryCountDevice():
|
|
492
|
-
c_count = c_uint32()
|
|
493
|
-
fn = _mtmlGetFunctionPointer("mtmlLibraryCountDevice")
|
|
494
|
-
ret = fn(_mtmlLib, byref(c_count))
|
|
495
|
-
_mtmlCheckReturn(ret)
|
|
496
|
-
return c_count.value
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
def mtmlLibraryInitDeviceByIndex(index):
|
|
500
|
-
c_index = c_uint(index)
|
|
501
|
-
device = c_MtmlDevice_t()
|
|
502
|
-
fn = _mtmlGetFunctionPointer("mtmlLibraryInitDeviceByIndex")
|
|
503
|
-
ret = fn(_mtmlLib, c_index, byref(device))
|
|
504
|
-
_mtmlCheckReturn(ret)
|
|
505
|
-
return device
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
def mtmlLibraryFreeDevice(device):
|
|
509
|
-
fn = _mtmlGetFunctionPointer("mtmlLibraryFreeDevice")
|
|
510
|
-
ret = fn(_mtmlLib, device)
|
|
511
|
-
_mtmlCheckReturn(ret)
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
@convertStrBytes
|
|
515
|
-
def mtmlSystemGetDriverVersion():
|
|
516
|
-
system = mtmlLibraryInitSystem()
|
|
517
|
-
try:
|
|
518
|
-
c_version = create_string_buffer(MTML_DRIVER_VERSION_BUFFER_SIZE)
|
|
519
|
-
fn = _mtmlGetFunctionPointer("mtmlSystemGetDriverVersion")
|
|
520
|
-
ret = fn(system, c_version, MTML_DRIVER_VERSION_BUFFER_SIZE)
|
|
521
|
-
_mtmlCheckReturn(ret)
|
|
522
|
-
return c_version.value
|
|
523
|
-
finally:
|
|
524
|
-
mtmlLibraryFreeSystem(system)
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
def mtmlDeviceInitGpu(device):
|
|
528
|
-
gpu = c_MtmlGpu_t()
|
|
529
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceInitGpu")
|
|
530
|
-
ret = fn(device, byref(gpu))
|
|
531
|
-
_mtmlCheckReturn(ret)
|
|
532
|
-
return gpu
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
def mtmlDeviceFreeGpu(gpu):
|
|
536
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceFreeGpu")
|
|
537
|
-
ret = fn(gpu)
|
|
538
|
-
_mtmlCheckReturn(ret)
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
def mtmlDeviceInitMemory(device):
|
|
542
|
-
memory = c_MtmlMemory_t()
|
|
543
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceInitMemory")
|
|
544
|
-
ret = fn(device, byref(memory))
|
|
545
|
-
_mtmlCheckReturn(ret)
|
|
546
|
-
return memory
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
def mtmlDeviceFreeMemory(memory):
|
|
550
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceFreeMemory")
|
|
551
|
-
ret = fn(memory)
|
|
552
|
-
_mtmlCheckReturn(ret)
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
def mtmlDeviceInitVpu(device):
|
|
556
|
-
vpu = c_MtmlVpu_t()
|
|
557
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceInitVpu")
|
|
558
|
-
ret = fn(device, byref(vpu))
|
|
559
|
-
_mtmlCheckReturn(ret)
|
|
560
|
-
return vpu
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
def mtmlDeviceFreeVpu(vpu):
|
|
564
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceFreeVpu")
|
|
565
|
-
ret = fn(vpu)
|
|
566
|
-
_mtmlCheckReturn(ret)
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
def mtmlDeviceGetIndex(device):
|
|
570
|
-
c_index = c_uint32()
|
|
571
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetIndex")
|
|
572
|
-
ret = fn(device, byref(c_index))
|
|
573
|
-
_mtmlCheckReturn(ret)
|
|
574
|
-
return c_index.value
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
@convertStrBytes
|
|
578
|
-
def mtmlDeviceGetUUID(device):
|
|
579
|
-
c_uuid = create_string_buffer(MTML_DEVICE_UUID_BUFFER_SIZE)
|
|
580
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetUUID")
|
|
581
|
-
ret = fn(device, c_uuid, MTML_DEVICE_UUID_BUFFER_SIZE)
|
|
582
|
-
_mtmlCheckReturn(ret)
|
|
583
|
-
return c_uuid.value
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
def mtmlDeviceGetBrand(device):
|
|
587
|
-
c_brand = c_uint32()
|
|
588
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetBrand")
|
|
589
|
-
ret = fn(device, byref(c_brand))
|
|
590
|
-
_mtmlCheckReturn(ret)
|
|
591
|
-
return c_brand.value
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
@convertStrBytes
|
|
595
|
-
def mtmlDeviceGetName(device):
|
|
596
|
-
c_name = create_string_buffer(MTML_DEVICE_NAME_BUFFER_SIZE)
|
|
597
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetName")
|
|
598
|
-
ret = fn(device, c_name, MTML_DEVICE_NAME_BUFFER_SIZE)
|
|
599
|
-
_mtmlCheckReturn(ret)
|
|
600
|
-
return c_name.value
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
def mtmlDeviceGetPciInfo(device):
|
|
604
|
-
pciInfo = c_MtmlPciInfo_t()
|
|
605
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetPciInfo")
|
|
606
|
-
ret = fn(device, byref(pciInfo))
|
|
607
|
-
_mtmlCheckReturn(ret)
|
|
608
|
-
return mtmlStructToFriendlyObject(pciInfo)
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
def mtmlDeviceGetPowerUsage(device):
|
|
612
|
-
c_power_usage = c_uint32()
|
|
613
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetPowerUsage")
|
|
614
|
-
ret = fn(device, byref(c_power_usage))
|
|
615
|
-
_mtmlCheckReturn(ret)
|
|
616
|
-
return c_power_usage.value
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
def mtmlDeviceGetProperty(device):
|
|
620
|
-
c_property = c_MtmlDeviceProperty_t()
|
|
621
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetProperty")
|
|
622
|
-
ret = fn(device, byref(c_property))
|
|
623
|
-
_mtmlCheckReturn(ret)
|
|
624
|
-
return mtmlStructToFriendlyObject(c_property)
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
@convertStrBytes
|
|
628
|
-
def mtmlDeviceGetSerialNumber(device):
|
|
629
|
-
c_serial = create_string_buffer(MTML_DEVICE_SERIAL_NUMBER_BUFFER_SIZE)
|
|
630
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetSerialNumber")
|
|
631
|
-
ret = fn(device, MTML_DEVICE_SERIAL_NUMBER_BUFFER_SIZE, c_serial)
|
|
632
|
-
_mtmlCheckReturn(ret)
|
|
633
|
-
return c_serial.value
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
def mtmlDeviceCountGpuCores(device):
|
|
637
|
-
c_count = c_uint32()
|
|
638
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceCountGpuCores")
|
|
639
|
-
ret = fn(device, byref(c_count))
|
|
640
|
-
_mtmlCheckReturn(ret)
|
|
641
|
-
return c_count.value
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
def mtmlDeviceCountAvailVirtTypes(device):
|
|
645
|
-
c_count = c_uint32()
|
|
646
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceCountAvailVirtTypes")
|
|
647
|
-
ret = fn(device, byref(c_count))
|
|
648
|
-
_mtmlCheckReturn(ret)
|
|
649
|
-
return c_count.value
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
def mtmlDeviceCountActiveVirtDevices(device):
|
|
653
|
-
c_count = c_uint32()
|
|
654
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceCountActiveVirtDevices")
|
|
655
|
-
ret = fn(device, byref(c_count))
|
|
656
|
-
_mtmlCheckReturn(ret)
|
|
657
|
-
return c_count.value
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
def mtmlDeviceGetActiveVirtDeviceUuids(device):
|
|
661
|
-
entryCount = mtmlDeviceCountActiveVirtDevices(device)
|
|
662
|
-
entryLength = MTML_DEVICE_UUID_BUFFER_SIZE
|
|
663
|
-
uuids = (c_char * (entryLength * entryCount))()
|
|
664
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetActiveVirtDeviceUuids")
|
|
665
|
-
ret = fn(device, uuids, entryLength, entryCount)
|
|
666
|
-
_mtmlCheckReturn(ret)
|
|
667
|
-
uuid_list = []
|
|
668
|
-
for i in range(entryCount):
|
|
669
|
-
start = i * entryLength
|
|
670
|
-
end = start + entryLength
|
|
671
|
-
uuid = bytes(uuids[start:end]).split(b"\x00", 1)[0].decode()
|
|
672
|
-
uuid_list.append(uuid)
|
|
673
|
-
return uuid_list
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
def mtmlDeviceInitVirtDevice(device, uuid):
|
|
677
|
-
c_uuid = c_char_p(uuid.encode())
|
|
678
|
-
virtDevice = c_MtmlDevice_t()
|
|
679
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceInitVirtDevice")
|
|
680
|
-
ret = fn(device, c_uuid, byref(virtDevice))
|
|
681
|
-
_mtmlCheckReturn(ret)
|
|
682
|
-
return virtDevice
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
def mtmlDeviceFreeVirtDevice(virtDevice):
|
|
686
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceFreeVirtDevice")
|
|
687
|
-
ret = fn(virtDevice)
|
|
688
|
-
_mtmlCheckReturn(ret)
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
def mtmlDeviceGetVirtType(virtDevice):
|
|
692
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetVirtType")
|
|
693
|
-
c_virtType = c_MtmlVirtType_t()
|
|
694
|
-
ret = fn(virtDevice, byref(c_virtType))
|
|
695
|
-
_mtmlCheckReturn(ret)
|
|
696
|
-
return c_virtType
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
def mtmlGpuGetUtilization(deviceGpu):
|
|
700
|
-
c_util = c_uint32()
|
|
701
|
-
fn = _mtmlGetFunctionPointer("mtmlGpuGetUtilization")
|
|
702
|
-
ret = fn(deviceGpu, byref(c_util))
|
|
703
|
-
_mtmlCheckReturn(ret)
|
|
704
|
-
return c_util.value
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
def mtmlGpuGetTemperature(deviceGpu):
|
|
708
|
-
c_temp = c_int()
|
|
709
|
-
fn = _mtmlGetFunctionPointer("mtmlGpuGetTemperature")
|
|
710
|
-
ret = fn(deviceGpu, byref(c_temp))
|
|
711
|
-
_mtmlCheckReturn(ret)
|
|
712
|
-
return c_temp.value
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
def mtmlGpuGetEngineUtilization(deviceGpu, engineType=MTML_GPU_ENGINE_COMPUTE):
|
|
716
|
-
c_util = c_uint32()
|
|
717
|
-
c_engineType = c_uint32(engineType)
|
|
718
|
-
fn = _mtmlGetFunctionPointer("mtmlGpuGetEngineUtilization")
|
|
719
|
-
ret = fn(deviceGpu, c_engineType, byref(c_util))
|
|
720
|
-
_mtmlCheckReturn(ret)
|
|
721
|
-
return c_util.value
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
def mtmlMemoryGetTotal(deviceMemory):
|
|
725
|
-
c_total = c_uint64()
|
|
726
|
-
fn = _mtmlGetFunctionPointer("mtmlMemoryGetTotal")
|
|
727
|
-
ret = fn(deviceMemory, byref(c_total))
|
|
728
|
-
_mtmlCheckReturn(ret)
|
|
729
|
-
return c_total.value
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
def mtmlMemoryGetUsed(deviceMemory):
|
|
733
|
-
c_used = c_uint64()
|
|
734
|
-
fn = _mtmlGetFunctionPointer("mtmlMemoryGetUsed")
|
|
735
|
-
ret = fn(deviceMemory, byref(c_used))
|
|
736
|
-
_mtmlCheckReturn(ret)
|
|
737
|
-
return c_used.value
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
def mtmlMemoryGetUtilization(deviceMemory):
|
|
741
|
-
c_util = c_uint32()
|
|
742
|
-
fn = _mtmlGetFunctionPointer("mtmlMemoryGetUtilization")
|
|
743
|
-
ret = fn(deviceMemory, byref(c_util))
|
|
744
|
-
_mtmlCheckReturn(ret)
|
|
745
|
-
return c_util.value
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
def mtmlDeviceGetMpcMode(device):
|
|
749
|
-
c_mode = c_uint32()
|
|
750
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetMpcMode")
|
|
751
|
-
ret = fn(device, byref(c_mode))
|
|
752
|
-
_mtmlCheckReturn(ret)
|
|
753
|
-
return c_mode.value
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
def mtmlDeviceGetMemoryAffinityWithinNode(device, nodeSetSize):
|
|
757
|
-
affinity_array = c_ulonglong * nodeSetSize
|
|
758
|
-
c_affinity = affinity_array()
|
|
759
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetMemoryAffinityWithinNode")
|
|
760
|
-
ret = fn(device, nodeSetSize, byref(c_affinity))
|
|
761
|
-
_mtmlCheckReturn(ret)
|
|
762
|
-
return c_affinity
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
def mtmlDeviceGetTopologyLevel(device1, device2):
|
|
766
|
-
c_level = c_uint()
|
|
767
|
-
fn = _mtmlGetFunctionPointer("mtmlDeviceGetTopologyLevel")
|
|
768
|
-
ret = fn(device1, device2, byref(c_level))
|
|
769
|
-
_mtmlCheckReturn(ret)
|
|
770
|
-
return c_level.value
|