-
Notifications
You must be signed in to change notification settings - Fork 0
/
afterburn.py
executable file
·59 lines (48 loc) · 1.79 KB
/
afterburn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python3
############################################################################
# #
# Handles my fan speed on my GTX1080. Works surprisingly well. #
# Recommended to add on startup. Can work on Windows with tweaks. #
# #
############################################################################
from time import sleep
from subprocess import run,PIPE
import re
from math import floor
import psutil
from os import getpid
# Kill self if already running. Assumes script is named afterburn.py
pid = getpid()
for p in psutil.process_iter():
if 'afterburn.py' in ' '.join(p.cmdline()) and not p.pid == pid:
exit()
# Setup Regular expressions
qt = re.compile("Current Temp.*: ([0-9]+) C")
# Wait time, in seconds, between GPU polls. Fan is updated at this frequency as well.
waittime=5
def call_pipe(arg):
return run(arg,stdout=PIPE,stderr=PIPE,universal_newlines=True,shell=True)
def set_auto(tf):
call_pipe("nvidia-settings -a [gpu:0]/GPUFanControlState="+str(tf))
def set_fan(speed):
call_pipe("nvidia-settings -a [gpu:0]/GPUFanControlState=1")
return call_pipe("nvidia-settings -a [fan:0]/GPUTargetFanSpeed="+str(speed))
def query_gpu():
x = call_pipe("nvidia-smi -q")
x = x.stdout
ret = int(qt.findall(x)[0])
return ret
speed = 15
while True:
gpud = query_gpu()
curTemp = gpud
# Start raising speed at 30C,and max out at 75C
st = floor((curTemp-30)*2.125)
# Cap speed at 100% just in case things go haywire
if st > 100:
st = 100
if not st == speed:
set_fan(st)
print("Setting fan speed to {} %".format(st))
speed = st
sleep(waittime)