SOP - SetOptimusProfile demo application ------------------------------------------------------------------------------- Copyright (c) 2012, Daniel Cornel. Published on drivenbynostalgia.com. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------- NVIDIA Optimus is an energy-saving technology that allows automatic seamless switching between an integrated and a discrete high-performant GPU in mobile devices. Unfortunately, the switching decision is currently based* on a profile system in which application profiles have to be created either by NVIDIA (pre- defined profiles for popular applications such as video games) or by the user. * Informations regarding the switching system are sparse. According to the NVIDIA Optimus whitepaper (http://www.nvidia.com/object/LO_optimus_whitepapers.html), the discrete NVIDIA GPU is triggered by DX, DXVA and CUDA calls, but no OpenGL calls. From my experience, CUDA calls do not trigger the switching mechanism. For a developer on an Optimus system, this is rather annoying since an own application profile has to be createdfor each GPU-intensive application. Even more annoying, every application user with an Optimus system has to create a profile for the application, too, or else the application will use the integrated GPU, which might be inperformant or might not work at all because of missing hardware features. SOP.hpp is a simple workaround for developers based on NVIDIA's NvAPI that creates an application profile for the current application such that it is always started using the discrete GPU. If the profile already exists, the application is bound to the existing profile. Multiple applications can be gathered in one generic profile, thus keeping the profile system neat and tidy. The profile itself can also be edited in the NVIDIA Control Center. - #include "SOP.hpp" in your application - Call SOP_CheckProfile() at startup with the desired profile name to check if an Optimus profile of the specified name exists. If it does not, the user may be asked if it shall be created. - Call SOP_SetProfile() with the desired profile name and the name of the executable. In the demo application, the generic profile name "OpenGL Developer Profile" is used. Note: The switching depends on the filename, so all applications with the same name as the provided executable name will start with the discrete GPU. - If the application profile was created or updated (SOP_Profile() returns SOP_RESULT_CHANGE) the application has to be restarted automatically or by the user. - ? - Profit If you have to remove a profile, you can either do this manually in the NVIDIA Control Center or call the function SOP_RemoveProfile() from your application. Again, after changes have been made, the application has to be restarted for the changes to take effect, i.e. for the integrated GPU to kick in. Demo application usage: Syntax: SOP_Demo [-c | -s | -r] Options: no arguments Print device information for the current video card -c Check if the Optimus profile exists -s Set the Optimus profile and restart the application if necessary -r Remove the Optimus profile and restart the application if necessary