Skip to content

Instantly share code, notes, and snippets.

@helinwang
Last active March 3, 2025 22:06
Show Gist options
  • Save helinwang/507b2fccbd04083854fbda4dcc88ccc6 to your computer and use it in GitHub Desktop.
Save helinwang/507b2fccbd04083854fbda4dcc88ccc6 to your computer and use it in GitHub Desktop.
Make Nvidia GPU idle at around 9W instead of 20W
# save to /usr/local/bin/gpu-run
# exmaplea: gpu-run python train.py
# this makes Nvidia GPU idle at around 9W instead of 20W with the requirement of:
# 1. make sure no process using Nvidia GPU at idle, this requires setting up desktop manager to use iGPU
# 2. run this script
# 3. setup and run the systemd target at bottom of this file
# Function to restore low power state
function restore_power {
echo "Restoring low power state..."
# need to set pm to 0 before 1, otherwise power draw could stuck at 20W
sudo nvidia-smi -pm 0
sudo nvidia-smi -pm 1
sudo nvidia-smi -pl 100
}
# Set up trap to ensure power is restored even if program crashes
trap restore_power EXIT
# Reset GPU to full power
echo "Setting GPU to full performance..."
sudo nvidia-smi -rgc
sudo nvidia-smi --gpu-reset
sudo nvidia-smi -pm 1
sudo nvidia-smi -pl 374 # set to your GPU's max power draw
# Run the actual program
echo "Running program: $@"
"$@"
# /etc/systemd/system/nvidia-lowpower.service
# [Unit]
# Description=NVIDIA Low Power Mode
# After=syslog.target systemd-modules-load.service
# [Service]
# Type=oneshot
# ExecStart=/usr/bin/nvidia-smi -pm 1
# ExecStart=/usr/bin/nvidia-smi -pl 100
# RemainAfterExit=yes
# [Install]
# WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment