Should I cache get_global_id(0)?


Should I cache get_global_id(0) to a private integer like that:

size_t idx = get_global_id(0)

or should I call get_global_id(0) several times?

I want to reduce the number of registers if it does mean high penalty on some (popular) platforms.

Choose the option that is easiest to read and maintain. It probably won’t make a difference in terms of performance. Compilers have optimizations such as Common Subexpression Elimination that will make both options effectively the same.