Memory fences

OpenCL C specification provides for runtime barriers in a work item and across a single work group. Barriers may only synchronize threads in the same workgroup. There is no way to synchronize between different work groups. For synchronizing outside of the work group the kernel should complete its execution. There are two types of memory fences:

  • CLK_LOCAL_MEM_FENCE: This ensures correct ordering of operations on local memory. It is used as follows:
    barrier(CLK_LOCAL_MEM_FENCE);

    The barrier function will either flush any variables stored in local memory or queue a memory fence to ensure correct ordering of memory operations to local memory.

  • CLK_GLOBAL_MEM_FENCE: This ensures correct ordering of operations on global memory. It is used as ...

Get OpenCL Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.