forked from MooreThreads/mthreads-ml-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
64 lines (45 loc) · 1.4 KB
/
example.py
File metadata and controls
64 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#
# Sample script to demonstrate the usage of MTML API python bindings
#
# To Run:
# $ python ./example.py
from pymtml import *
#
# Converts errors into string messages
#
def handleError(err):
if err.value == MTML_ERROR_NOT_SUPPORTED:
return "N/A"
else:
return err.__str__()
#######
def deviceQuery():
strResult = ""
try:
#
# Initialize MTML
#
mtmlLibraryInit()
deviceCount = mtmlLibraryCountDevice()
strResult += " <attached_gpus>" + str(deviceCount) + "</attached_gpus>\n"
for i in range(0, deviceCount):
handle = mtmlLibraryInitDeviceByIndex(i)
strResult += ' <gpu id="%s">\n' % i
try:
uuid = mtmlDeviceGetUUID(handle)
except MTMLError as err:
uuid = handleError(err)
strResult += " <uuid>" + uuid + "</uuid>\n"
try:
mtLinkSpec = mtmlDeviceGetMtLinkSpec(handle)
except MTMLError as err:
mtLinkSpec = handleError(err)
strResult += " <mt_link>" + str(mtLinkSpec) + "</mt_link>\n"
strResult += " </gpu>\n"
except MTMLError as err:
strResult += "example.py: " + err.__str__() + "\n"
mtmlLibraryShutDown()
return strResult
# If this is not executed when module is imported
if __name__ == "__main__":
print(deviceQuery())