Search code examples
opencldata-transfer

Passing data from global memory to local memory in OpenCL kernel


Let's say I have the following kernel:

__kernel void classify_data_points( __global float* data,
                                    __local float* datasegment)
{
    int gid0 = get_global_id(0);
    int lid = get_local_id(0);
    dataSegment[lid] = data[gid];
}

As it is seen, I want to take data from global memory into local memory. Is the size of local memory important to do this action at one time? I mean, dataSegment array size is 64bytes. Then, by this line 'dataSegment[lid] = data[gid]', can I assume whole 64bytes memory space is filled by data taken from global memory?(There is enough data in global memory) Or for 512 bytes long local memory, could we say same thing?


Solution

  • In your example, the amount of memory copied depends on the workgroup size, not the size of datasegment. You cannot assume that 64 bytes of memory will be copied.

    If you want to perform a copy as a single action, look at the async_work_group_copy functions.