python nvidia 显卡信息 格式数据.
python
def get_gpu_memory():
result = subprocess.check_output(['nvidia-smi', '--query-gpu=pci.bus_id,memory.used,memory.total,memory.free', '--format=csv'])
# 返回 GPU 的显存使用情况,单位为 M
info = []
for t in csv.DictReader(result.decode().splitlines()):
info.append({'id':t['pci.bus_id'],
'used':int(t[' memory.used [MiB]'].split()[0]),
'total':int(t[' memory.total [MiB]'].split()[0]),
'free':int(t[' memory.free [MiB]'].split()[0])})
return info
参考