-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
summary_env.py
214 lines (176 loc) · 5.66 KB
/
summary_env.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import platform
import subprocess
import sys
import distro
envs_template = """
Paddle version: {paddle_version}
Paddle With CUDA: {paddle_with_cuda}
OS: {os_info}
GCC version: {gcc_version}
Clang version: {clang_version}
CMake version: {cmake_version}
Libc version: {libc_version}
Python version: {python_version}
CUDA version: {cuda_version}
cuDNN version: {cudnn_version}
Nvidia driver version: {nvidia_driver_version}
Nvidia driver List: {nvidia_gpu_driver}
"""
envs = {}
def get_paddle_info():
try:
import paddle
envs['paddle_version'] = paddle.__version__
envs['paddle_with_cuda'] = paddle.base.core.is_compiled_with_cuda()
except:
envs['paddle_version'] = 'N/A'
envs['paddle_with_cuda'] = 'N/A'
def get_os_info():
if platform.system() == "Darwin":
plat = "macOS"
ver = run_shell_command('sw_vers -productVersion').strip('\n')
elif platform.system() == "Linux":
plat = distro.id()
ver = distro.version()
elif platform.system() == "Windows":
plat = "Windows"
ver = platform.win32_ver()[0]
else:
plat = 'N/A'
ver = 'N/A'
envs['os_info'] = f"{plat} {ver}"
def get_gcc_version():
try:
envs['gcc_version'] = (
run_shell_command("gcc --version").split('\n')[0].split("gcc ")[1]
)
except:
envs['gcc_version'] = 'N/A'
def get_clang_version():
try:
envs['clang_version'] = (
run_shell_command("clang --version")
.split('\n')[0]
.split("clang version ")[1]
)
except:
envs['clang_version'] = 'N/A'
def get_cmake_version():
try:
envs['cmake_version'] = (
run_shell_command("cmake --version")
.split('\n')[0]
.split("cmake ")[1]
)
except:
envs['cmake_version'] = 'N/A'
def get_libc_version():
if platform.system() == "Linux":
envs['libc_version'] = ' '.join(platform.libc_ver())
else:
envs['libc_version'] = 'N/A'
def get_python_info():
envs['python_version'] = sys.version.split(' ')[0]
def run_shell_command(cmd):
out, err = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
).communicate()
if err:
return None
else:
return out.decode('utf-8')
def get_cuda_info():
out = run_shell_command('nvcc --version')
if out:
envs['cuda_version'] = out.split('V')[-1].strip()
else:
envs['cuda_version'] = 'N/A'
def get_cudnn_info():
def _get_cudnn_ver(cmd):
out = run_shell_command(cmd)
if out:
return out.split(' ')[-1].strip()
else:
return 'N/A'
if platform.system() == "Windows":
cudnn_dll_path = run_shell_command('where cudnn*')
if cudnn_dll_path:
cudnn_header_path = (
cudnn_dll_path.split('bin')[0] + r'include\cudnn.h'
)
cmd = 'type "{0}" | findstr "{1}" | findstr /v "CUDNN_VERSION"'
else:
envs['cudnn_version'] = 'N/A'
return
else:
cudnn_header_path = run_shell_command(
'whereis "cudnn.h" | awk \'{print $2}\''
).strip('\n')
if cudnn_header_path:
cmd = 'cat "{0}" | grep "{1}" | grep -v "CUDNN_VERSION"'
if _get_cudnn_ver(cmd.format(cudnn_header_path, 'CUDNN_MAJOR')):
cudnn_header_path = run_shell_command(
'whereis "cudnn_version.h" | awk \'{print $2}\''
).strip('\n')
else:
envs['cudnn_version'] = 'N/A'
return
major = _get_cudnn_ver(cmd.format(cudnn_header_path, 'CUDNN_MAJOR'))
minor = _get_cudnn_ver(cmd.format(cudnn_header_path, 'CUDNN_MINOR'))
patch_level = _get_cudnn_ver(
cmd.format(cudnn_header_path, 'CUDNN_PATCHLEVEL')
)
if major != 'N/A':
envs['cudnn_version'] = f"{major}.{minor}.{patch_level}"
else:
envs['cudnn_version'] = 'N/A'
def get_driver_info():
driver_ver = run_shell_command('nvidia-smi')
if driver_ver:
driver_ver = (
driver_ver.split('Driver Version:')[1].strip().split(' ')[0]
)
else:
driver_ver = 'N/A'
envs['nvidia_driver_version'] = driver_ver
def get_nvidia_gpu_driver():
if platform.system() != "Windows" and platform.system() != "Linux":
envs['nvidia_gpu_driver'] = 'N/A'
return
try:
nvidia_smi = 'nvidia-smi'
gpu_list = run_shell_command(nvidia_smi + " -L")
result = "\n"
for gpu_info in gpu_list.split("\n"):
result += gpu_info.split(" (UUID:")[0] + "\n"
envs['nvidia_gpu_driver'] = result
except:
envs['nvidia_gpu_driver'] = 'N/A'
def main():
get_paddle_info()
get_os_info()
get_gcc_version()
get_clang_version()
get_cmake_version()
get_libc_version()
get_python_info()
get_cuda_info()
get_cudnn_info()
get_driver_info()
get_nvidia_gpu_driver()
print('*' * 40 + envs_template.format(**envs) + '*' * 40)
if __name__ == '__main__':
main()