Skip to content

Instantly share code, notes, and snippets.

@danielchalef
Last active May 11, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielchalef/21656d6a5c92d2d6689b3da601496d7d to your computer and use it in GitHub Desktop.
Save danielchalef/21656d6a5c92d2d6689b3da601496d7d to your computer and use it in GitHub Desktop.
Nvidia GPU Tuner
#!/bin/bash
#
# For Nvidia GPUs only
# Overclocks, underpowers, and sets fan speeds
#
# Requires bash, a compatible proprietary nvidia driver (tested with 375+), and a suitable xorg.conf
# NOTE:
# - Ensure that your Xorg configuration has coolbits configured to allow manipulation of fan and clocks. Create
# a suitable xorg.conf using the following command:
# sudo nvidia-xconfig -a --allow-empty-initial-configuration --cool-bits=28
# - You can run this script in a headless (server) setup. Just ensure that you have an X server running:
# sudo xinit
#
# USAGE:
# You will need root privileges to manage clocks. The following underclocks cards to 115 watts.
# Modify the script itself to set memory and graphics clock offsets
# sudo ./nv_tune.sh 115
#
# Much of this script was borrowed from https://gist.github.com/squadbox/e5b5f7bcd86259d627ed
#
DISPLAY=:0
# Clock offsets in MHz
CLOCK=125
MEM=1250
# Fan speed in %
FAN=60
# Paths to the utilities we will need
SMI='/usr/bin/nvidia-smi'
SET='/usr/bin/nvidia-settings'
# Read a numerical command line arg between 75 and 175. Min/Max power is card dependent.
if [ "$1" -eq "$1" ] >/dev/null && [ "0$1" -ge "75" ] && [ "0$1" -le "175" ]
then
power=$1 # set power
$SMI -pm 1 # enable persistance mode
# how many GPU's are in the system?
NUMGPU="$(nvidia-smi -L | wc -l)"
echo "Configuring $NUMGPU GPUs"
# loop through each GPU and individually
n=0
while [ $n -lt $NUMGPU ];
do
${SET} -V -a [gpu:${n}]/GPUPowerMizerMode=1 \
-a [gpu:${n}]/GPUFanControlState=1 \
-a [fan:${n}]/GPUTargetFanSpeed=$FAN \
-a [gpu:${n}]/GPUGraphicsClockOffset[3]=${CLOCK} \
-a [gpu:${n}]/GPUMemoryTransferRateOffset[3]=${MEM}
${SMI} -i ${n} -pl $power
let n=n+1
done
echo "Complete"; exit 0;
else
echo "Error: Please pick a power limit between 75 and 175, or stop."; exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment