Compiled CUDA samples use wrong GPU by default

I freshly installed Windows 8, Visual Studio 2012 and CUDA 5.5 on my laptop. I tried running some of the CUDA samples using the CUDA samples browser and all samples having SM <= 3.0 work since I have a Geforce GT 650M.

Now for the weird part… The samples compile fine but on execution they throw the following exception: “CUDA Runtime API error 46: all CUDA-capable devices are busy or unavailable.”. This follows from the line: “checkCudaErrors(cudaMallocArray(&array, &desc, iw, ih));”. The same samples work fine when executing the compiled sample binaries from the CUDA samples browser.

For example this behaviour is shown by compiling and executing the boxFilter and SobelFilter samples, but not on the convolutionSeparable sample.

Does anyone have an idea on what the problem is or where to start looking?

The utility programs “bandwidthTest” and “deviceQuery” do execute successfully after compilation.

OK, after some more debugging I found the source of the problem. It somehow decides to use the Intel GPU for running the samples. Does anyone know how to explicitly program that the NVIDIA GPU is used if it is available?

I know the user is able to right-click the executable and choose to run it on the NVIDIA GPU, but I think this shouldn’t be necessary. Does anyone know?

to affect all applications:
open nVidia control panel
in the Global Settings tab switchPreferred GPU from Automatic to NVIDA High Performance Processor

The default choice of GPU for a program may may also depend on whether the sample app links to any OpenGL API libraries or not.