Guide
nvidia-smi
1 2 3 4 5 6 7 8 9 10 11
| > nvidia-smi Thu Mar 21 09:41:18 2019 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 396.54 Driver Version: 396.54 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 1060 Off | 00000000:01:00.0 Off | N/A | | N/A 65C P0 30W / N/A | 538MiB / 6078MiB | 0% Default | +-------------------------------+----------------------+----------------------+
|
nvidia-ml-py
This is a wrapper around the NVML library.
Python methods wrap NVML functions, implemented in a C shared library.
Each function’s use is the same with the following exceptions: Instead of returning error codes, failing error codes are raised as Python exceptions.
1 2
| pip install nvidia-ml-py2 --user pip install nvidia-ml-py3 --user
|
demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
import pynvml
try: pynvml.nvmlInit() except pynvml.NVMLError as error: print(error) exit()
try: print(pynvml.nvmlDeviceGetCount()) except pynvml.NVMLError as error: print(error)
print(pynvml.nvmlDeviceGetCount()) print(pynvml.nvmlSystemGetDriverVersion())
GPU_ID = 0 handle = pynvml.nvmlDeviceGetHandleByIndex(GPU_ID) print(pynvml.nvmlDeviceGetName(handle))
meminfo = pynvml.nvmlDeviceGetMemoryInfo(handle) MB_SIZE = 1024*1024 print(meminfo.total/MB_SIZE) print(meminfo.used/MB_SIZE) print(meminfo.free/MB_SIZE)
pynvml.nvmlShutdown()
|
Reference
History