Created
May 1, 2021 12:20
-
-
Save nanom1t/1150f3b5239fe3194c787d4dedae3f79 to your computer and use it in GitHub Desktop.
AMD GPU scripts for Linux, one to overclock, one to get stats on the GPU. Written for my Vega 64
This file contains hidden or 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/bash | |
<<LICENSE | |
Copyright (C) 2018-2019 kevinlekiller | |
This program is free software; you can redistribute it and/or | |
modify it under the terms of the GNU General Public License | |
as published by the Free Software Foundation; either version 2 | |
of the License, or (at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html | |
LICENSE | |
# This script uses https://github.com/Eliovp/amdmemorytweak and https://github.com/Lucie2A/amdtweak/tree/contribution | |
# Enables GPU scaling so the monitor doesn't go out of range when using non supported modes. | |
for output in $(xrandr --prop | grep -E -o -i "^[A-Z\-]+-[0-9]+"); do xrandr --output "$output" --set "scaling mode" "Full aspect"; done | |
# These modes allow for 75% of 4K if a game is too demanding, a 60 and 30hz mode are added. | |
if ! [[ $(xrandr) =~ 3200x1800.*60 ]]; then | |
xrandr --newmode "3200x1800" 364.47 3200 3208 3240 3280 1800 1838 1846 1852 +hsync -vsync | |
xrandr --addmode HDMI-A-0 "3200x1800" | |
fi | |
if ! [[ $(xrandr) =~ 3200x1800.*30 ]]; then | |
xrandr --newmode "3200x1800_30" 179.68 3200 3208 3240 3280 1800 1812 1820 1826 +hsync -vsync | |
xrandr --addmode HDMI-A-0 "3200x1800_30" | |
fi | |
# Which GPU to use. | |
GPUID=${GPUID:-0} | |
############################################################################################ | |
CARDWD="/sys/class/drm/card$GPUID/device" | |
if [[ $(grep 0x1002 $CARDWD/vendor 2> /dev/null) == "" ]]; then | |
echo "AMD GPU not found, exiting." | |
exit 1 | |
fi | |
HWMON="$(find $CARDWD/hwmon/ -name hwmon[0-9] -type d | head -n 1)" | |
if [[ ! -d $HWMON ]]; then | |
echo "Unable to find hwmon directory for the GPU, fan control and power control requires it, exiting." | |
exit 1 | |
fi | |
DBGFILE=/sys/kernel/debug/dri/0/amdgpu_pm_info | |
function stats() { | |
echo "Fan Speed: $(cat $HWMON/fan1_input) RPM" | |
sudo pcregrep -M "GFX Clocks.*(\n.*)*GPU Load.*" /sys/kernel/debug/dri/0/amdgpu_pm_info | |
cat $CARDWD/pp_power_profile_mode | |
cat $CARDWD/pp_od_clk_voltage | |
cat $CARDWD/pp_dpm_sclk | |
cat $CARDWD/pp_dpm_mclk | |
echo "Limit (currently) : $(($(cat $HWMON/power1_cap)/1000000)) watts" | |
} | |
trap cleanup SIGHUP SIGINT SIGQUIT SIGFPE SIGKILL SIGTERM | |
function cleanup() { | |
echo "Reverting overclock settings." | |
sudo amdtweak.sh r | |
sudo amdmemtweak --ref 3900 | |
sudo bash -c "echo $(($DEFAULTPOWERCAP*1000000)) > $HWMON/power1_cap" | |
stats | |
exit | |
} | |
# Changes the powerplay table, see the included script. | |
sudo amdtweak.sh | |
# Raises the power limit from 220 watts to 330 (50%) | |
sudo bash -c "echo 330000000 > $HWMON/power1_cap" | |
# Changes the tref, seems to be the only timing that makes any significant difference on my card. | |
sudo amdmemtweak --ref 25000 | |
while [[ true ]]; do | |
clear | |
stats | |
sleep 1 | |
done |
This file contains hidden or 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/bash | |
<<LICENSE | |
Copyright (C) 2018-2019 kevinlekiller | |
This program is free software; you can redistribute it and/or | |
modify it under the terms of the GNU General Public License | |
as published by the Free Software Foundation; either version 2 | |
of the License, or (at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html | |
LICENSE | |
# This file has info on the GPU voltage (VDDGFX) ; Alternatively, without root | |
# access you can get the voltage from /sys/class/drm/card0/device/hwmon/hwmon2/in0_input | |
DBGFILE=/sys/kernel/debug/dri/0/amdgpu_pm_info | |
CARDWD="/sys/class/drm/card0/device" | |
HWMON="$(find $CARDWD/hwmon/ -name hwmon[0-9] -type d | head -n 1)" | |
while [[ true ]]; do | |
echo "Fan Speed: $(cat $HWMON/fan1_input) RPM" | |
sudo pcregrep -M "GFX Clocks.*(\n.*)*GPU Load.*" "$DBGFILE" | |
cat $CARDWD/pp_power_profile_mode | |
cat $CARDWD/pp_od_clk_voltage | |
echo "GPU CLK:" | |
grep "*" $CARDWD/pp_dpm_sclk | |
echo "HBM CLK:" | |
grep "*" $CARDWD/pp_dpm_mclk | |
echo "SOC CLK:" | |
cat $CARDWD/pp_dpm_socclk | |
sleep 2 | |
clear | |
done | |
<<EXAMPLE | |
$ ./AMDGPUStats.sh | |
Fan Speed: 391 RPM | |
GFX Clocks and Power: | |
167 MHz (MCLK) | |
27 MHz (SCLK) | |
1138 MHz (PSTATE_SCLK) | |
800 MHz (PSTATE_MCLK) | |
856 mV (VDDGFX) | |
6.0 W (average GPU) | |
GPU Temperature: 32 C | |
GPU Load: 0 % | |
NUM MODE_NAME BUSY_SET_POINT FPS USE_RLC_BUSY MIN_ACTIVE_LEVEL | |
0 BOOTUP_DEFAULT*: 70 60 0 0 | |
1 3D_FULL_SCREEN : 70 60 1 3 | |
2 POWER_SAVING : 90 60 0 0 | |
3 VIDEO : 70 60 0 0 | |
4 VR : 70 90 0 0 | |
5 COMPUTE : 30 60 0 6 | |
6 CUSTOM : 0 0 0 0 | |
OD_SCLK: | |
0: 852Mhz 800mV | |
1: 991Mhz 900mV | |
2: 1084Mhz 950mV | |
3: 1138Mhz 1000mV | |
4: 1200Mhz 1050mV | |
5: 1401Mhz 1100mV | |
6: 1536Mhz 1150mV | |
7: 1630Mhz 1200mV | |
OD_MCLK: | |
0: 167Mhz 800mV | |
1: 500Mhz 800mV | |
2: 800Mhz 950mV | |
3: 945Mhz 1100mV | |
OD_RANGE: | |
SCLK: 852MHz 2400MHz | |
MCLK: 167MHz 1500MHz | |
VDDC: 800mV 1200mV | |
GPU CLK: | |
0: 852Mhz * | |
HBM CLK: | |
0: 167Mhz * | |
SOC CLK: | |
0: 600Mhz * | |
1: 720Mhz | |
2: 800Mhz | |
3: 847Mhz | |
4: 900Mhz | |
5: 960Mhz | |
6: 1028Mhz | |
EXAMPLE |
This file contains hidden or 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
#!/usr/bin/env bash | |
AMDTWEAK_DIR="/home/kevin/git/amdtweak" | |
cd $AMDTWEAK_DIR | |
# Revert to stock settings. | |
if [[ $1 == "r" ]]; then | |
sudo node ${AMDTWEAK_DIR}/amdtweak.js \ | |
--card @ \ | |
--read-card-pp \ | |
--set VddcLookupTable.Entries[0].Vdd=800 \ | |
--set VddcLookupTable.Entries[1].Vdd=900 \ | |
--set VddcLookupTable.Entries[2].Vdd=950 \ | |
--set VddcLookupTable.Entries[3].Vdd=1000 \ | |
--set VddcLookupTable.Entries[4].Vdd=1050 \ | |
--set VddcLookupTable.Entries[5].Vdd=1100 \ | |
--set VddcLookupTable.Entries[6].Vdd=1150 \ | |
--set VddcLookupTable.Entries[7].Vdd=1200 \ | |
--set GfxClockDependencyTable.Entries[0].Clock=85200 \ | |
--set GfxClockDependencyTable.Entries[1].Clock=99100 \ | |
--set GfxClockDependencyTable.Entries[2].Clock=108400 \ | |
--set GfxClockDependencyTable.Entries[3].Clock=113800 \ | |
--set GfxClockDependencyTable.Entries[4].Clock=120000 \ | |
--set GfxClockDependencyTable.Entries[5].Clock=140100 \ | |
--set GfxClockDependencyTable.Entries[6].Clock=153600 \ | |
--set GfxClockDependencyTable.Entries[7].Clock=163000 \ | |
--set MemClockDependencyTable.Entries[3].MemClock=94500 \ | |
--set MemClockDependencyTable.Entries[3].VddIndex=5 \ | |
--set SocClockDependencyTable.Entries[6].Clock=102800 \ | |
--write-card-pp | |
# This is to force the card to go back to switching to lower states, any time I touch anything | |
# relating to power play the clocks or voltages never go back down to minimum. | |
sudo bash -c "echo low > /sys/class/drm/card0/device/power_dpm_force_performance_level" | |
sudo bash -c "echo auto > /sys/class/drm/card0/device/power_dpm_force_performance_level" | |
else | |
# By setting the 6th SOC state clock speed higher, it allows the 3rd HBM state clock speed to | |
# clock higher (it can only go as high as the 6th SOC clock speed). | |
# Vddc 2 to 6 must be all the same voltage or HBM will only go as high as HBM state 2 (800MHz) | |
# I've spent hours trying to change other settings, like fooling around with | |
# MemClockDependencyTable.Entries[].VddIndex= for example, but only setting those the same | |
# voltage worked. | |
sudo node ${AMDTWEAK_DIR}/amdtweak.js \ | |
--card @ \ | |
--read-card-pp \ | |
--set VddcLookupTable.Entries[0].Vdd=800 \ | |
--set VddcLookupTable.Entries[1].Vdd=900 \ | |
--set VddcLookupTable.Entries[2].Vdd=950 \ | |
--set VddcLookupTable.Entries[3].Vdd=950 \ | |
--set VddcLookupTable.Entries[4].Vdd=950 \ | |
--set VddcLookupTable.Entries[5].Vdd=950 \ | |
--set VddcLookupTable.Entries[6].Vdd=950 \ | |
--set VddcLookupTable.Entries[7].Vdd=975 \ | |
--set GfxClockDependencyTable.Entries[0].Clock=85200 \ | |
--set GfxClockDependencyTable.Entries[1].Clock=99100 \ | |
--set GfxClockDependencyTable.Entries[2].Clock=108400 \ | |
--set GfxClockDependencyTable.Entries[3].Clock=113800 \ | |
--set GfxClockDependencyTable.Entries[4].Clock=120000 \ | |
--set GfxClockDependencyTable.Entries[5].Clock=145000 \ | |
--set GfxClockDependencyTable.Entries[6].Clock=160200 \ | |
--set GfxClockDependencyTable.Entries[7].Clock=170200 \ | |
--set MemClockDependencyTable.Entries[3].MemClock=110000 \ | |
--set MemClockDependencyTable.Entries[3].VddIndex=5 \ | |
--set SocClockDependencyTable.Entries[6].Clock=110000 \ | |
--write-card-pp | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment