大した話じゃないんですが、この4 GPU system (1080Ti)
を4つを完全並列でフルに使ってpycudaで計算すると時々落ちるのです。開けっ放しにしたり置く場所を変えてたりしたんですが、やっぱり時々落ちる。どれか一つが落ちると再起動しないとならなくて面倒くさいので、この4つのGPUの最大温度を取得して、ある温度maxtを超えたら、settに落ち着くまで、sleepさせるパスタコードを書いたのでメモ。といってもnvidia-smiをsubprocessでよんでsleepさせるというなんかアレなコードですが、もっと良さそうな何かを知っていたら教えてください。
これが元になっています。複数GPUの最大温度がmaxtを越えてたら、sett度になるまでsleepさせ30秒ごとにチェックするという単純なコードですが意外とうまくいきます。
gpucheck.py
import subprocess
import numpy as np
DEFAULT_ATTRIBUTES = (
'index',
'temperature.gpu',
)
def get_gpu_temperature(nvidia_smi_path='nvidia-smi', keys=DEFAULT_ATTRIBUTES, no_units=True):
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("utf-8").split('\n')
lines = [ line.strip() for line in lines if line.strip() != '' ]
return [ { k: v for k, v in zip(keys, line.split(', ')) } for line in lines ]
def getmaxgput_gput():
a=get_gpu_temperature()
gputemp=[]
for i in range(0,len(a)):
gputemp.append(float(a[i]["temperature.gpu"]))
gputemp=np.array(gputemp)
maxgput=np.max(gputemp)
return maxgput
if __name__ == "__main__":
from time import sleep
#### GPU HEALTH CHECK #######
maxt=85.0 #max temperature C
sett=40.0 #setting C
sleeptime=30.0 #sec
maxgput=getmaxgput_gput()
if maxgput > maxt:
print("Fever. Waiting for cool down of the fevered GPU. ")
fever = True
while fever :
sleep(sleeptime)
maxgput=getmaxgput_gput()
print(maxgput,"[C]")
if maxgput < sett:
fever = False