|
1
|
|
|
''' |
|
2
|
|
|
Functions to retrieve host information. |
|
3
|
|
|
''' |
|
4
|
|
|
|
|
5
|
|
|
import platform |
|
6
|
|
|
from subprocess import getoutput |
|
7
|
|
|
|
|
8
|
|
|
# def from_cmd(cmd, stdhndl=" 2>&1", e_shell=True): |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
def from_cmd(cmd): |
|
12
|
|
|
''' |
|
13
|
|
|
Determine some system information based on a shell command. |
|
14
|
|
|
''' |
|
15
|
|
|
return getoutput(cmd) |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
def ipaddress(): |
|
19
|
|
|
''' |
|
20
|
|
|
Determine our own IP adress. |
|
21
|
|
|
This seems to be far more complicated than you would think: |
|
22
|
|
|
''' |
|
23
|
|
|
try: |
|
24
|
|
|
import socket |
|
25
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
26
|
|
|
s.connect(("gmail.com", 80)) |
|
27
|
|
|
result = s.getsockname()[0] |
|
28
|
|
|
s.close() |
|
29
|
|
|
return result |
|
30
|
|
|
except Exception: |
|
31
|
|
|
return "" |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
def opencl(): |
|
35
|
|
|
''' |
|
36
|
|
|
Determine some system information about the installed OpenCL device. |
|
37
|
|
|
''' |
|
38
|
|
|
result = [] |
|
39
|
|
|
try: |
|
40
|
|
|
import pyopencl as ocl |
|
41
|
|
|
for plt in ocl.get_platforms(): |
|
42
|
|
|
result.append("Platform: " + platform.name) |
|
43
|
|
|
for device in plt.get_devices(): |
|
44
|
|
|
result.append(" Device:" + device.name.strip()) |
|
45
|
|
|
infoset = [key for key in dir(device) if not key.startswith( |
|
46
|
|
|
"__") and key not in ["extensions", "name"]] |
|
47
|
|
|
for attr in infoset: |
|
48
|
|
|
try: |
|
49
|
|
|
result.append(" %s: %s" % ( |
|
50
|
|
|
attr.strip(), getattr(device, attr).strip())) |
|
51
|
|
|
except Exception: |
|
52
|
|
|
pass |
|
53
|
|
|
return "\n".join(result) |
|
54
|
|
|
except Exception: |
|
55
|
|
|
return "" |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
def os(): |
|
59
|
|
|
conf = platform.uname() |
|
60
|
|
|
return "%s %s %s (%s)" % (conf[0], conf[2], conf[3], conf[4]) |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
def cpu(): |
|
64
|
|
|
try: |
|
65
|
|
|
from cpuinfo import cpuinfo |
|
66
|
|
|
cpu = cpuinfo.get_cpu_info() |
|
67
|
|
|
return "%s, %s, %s Family %d Model %d Stepping %d #%d" % (cpu["brand"], cpu["vendor_id"], cpu["arch"], cpu['family'], cpu['model'], cpu['stepping'], cpu["count"]) |
|
68
|
|
|
except Exception: |
|
69
|
|
|
# may be empty on Linux because of partial implemtation in platform |
|
70
|
|
|
return platform.processor() |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
def compiler(): |
|
74
|
|
|
if platform.system() == "Windows": |
|
75
|
|
|
conf = from_cmd("cl.exe|@echo off", "") # force returncode 0 |
|
76
|
|
|
conf = conf.split("\n")[0] # extract version info |
|
77
|
|
|
else: |
|
78
|
|
|
conf = from_cmd("cc -v") |
|
79
|
|
|
return conf |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
def all_host_infos(): |
|
83
|
|
|
''' |
|
84
|
|
|
Summarize all host information. |
|
85
|
|
|
''' |
|
86
|
|
|
output = [] |
|
87
|
|
|
output.append(["Operating system", os()]) |
|
88
|
|
|
output.append(["CPUID information", cpu()]) |
|
89
|
|
|
output.append(["CC information", compiler()]) |
|
90
|
|
|
output.append(["JDK information", from_cmd("java -version")]) |
|
91
|
|
|
output.append(["MPI information", from_cmd("mpirun -version")]) |
|
92
|
|
|
output.append(["Scala information", from_cmd("scala -version")]) |
|
93
|
|
|
output.append(["OpenCL headers", from_cmd( |
|
94
|
|
|
"find /usr/include|grep opencl.h")]) |
|
95
|
|
|
output.append(["OpenCL libraries", from_cmd( |
|
96
|
|
|
"find /usr/lib/ -iname '*opencl*'")]) |
|
97
|
|
|
output.append(["NVidia SMI", from_cmd("nvidia-smi -q")]) |
|
98
|
|
|
output.append(["OpenCL Details", opencl()]) |
|
99
|
|
|
return output |
|
100
|
|
|
|