CUDA on notebook

Hi,
i have a notebook with 2 graphic cards, Intel and Nvidia.
My software uses CUDA for some steps, but i found some troubles.

In Nvidia Control Panel i can set preferred card(Automatic, Nvidia or Intel).
If selected Automatic or Intel, my CUDA program dosn’t work, calls like “cudaGetDeviceProperties” fails or “cudaGetDeviceCount” return only 1 device(wrong one).

So, how can i PRETENT to use the NVIDIA card?
(On notebook there is an NVIDIA application that show programs using CUDA, my one dosn’t appear in that state)

Thanks.

https://devtalk.nvidia.com/default/topic/806887/cuda-programming-and-performance/programmatically-forcing-the-nvidia-gpu-over-integrated-graphics/

Actually i used

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

and is linked “cudart_static.lib”(it’s necessary for linking) and still not working, i am checking a compatibile GPU is present with:

bool ElaborazioneDati::IsGpuAvailable()
{
	cuInit(0);
	_sleep(500);

	int devicesCount;
	cudaGetDeviceCount(&devicesCount);
	for (int deviceIndex = 0; deviceIndex < devicesCount; ++deviceIndex)
	{
		cudaDeviceProp deviceProperties;
		cudaGetDeviceProperties(&deviceProperties, deviceIndex);
		if (deviceProperties.major >= 2	&& deviceProperties.minor >= 0)
		{
			cudaSetDevice(deviceIndex);
			return true;
		}
	}
	return false;
}

I get false from this function.

sorry, i have no idea how it should be implemented. but if you can provide full compilable source code, i will at least try it here (i7-4770 + gf560, win7, cuda 7.5)

try this piece of code posted above, call it and check if return true or false on your machine.
Change preferred card too(and restart) if you have a notebook.

Thanks.

“cudaGetDeviceCount” return only 1

Right, you have only one CUDA device (nVidia), Intel card is not CUDA aware

Yes, but this happens onyl sometimes(this 1 can be INTEL too).
I investigated and this is what i found:
cudaInit(0) return “CUDA_ERROR_UNKNOWN”, from here there is no chance to make CUDA work in this instance, but wakeup CUDA.
I need start a new instance of same software to make it work.