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

[Enhancement] Fix collect_env on Windows #1789

Merged
merged 12 commits into from
Apr 5, 2022

Conversation

SuTanTank
Copy link
Contributor

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

collect_env() use tail and head which is not available on most Windows machines.

'tail' is not recognized as an internal or external command, operable program or batch file.
'head' is not recognized as an internal or external command, operable program or batch file.

Modification

Remove the tail and head, and use string find to extract env infos.

BC-breaking (Optional)

No

Use cases (Optional)

Checklist

Before PR:

  • I have read and followed the workflow indicated in the CONTRIBUTING.md to create this PR.
  • Pre-commit or linting tools indicated in CONTRIBUTING.md are used to fix the potential lint issues.
  • Bug fixes are covered by unit tests, the case that causes the bug should be added in the unit tests.
  • New functionalities are covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, including docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with some of those projects, like MMDet or MMCls.
  • CLA has been signed and all committers have signed the CLA in this PR.

@mm-assistant mm-assistant bot added the size/XS label Mar 10, 2022
Copy link
Contributor

@teamwong111 teamwong111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

gcc = gcc.decode('utf-8').strip()
first_line = gcc.find('\n')
gcc = gcc[:first_line].strip()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your contribution. mmcv compiled with cl.exe in windows, it could be better if collect_env can output the
information of 'cl.exe'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually there are multiple cl.exe on one machine (multiple VS version and cross-compliation tools) and cl is not avaliable in common shell environment. So it would be not an easy task and might even output misleading information.

The main reason I need to patch this is, when I use mmcv lite version on Windows, it complains that no CUDA runtime is found, probably because of the missing tail and head.

Copy link
Collaborator

@HAOCHENYE HAOCHENYE Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But on windows, mmcv does not compiled with gcc, so it is confusing if it happens to output mingw gcc information. Should we choose how to export gcc information via sys.platform? We can make env_info['GCC'] = 'n/a' as before. Besides, how does “no CUDA runtime is found” occurs?

@@ -56,16 +56,20 @@ 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)
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

On Windows (11.5)

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:52:33_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Contributor

@imabackstabber imabackstabber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SuTanTank
Copy link
Contributor Author

SuTanTank commented Mar 12, 2022

Since gcc is not always the compiler. I changed the key to CC. On windows, it returns the first line of copyright banner of cl.exe, like

Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30140 for x64

@SuTanTank SuTanTank changed the title [fix] fix collect_env() on Windows [feature] make collect_env() works on Windows Mar 14, 2022
mmcv/utils/env.py Outdated Show resolved Hide resolved
@zhouzaida zhouzaida changed the title [feature] make collect_env() works on Windows [feature] Fix collect_env() on Windows Apr 2, 2022
@zhouzaida zhouzaida changed the title [feature] Fix collect_env() on Windows [feature] Fix collect_env on Windows Apr 2, 2022
@zhouzaida zhouzaida changed the title [feature] Fix collect_env on Windows [Enhancement] Fix collect_env on Windows Apr 2, 2022
@zhouzaida zhouzaida self-requested a review April 2, 2022 10:59
Copy link
Collaborator

@zhouzaida zhouzaida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnicodeDecodeError was raised on my computer.

>>> from mmcv.utils import collect_env
>>> collect_env()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\codebases\mmcv\mmcv\utils\env.py", line 89, in collect_env
    env_info['MSVC'] = cc.decode('utf-8').partition('\n')[0].strip()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3 in position 0: invalid continuation byte

mmcv/utils/env.py Outdated Show resolved Hide resolved
encoding = locale.getdefaultlocale()[1]
env_info['MSVC'] = cc.decode(encoding).partition('\n')[0].strip()
env_info['GCC'] = 'n/a'
del ccompiler
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to manually delete ccompiler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not. I did this because that initialize() call took a few seconds, so I thought this object may take some unnecessary memory.

Copy link
Collaborator

@zhouzaida zhouzaida Apr 4, 2022

Choose a reason for hiding this comment

The 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.

mmcv/utils/env.py Outdated Show resolved Hide resolved
@zhouzaida zhouzaida merged commit c33f248 into open-mmlab:master Apr 5, 2022
@SuTanTank SuTanTank deleted the fix/envs branch April 6, 2022 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants