-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvidia_offset_basic.sh
42 lines (34 loc) · 1.66 KB
/
nvidia_offset_basic.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
#!/bin/bash
# User-configurable parameters
nvidia_smi_lgc_min= # Minimum Graphics Clock frequency
nvidia_smi_lgc_max= # Maximum Graphics Clock frequency
frequency_min= # Minimum frequency limit for offset calculations
frequency_max= # Maximum frequency limit for offset calculations
freq_offset_max= # Maximum frequency offset
freq_offset_min= # Minimum frequency offset
refresh_interval= # Refresh interval in seconds
# Check if frequency_min is higher than nvidia_smi_lgc_max
if [ $frequency_min -gt $nvidia_smi_lgc_max ]; then
echo "Error: frequency_min is higher than nvidia_smi_lgc_max. Please adjust the parameters."
exit 1
fi
sudo nvidia-smi -i 0 -lgc $nvidia_smi_lgc_min,$nvidia_smi_lgc_max
# Calculate freq_offset linearly from frequency_min to frequency_max and round to nearest multiple of 5
calculate_freq_offset() {
freq=$1
if [ $freq -lt $frequency_min ]; then
freq_offset=$freq_offset_max
elif [ $freq -gt $frequency_max ]; then
freq_offset=$freq_offset_min
else freq_offset=$((freq_offset_max - ((freq - frequency_min) * (freq_offset_max - freq_offset_min) / (frequency_max - frequency_min))))
fi
rounded_offset=$(( (freq_offset + 2) / 5 * 5 )) # Round to nearest multiple of 5
echo $rounded_offset
}
while true; do
current_gpu_frequency=$(nvidia-smi --query-gpu=clocks.gr --format=csv,noheader | cut -c 1-4)
freq_offset=$(calculate_freq_offset $current_gpu_frequency)
echo "Setting GPU frequency offset to $freq_offset"
nvidia-settings -a "[gpu:0]/GPUGraphicsClockOffsetAllPerformanceLevels=$freq_offset"
sleep $refresh_interval
done