How to Choose Which GPU an Application Uses on a Multi-GPU Server
In this article
To direct a specific application to use a designated GPU in a multi-GPU server environment, you must configure environment variables or system-level display settings before launching the software. This approach ensures that compute-intensive tasks, such as machine learning training, rendering, or scientific simulations, are routed to the correct hardware instance, preventing resource contention and optimizing performance across available devices.
What You'll Need
- Administrative access to the server operating system (Linux or Windows)
- Installed and verified drivers for all GPUs present in the system
- Command-line interface (Terminal/PowerShell) or GUI tools appropriate for your OS
- The executable file or launch command for the target application
- Basic knowledge of GPU indexing (0, 1, 2, etc.)
Step-by-Step
- Identify Your GPU Indices: Before assigning tasks, you must know which physical card corresponds to which logical index. On Linux, open a terminal and run
nvidia-smi. Look at the top section of the output; each GPU is listed with a unique ID (e.g., GPU 0, GPU 1). On Windows, open the NVIDIA Control Panel, navigate to "System Information," and check the "PCI Slot" column to correlate physical positions with logical IDs. Note these indices down. - Determine Your Operating System Strategy: The method for binding applications differs significantly between Linux and Windows. Linux relies heavily on environment variables passed at runtime, while Windows often uses global display settings or specific API calls. Decide if you want this setting to apply only to one specific launch command or persistently for a group of applications.
- For Linux: Use the CUDA_VISIBLE_DEVICES Variable: If your application uses NVIDIA CUDA, the most robust method is to restrict visibility to a single GPU. Open your terminal and prefix your launch command with the variable. For example, to force an app to use only GPU 1, run:
CUDA_VISIBLE_DEVICES=1 ./your_application. This hides all other GPUs from the application's perspective, ensuring it cannot accidentally spawn processes on the wrong card. For multiple GPUs, use comma-separated values likeCUDA_VISIBLE_DEVICES=0,2. - For Linux: Set DISPLAY for X11 Applications: If the application uses OpenGL or Vulkan via X11 rather than CUDA, you may need to set the
DISPLAYvariable. First, identify which display number corresponds to which GPU by checkingnvidia-xconfigoutputs orxrandr. Then, launch the app withDISPLAY=:0.1 ./app_name, replacing:0.1with the specific display identifier linked to your target GPU. - For Windows: Configure NVIDIA Control Panel Settings: Launch the NVIDIA Control Panel as Administrator. Navigate to "Manage 3D Settings" under the Global Settings tab. While this applies globally, you can create profiles for specific executables. Select "Program Settings," choose your application from the list (or add it manually), and look for the "Preferred GPU" option. Change it from "Auto-select" to the specific GPU model or ID you wish to use. Click Apply to save.
- For Windows: Use Command Line Switches: Some professional applications support command-line arguments to specify device IDs. Check the documentation for your specific software. Common switches include
--gpu_id 1or-d 1. Run your application from PowerShell or Command Prompt with these flags appended to the end of the command string. - Verify the Assignment: After launching the application, verify that it is using the intended GPU. On Linux, run
nvidia-smiagain and look for the process name associated with the correct GPU ID. On Windows, open Task Manager, go to the Performance tab, select the specific GPU, and check the "Processes" tab to see if your application is listed there. If the process appears on the wrong GPU, stop the application and re-check your configuration steps.
Common Mistakes
A frequent error is assuming that GPU indices remain static after a reboot. While they usually do, driver updates or hardware changes can sometimes shift indices. Always verify nvidia-smi or the control panel immediately after major system changes. Another common mistake is neglecting to use administrative privileges when configuring global settings on Windows, resulting in saved settings not applying to system-wide services or background processes.
Tips
Create shell scripts or batch files for complex launches that include all necessary environment variables. This prevents typos and ensures consistency across different users or automated jobs. On Linux, consider adding the CUDA_VISIBLE_DEVICES export to your .bashrc file if you always work with a specific subset of GPUs, but be cautious as this affects all subsequent commands. Always keep your GPU drivers updated, as older versions may have bugs related to multi-GPU scheduling and memory management.
Troubleshooting
If the application still uses the wrong GPU, ensure that no other environment variables are overriding your settings. On Linux, check for conflicting LD_LIBRARY_PATH entries that might load incorrect driver libraries. On Windows, ensure that no third-party overlay software (like Discord or GeForce Experience) is intercepting the GPU selection. If the application fails to start entirely, it may require a specific driver version or lack support for the selected GPU architecture. Consult the application logs for specific error codes regarding device initialization.
Frequently Asked Questions
Can I switch GPUs while an application is running?
No. GPU assignment is determined at launch time. You must close the application, change the configuration, and restart it for the change to take effect.
Does this work for AMD GPUs?
Yes, but the methods differ. AMD uses ROCm on Linux, where you set HIP_VISIBLE_DEVICES. On Windows, you use the Radeon Software settings similar to NVIDIA’s control panel to assign preferred graphics processors.
Will forcing a specific GPU improve performance?
It improves efficiency by preventing resource contention. If one GPU is idle and another is maxed out, directing new tasks to the idle card balances the load. It does not inherently make the GPU faster, but it prevents bottlenecks caused by shared resources.
How do I reset GPU assignments to default?
On Linux, simply remove the environment variable prefixes from your launch commands. On Windows, revert the "Preferred GPU" setting in the NVIDIA Control Panel back to "Auto-select" or delete the custom profile for the application.
Is it safe to use multiple GPUs for a single application?
Yes, provided the application supports multi-GPU scaling (like CUDA-aware MPI or distributed training frameworks). However, improper configuration can lead to deadlocks or memory errors. Ensure the software explicitly supports parallel execution across devices.