codingdir logo sitemap sitemap |

How to disable registered OpenCL platforms on Windows?

By : , Category : registry

As you mention, the OpenCL ICD loader gets the list of available OpenCL platforms from the Windows registry. To prevent an OpenCL platform from appearing to any OpenCL application running on your system, you just need to remove the corresponding value from one or both of these registry keys:

For 32-bit machines or 64-bit apps on a 64-bit machine: HKEY_LOCAL_MACHINESOFTWAREKhronosOpenCLVendors

For 32-bit apps on a 64-bit machine: HKEY_LOCAL_MACHINESOFTWAREWow6432NodeKhronosOpenCLVendors

The name of the registry value will be the full path to the .dll providing the OpenCL runtime implementation.

This is a fairly heavy-handed approach to solving the problem, in my opinion. Most OpenCL applications provide the user with a means to manually select/override the desired OpenCL platform (e.g. via a command-line argument, environment variable, or even if GUI if applicable).

ReLated :

It is hard to say without running the specific code on your machine but looking at the difference between the example C code you said was working and the cl.hpp might give us a clue. In particular, notice that the C example uses the following line to simply read a single platform ID:

cl_platform_id platform_id = NULL; 
cl_int ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);

Notice that is passes 1 as its first argument. This assumes that at least one OpenCL platform exists and requests that the first one found is placed in platform_id. Additionally, note that even though the return code is assigned to "ret" is it not used to actually check if an error is returned.

Now if we look at the implementation of the static method used to queue the set of platforms in cl.hpp, i.e. cl::Platform::get:

static cl_int get(
    VECTOR_CLASS<Platform>* platforms)
    cl_uint n = 0;
    cl_int err = ::clGetPlatformIDs(0, NULL, &n);
    if (err != CL_SUCCESS) {
        return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);

    cl_platform_id* ids = (cl_platform_id*) alloca(
        n * sizeof(cl_platform_id));
    err = ::clGetPlatformIDs(n, ids, NULL);
    if (err != CL_SUCCESS) {
        return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);

    platforms->assign(&ids[0], &ids[n]);
    return CL_SUCCESS;

we see that it first calls

::clGetPlatformIDs(0, NULL, &n);

notice that the first parameter is 0, which tells the OpenCL runtime to return the number of platforms in "n". If this is successful it then goes on to request the actual "n" platform IDs.

So the difference here is that the C version is not checking that there is at least one platform and simply assuming that one exists, while the cl.hpp variant is and as such maybe it is this call that is failing.

The most likely reason for all this is that the ICD is not correctly installed. You can see this thread for an example of how to fix this issue:

ERROR: clGetPlatformIDs -1001 when running OpenCL code (Linux)

I hope this helps.

1: On Windows, OpenCL.lib is a static wrapper around OpenCL.dll, which is the ICD loader, and exposes all of the available platforms. It is provided by Khronos and redistributed by the OpenCL platform vendors. So go ahead and link to it; it will work with whatever is installed (although if nothing is installed your application won't run because it can't find OpenCL.dll; this is solved other ways).

2: Yes. As long as the ICD loader is the latest, you can get at the newer API on newer platforms / devices. Just don't use new API on old devices; that will crash or worse.

AFAIK deprecated functions do not have to be implemented, hence code should check the OpenCL platform version number and avoid calling deprecated functions on that platform. See this earlier discussion: At present, calling deprecated OpenCL 1.1 functions on AMD or Intel platforms (OpenCL 1.2) still works, but there are no guarantees that this will remain true in the future or on other platforms. I guess that as soon as supporting those deprecated functions becomes too much hassle for the maintainers of an implementation, they'll be removed.

Admittedly, I'm naughty as I have just ignored the problem and continued to use OpenCL 1.1 functions. However, if you are starting a new project (and have the time) then rather wrap the deprecated functions in some sort of generic function that has paths for each version of OpenCL - faster to do it now than later in my opinion. There is a list of frameworks and libraries at Perhaps you will find that one of them solves this problem well enough. If not, and if you have enough time then you could build a framework that hides most of the OpenCL functions from your program. Then, as more functions get deprecated you will hopefully only need to change your framework, but not the programs that use it. At the moment, I don't know of any framework that does this for one in C++.

actually, I uninstalled the driver and realized that there was some conflicts.
I then installed the latest release and here we go, it's working fine now.
Thank you all for your help.


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © All Rights Reserved .