Hey all, I didn’t see much in the way of syntax for __constant variable allocation in OpenCL in the guides from Nvidia.
When I call clCreateBuffer, do I have to give it the flag CL_MEM_READ_ONLY. It doesn’t seem to mind that I set it to CL_MEM_READ_WRITE for now, though I bet trying to write to constant cache in the kernel will screw something up.
Are there any gotchas or special things I need to remember to do on the host side? If I declare the arguement as __constant in the device kernel code, then am I good to go with using the constant cache variable so long as I don’t write to it?
Yes, that’s basically it. You have to keep in mind that the constant cache has a size limit of 64 KB, though. Since the __constant address space is inherently read-only, the compiler should complain if you try to write to it.
Unfortunately, __constant memory altogether is a bit buggy with NVidia’s implementation. Occasionally the compiler will emit wrong code, reads from constant memory simply return zero. As of the 260.x driver series they haven’t fixed the problem.