728x90
반응형
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 12955634870229076918
xla_global_id: -1
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 7377227776
locality {
bus_id: 1
links {
}
}
incarnation: 2459137103494862056
physical_device_desc: "device: 0, name: NVIDIA GeForce RTX 3080, pci bus id: 0000:01:00.0, compute capability: 8.6"
xla_global_id: 416903419
]
import subprocess
import json
def get_gpu_info(nvidia_smi_path='nvidia-smi', no_units=False):
keys = (
'index',
'uuid',
'name',
'timestamp',
'memory.total',
'memory.free',
'memory.used',
'utilization.gpu',
'utilization.memory'
)
nu_opt = '' if not no_units else ',nounits'
cmd = '%s --query-gpu=%s --format=csv,noheader%s' % (nvidia_smi_path, ','.join(keys), nu_opt)
output = subprocess.check_output(cmd, shell=True)
lines = output.decode().split('\n')
lines = [ line.strip() for line in lines if line.strip() != '' ]
tmp = [ { k: v for k, v in zip(keys, line.split(', ')) } for line in lines ]
ss = ''
for key in tmp[0].keys():
ss += f"{key}:{tmp[0][key]}"
# if key == 'memory.total' or key == 'memory.free' or key == 'memory.used':
# ss += " KB\n"
# else:
# ss += "\n"
ss += "\n"
return ss
import pprint
pprint.pprint(get_gpu_info())
728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 문제 : 그래프에서 최고점, 최저정 찾아 계산하고 엑셀 저장 (0) | 2023.07.27 |
---|---|
[파이썬] 사인파 곡선에서 최저, 최고점 찾기 (scipy, argrelextrema) (0) | 2023.07.27 |
[파이썬] Flask를 사용해 웹서버 만들기 (외부에서 접속하기) (0) | 2023.07.19 |
[파이썬] 주식 차분 Plot (0) | 2023.07.18 |
[파이썬] 주식 Plot 애니메이션 (matplotlib.animation, FuncAnimation) (0) | 2023.07.18 |
댓글