Sunday, September 11, 2022

Python how to print GPU info


pip install gputil

pip install tabulate


However this below was returning empty on an Macbook M1 Pro Chip


 import GPUtil

from tabulate import tabulate

print("="*40, "GPU Details", "="*40)

gpus = GPUtil.getGPUs()

print("GPU list ",gpus)

list_gpus = []

for gpu in gpus:

    # get the GPU id

    gpu_id = gpu.id

    # name of GPU

    gpu_name = gpu.name

    # get % percentage of GPU usage of that GPU

    gpu_load = f"{gpu.load*100}%"

    # get free memory in MB format

    gpu_free_memory = f"{gpu.memoryFree}MB"

    # get used memory

    gpu_used_memory = f"{gpu.memoryUsed}MB"

    # get total memory

    gpu_total_memory = f"{gpu.memoryTotal}MB"

    # get GPU temperature in Celsius

    gpu_temperature = f"{gpu.temperature} °C"

    gpu_uuid = gpu.uuid

    list_gpus.append((

        gpu_id, gpu_name, gpu_load, gpu_free_memory, gpu_used_memory,

        gpu_total_memory, gpu_temperature, gpu_uuid

    ))

print(tabulate(list_gpus, headers=("id", "name", "load", "free memory", "used memory", "total memory", "temperature", "uuid")))

No comments:

Post a Comment