You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

get_gpu_memory.py 521 B

4 years ago
1234567891011121314
  1. from pynvml import smi as nvidia_smi
  2. nvidia_smi.nvmlInit()
  3. handle = nvidia_smi.nvmlDeviceGetHandleByIndex(0)
  4. # card id 0 hardcoded here, there is also a call to get all available card ids, so we could iterate
  5. ans = 0
  6. while(True):
  7. mem_res = nvidia_smi.nvmlDeviceGetMemoryInfo(handle)
  8. # print(mem_res.used / (1024**2)) # usage in GiB
  9. if (mem_res.used / (1024**2) > ans):
  10. ans = mem_res.used / (1024**2)
  11. print(ans)
  12. # print(f'mem: {100 * (mem_res.used / mem_res.total):.3f}%') # percentage usage

分布式深度学习系统