Programmatically Enabling the Discrete GPU with NVIDIA Optimus

Here's a quick little post to make something known that I just found in some research online. According to a document released by NVIDIA in July of 2012, there are 6 ways to enable the "High Performance Graphics Rendering" mode in Optimus:

This feature is enabled using the following set of methods, listed in order from highest to lowest precedence:

  1. Forced Rendering Mode
  2. Right-Click Context Menu
  3. Application Profile Settings
  4. Static Library Bindings
  5. Global Variable NvOptimusEnablement (new in Driver Release 302)
  6. Global Profile Settings

The first 3 are completely out of our hands, controlled by OEM's and the user. The fourth, "Static Library Bindings," simply involves linking to certain libraries that force the usage of high-performance hardware:

  • vcamp110.dll / vcamp110d.dll
  • nvapi.dll / nvapi64.dll
  • opencl.dll
  • nvcuda.dll / cudart*.*

It is the fifth, "Global Variable NvOptimusEnablement," however that caught my attention. Apparently, the Optimus driver searches any executable that needs it for a DLL-exported Win32 DWORD called NvOptimusEnablement. As in:

extern "C" {  
    _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;

That's it. That's all there is to it. Witholding any other intervention of the user (an explicit right-click or application profiles) your application should now force-enable the discrete GPU in a system using NVIDIA's Optimus driver.

Source: NVIDIA TB-05942-003v02