I am looking at a piece of OpenCL code. Currently we do a typedef:
"#if __OPENCL_VERSION__ <= 120\n"
"#define " + dataName + "_type __constant\n"
"#else \n"
"#define " + dataName + "_type const __global\n"
Does const __global
work or should it just be __global
?
If it's a constant, it probably shouldn't be just '__global'. It is okay to use 'const __global' as this will give you good portability but will be stored in global memory. Graphics cards often have a separate address space and cache for constants which is very small relative to global memory, and some (usually old) graphics cards have no cache at all on global memory. If high latency of the constant buffer will hurt your application's performance, and the contant buffer size is small, say a few KB, then you may get better performance using '__constant'. I don't know if OpenCL is obliged to use the constant cache if you specify '__constant'. I suspect it can choose to use read-only global memory anyway or you may get errors when it tries to build the program if you try to allocate too much '__constant' memory, or if it being used by another application. Other devices, such as CPUs, also support OpenCL but I don't think they have special memory for constants.
Your code appears to suggest '__constant' is deprecated after OpenCL1.2 but this is not the case.