How to Set NVIDIA Power Limit on Ubuntu

Managing the power consumption of your NVIDIA GPU on Ubuntu can lead to improved efficiency, especially for tasks that don’t fully utilize the GPU’s capabilities. This guide will walk you through the process of checking and setting power limits for your NVIDIA GPU, ensuring that your device runs optimally without unnecessary power usage.

In this tutorial you will learn:

  • How to check your current NVIDIA GPU power limits.
  • How to set a new power limit for your NVIDIA GPU.
  • How to confirm the new settings.
  • How to make the NVIDIA power limit persistent across reboots.
How to Set NVIDIA Power Limit on Ubuntu
How to Set NVIDIA Power Limit on Ubuntu
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu or any other Linux distribution with NVIDIA GPU support
Software NVIDIA Drivers and nvidia-smi tool
Other Terminal access and basic knowledge of command line interface (CLI)
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Step-by-Step Guide to Setting NVIDIA Power Limits

  1. Check Your Current Power Limits: Begin by assessing the current power limits set for your NVIDIA GPU. This step is crucial for understanding your starting point.
    $ nvidia-smi -q -d POWER

    This command displays detailed power usage information of your NVIDIA GPU, including the current power limit, default power limit, and the minimum and maximum power limits allowed.

    Check Your Current Power Limits of your NVIDIA card
    Check Your Current Power Limits of your NVIDIA card
  2. Set New NVIDIA Power Limit: Adjust the power limit to a desired value, considering the GPU’s capabilities and your power efficiency goals.
    $ sudo nvidia-smi -pl 200

    This example sets the power limit to 200W. Ensure that the value you choose is within the minimum and maximum limits shown in the previous step.

    Set New NVIDIA Power Limit
    Set New NVIDIA Power Limit
  3. Confirm the Settings: Verify that the new power limit has been correctly applied to your NVIDIA GPU.
    $ nvidia-smi -q -d POWER

    Review the output to ensure that the “Current Power Limit” reflects the value you set in the previous step.

    Confirm the new NVIDIA power limit Settings
    Confirm the new NVIDIA power limit Settings
  4. Make NVIDIA Power Limit Persistent (Optional): If you wish for the power limit setting to persist across reboots, you can create a custom systemd service script.

    Despite following standard procedures to ensure NVIDIA power limit settings persist across system reboots, I encountered challenges. Initially, I attempted to activate persistence mode directly through the NVIDIA Management Interface (nvidia-smi) using the command sudo nvidia-smi -pm 1. This approach is often recommended as it’s supposed to make power management settings persistent without further user intervention. Unfortunately, this method did not succeed, leaving the power limit settings to revert upon system restart.

    In search of a solution, I turned to another common approach: modifying the systemd service script for NVIDIA persistence. This method involves using the command sudo systemctl edit nvidia-persistenced.service to modify the NVIDIA Persistence Daemon, aiming to ensure that the GPU settings, including the power limit, remain constant even after rebooting. However, this attempt also did not yield the desired outcome. The modifications to the systemd service script did not lead to persistent power limit settings, indicating that the changes were either not applied correctly or were overridden by some other system process.

    Faced with these setbacks, the solution was to create a custom systemd service script specifically for setting the NVIDIA GPU power limit. This approach allows for direct control over the power limit setting at system startup, ensuring persistence across reboots without relying on the built-in persistence options that failed to work as expected.

    $ sudo nano /etc/systemd/system/nvidia-power-limit.service

    Insert the following content into the file:

    [Unit]
    Description=Set NVIDIA GPU Power Limit
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/nvidia-smi -pl 200
    
    [Install]
    WantedBy=multi-user.target
    

    Enable the service to apply the power limit automatically at boot:

    $ sudo systemctl enable nvidia-power-limit.service

    This ensures your power limit setting is restored every time the system starts.

    Make NVIDIA Power Limit Persistent between reboots with systems service script
    Make NVIDIA Power Limit Persistent between reboots with systems service script

Conclusion

Setting a power limit on your NVIDIA GPU on Ubuntu can help manage power consumption efficiently. By following the steps outlined in this guide, you can ensure that your GPU operates within the desired power limits, potentially saving energy and reducing thermal output. Remember to consider your specific hardware and workload requirements when adjusting power limits.

Frequently Asked Questions (FAQs) about Setting NVIDIA Power Limit on Ubuntu

  1. What is the purpose of setting a power limit on NVIDIA GPUs?Setting a power limit on NVIDIA GPUs helps manage and reduce power consumption, leading to potentially lower electricity costs and decreased heat output, which can prolong the hardware’s lifespan and improve its efficiency, especially in thermally constrained environments.
  2. Can setting a power limit on my NVIDIA GPU affect its performance?Yes, setting a power limit can affect the GPU’s performance, especially if the limit is set below the GPU’s usual power consumption for high-performance tasks. It can lead to reduced performance but is beneficial for controlling energy use and thermal output.
  3. Is it possible to set different power limits for multiple NVIDIA GPUs in the same system?Yes, you can set different power limits for multiple NVIDIA GPUs by specifying the GPU’s unique identifier with the `nvidia-smi -i` option followed by the desired power limit setting for each GPU individually.
  4. How do I find the minimum and maximum power limit allowed for my NVIDIA GPU?You can find the minimum and maximum power limits allowed for your NVIDIA GPU by using the command `nvidia-smi -q -d POWER`, which provides detailed power-related information, including these limits.
  5. Do I need to reboot my system after setting a new power limit?No, you do not need to reboot your system after setting a new power limit. The change takes effect immediately but will not persist across reboots unless you create a systemd service or another persistence mechanism.
  6. Will the power limit setting persist across driver updates?Power limit settings may not persist across NVIDIA driver updates. It is advisable to check and reapply your preferred power limit settings after updating your drivers to ensure they remain in effect.
  7. Can I use this method to set power limits on non-NVIDIA GPUs?No, the method described using `nvidia-smi` is specific to NVIDIA GPUs. Other manufacturers’ GPUs will require different tools or methods to adjust power settings.
  8. What should I do if setting a power limit does not seem to affect power consumption?If setting a power limit does not affect power consumption, ensure you’re applying the setting correctly and that your GPU supports power management features. Additionally, consider consulting NVIDIA’s documentation or seeking support to ensure there are no underlying issues with your hardware or software configuration.
  9. Is there a way to automate the process of setting the power limit at system startup?Yes, creating a custom systemd service script, as outlined in the guide, is an effective way to automate setting the power limit at system startup. This ensures the power limit is applied consistently across reboots without manual intervention.


Comments and Discussions
Linux Forum