GPUtil
GPUtil is a Python module designed to query the status of NVIDIA GPUs using the `nvidia-smi` command-line utility. It provides access to metrics like GPU load, memory usage, temperature, and UUID. The current version is 1.4.0, and releases occur intermittently, focusing on bug fixes, expanded platform support (e.g., Windows), and new features.
Warnings
- breaking The project was renamed from `GPUstats` to `GPUtil` in version 1.2.0. Code using `import GPUstats` or other `GPUstats` specific imports will break.
- gotcha GPUtil relies on the NVIDIA System Management Interface (`nvidia-smi`) executable. This utility must be installed as part of your NVIDIA display driver package and be accessible within your system's PATH environment variable.
- gotcha GPU temperature reporting and robust Windows support were significantly improved and added in version 1.4.0. Users on older versions will not have access to the `gpu.temperature` attribute or may experience issues on Windows.
- gotcha For Python 2.x users, versions of GPUtil prior to 1.2.3 had a bug that caused GPU memory utilization to always show as 0% due to integer division issues. This bug was not present in Python 3.x.
Install
-
pip install GPUtil
Imports
- GPUtil
import GPUtil
- getGPUs
GPUtil.getGPUs()
Quickstart
import GPUtil
try:
gpus = GPUtil.getGPUs()
if not gpus:
print("No NVIDIA GPUs found or nvidia-smi is not in PATH.")
for i, gpu in enumerate(gpus):
print(f"--- GPU {i} ---")
print(f" Name: {gpu.name}")
print(f" Load: {gpu.load * 100:.2f}%")
print(f" Memory Total: {gpu.memoryTotal} MB")
print(f" Memory Used: {gpu.memoryUsed} MB")
print(f" Memory Free: {gpu.memoryFree} MB")
print(f" Temperature: {gpu.temperature} °C")
print(f" UUID: {gpu.uuid}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure NVIDIA drivers are installed and nvidia-smi is accessible in your system's PATH.")