最小采集脚本
最小采集脚本
from pynvml import (nvmlInit, nvmlDeviceGetCount,
nvmlDeviceGetHandleByIndex, nvmlDeviceGetMemoryInfo)
nvmlInit()
for i in range(nvmlDeviceGetCount()):
h = nvmlDeviceGetHandleByIndex(i)
m = nvmlDeviceGetMemoryInfo(h)
print(i, m.used // 2**20, 'MiB /', m.total // 2**20, 'MiB')
采集频率保持秒级即可,高频调用 NVML 也有开销;容器里使用需要把 GPU 设备挂进容器。