concept __global in category opencl

appears as: __global
OpenCL in Action: How to Accelerate Graphics and Computation

This is an excerpt from Manning's book OpenCL in Action: How to Accelerate Graphics and Computation.

Now we come to an important point: all pointers passed to a kernel must be preceded by an address space qualifier. This tells the device what address space the argument should be stored in. Section 4.5 discusses this topic in depth, but for now, keep in mind that there are four possible qualifiers: __global, __constant, __local, and __private. In listing 4.1, the function declaration states that the msg argument should be stored in the device’s global address space.

  • __global—The argument’s data will be placed in global memory
  • Every kernel argument in this chapter’s example code has been stored in global memory with the __global qualifier. In our earlier code examples, the types of the vector arguments are __global char16* and __global uchar16*. This __global qualifier can be used for all kernel arguments, not just pointers.

    In addition to arguments, __global can qualify pointer variables declared within a kernel. This is shown in the following code:

    __kernel void kernel_func(__global float *f) {
    
       __global uint *x = 5;
       f = (global float*)x;
    }

    Here, the cast from x to f is only possible because both pointers reference global memory. If *x was declared as __local, the cast would not be possible. Also, if x wasn’t a pointer, this code couldn’t compile. Inside a kernel, the __global qualifier can only be used with pointer variables.