Skip to content

Instantly share code, notes, and snippets.

@ald2004
Forked from squadbox/cool_gpu2.sh
Created July 5, 2022 08:12
Show Gist options
  • Select an option

  • Save ald2004/85b3979539d40311a9968ed8bfd9e5e0 to your computer and use it in GitHub Desktop.

Select an option

Save ald2004/85b3979539d40311a9968ed8bfd9e5e0 to your computer and use it in GitHub Desktop.

Revisions

  1. @squadbox squadbox revised this gist Sep 2, 2015. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions cool_gpu2.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    # cool_gpu2.sh This script will enable or disable fixed gpu fan speed
    #
    # Description: A script to control Nvidia GPU fan speed on headless (non-X) linux nodes
    # Description: A script to control GPU fan speed on headless (non-X) linux nodes

    # Original Script by Axel Kohlmeyer <[email protected]>
    # https://sites.google.com/site/akohlmey/random-hacks/nvidia-gpu-coolness
    @@ -18,6 +18,8 @@
    # * Coolbits enabled and empty config setting
    # nvidia-xconfig -a --cool-bits=28 --allow-empty-initial-configuration

    # You may have to run this as root or with sudo if the current user is not authorized to start X sessions.


    # Paths to the utilities we will need
    SMI='/usr/bin/nvidia-smi'
    @@ -68,7 +70,7 @@ then
    while [ $n -lt $NUMGPU ];
    do
    # start an x session, and call nvidia-settings to enable fan control and set speed
    xinit ${SET} -a [gpu:${n}]/GPUFanControlState=0 -- :0 -once
    xinit ${SET} -a [gpu:${n}]/GPUFanControlState=0 -- :0 -once
    let n=n+1
    done

  2. @squadbox squadbox created this gist Sep 2, 2015.
    79 changes: 79 additions & 0 deletions cool_gpu2.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    #!/bin/bash

    # cool_gpu2.sh This script will enable or disable fixed gpu fan speed
    #
    # Description: A script to control Nvidia GPU fan speed on headless (non-X) linux nodes

    # Original Script by Axel Kohlmeyer <[email protected]>
    # https://sites.google.com/site/akohlmey/random-hacks/nvidia-gpu-coolness
    #
    # Modified for newer drivers and removed old work-arounds
    # Tested on Ubuntu 14.04 with driver 352.41
    # Copyright 2015, squadbox

    # Requirements:
    # * An Nvidia GPU
    # * Nvidia Driver V285 or later
    # * xorg
    # * Coolbits enabled and empty config setting
    # nvidia-xconfig -a --cool-bits=28 --allow-empty-initial-configuration


    # Paths to the utilities we will need
    SMI='/usr/bin/nvidia-smi'
    SET='/usr/bin/nvidia-settings'

    # Determine major driver version
    VER=`awk '/NVIDIA/ {print $8}' /proc/driver/nvidia/version | cut -d . -f 1`

    # Drivers from 285.x.y on allow persistence mode setting
    if [ ${VER} -lt 285 ]
    then
    echo "Error: Current driver version is ${VER}. Driver version must be greater than 285."; exit 1;
    fi

    # Read a numerical command line arg between 40 and 100
    if [ "$1" -eq "$1" ] 2>/dev/null && [ "0$1" -ge "40" ] && [ "0$1" -le "100" ]
    then
    $SMI -pm 1 # enable persistance mode
    speed=$1 # set speed

    echo "Setting fan to $speed%."

    # how many GPU's are in the system?
    NUMGPU="$(nvidia-smi -L | wc -l)"

    # loop through each GPU and individually set fan speed
    n=0
    while [ $n -lt $NUMGPU ];
    do
    # start an x session, and call nvidia-settings to enable fan control and set speed
    xinit ${SET} -a [gpu:${n}]/GPUFanControlState=1 -a [fan:${n}]/GPUTargetFanSpeed=$speed -- :0 -once
    let n=n+1
    done

    echo "Complete"; exit 0;

    elif [ "x$1" = "xstop" ]
    then
    $SMI -pm 0 # disable persistance mode

    echo "Enabling default auto fan control."

    # how many GPU's are in the system?
    NUMGPU="$(nvidia-smi -L | wc -l)"

    # loop through each GPU and individually set fan speed
    n=0
    while [ $n -lt $NUMGPU ];
    do
    # start an x session, and call nvidia-settings to enable fan control and set speed
    xinit ${SET} -a [gpu:${n}]/GPUFanControlState=0 -- :0 -once
    let n=n+1
    done

    echo "Complete"; exit 0;

    else
    echo "Error: Please pick a fan speed between 40 and 100, or stop."; exit 1;
    fi