-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvidia-offset-advanced_example.sh
197 lines (175 loc) · 8.17 KB
/
nvidia-offset-advanced_example.sh
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# Example of values, which I find stable for my Ampere mobile GPU (3070M) with 150W TGP
# User-configurable parameters
gpu_memory_offset=-2000
nvidia_smi_lgc_min=420
nvidia_smi_lgc_max=1800
temperature_min=20
temperature_max=80
plimit_min=20
plimit_max=120
frequency_min=900
frequency_max=1800
freq_offset_max=330
freq_offset_min=150
low_freq_min=900
low_freq_max=1400
drain_offset_lmin=-30
drain_offset_lmax=0
high_freq_min=1500
high_freq_max=1800
drain_offset_hmin=0
drain_offset_hmax=15
critical_temp_min=48
critical_temp_max=61
power_offset_max=45
power_offset_min=0
refresh_interval=1
show_info=true
drain_offset_control=true
power_offset_control=true
critical_temp_range_control=true
help_message="Usage: $0 [options]\n\
Options:\n\
-o, options Show configurable parameters\n\
-c, config Show configured values\n\""
# Function to display the help message
function display_help {
echo -e "$help_message"
}
# Help section
if [[ $1 == "options" || $1 == "-o" ]]; then
echo ""
echo " This tool designed for advanced control of Nvidia GPU offsets with this configurable parameters:"
echo ""
echo " --gpu_memory_offset: VRAM offset to overclock/underclock memory speed"
echo " --nvidia_smi_lgc_min: Minimum value for nvidia-smi lgc"
echo " --nvidia_smi_lgc_max: Maximum value for nvidia-smi lgc"
echo " --temperature_min: Minimum temperature limit"
echo " --temperature_max: Maximum temperature limit"
echo " --plimit_min: Minimum power limit"
echo " --plimit_max: Maximum power limit"
echo " --frequency_min: Minimum frequency limit"
echo " --frequency_max: Maximum frequency limit"
echo " --freq_offset_max: Maximum frequency offset value"
echo " --freq_offset_min: Minimum frequency offset value"
echo " --low_freq_min: Low frequency range min"
echo " --low_freq_max: Low frequency range max"
echo " --drain_offset_lmin: Low frequency drain offset min"
echo " --drain_offset_lmax: Low frequency drain offset max"
echo " --high_freq_min: High frequency range min"
echo " --high_freq_max: High frequency range max"
echo " --drain_offset_hmin: High frequency drain offset min"
echo " --drain_offset_hmax: High frequency drain offset max"
echo " --critical_temp_min: Critical temperature min"
echo " --critical_temp_max: Critical temperature max"
echo " --power_offset_max: Maximum power offset"
echo " --power_offset_min: Minimum power offset"
echo " --critical_temp_range_control: Set critical temperature range offset (default: true)"
echo " --drain-offset-control Set drain offset control mode (default: true)"
echo " --power-offset-control Set power offset control mode (default: true)"
echo " --refresh_interval Set refresh rate in seconds (default: 5)"
exit
fi
# Help section for showing configured values
if [[ $1 == "config" || $1 == "-c" ]]; then
echo "Configured values:"
echo "gpu_memory_offset: $gpu_memory_offset"
echo "nvidia_smi_lgc_min: $nvidia_smi_lgc_min, nvidia_smi_lgc_max: $nvidia_smi_lgc_max"
echo "temperature_min: $temperature_min, temperature_max: $temperature_max"
echo "plimit_min: $plimit_min, plimit_max: $plimit_max"
echo "frequency_min: $frequency_min, frequency_max: $frequency_max"
echo "freq_offset_max: $freq_offset_max, freq_offset_min: $freq_offset_min"
echo "low_freq_min: $low_freq_min, low_freq_max: $low_freq_max"
echo "drain_offset_lmin: $drain_offset_lmin, drain_offset_lmax: $drain_offset_lmax"
echo "high_freq_min: $high_freq_min, high_freq_max: $high_freq_max"
echo "drain_offset_hmin: $drain_offset_hmin, drain_offset_hmax: $drain_offset_hmax"
echo "critical_temp_min: $critical_temp_min, critical_temp_max: $critical_temp_max"
echo "power_offset_max: $power_offset_max, power_offset_min: $power_offset_min"
exit
fi
# Help section for displaying the help message with configurable parameters
if [[ "$1" == "help" || $1 == "-h" ]]; then
display_help
exit
fi
# Apply nvidia-smi lgc
sudo nvidia-smi -i 0 -lgc $nvidia_smi_lgc_min,$nvidia_smi_lgc_max
# Apply VRAM oveclock/underclock offset
nvidia-settings -a "[gpu:0]/GPUMemoryTransferRateOffsetAllPerformanceLevels=$gpu_memory_offset"
while true; do
# Get current time
current_time=$(date +"%T")
# Get GPU statistics
frequency=$(nvidia-smi --query-gpu=clocks.gr --format=csv,noheader | cut -c 1-4)
temperature=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader)
power=$(nvidia-smi --query-gpu=power.draw --format=csv,noheader | awk '{ print int($1 + 0.5) }')
voltage=$(nvidia-smi -q -d VOLTAGE | grep 'Graphics' | awk '{print $3,$4}')
# Calculate freq_offset
if [ $frequency -lt $frequency_min ]; then
freq_offset=$freq_offset_max
elif [ $frequency -gt $frequency_max ]; then
freq_offset=$freq_offset_min
else freq_offset=$((freq_offset_max - ((frequency - frequency_min) * (freq_offset_max - freq_offset_min) / (frequency_max - frequency_min))))
fi
# Calculate drain_offset if control is enabled
if [ $drain_offset_control == true ]; then
if [ $frequency -ge $low_freq_min ] && [ $frequency -le $low_freq_max ]; then
drain_offset=$(( (drain_offset_lmax - drain_offset_lmin) * (temperature - temperature_min) / (temperature_max - temperature_min) + drain_offset_lmin ))
if [ $temperature -gt $temperature_max ]; then
drain_offset=$drain_offset_lmax # Apply drain_offset_lmax if temperature exceeds temperature_max
fi
elif [ $frequency -ge $high_freq_min ] && [ $frequency -le $high_freq_max ]; then
drain_offset=$(( (drain_offset_hmax - drain_offset_hmin) * (temperature - temperature_min) / (temperature_max - temperature_min) + drain_offset_hmin ))
if [ $temperature -gt $temperature_max ]; then
drain_offset=$drain_offset_hmin # Apply drain_offset_hmin if temperature exceeds temperature_max
fi
fi
# Apply specific drain_offsets based on temperature exceeding threshold and critical_temp_range_control
if [ $critical_temp_range_control == true ] && [ $temperature -gt $critical_temp_min ] && [ $temperature -lt $critical_temp_max ]; then
if [ $frequency -ge $low_freq_min ] && [ $frequency -le $low_freq_max ]; then
drain_offset=$drain_offset_lmin
elif [ $frequency -ge $high_freq_min ] && [ $frequency -le $high_freq_max ]; then
drain_offset=$drain_offset_hmin
fi
fi
fi
# Calculate power_offset if control is enabled
if [ $power_offset_control == true ]; then
if [ $power -le $plimit_min ]; then
power_offset=$power_offset_max
elif [ $power -gt $plimit_min ] && [ $power -le $plimit_max ]; then
power_offset=$(($power_offset_max - ($power_offset_max - $power_offset_min) * ($power - $plimit_min) / ($plimit_max - $plimit_min)))
else
power_offset=$power_offset_min
fi
fi
# Calculate total_offset based on control settings
if [ $power_offset_control == true ] && [ $drain_offset_control == true ]; then
total_offset=$(( freq_offset + drain_offset + power_offset ))
elif [ $power_offset_control == true ] && [ $drain_offset_control == false ]; then
total_offset=$(( freq_offset + power_offset ))
elif [ $power_offset_control == false ] && [ $drain_offset_control == true ]; then
total_offset=$(( freq_offset + drain_offset ))
else
total_offset=$freq_offset
fi
# Round total_offset to nearest multiple of 5
total_offset=$(echo $((total_offset / 5 * 5)))
# Show GPU statistics if show_info is true
if [ "$show_info" = true ]; then
echo "Current time: $current_time"
echo "Frequency: $frequency MHz"
echo "Temperature: $temperature °C"
echo "Power: $power W"
echo "Voltage: $voltage"
echo "Freq Offset: $freq_offset"
echo "Drain Offset: $drain_offset"
echo "Power Offset: $power_offset"
echo "Total Offset: $total_offset"
fi
# Apply offset
nvidia-settings -a "[gpu:0]/GPUGraphicsClockOffsetAllPerformanceLevels=$total_offset"
# Wait for refresh interval
sleep $refresh_interval
done