0
votes

I've been starting out with OpenCL, and I've been wanting to create a cl::Context with multiple devices. While looking into the OpenCL 1.2 C++ Wrapper Api Specifications, I found this constructor for cl::Context:

The constructor

cl::Context::Context(VECTOR_CLASS<Device>& devices, cl_context_properties * properties = NULL, void (CL_CALLBACK * pfn_notify)( const char * errorinfo, const void * private_info, ::size_t cb, void * user_data) = NULL, void * user_data = NULL, cl_int * err = NULL)

creates an OpenCL context.

devices is a pointer to a vector of unique devices returned by cl::Platform::getDevices. If more than one device is specified, a selection criteria may be applied to determine if the list of devices specified can be used together to create a context.

...

My questions are: What are the "criteria" applied by the OpenCL implementation? How should I guarantee that the list of devices I pass in are compatible? What devices are compatible (ie do they have to be the same device type or something?) And do they have to be from the same platform/vendor (it is kind of implied by "unique devices returned by cl::Platform::getDevices")?

The constructor would set the errcode to CL_INVALID_DEVICE if devices contains an invalid device.

1

1 Answers

1
votes

What are the "criteria" applied by the OpenCL implementation? How should I guarantee that the list of devices I pass in are compatible? What devices are compatible (ie do they have to be the same device type or something?)

The answers to all these questions are implementation-dependent. You have to guarantee that the list of devices is coming from a single Platform, but the implementation might apply some selection "criteria", if not all of the supported devices can work together within one context, which again is implementation-specific. You can use cl::Context::getInfo to see which devices are associated with the Context you created.

And do they have to be from the same platform/vendor (it is kind of implied by "unique devices returned by cl::Platform::getDevices")?

The documentation states:

devices is a pointer to a vector of unique devices returned by cl::Platform::getDevices

The vector here is returned from a specific platform, hence only one Platform can be used to create the context.

There is another constructor:

cl::Context::Context(cl_device_type type, ... )

creates an OpenCL context from a device type that identifies the specific devices to use. The constructor attempts to use the first platform that has a device of the specified type.

So also in this case, there is always a single Platform per Context. A platform basically is a specific OpenCL implementation by some vendor. In general, they do not interoperate with each other.