# How can I set my application to run on the High performance GPU by default?

Nowadays a good deal of laptops come with 2 GPUs - a high-performance one and a power-saving one (less powerful). Most of the application, which I use on my laptop run with my integrated(power-saving) GPU, but still some of them are set to open with the high-performance card. I am trying to config the app which I am building to run on the high performance GPU by default, but I can't find any information about the topic anywhere. I hope that someone can shed a bit of light onto this. I will distribute my application with an NSIS installer and I guess that I'll have to add the path of my application to a list of applications for NVidia/ATI cards. The application is programmed in C#. Also, does anyone know how things stand with desktop PCs? What happens if a PC has 2 GPUs and I have to choose the more powerful one?

Milcho

NVIDIA have a document here outlining some strategies that may be helpful for you: http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf - unfortunately, the one I would otherwise suggest - the NvOptimusEnablement export - is only documented for C++; it may be possible to also do this with C# but someone who actually knows would have to chime in with the info.

I'm not aware of anything similar for AMD.

So unfortunately it looks as though there is no vendor-agnostic way of doing this (even enumerating display devices would leave you at the mercy of users forcing settings through their driver control panels, which users have an unfortunate tendency to do in order to max out games that don't come with fully configurable graphics settings). In the absense of such you may have to rely on a readme and hope that people actually read it!

• +1: I didn't know this Optimus NvOptimusEnablement trick, but I should have. Sounds like it's a recent thing (driver 302.x+) Thank you. – Sean Middleditch Jul 3 '13 at 21:35
• stackoverflow.com/questions/17458803/… For anyone else curious about AMD equivalents, I asked this (on SO since not game-specific). – Sean Middleditch Jul 3 '13 at 21:59
• You can call C++ functions from C# using p/invoke, as a last resort. – BlueRaja - Danny Pflughoeft Jul 3 '13 at 22:03
• @BlueRaja-DannyPflughoeft - It's not a C++ function; it's an exported global variable. – Maximus Minimus Jul 4 '13 at 0:03

In general, you can't.

The dual-GPU driver hides the two GPUs behind a single interface, so solutions like Nathan Reed's typically don't work in most common high-speed/low-power dual-GPU setups.

The GPU selection must be handled by the driver in some way. With NVIDIA Optimus, you usually update the Optimus profiles to add the application to the list of applications that use the discrete GPU, generally by right-clicking the EXE and clicking on Properties. You can also use some very-specific-to-Optimus calls. as per mh01's answer. With AMD setups, this is totally different.

On yet other systems, there is a hardware switch or an OS flag to decide which GPU is active. Again, the application has no control over which GPU is used.

This is something I'm really hoping is "fixed" in a future DirectX update. Ideally both GPUs would be enumerated like Nathan suggested and then there would be hints to indicate which of them is meant for high-speed or low-power, so an application can intelligently choose the right one or even switch which device it uses based on whatever factors (say, letting a web browser choose depending on WebGL load).

• Ahh, interesting. I haven't used one of these dual-GPU systems so I didn't know the driver pretends they're the same. You'd think the driver could monitor the level of GPU usage for a given app and switch it to the high-perf one if necessary. – Nathan Reed Jul 3 '13 at 21:26
• It can't. The hardware has different capabilities. Imagine if you got switched from a GPU with a max texture size of 2048 to one with a max of 1024, or some other characteristic - your whole app would break. If if going to a more capable GPU in everyway, buffers would need migration (taking time and causing an unwanted frame hitch) and shaders would need recompilaton. The app needs to be in charge of this process and opt in or opt out of any switch. The APIs for it just aren't really fleshed out yet, unfortunately. – Sean Middleditch Jul 3 '13 at 21:30
• This is complicated by the fact that users often want to override the GPU switching on their laptop, perhaps to save battery. This is one reason I prefer delegating the GPU-switching to the OS, because it also knows the power-state of the laptop. – Fake Name Jul 4 '13 at 6:20

You should be able to enumerate the GPUs on the system and pick which one to use when your application starts up. You didn't mention which API you're using, but for instance in D3D11 you'd use IDXGIFactory::EnumAdapters to get the list of GPUs and pass the one you want to D3D11CreateDevice.

DXGI can give you some limited information about the GPU, such as a description string, vendor ID, and device ID. I suppose you can use this information to tell which GPU is the high-performance one, but you'd have to build some kind of database of GPUs, or try to use some heuristics to guess. Or you could let the user pick which GPU to use on startup.