concept local memory in category opencl

This is an excerpt from Manning's book OpenCL in Action: How to Accelerate Graphics and Computation.
If you transfer data to a kernel using a memory object, you can’t set the kernel argument’s specifier to __local. If you attempt this, you’ll receive a runtime error whose code is –50: CL_INVALID_ARG_VALUE. As it turns out, the host can’t directly access a device’s local memory. That is, a host application can neither read nor write data in local memory space.
But a host application can tell the device to allocate local memory for a kernel argument. To configure this in code, set the last argument of clSetKernelArg to NULL. For example, the following code, executed by the host, configures a local argument to occupy space sufficient to hold 16 floats:
__kernel void test(__global int4 *in_data, __global int4 *out_data) { __local int4 local_data; int id = get_local_id(0); local_data = in_data[id]; ...process data in local memory... out_data[id] = local_data; }
Chapter 4 discussed the OpenCL device model, which defines address spaces within a device: global memory, constant memory, local memory, and private memory. Work-items can access local memory faster than they can access global or constant memory, so we’d like to process local data whenever possible.
Each block of local memory is specific to the work-items in a work-group. A MapReduce data set is much too large to be processed by a single work-group, so any MapReduce implementation will have to combine the results of multiple work-groups in global memory. Figure 11.3 shows one method of implementing mapping and reduction on an OpenCL-compliant device. It depicts two work-groups, each with two work-items.
The MapReduce implementation method presented in this figure splits the reduction stage into two substages: local reduction and global reduction. Local reduction, like the mapping stage, operates on data in local memory. Global reduction receives the results of the local reduction stages and produces a result to be sent back to the host.