File tree 3 files changed +31
-3
lines changed 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ __pycache__/
12
12
# Distribution / packaging
13
13
.Python
14
14
env /
15
+ venv /
15
16
build /
16
17
develop-eggs /
17
18
dist /
Original file line number Diff line number Diff line change 14
14
) from ex
15
15
16
16
from .core import GPUStat , GPUStatCollection
17
- from .core import new_query
17
+ from .core import new_query , gpu_count , is_available
18
18
from .cli import print_gpustat , main
19
19
20
20
21
21
__all__ = (
22
22
'__version__' ,
23
- 'GPUStat' , 'GPUStatCollection' ,
23
+ 'GPUStat' ,
24
+ 'GPUStatCollection' ,
24
25
'new_query' ,
25
- 'print_gpustat' , 'main' ,
26
+ 'gpu_count' ,
27
+ 'is_available' ,
28
+ 'print_gpustat' ,
29
+ 'main' ,
26
30
)
Original file line number Diff line number Diff line change @@ -740,3 +740,26 @@ def new_query():
740
740
to get the list of GPUs and running process information.
741
741
'''
742
742
return GPUStatCollection .new_query ()
743
+
744
+
745
+ def gpu_count () -> int :
746
+ '''
747
+ Return the number of GPUs in the system.
748
+ '''
749
+ try :
750
+ N .nvmlInit ()
751
+ return N .nvmlDeviceGetCount ()
752
+ except N .NVMLError :
753
+ return 0 # fallback
754
+ finally :
755
+ try :
756
+ N .nvmlShutdown ()
757
+ except N .NVMLError :
758
+ pass
759
+
760
+
761
+ def is_available () -> bool :
762
+ '''
763
+ Return True if the NVML library and GPU devices are available.
764
+ '''
765
+ return gpu_count () > 0
You can’t perform that action at this time.
0 commit comments