Skip to content

Commit

Permalink
New GPU available function (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
LightArrowsEXE authored Nov 4, 2024
1 parent fe8b55d commit b1e7a73
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ see the [tags page](https://github.com/Jaded-Encoding-Thaumaturgy/vs-tools/tags)
- Updated lint action to use ruff
- Added top-level noqa to `__init__.py`

- Other:
- Improve type-checking for pyright
- New `is_gpu_available` function to check if any GPU is available

## v3.3.3

**Full Changelog**: https://github.com/Jaded-Encoding-Thaumaturgy/vs-tools/compare/v3.3.1...v3.3.3
Expand Down
26 changes: 25 additions & 1 deletion vstools/utils/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

__all__ = [
'IS_DOCS',
'get_nvidia_version'
'get_nvidia_version',
'is_gpu_available'
]


IS_DOCS = not TYPE_CHECKING and (
# if loaded from sphinx
'sphinx' in sys.modules
Expand Down Expand Up @@ -44,3 +46,25 @@ def get_nvidia_version() -> tuple[int, int] | None:
return _str_to_ver(smi.stdout.splitlines()[5].decode().split(':')[-1])

return None


def is_gpu_available() -> bool:
"""Check if any GPU is available."""

try:
smi = run(['nvidia-smi'], capture_output=True, text=True)
except FileNotFoundError:
pass
else:
if smi.returncode == 0:
return True

try:
rocm_smi = run(['rocm-smi'], capture_output=True, text=True)
except FileNotFoundError:
pass
else:
if rocm_smi.returncode == 0:
return True

return False

0 comments on commit b1e7a73

Please sign in to comment.