Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tools] Update summary env #48627

Merged
merged 9 commits into from
Dec 13, 2022
100 changes: 83 additions & 17 deletions tools/summary_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
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 = {}
Expand All @@ -39,27 +44,64 @@ def get_paddle_info():
envs['paddle_version'] = paddle.__version__
envs['paddle_with_cuda'] = paddle.fluid.core.is_compiled_with_cuda()
except:
envs['paddle_version'] = None
envs['paddle_with_cuda'] = None
envs['paddle_version'] = 'N/A'
envs['paddle_with_cuda'] = 'N/A'


def get_os_info():
plat = platform.system()
if platform.system() == "Darwin":
plat = "macOs"
ver = platform.mac_ver()[0]
plat = "macOS"
ver = run_shell_command('sw_vers -productVersion').strip('\n')
elif platform.system() == "Linux":
plat = distro.linux_distribution()[0]
ver = distro.linux_distribution()[1]
plat = distro.id()
ver = distro.version()
elif platform.system() == "Windows":
plat = "Windows"
ver = platform.win32_ver()[0]
else:
plat = None
ver = None
plat = 'N/A'
ver = 'N/A'
envs['os_info'] = "{0} {1}".format(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]

Expand All @@ -79,7 +121,7 @@ def get_cuda_info():
if out:
envs['cuda_version'] = out.split('V')[-1].strip()
else:
envs['cuda_version'] = None
envs['cuda_version'] = 'N/A'


def get_cudnn_info():
Expand All @@ -88,7 +130,7 @@ def _get_cudnn_ver(cmd):
if out:
return out.split(' ')[-1].strip()
else:
return None
return 'N/A'

if platform.system() == "Windows":
cudnn_dll_path = run_shell_command('where cudnn*')
Expand All @@ -98,17 +140,21 @@ def _get_cudnn_ver(cmd):
)
cmd = 'type "{0}" | findstr "{1}" | findstr /v "CUDNN_VERSION"'
else:
envs['cudnn_version'] = None
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:
cudnn_header_path = cudnn_header_path.strip()
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'] = None
envs['cudnn_version'] = 'N/A'
return

major = _get_cudnn_ver(cmd.format(cudnn_header_path, 'CUDNN_MAJOR'))
Expand All @@ -117,7 +163,10 @@ def _get_cudnn_ver(cmd):
cmd.format(cudnn_header_path, 'CUDNN_PATCHLEVEL')
)

envs['cudnn_version'] = "{0}.{1}.{2}".format(major, minor, patch_level)
if major != 'N/A':
envs['cudnn_version'] = "{0}.{1}.{2}".format(major, minor, patch_level)
else:
envs['cudnn_version'] = 'N/A'


def get_driver_info():
Expand All @@ -127,17 +176,34 @@ def get_driver_info():
driver_ver.split('Driver Version:')[1].strip().split(' ')[0]
)
else:
driver_ver = None
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
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


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)


Expand Down