Skip to content

Instantly share code, notes, and snippets.

@xu-ji
Last active April 2, 2020 20:44
Show Gist options
  • Save xu-ji/2f88c41362893ca926485b227f1c116a to your computer and use it in GitHub Desktop.
Save xu-ji/2f88c41362893ca926485b227f1c116a to your computer and use it in GitHub Desktop.
GPU stat
from pynvml.smi import nvidia_smi
def get_gpu_mem(nvsmi, gpu_ind):
mem_stats = nvsmi.DeviceQuery('memory.free, memory.total')["gpu"][gpu_ind]["fb_memory_usage"]
return mem_stats["total"] - mem_stats["free"]
nvsmi = nvidia_smi.getInstance()
gpu_ind = 0
print(get_gpu_mem(nvsmi, gpu_ind))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment