Use GPU Acceleration for Graphical Applications
This guide explains how to enable GPU hardware acceleration for applications in a remote desktop (VNC) or local graphical environment to improve rendering performance. It is suitable for scenarios such as 3D design, scientific visualization, video processing, and CAD/CAM that require high-performance graphics processing.
Technical Architecture
VirtualGL provides GPU acceleration through two technical approaches:
| Rendering Path | Advantages | Disadvantages | Recommended Scenarios |
|---|---|---|---|
| GLX backend acceleration | Strong compatibility, supports most 3D applications | More complex configuration and higher system overhead | Traditional 3D applications and environments with high compatibility requirements |
| EGL backend acceleration | Simpler configuration, lower system overhead, better performance | Limited compatibility with some legacy 3D applications | Modern applications, containerized environments, and cloud platforms |
Prerequisites
- The required GPU driver has been installed.
Method 1: GLX Backend Accelerated Rendering
Configure the X Server
NVIDIA GPU configuration steps:
-
Generate the Xorg configuration:
sudo nvidia-xconfig --enable-all-gpus --separate-x-screens -
Query the GPU BusID:
lspci | grep NVIDIA
# Example output: 00:07.0 3D controller: NVIDIA Corporation GP104GL [Tesla P4] -
Edit the Xorg configuration:
sudo vi /etc/X11/xorg.confAdd
BusIDto the correspondingDevicesection:Section "Device"
Identifier "Device0"
Driver "nvidia"
BusID "PCI:0:7:0" # Adjust according to the actual BusID
EndSection -
Reboot the system:
sudo reboot
Install a Display Manager
Multiple display managers are supported, such as GDM, KDM, and LightDM. The following example installs LightDM on Ubuntu 18.04:
Ubuntu/Debian systems (LightDM):
# Install LightDM
sudo apt update
sudo apt install lightdm
# Set it as the default display manager
sudo dpkg-reconfigure lightdm
# Or enable it by command
sudo systemctl enable lightdm
# Restart the display service
sudo systemctl restart lightdm
Configure the VirtualGL Server
Run the configuration script:
sudo /opt/VirtualGL/bin/vglserver_config
Configuration options:
Please choose a configuration option:
1) Configure server for use with VirtualGL (GLX + EGL back ends)
2) Configure server for use with VirtualGL (EGL back end only)
X) Exit
Choose 1 (GLX + EGL)
Restrict 3D X server access to the vglusers group?
[Y/n] n
# Choose n: all users can access it; choose Y: only members of the vglusers group can access it
Restrict framebuffer device access to the vglusers group?
[Y/n] n
Disable the XTEST extension?
[Y/n] n # You must choose n, otherwise remote desktop operations are affected
Restart the display service:
sudo systemctl restart lightdm # or gdm
# or reboot the system
sudo reboot
Verify the Configuration
Check the X Server configuration:
# Check the display configuration
xdpyinfo -display :0
# Check the OpenGL configuration
/opt/VirtualGL/bin/glxinfo -display :0 -c
Expected results:
- The list of available visual effects should be displayed.
- No error messages should be shown.
- The GPU should be detected correctly.
Run a 3D Application
Run after connecting through VNC:
# Basic usage
vglrun ./my_3d_app
# Explicitly specify the display device (optional)
vglrun -d :0 ./my_3d_app
VNC session example:
# Run in a new terminal after connecting to VNC
vglrun glxgears # Test application
Method 2: EGL Backend Accelerated Rendering
Advantages and Limitations of EGL
Advantages:
- Lower system overhead
- Better performance
- Simpler configuration
Limitations:
- The application must support EGL. Some legacy applications may not be compatible.
Configure the EGL Backend
Run the configuration script:
sudo /opt/VirtualGL/bin/vglserver_config
Configuration options:
Choose option 2 (Configure server for use with VirtualGL (EGL back end only))
Restrict framebuffer device access to the vglusers group?
[Y/n] n # Choose n to allow all users to access it
Verify the EGL Configuration
# Check EGL support
/opt/VirtualGL/bin/eglinfo egl0
# Expected result: the EGL configuration list is displayed with no errors
Run a 3D Application in EGL Mode
Using environment variables:
# Method 1: use an environment variable
export VGL_DISPLAY=egl
vglrun ./my_3d_app
# Method 2: set it inline for a single command
VGL_DISPLAY=egl vglrun ./my_3d_app
Using command-line parameters:
# Use the -d parameter to specify the EGL device
vglrun -d egl0 ./my_3d_app
Multi-GPU Environment Configuration (To Be Verified)
GPU Detection and Selection
View available GPUs:
# NVIDIA
nvidia-smi -L
# AMD
rocm-smi --showproductname
# Generic method
lspci | grep -E "(VGA|3D)"
Multi-GPU Configuration for the GLX Backend
Different X Server configurations:
# Start an additional X Server. Make sure the port does not conflict with the VNC session.
Xorg :10 -ac -br -noreset -sharevts -logfile /var/log/Xorg.10.log -config /etc/X11/xorg.conf.gpu1
# Use a specific GPU
vglrun -d :10 ./app
Multi-GPU Configuration for the EGL Backend
Using device paths:
# Select by DRI device path
VGL_DISPLAY=egl vglrun -d /dev/dri/card0 ./app
VGL_DISPLAY=egl vglrun -d /dev/dri/card1 ./app
Using EGL device IDs:
# Select by EGL device ID
vglrun -d egl0 ./app # GPU0
vglrun -d egl1 ./app # GPU1
vglrun -d egl2 ./app # GPU2
Frequently Asked Questions
Q: Can one GPU card be used by multiple users or processes at the same time?
A: Yes. This can be achieved through software-level resource sharing or hardware-level partitioning and isolation through GPU virtualization such as MIG. Choose the appropriate approach based on job requirements and isolation needs.
Q: How can I prevent multiple users or processes from concentrating work on only a few GPUs, such as gpu0-10?
A: In FCP scenarios, GPU resource isolation is generally implemented by binding users to login nodes. In cluster planning, different login nodes and their GPUs are already assigned to specific users or groups. This mapping is configured and maintained centrally by the system administrator.