Description

The following table describes built-in functions to synchronize the work-items in a work-group.

Table 1. Built-in Work-group Synchronization Functions
Function Description

void barrier(
cl_mem_fence_flags flags)

For OpenCL C 2.0 or newer, as an alias for barrier:

void work_group_barrier(
cl_mem_fence_flags flags)

void work_group_barrier(
cl_mem_fence_flags flags,
memory_scope scope)

For these functions, if any work-item in a work-group encounters a barrier, the barrier must be encountered by all work-items in the work-group before any are allowed to continue execution beyond the barrier.

If the barrier is inside a conditional statement, then all work-items in the work-group must enter the conditional if any work-item in the work-group enters the conditional statement and executes the barrier.

If the barrier is inside a loop, then all work-items in the work-group must execute the barrier on each iteration of the loop if any work-item executes the barrier on that iteration.

The barrier and work_group_barrier functions can specify which memory operations become visible to the appropriate memory scope identified by scope [1]. The flags argument specifies the memory address spaces. This is a bitfield and can be set to 0 or a combination of the following values OR’ed together. When these flags are OR’ed together the barrier acts as a combined barrier for all address spaces specified by the flags ordering memory accesses both within and across the specified address spaces. For barrier and the work_group_barrier variant that does not take a memory scope, the scope is memory_scope_work_group.

CLK_LOCAL_MEM_FENCE - ensure that all local memory accesses become visible to all work-items in the work-group. Note that the value of scope is ignored as the memory scope is always memory_scope_work_group.

CLK_GLOBAL_MEM_FENCE - ensure that all global memory accesses become visible to the appropriate memory scope as given by scope.

CLK_IMAGE_MEM_FENCE - ensure that all image memory accesses become visible to the appropriate scope given by scope. The value of scope must be memory_scope_work_group.

The values of flags and scope must be the same for all work-items in the work-group.

See Also

No cross-references are available

Document Notes

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.

Copyright 2014-2023 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0


1. Refer to the description and restrictions for memory_scope.