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

Added Windows cmd to count GPU devices #7891

Merged
merged 2 commits into from
May 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ def torch_distributed_zero_first(local_rank: int):

def device_count():
# Returns number of CUDA devices available. Safe version of torch.cuda.device_count(). Only works on Linux.
assert platform.system() == 'Linux', 'device_count() function only works on Linux'
system_platform = platform.system()
assert system_platform == 'Linux' or 'Windows', 'device_count() function only works on Linux or Windows'
try:
cmd = 'nvidia-smi -L | wc -l'
if system_platform == 'Linux':
cmd = 'nvidia-smi -L | wc -l'
elif system_platform == 'Windows':
cmd = 'nvidia-smi -L | find /c /v ""'
return int(subprocess.run(cmd, shell=True, capture_output=True, check=True).stdout.decode().split()[-1])
except Exception:
return 0
Expand Down