Last active
November 7, 2020 15:32
-
-
Save riaqn/e5a1db064400306e84d55672c196a030 to your computer and use it in GitHub Desktop.
fan control script for AMD GPU in linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
import time | |
import os | |
import math | |
os.chdir('/sys/class/drm/card0/device/hwmon/hwmon2/') | |
temp = 'temp1' | |
fan = 'fan1' | |
def read(path): | |
with open(path) as f: | |
return int(f.read()) | |
def write(path, n): | |
with open(path, 'w') as f: | |
f.write(str(n)) | |
fan_min = read(fan+"_min") | |
fan_max = read(fan+"_max") | |
print(fan_min, fan_max) | |
write(fan+"_enable", 1) | |
while True: | |
t = read(temp+"_input")/1000 | |
temp_min = 40 | |
temp_max = 80 | |
if t < temp_min: | |
f = fan_min | |
elif t > temp_max: | |
f = fan_max | |
else: | |
p = math.floor((t-temp_min)/(temp_max - temp_min)*(fan_max - fan_min) + fan_min) | |
print(t, p) | |
write(fan+'_target', p) | |
time.sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=AMD GPU fan control | |
[Service] | |
Type=simple | |
ExecStart=/home/riaqn/projects/amdgpu-fan/fanctl.py | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment