You may already know this, but thanks to this Reddit post humanity finally knows the answer to one of the greatest mysteries: “How can one overclock an NVIDIA GPU under Wayland?”.
Based on the previously mentioned post I will give you an example on how to automate the overclocking and apply it on user login.
Setup the overclocking script:
- firstly we need to enter the system root user via the
su
command (will explain why later) and then usecd ~/
to enter the root’s home directory (we want all changes to be made in the root’s home "will explain"™) - now we are going to prepare a new python environment for running our script
- as the root user create folder named ‘nvgpu-overclock’:
mkdir nvgpu-overclock
- enter the folder:
cd nvgpu-overclock
- create a new python environment:
python3 -m venv ./
- enter the new environment:
source ./bin/activate
(for fish useactivate.fish
) - install dependencies:
pip install nvidia-ml-py pynvml
- create the script
- using your favorite CLI text editor (for example nano) create file named ‘
overclock.py
’ with the following content while tweaking the values as needed (some offsets may not work on certain GPUs, if this script fails, try commenting an offset instruction(s) and see if it helps to at leas get access to some vaues):
from pynvml import *
nvmlInit()
# This sets the GPU to adjust - if this gives you errors or you have multiple GPUs, set to 1 or try other values.
myGPU = nvmlDeviceGetHandleByIndex(0)
# The GPU frequency offset value should replace the "80" in the line below.
nvmlDeviceSetGpcClkVfOffset(myGPU, 80)
# The Mem frequency Offset should be **multiplied by 2** to replace the "2500" below
# for example, an offset of 500 in GWE means inserting a value of 1000 in the next line
nvmlDeviceSetMemClkVfOffset(myGPU, 2500)
# The power limit should be set below in mW - 216W becomes 216000, etc. May not work for laptops. Remove the below line if you don't want to adjust power limits.
nvmlDeviceSetPowerManagementLimit(myGPU, 216000)
- before setting the script to run automatically on startup it’s a good idea to manually test it for correct offsets, to do this you just need to run the script by executing
python3 /root/nvgpu-overclock/overclock.py
, while still being in the newly created python environment as described in stage 2, enter the environment as described in stage 2 if needed (no need to again create the folder and install dependancies) - now time for the root user part and utomatically applying the overclocking, due to NVML’s setup this method requires root privileges to apply the changes and because of that we are doing all the changes in the root’s home directory (for security and later convenience reasons);
to run the script automatically we will use cron and sudo following one of the 2 methods:
- (apply on user login)
- first we need to create a simple bash script that will run the actual overclocking python script so we can later create a new sudo rule, to create this bash script just create a file named ‘
run-nvgpu-overclock
’ (while in the python script directory) with 2 lines of the following content:
#!/usr/bin/bash
bash -c 'source /root/nvgpu-overclock/bin/activate && python3 /root/nvgpu-overclock/overclock.py'
- after creating the bash script make it executable:
chmod +x ./run-nvgpu-overclock
- now we need to create a custom sudo rule, to do this create file
/etc/sudoers.d/nv-overclock
using your favorite CLI text editor (for example:nano /etc/sudoers.d/nv-overclock
) with the following line (make sure to replace theyour_user_name
with your regular Linux user account name):
your_user_name ALL=(root) NOPASSWD: /root/nvgpu-overclock/run-nvgpu-overclock
- exit the root user with the
exit
command to enter back your regular user console - create the following cron entry:
@reboot /usr/bin/sudo /root/nvgpu-overclock/run-nvgpu-overclock
(usecrontab -e
to add the cron entry, if it runs in vim see this guide if not familiar with vim)
- first we need to create a simple bash script that will run the actual overclocking python script so we can later create a new sudo rule, to create this bash script just create a file named ‘
- (apply on OS startup)
- you should think twice before using this method because if you set any wrong offset values that make your GPU crash on system startup you may not be able to enter your system without using a recovery media (a recovery system ISO for example)
- to do this you just need to add the following cron entry:
@reboot /usr/bin/bash -c 'source /root/nvgpu-overclock/bin/activate && python3 /root/nvgpu-overclock/overclock.py'
(usecrontab -e
to add the cron entry, if it runs in vim see this guide if not familiar with vim)
If it works for you then my sleepy mind managed to put it down more or less correct.
If you have any proposals on how to make this mess batter and more understandable please post a comment.