GPUtil

1.4.0 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

This quickstart demonstrates how to import GPUtil and retrieve information for all available NVIDIA GPUs. It iterates through each GPU, printing key metrics like name, load, memory usage, temperature, and UUID. It includes basic error handling for when `nvidia-smi` is not found.

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.")

view raw JSON →