LinuxCommandLibrary

prime-run

Run application using dedicated graphics card

TLDR

Run a program using a dedicated Nvidia GPU

$ prime-run [command]
copy

Validate whether the Nvidia card is being used
$ prime-run glxinfo | grep "OpenGL renderer"
copy

SYNOPSIS

prime-run <command> [<arguments...>]

PARAMETERS

<command>
    The executable command or script to be run on the discrete NVIDIA GPU.

<arguments...>
    Optional arguments to be passed to the specified <command>.

DESCRIPTION

`prime-run` is a utility command used on Linux systems equipped with NVIDIA Optimus or similar hybrid graphics configurations. Its primary purpose is to launch applications using the discrete NVIDIA GPU, rather than the integrated graphics processor (iGPU) that the system typically defaults to for power efficiency. This allows users to leverage the more powerful dedicated GPU for demanding tasks like gaming, video editing, or scientific computing, while still benefiting from the iGPU's power savings for less intensive workloads. Essentially, `prime-run` acts as a convenient wrapper, setting the necessary environment variables (`__NV_PRIME_RENDER_OFFLOAD`, `__GLX_VENDOR_LIBRARY_NAME`, etc.) that instruct the graphics stack to use the NVIDIA GPU for the specified command.

CAVEATS

Requires NVIDIA PRIME setup: `prime-run` relies on a properly configured NVIDIA PRIME render offload setup, which involves NVIDIA drivers and a compatible Xorg/Wayland environment. It may not work out-of-the-box on all distributions without specific configuration.
Power Consumption: Running applications with the discrete GPU consumes significantly more power and generates more heat compared to using the integrated GPU, which can reduce battery life on laptops.
Application Compatibility: While generally effective, some older or specific applications might not fully utilize the discrete GPU or may require additional environment variables for optimal performance.
No Direct Options: `prime-run` itself does not have command-line options; it simply wraps the execution of another command.

HOW IT WORKS

When you execute a command with `prime-run`, it typically sets environment variables like `__NV_PRIME_RENDER_OFFLOAD=1` and `__GLX_VENDOR_LIBRARY_NAME=nvidia` (for OpenGL) or `__VK_LAYER_NV_optimus=NVIDIA_only` (for Vulkan) before launching the application. These variables signal to the NVIDIA driver and graphics stack that the specific application should utilize the discrete GPU for rendering. The output is then passed back to the integrated GPU for display.

VERIFYING GPU USAGE

To confirm that an application is running on the discrete GPU, you can monitor its usage using `nvidia-smi` in another terminal. Look for the process name and its associated GPU memory usage. For OpenGL applications, you can also run `glxinfo | grep -i "vendor\|renderer"` from within the `prime-run` context (e.g., `prime-run sh -c 'glxinfo | grep -i "vendor\|renderer"'`) to see if the NVIDIA renderer is listed.

HISTORY

`prime-run` emerged as part of the broader adoption and standardization of NVIDIA's PRIME render offload capabilities on Linux. It succeeded older, less officially supported solutions like `optirun` (from the Bumblebee project), which aimed to provide similar hybrid graphics functionality. The development of `prime-run` aligns with NVIDIA's efforts to integrate Optimus-like features more seamlessly into the Linux ecosystem, leveraging direct driver support rather than third-party wrappers. Its usage became prominent with desktop environments and display servers (Xorg/Wayland) better supporting GPU offloading.

SEE ALSO

optirun(1), nvidia-smi(1), glxinfo(1), vulkaninfo(1)

Copied to clipboard