Working on Mutli-GPU machines can be a real pain in the neck. Dedicated chips draw more power even when they are idle. Windows switch GPU nicely based on the load while Ubuntu doesn’t come with such luxuries.
Notebook machines suffer the most in this scenario. To address the problem to some extend, I wrote a shell script to swtich the GPU and go for a reboot without having me to write a bunch of commands on terminal; one after the other.
prime-select is a useful NVIDIA utility to see and change GPUs. Firstly, query to see which GPU is currently active and save the response.
prime-select query queries to get the active GPU;
$ saves the response in a variable.
Next, we need to change to other chip based on the query response. This is achievable using a set of IF…ELSE statements.
prime-select x selects an Intel or Nvidia GPU based on the value of
x. A nice sudo approvable comes handy in such matters.
echo can be used to plug values into other commands. All these coopearte to do the real task at hand.
echo enter-sudo-pass-here | sudo -S prime-select intel
Based on your liking,
sleep x the system for
x seconds to save the existing work: just to be on safe side.
Get the complete script here.