-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Enhancement] Fix collect_env on Windows #1789
Changes from 10 commits
65975d7
746fecb
9d57970
29692f9
72666bb
f29bb33
6363b09
3ebdefb
ecd4e72
433cbe7
f59c2b3
3fe1bfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ def collect_env(): | |
- CUDA_HOME (optional): The env var ``CUDA_HOME``. | ||
- NVCC (optional): NVCC version. | ||
- GCC: GCC version, "n/a" if GCC is not installed. | ||
- MSVC: Microsoft Virtual C++ Compiler version, Windows only. | ||
- PyTorch: PyTorch version. | ||
- PyTorch compiling details: The output of \ | ||
``torch.__config__.show()``. | ||
|
@@ -56,18 +57,39 @@ def collect_env(): | |
if CUDA_HOME is not None and osp.isdir(CUDA_HOME): | ||
try: | ||
nvcc = osp.join(CUDA_HOME, 'bin/nvcc') | ||
nvcc = subprocess.check_output( | ||
f'"{nvcc}" -V | tail -n1', shell=True) | ||
nvcc = subprocess.check_output(f'"{nvcc}" -V', shell=True) | ||
nvcc = nvcc.decode('utf-8').strip() | ||
release = nvcc.rfind('Cuda compilation tools') | ||
build = nvcc.rfind('Build ') | ||
nvcc = nvcc[release:build].strip() | ||
except subprocess.SubprocessError: | ||
nvcc = 'Not Available' | ||
env_info['NVCC'] = nvcc | ||
|
||
try: | ||
gcc = subprocess.check_output('gcc --version | head -n1', shell=True) | ||
gcc = gcc.decode('utf-8').strip() | ||
env_info['GCC'] = gcc | ||
except subprocess.CalledProcessError: # gcc is unavailable | ||
# Check C++ Compiler. | ||
# For Unix-like, sysconfig has 'CC' variable like 'gcc -pthread ...', | ||
# indicating the compiler used, we use this to get the compiler name | ||
import sysconfig | ||
HAOCHENYE marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cc = sysconfig.get_config_var('CC') | ||
if cc: | ||
cc = osp.basename(cc.split()[0]) | ||
cc_info = subprocess.check_output(f'{cc} --version', shell=True) | ||
env_info['GCC'] = cc_info.decode('utf-8').partition( | ||
'\n')[0].strip() | ||
else: | ||
# on Windows, cl.exe is not in PATH. We need to find the path. | ||
# distutils.ccompiler.new_compiler() returns a msvccompiler | ||
# object and after initialization, path to cl.exe is found. | ||
from distutils.ccompiler import new_compiler | ||
ccompiler = new_compiler() | ||
ccompiler.initialize() | ||
cc = subprocess.check_output( | ||
f'{ccompiler.cc}', stderr=subprocess.STDOUT, shell=True) | ||
env_info['MSVC'] = cc.decode('utf-8').partition('\n')[0].strip() | ||
SuTanTank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
env_info['GCC'] = 'n/a' | ||
del ccompiler | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to manually delete There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not. I did this because that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be released by gc in later so we can remove this line.
SuTanTank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
except subprocess.CalledProcessError: | ||
env_info['GCC'] = 'n/a' | ||
|
||
env_info['PyTorch'] = torch.__version__ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be better if we can get the last line of
nvcc -V
which is consistent with the former version.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Linux
On Windows (11.5)
Not sure what it looks like on other Windows machines. but the last line on Linux match with the second last line on Windows.
I will add 'Cuda compilation tools' to the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK~ thanks for your explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May leave comments in the code to explain.