title: What do OpenCL contexts mean? Why do they make sense?
body: <p>The OpenCL API involves creating an "execution context", with many API calls require both a context and a device ID.</p>
  
  <p>But what's the use in those? We create contexts using an array of devices. Isn't it a very artificial construct? I mean, if we would have, say, all devices sharing some common memory space as a pre-defined context, then I guess it makes some sense. But otherwise - why not just have device-specific OpenCL APIs ignore contexts altogether, while multi-device-related APIs happen at the platform level?</p>
  
  <p>Now, if you tell me "oh, but context have X or do Y which devices and platforms don't" - please explain why X or Y should not be at device-context or at platform-context. The <a href="https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateContext.html" rel="nofollow">clCreateContext reference page</a> (OpenCL 1.2) lists:</p>
  
  <ul>
  <li><em>command queues</em>: device-specific.</li>
  <li><em>memory</em>: could be multi-device, but since the choice of devices into the context is arbitrary, it doesn't seem like the right abstraction.</li>
  <li><em>program and kernel objects</em>: why is this not device-specific? (or maybe - device and user specific?)</li>
  <li>used for <em>"executing kernels on one or more devices specified in the context"</em>: not clear what's wrong with that being device-specific (or platform-scope if we care about synchornization more).</li>
  </ul>
  
  <p>PS - CUDA also has "contexts", but those are thread-specific and device-specific, and encapsulate policies such as "should this thread block when synchronizing?" or "should this thread yield after scheduling GPU work" etc.)</p>