constant address space name is used to describe
read-only variables that are accessible globally. They may
be declared in program scope or in the outermost kernel scope or inside
functions with a
extern storage class specifier. Such variables
can be accessed by all work-items or by different kernels during the program execution.
Each argument to a kernel that is a pointer to the
It is illegal to write to a variable in the constant address space and will result in a compilation error.
constant int a = 3; // int allocated in the constant address space
kernel void k1(global int *buf)
buf[a] = ...; // OK. All work items access element with index 3.
kernel void k2(global int *buf)
*buf = a; // OK. All work items store value 3.
a = 42; // Error. a is in constant memory.
Implementations are not required to aggregate these declarations into the fewest number of constant arguments. This behavior is implementation-defined.
Thus portable code must conservatively assume that each variable declared
inside a function or in program scope allocated in the
address space counts as a separate constant argument.
For more information, see the OpenCL C Specification
This page is extracted from the OpenCL C Specification. Fixes and changes should be made to the Specification, not directly.