title: OpenCL: Difference between __constant memory and const __global memory
body: <p>I would like to understand what the difference is when I create a buffer with read-only property and use it with <code>__constant</code> address space qualifier in the kernel or use it with <code>const __global</code> address space qualifier.</p>
  <p>What I have already found those are not really answers for my question but they contain some useful information:</p>
  <ul>
  <li><p><a href="https://community.khronos.org/t/constant-vs-const-global" rel="nofollow noreferrer">https://community.khronos.org/t/constant-vs-const-global</a></p>
  </li>
  <li><p><a href="https://stackoverflow.com/questions/12153443/is-the-access-performance-of-constant-memory-as-same-as-global-memory-on-ope?rq=1">Is the access performance of __constant memory as same as __global memory on OpenCL</a></p>
  </li>
  <li><p><a href="https://stackoverflow.com/questions/1576862/using-constant-qualifer-in-opencl-kernels">Using __constant qualifer in OpenCL kernels</a></p>
  </li>
  </ul>
  <p>If I understand well the allocation in GPU's memory happens at clCreateBuffer function call. So what I do not understand is how the compiler decides the buffer is in the constant memory (which has a 64 KB limit) or in the global memory. (I know that in most of the cases the constant memory is a part of the global memory space.) If it depends on the address qualifier that means the 64 KB limit can be ignored using <code>const __global</code>.</p>
  <p>Is there any difference in performance between <code>__constant</code> and <code>const __global</code>? The __global memory may be cached so both of them is read-only and (may be) cached.
  (Source: 3.3 Memory Model/Global memory section and Figure 3.3;  <a href="http://www.khronos.org/registry/cl/specs/opencl-1.x-latest.pdf#page=24" rel="nofollow noreferrer">http://www.khronos.org/registry/cl/specs/opencl-1.x-latest.pdf#page=24</a>)</p>