Shared Context for CPU and Intel® Xeon Phi™ Coprocessor

Intel® OpenCL™ implementation features Common Runtime, which enables you to interface with Intel® Xeon Phi™ coprocessor and CPU devices using a single context.

You can create a “shared” context with both devices. Commands, resource sharing and synchronization instructions on different devices should follow the OpenCL™ 1.2 specification requirements.

The following is an example, demonstrating a specific way to create a shared context by providing a list of devices explicitly:

cl_device_id devices[2] = {cpuDeviceId , acceleratorDeviceId};
cl_context shared_context = clCreateContext(prop, 2, devices, …);

Avoid using CL_DEVICE_TYPE_ALL. For example clCreateBuffer cost for the shared context is much higher than for the CPU-only context If you need a context with just CPU or Intel Xeon Phi device, use CL_DEVICE_TYPE_CPU or CL_DEVICE_TYPE_ACCELERATOR explicitly. In this case, the context you create is optimized for the target device.

NOTE: Shared context does not imply any “shared queue”. The OpenCL™ specification requires you to create a separate queue per device.

See Also

The OpenCL™ 1.2 Specification at https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf