I have my own take on the autofan which targets a fixed temperature rather than a coefficient-based fan increase:
for (( i = 0; i < $NV_CARDS; i++ )); do
NV_DATA=`nvidia-smi -i $i --query-gpu=fan.speed,temperature.gpu --format=csv,noheader,nounits`
CURRENT_FAN=`awk -F', ' '{print $1}' <<< $NV_DATA`
CURRENT_TEMP=`awk -F', ' '{print $2}' <<< $NV_DATA`
DIFF=$(( $CURRENT_TEMP - $TARGET_TEMP )) # low: 60-65=-5 High: 70-65=5
NEW_FAN=$CURRENT_FAN
if [[ $DIFF -ge 2 ]]; then # too high temperature
NEW_FAN=$(( $CURRENT_FAN + $DIFF ))
if [[ $NEW_FAN -gt $MAX_SPEED ]]; then
NEW_FAN=$MAX_SPEED
fi
elif [[ $DIFF -le -2 ]]; then # too low temperature
NEW_FAN=$(( $CURRENT_FAN - ${DIFF#-} / 2 )) # get absolute number of $DIFF and divide it by 2
if [[ $NEW_FAN -lt $MIN_SPEED ]]; then
NEW_FAN=$MIN_SPEED
fi
fi
if [[ $NEW_FAN -eq 0 || $NEW_FAN -eq $CURRENT_FAN ]]; then # do nothing
echo -e "GPU${i} ${CURRENT_TEMP}\xc2\xb0C ${CURRENT_FAN}%"
else
echo -e "GPU${i} ${CURRENT_TEMP}\xc2\xb0C ${CURRENT_FAN}% -> ${NEW_FAN}%"
ARGS+=" -a [gpu:$i]/GPUFanControlState=1 -a [fan:$i]/GPUTargetFanSpeed=$NEW_FAN"
fi
done
This essentially increase the fan speed by the temp difference and then if it gets too cold, reduces it by diff/2. Runs only if the difference is >=2 degrees and doesn’t go below and above a specified min/max fan %.
It’d be lovely if you can implement it into your script. I’ve been running it for nearly 2 months and works just fine.