-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvega-power-control
executable file
·157 lines (147 loc) · 5.1 KB
/
vega-power-control
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
#
# Script to set AMD Vega clock/voltage/profile settings.
#
# authored-by: Aaron Echols
# email: atechols at gmail dot com
#
# NOTES:
#
# This script has been released under the GNU GENERAL PUBLIC LICENSE.
# Please contribute to the upstream author at:
# https://github.com/dasunsrule32/radeon-scripts
#
# Install Instructions:
#
# https://github.com/dasunsrule32/radeon-scripts/blob/master/systemd/INSTALL-vega-power-control.md
#
# Variables:
# ----------
DEBUG=0 # Enable (1) or Disable (0) DEBUG.
AMDSYSFILE="power_dpm_force_performance_level" # ADM SYSFS file to search for.
SYSPATH=$(awk '{print}' <<< `find /sys/devices -name $AMDSYSFILE -type f -exec dirname {} \;`) # Autodetect SYSFS path.
HWMONPATH="hwmon/hwmon0"
KERNELVER=$(awk -F. '{printf("%d%02d\n", $1, $2)}' <<< `uname -r`) # Get kernel version.
KERNELREQ="415" # Minimum required kernel version for script.
KERNELREQPOW="420" # Kernel version required for POWERCAP control.
POWERCAP="0" # Enable (1) or Disable (0) AMD powercap settings, requires DEFAULTDPMPERFLVL set to manual.
DEFAULTDPMSTATE="balanced" # Set power profile, options: battery (Won't work with discrete cards), balanced, performance.
DEFAULTDPMPERFLVL="auto" # Default to auto, possible options are: auto, low, high, manual. See docs for more options.
HWDEVID=`cut -c 3- <<< cat $SYSPATH/device` # Get device ID for card.
SUBSYSDEV=`cut -c 3- <<< cat $SYSPATH/subsystem_device` # Get Subsystem device ID for card.
SUBSYSVEN=`cut -c 3- <<< cat $SYSPATH/subsystem_vendor` # Get Subsystem vendor ID for card.
SUBSYSID="$SUBSYSVEN:$SUBSYSDEV" # Get Subsystem ID for card.
HWID="$SUBSYSVEN:$HWDEVID" # Get hardware ID for card.
typeset -A CORE_TABLE=(
[0]="852 800"
[1]="991 900" # core states 0-7 clock and voltge
[2]="1084 910"
[3]="1138 930"
[4]="1200 945"
[5]="1400 955"
[6]="1500 970"
[7]="1600 1000"
)
typeset -A MEM_TABLE=(
[0]="167 800"
[1]="500 850" # mem states 0-3 clock and core voltage floor, the hbm never
[2]="800 910" # actually goes below 1.35v, this changes the lower voltage floor for the core
[3]="1000 1000"
)
# Constant Variables:
# ------------------
# Vendor IDs:
# Reference: https://www.amd.com/en/support/kb/faq/gpu-55#faq-Subsystem-Vendor-ID-and-Device-ID
# Device hunt: https://devicehunt.com
AMD="1002"
ASUSTEK="1043"
CLUB3D="196D"
DIAMOND="1092"
GECUBE="18BC"
GIGABYTE="17AF"
HIS="17AF"
JETWAY="16F3"
MSI="1462"
SAPPHIRE="1DA2"
POWERCOLOR="148C"
VISIONTEK="1545"
XFX="1682"
ACER="1025"
APPLE="106B"
DELL="1028"
GATEWAY="107B"
HP="103C"
LENOVO="17AA"
SONY="104D"
TOSHIBA="1179"
# Functions:
# ----------
# Echo a string value that is passed
echo_text() {
echo -e >&2 "$@";
}
# Main body:
# ----------
# Check if root:
if [[ $EUID -ne 0 ]]; then
echo_text "You need to be root to run this script..."
exit 1
fi
# Check if kernel version is new enough:
if [ $KERNELVER -lt $KERNELREQ ]; then
echo_text "Kernel is too old, exiting..."
exit 2
else
echo_text "Kernel requirements met, continuing..."
fi
# Echo Hardware/Subsystem ID when DEBUG is enabled:
if [ $DEBUG -eq 1 ]; then
echo_text "Device ID: $HWID"
echo_text "Subsystem ID: $SUBSYSID"
fi
# Set profile (auto|manual):
if [ "$DEFAULTDPMPERFLVL" == "auto" ]; then
POWERDPMPERFLVL=`cat $SYSPATH/power_dpm_force_performance_level`
if [ $DEBUG -eq 1 ]; then
echo_text "Current state: $POWERDPMPERFLVL"
fi
# Set back to defaults if manual profile was set previously:
if [ "$POWERDPMPERFLVL" != "auto" ]; then
echo_text "Restoring to factory default settings..."
echo "$DEFAULTDPMPERFLVL" > "$SYSPATH/power_dpm_force_performance_level"
echo "r" > "$SYSPATH/pp_od_clk_voltage"
echo "c" > "$SYSPATH/pp_od_clk_voltage"
fi
# power_dpm_state is for older AMD cards only.
# FROM THE DOCS: The power_dpm_state file is a legacy interface and is
# only provided for backwards compatibility.
#
# TODO: Set a check on this block to differentiate
# VEGA/POLARIS, etc.
echo_text "Setting profile to: $DEFAULTDPMSTATE..."
echo "$DEFAULTDPMSTATE" > "$SYSPATH/power_dpm_state"
elif [ "$DEFAULTDPMPERFLVL" == "manual" ]; then
# TODO: Add custom values to arrays for specific cards.
# This will require the refactoring of device/model detection.
#
# Set GPU/HBM frequencies/voltages:
echo_text "Applying custom power settings..."
echo "$DEFAULTDPMPERFLVL" > "$SYSPATH/power_dpm_force_performance_level"
for ((i = 0; i <= 7; i++)); do
[[ ${CORE_TABLE[$i]} ]] && echo "s $i ${CORE_TABLE[$i]}" > "$SYSPATH/pp_od_clk_voltage"
[[ $i -le 3 && ${MEM_TABLE[$i]} ]] && echo "m $i ${MEM_TABLE[$i]}" > "$SYSPATH/pp_od_clk_voltage"
done
# Set Power consumption - Requires Kernel 4.20+:
if [ $KERNELVER -ge $KERNELREQPOW ]; then
if [ $DEBUG -eq 1 ]; then
echo_text "Kernel Version: $KERNELVER"
fi
if [ $POWERCAP -eq 1 ]; then
echo_text "Adjusting AMD Power Cap"
# To set the allowed maximum power consumption of the GPU to e.g. 220 Watts (Default wattage):
echo 220000000 > "$SYSPATH/$HWMONPATH/power1_cap"
fi
fi
# Commit power changes:
echo "c" > "$SYSPATH/pp_od_clk_voltage"
fi