OpenCL doesn't detect the platforms from Windows Service Environment

Hello, i have some problems with calling the OpenCL functions from windows service environment. I made a small test application which just do

  cl_uint numPlatforms = 0;
	cl_platform_id *the_platforms;
	cl_uint nDevices  =0;
	char Version[256];

	cl_int tN = clGetPlatformIDs(0,NULL,&numPlatforms);
	
		platforms = (cl_platform_id *)malloc(numPlatforms*sizeof(cl_platform_id));
	tN = clGetPlatformIDs(numPlatforms, platforms, NULL);
	
	int i =0;
	for (i = 0; i < numPlatforms; i++) 
	{
	
		cl_int status = clGetPlatformInfo(platform[i], CL_PLATFORM_VERSION, sizeof(Version), Version, NULL);
		if (status != CL_SUCCESS)
			strcpy(pVersion,"failed");
		logTo(Version); 
		tN = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &nDevices);
	}

The problem is, if i call this code from a service, on my and other laptops it seems to return only the integrated Intel HD Graphics platform, and the

clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &nDevices);

fails for this platform. On my laptop i have also the NVIDIA 610M. If i run the code that i posted from the regular application the

clGetPlatformIDs(0,NULL,&numPlatforms);

returns the correct number of platforms which is two. So my question is, does the OpenCL work from a service environment? If it does, whats the problem with the platform detection and how i can fix it?

P.S I’m using the MinGW environment for windows with the AMD APP SDK 2.9 x64, and the library i’m linking against is ‘x86/libOpenCL.a’ which should link against khronos OpenCL.dll

This is a problem with Windows that cannot be solved. Windows only allows the user that is logged in to access the GPUs, hence services cannot access any GPUs. This has also been noted in the folding@home forums at Folding Forum - Login and System Level Process Questions - Folding Forum. Unfortunately you will have to find a way to work without using a service.

For some reason i’m getting the error Post denied. New posts are limited by number of URLs it may contain and checked if it doesn't contain forbidden words. when i try to reply you.

I looked up in the AMD APP SDK 2.5, and in the release notes there, there is this sentence:

OpenCL can now be used by a Windows service

So i thought it’s gonna work from service.

Today i tried to run the service on the PC and the service has detected the correct platform (The system was windows 7 x64) and has detected the GPU after the call to the

clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &nDevices);

the Gpu was Radeon hd 7900. Then i also done the test on the laptop with amd Radeon 6400M. And again the serivce detected the correct platform, and detected the GPU.

hence services cannot access any GPUs

Ffrom the technical point, as i’m aware a bit of it, i think that opencl communicates with display miniport driver using some binary protocol to execute things. It is possible to access the the specific minipot driver from any session, using the winapi, to open the handle and exchange the data using the protocol.
So if OpenCL doesn’t work from Service, why is it working on some platforms? I have checked your links, but there is a little technical info, please see the link, about AMD APP SDK 2.5 release notes.

Also you have some time and just curious about this issue, try the code i posted, or if you want i can attach the full project with the service structure, so you can see that opencl calls is working from the service. (At least on the GPU’s i posted before). Please reply, and i will attach the project, if you want to.

Thanks for pointing out that AMD GPUs can be used from a service. I should probably rephrase my statement to say that services cannot access the graphics drivers, rather than making the blanket statement that they can’t access the GPUs. Please do post the project for the service version of your program. I don’t have access to any AMD GPUs anymore so I can’t test your code when it should work as a service, but I would like to explore the limitations of Nvidia GPUs.

I don’t know the specifics about how the driver’s work but here’s what I do know. Windows Vista and later have something called the Windows Display Driver Model (WDDM) that is the architecture used for GPU drivers. In Nvidia’s GPUs, OpenCL/CUDA and graphics API commands go through this graphics driver model. There is actually a separate non-WDDM driver for the Nvidia Tesla GPUs so that they can be used without extra monitors attached and without long-running kernels causing timeouts, as is the case for graphics drivers.

In AMD’s case, I guess they invested the effort to make OpenCL commands follow a different path, instead of going through the WDDM architecture. If Nvidia wanted to, they could probably to the same but it probably isn’t worthwhile for them since they have the profitable Tesla GPUs that they would prefer all of us to buy.

I can’t upload and attach the rar here for some reason, so there is the link

This one is for gcc mingw environment, to compile it use:

gcc -Wall cl.c -LCL/lib -lOpenCL -o test -g

To install use, from the command prompt:

sc create "Name" binPath= C:\jane\path_to_exe	est.exe

Then you can start it from the task manager, make sure the task manager is ran from the admin. There is a

Sleep

in the code, you can remove it if you want, i put it in there, so i can have some time to attach the gdb to the process with (attach pid) command.

My cursory understanding is that it’s up to the vendor’s driver and how it’s implemented. From what I’m reading above, AMD’s driver support it. I think NVIDIA Tesla cards run in the non-graphics mode can be used from services too.

I Updated, the link with the project archive

      • Updated - - -

I don’t have any tesla cards to test on, so please if you come across one and wanna clear this issue, try the test service application.

Hello! It’s been a while, is there any news? I still didn’t find any cards to test on, but i would really love to solve this problem somehow.

Hi,

I tried experimenting with different user accounts to see if I could give the service permission to access the video drivers, but without success. Regarding Tesla cards, I’m not that rich :slight_smile:

As you can read here Windows Session 0 Isolation Impact On GPU As Service | PDF | User Interface | Graphics Processing Unit and here Application Compatibility: Session 0 Isolation | Microsoft Learn this is a “security feature” meant to protect us from evil programs (and make life difficult at the same time). Sorry, but there’s no easy solution. Basically, the service has to start another application that runs in the user’s session and actually handles the GPU code and communicate with that app, e.g. through remote procedure calls.

I know writing an extra layer sucks, but if you can’t restrict your work to AMD GPUs then you will have to put in this effort.

Windows 7 does not allow me to run the service in Windows XP compatibility mode either, so it doesn’t look like you can go back to the old days.

Good luck.