clCreateContext() question.

Hello everyone!

I am new to OpenCL programming so please don’t shoot if the question is a little bit silly! :slight_smile:
The question is about clCreateContext() function. This function takes as first argument a list of properties and its values. One of these properties is ‘CL_CONTEXT_PLATFORM’. As a third argument, this function takes a list of devices that will be used with this context. As a result, a programmer might accidentally pass a ‘platform A’ as the ‘CL_CONTEXT_PLATFORM’ property in the first argument and pass a list of devices from a ‘platform B’ in the third argument. Of course in such case the function will return an error. So, why ‘CL_CONTEXT_PLATFORM’ property exists? Shouldn’t the API internally figure out the platform ID from the device IDs? Is this an API design problem or I am missing something here?

Thanks for your time people! :slight_smile:

While platforms and devices are related, they do not necessarily have a unique relationship, e.g., an x86 or x86_64 CPU may be supported by the AMD and Intel platform regardless of the CPU vendor. And to make it more interesting IBM’s OpenCL Common Runtime is an abstract platform that unifies multiple vendor platforms into a single platform so you can create a context with CPU and GPU devices from different vendors.

The short answer seems to be CL_CONTEXT_PLATFORM provides more choices since one platform might be preferred over another platform for a given device.

We need to keep apart the physical device, i.e., the collections of transistors, from the device IDs, which is what is passed to clCreateContext(). While the same lump of transistors can be utilized by multiple platforms, each platform has its own device ID for that hardware.

At least I assume so, haven’t tested. Can’t remember the specification saying anything about this.

Ohhh OK! Now I get it!!! Thanks a lot guys! :slight_smile:

Cheers!