SpaceinvaderOne / nvidia_powersave

script to save power on Unraid server with Nvidia GPU

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unraid Nvidia GPU Power Management Script

Overview

This script is designed to manage the power consumption of Nvidia GPUs on Unraid servers, particularly when the GPUs are not actively passed through to a VM or used by Docker containers. It optimizes power usage by setting GPUs to their lowest power state when idle, potentially leading to significant electricity savings.

Key Features

  • Power State Management: Automatically sets Nvidia GPUs to their lowest power consumption state when not in use by VMs or Docker containers.
  • Savings Calculation: Optionally calculates and displays the estimated annual electricity savings from using the script.
  • Safe Operation: Carefully avoids adjusting power states for GPUs actively used by Docker containers or VMs, preventing server crashes and ensuring stable operation.

Requirements

  • Unraid Nvidia Driver: The script requires the Unraid server to have the Nvidia driver installed. This is necessary for controlling GPU power states and for querying GPU usage information.
  • bc Command: For the optional power savings calculation feature, the bc command-line calculator must be installed. This can be easily added via the Nerd Tools plugin available from the Community Applications store on Unraid.

Installation

  1. Install the Unraid Nvidia Driver: Ensure your Unraid server is equipped with the Nvidia driver. This driver is essential for the script to function as it relies on nvidia-smi commands to manage GPU power states.
  2. Install bc (if using savings calculation): If you wish to utilize the power savings calculation feature of the script, install bc from the Nerd Pack plugin available in the Community Applications store on Unraid.
  3. Download the Script: Copy the script and configure the variables if needed.

Configuring the Script

Before using the script, you may want to adjust its settings to suit your Unraid server's specific power management needs and your electricity billing details. This can be done by editing the following variables at the beginning of the script:

  • show_saving: Set this to "yes" if you want the script to calculate and display the estimated electricity savings from reducing the GPUs' power consumption. Any other value will disable this feature.

  • hours_server_running: Enter the number of hours per day your server is running. This is used in calculating the potential electricity savings. If your server runs 24/7, you would set this to 24.

  • electricity_cost_KWH: Specify your electricity cost in your local currency per kilowatt-hour (KWh). For example, if your electricity cost is 28 pence per KWh, you would enter .28.

  • Currency: Set this to the symbol of your local currency. For example, for pounds sterling, you would set this to "£". This symbol is used when displaying the estimated savings.

Example Configuration

Here's how you might configure the script for a server that runs 24/7, with an electricity cost of 28 pence per KWh, and using pounds sterling as the currency:

show_saving="yes"
hours_server_running="24"
electricity_cost_KWH=".28"
Currency="£"

Usage Instructions

To effectively use this script on your Unraid server for managing Nvidia GPU power savings, follow the steps below to set it up as a user script. This process requires the User Scripts plugin, which can be installed from the Community Applications store on Unraid.

Setting Up the Script to Run Hourly

  1. Install the User Scripts Plugin: If not already installed, add the User Scripts plugin to your Unraid server via the Community Applications store. This plugin allows you to run custom scripts at specified intervals.

  2. Create the Hourly Power Saving Script:

    • Navigate to the User Scripts page on your Unraid dashboard.
    • Click on the "Add New Script" button.
    • Name your new script something descriptive, such as Nvidia PowerSave Hourly.
    • Paste the contents of this power management script into the script editor.
    • Save your changes.
  3. Schedule the Script:

    • Within the User Scripts interface, find your Nvidia PowerSave Hourly script.
    • Set the script to run Hourly. This ensures that your GPUs are checked and adjusted for power saving on a regular basis.

Running the Script at Array Start

To ensure that your GPUs are also set to their optimal power state right from the start of your Unraid server's array, you can create a second user script that runs at array startup:

  1. Create the Array Start Script:

    • Follow the same steps as above to add a new script, this time naming it Nvidia PowerSave Array Start or a similar descriptive name.
    • Paste the same script contents into the script editor.
    • Save your changes.
  2. Configure Script to Run at Array Start:

    • Go to the "Edit Script" interface for your Nvidia PowerSave Array Start script.
    • Set the script to run At First Array Start Only. This setting ensures that the power management script is executed as soon as your Unraid server is first started.

Notes

In this script, nvidia-smi is utilized for managing GPU power states, as opposed to nvidia-persistenced. This decision stems from observations in my tests, where enabling persistence mode led to crashes of the Unraid server when a GPU in this mode was allocated to a VM. So, nvidia-smi has been chosen to avoid possibility of a server crash when the gpu is passed through to a vm.

About

script to save power on Unraid server with Nvidia GPU


Languages

Language:Shell 100.0%