Programmatic GPU Selection

 

Programmatic GPU Selection

 

How Do I Programmatically Select The Discrete (NVidia or AMD) GPU (dGPU) on a Hybrid GPU system instead of the Integrated GPU (iGPU)?

Modern laptops and desktops often include both an integrated GPU (iGPU) and a discrete GPU (dGPU). These systems, called hybrid GPU setups, aim to balance energy efficiency with performance. Most OpenGL, OpenSceneGraph, osgEart, Vulkan and VulkanSceneGraph programs will want to force themselves to run on the higher-capability discrete GPU (dGPU) for maximum performance and full feature set.

What Is a Hybrid GPU System?

A hybrid GPU system uses two different GPUs: an integrated GPU and a discrete GPU. Integrated GPUs are built into the CPU and share system memory, making them energy-efficient. Discrete GPUs are separate components with their own dedicated memory and processing power, offering superior performance for graphics-intensive tasks.

A common example of this setup is NVIDIA’s Optimus system. Optimus dynamically switches between the iGPU and dGPU based on the application’s needs. It’s designed to run low-demand tasks, like web browsing, on the iGPU to save power and switch to the dGPU for tasks like gaming or video rendering.

Why Do Hybrid GPU Systems Exist?

Balancing Power and Performance

Integrated GPUs consume less power, making them ideal for everyday tasks on battery-powered devices. Discrete GPUs, while more powerful, draw significantly more power.

Common Scenarios Where iGPU is Preferred

Tasks like browsing, video playback, using office applications or even basic graphics (2d or 3d) may not need the high performance of a discrete GPU. Running these on the iGPU helps conserve battery life.

Advantages of dGPUs

Discrete GPUs excel at graphics-heavy tasks like gaming, 3D rendering, CAD software, and machine learning. They also support advanced features like ray tracing and dedicated VRAM for handling complex workloads.

Why Might a Program Need the Discrete GPU?

Some programs require the dGPU’s power to function effectively. For example: games, rendering tools, and machine learning libraries need the dGPU to avoid lag or poor performance. Some features, like advanced shaders or CUDA cores for parallel processing, are only available on the dGPU.

How to Control or Direct Which GPU is Used

Operating systems provide tools to control GPU preferences:

Windows: Open Graphics Settings, add the application, and specify the preferred GPU (iGPU or dGPU).

Linux: Use PRIME Profiles (for NVIDIA) or DRI_PRIME (for AMD) to switch GPUs.

Developers can also signal GPU preference directly in their code. For example:

For NVIDIA GPUs, add the following code snippet to your application:

extern “C” {
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
}

For AMD GPUs, use this snippet:

extern “C” {
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}

These can be combined as per the GitHub Gist below:

#ifdef _WIN32
// Use discrete GPU by default.
extern “C” {
   //
http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf

   __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
   //
http://developer.amd.com/community/blog/2015/10/02/amd-enduro-system-for-developers/
   __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
#endif

These exports are detected at runtime by the Hybrid GPU driver and inform it to use the discrete GPU for the application.

Here’s a GitHub Gist with comments:

https://gist.github.com/statico/6809850727c708f08458

External references:

NVIDIA Optimus Documentation

https://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf

AMD Guides

https://gpuopen.com/learn/amdpowerxpressrequesthighperformance/



Programmatic GPU Selection
Scroll to top

connect

Have a difficult problem that needs solving? Talk to us! Fill out the information below and we'll call you as soon as possible.

Diagram of satellite communications around the Earth
Skip to content