瀏覽代碼

Added Windows cmd to count GPU devices (#7891)

* Added Windows cmd to count GPU devices

* Cleanup

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
modifyDataloader
xylieong GitHub 2 年之前
父節點
當前提交
f43cd53d44
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 1 個檔案被更改,包括 3 行新增3 行删除
  1. +3
    -3
      utils/torch_utils.py

+ 3
- 3
utils/torch_utils.py 查看文件

@@ -40,10 +40,10 @@ 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'
# Returns number of CUDA devices available. Safe version of torch.cuda.device_count(). Supports Linux and Windows
assert platform.system() in ('Linux', 'Windows'), 'device_count() only supported on Linux or Windows'
try:
cmd = 'nvidia-smi -L | wc -l'
cmd = 'nvidia-smi -L | wc -l' if platform.system() == 'Linux' else 'nvidia-smi -L | find /c /v ""' # Windows
return int(subprocess.run(cmd, shell=True, capture_output=True, check=True).stdout.decode().split()[-1])
except Exception:
return 0

Loading…
取消
儲存