12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

nvidia-settingsでGPU温度に応じてFan速度を変える

Last updated at Posted at 2018-12-25

温度が高いGPUのFanを速く回すと冷えるので,そのスクリプト.

  • cron.hourlyで1時間に1回実行.
  • nvidia-smiでGPU数と温度を取得
  • 温度が70度を超えたら,nvidia-settingsでFanを強制的に100%
  • 温度が40度を下回ったら,nvidia-settingsでFan自動調整

これで,80度を超えていたのが60度台になったのでhappy.

まずは

sudo nvidia-xconfig -a --cool-bits=4

を実行して再起動.

adapt_fan
#!/usr/bin/python3

import os
import subprocess

os.environ['DISPLAY'] = ':0'
os.environ['XAUTHORITY'] = '/run/user/121/gdm/Xauthority'   # hardcoded.要変更


try:
    gpu_temp = subprocess.check_output(["nvidia-smi",
                                        "--query-gpu=temperature.gpu",
                                        "--format=csv,noheader"])
except:
    exit()
    

gpu_temp = [int(t) for t in gpu_temp.split()]


for i, temp in enumerate(gpu_temp):

    if temp > 70:

        try:
            subprocess.check_call(["nvidia-settings", "-a",
                                   "[gpu:{}]/GPUFanControlState=1".format(i)],
                                  stdout = subprocess.DEVNULL)

            subprocess.check_call(["nvidia-settings", "-a",
                                   "[fan:{}]/GPUTargetFanSpeed=100".format(i)],
                                  stdout = subprocess.DEVNULL)
        except:
            pass # exit()


    if temp < 40:

        try:
            subprocess.check_call(["nvidia-settings", "-a",
                                   "[gpu:{}]/GPUFanControlState=0".format(i)],
                                  stdout = subprocess.DEVNULL)
        except:
            pass # exit()
        

あとはcronで実行すればOK.

sudo install -v adapt_fan /etc/cron.hourly

で,1時間に1回実行される.

3分ごとに実行したいならcron.dに以下のファイルを作る.

/etc/cron.d/adapt_fan_crond
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
*/3 * * * *   root    python3 /etc/cron.hourly/adapt_fan
12
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?