Friday, February 4, 2011

Scripts to control nVidia fan speeds

In my previous post, I discussed how to set up your xorg.conf file to allow you to manually control fan speed on headless nVidia cards.  Now, I'm going to talk about some command line utilities, and ways to script fan speed control so that you don't have to do it with a GUI every time you want your cards to cool down.

The trick here is that the nvidia-settings utility is actually a very powerful command line tool as well.  You can set fan speeds with it very effectively.

The man page for it is a great read, but I'll skip the deep dive into it.  Instead, I offer some scripts that you can modify to control your fan speeds!

This will set fans to max:

nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed=100 -a [gpu:1]/GPUFanControlState=1 -a [fan:1]/GPUCurrentFanSpeed=100 -a [gpu:2]/GPUFanControlState=1 -a [fan:2]/GPUCurrentFanSpeed=85 -c :0.0

Should you want to set them back to automatic control:

nvidia-settings -a [gpu:0]/GPUFanControlState=0 -a [gpu:1]/GPUFanControlState=0 -a [gpu:2]/GPUFanControlState=0 -c :0.0

You'll need to modify these slightly to match your setup, so I'll go through each command in useful detail.

The '-a' command line option sets an attribute.  For fan control, there are two attributes you need to be aware of.

GPUFanControlState enables and disables manual fan control.  If it is set to 0, the fans are controlled automatically.  If it is set to 1, fans are controlled manually.

GPUCurrentFanSpeed sets the current fan speed, in percent.  As I noted in my last post, on my eVGA GTX580, I cannot set the fan speed above 85% - it simply ignores it.

The [gpu:0] and [fan:0] identifiers select which GPU or fan you are setting things on.  For modern, single-fan GPUs, they correspond to each other.

Finally, the '-c 0:0' sets the display you are attaching to.  I'm not sure why this needs to be set, but it seemed to be required when I was playing around.

So, for my "Set Fans Takeoff Power" script, I go through and sequentially set each GPU to use manual fan control, and then set the fan speed.  If you set the fan speed without enabling manual fan control, it doesn't do anything.

For the "Set Fans Autothrottle" script, I simply turn each GPU back to automatic fan control, and the GPU takes over the rest of the work.

Make sense?


  1. great job, very helpful. made me thinking about how to get it to go all the way and apply this to real headless GPU compute nodes. ...and it _is_ possible with some extra effort:

  2. Hi, thank you for your helpful blog.
    Do you know what is the reason when I execute this command, my GPU Titan X throws some errors like this:

    ERROR: The attribute 'GPUCurrentFanSpeed' specified in assignment
    '[fan:0]/GPUCurrentFanSpeed=100' cannot be assigned (it is a read-only

    Thank you.

  3. Thank you.
    I found the solution in Since the drivers version 349.16, GPUCurrentFanSpeed has to be replaced with GPUTargetFanSpeed.
    Best regards,

  4. Thank you, I'm following your blog and articles. The idea is excellent, but only if you find out in advance which driver you need for sure, otherwise there will be problems with compatibility, and this will cause even greater difficulties than before. Just go into details and use NVidia drivers download for your PC, even simple but right driver makes job like no software or device could ever do.