Collectives

The collective functions perform communications that involve all work-items in a sub-group, providing several common communication patterns, such as:

The plus, minimum, and maximum functors in the cl::sycl namespace correspond to the collective operations supported by OpenCL 2.0. Supporting other operations (for example, minus and multiplies) and user-defined functors may be of interest in the future.

Member function Description
template <typename T>
T broadcast(T x, id<1> local_id) const

Broadcasts the value of x from the work-item with the specified id to all work-items within the sub-group. The value of local_id must be the same for all work-items in the sub-group.

template <typename T, class BinaryOp>
T reduce(T x, BinaryOp binary_op) const

Combines the values of x from all work-items in the sub-group using the specified operator, which must be one of: plus, minimum, or maximum.

template <typename T, class BinaryOp>
T reduce(T x, T init, BinaryOp binary_op) const

Combines the values of x from all work-items in the sub-group using an initial value of init and the specified operator, which must be one of: plus, minimum or maximum.

template <typename T, class BinaryOp>
T exclusive_scan(T x, BinaryOp binary_op) const

Performs an exclusive scan over the values of x from all work-items in the sub-group using the specified operator, which must be one of: plus, minimum or maximum.

The value returned on work-item i is the exclusive scan of the first i work-items in the sub-group. The initial value is the identity value of the operator.

template <typename T, class BinaryOp>
T exclusive_scan(T x, T init, BinaryOp binary_op) const

Performs an exclusive scan over the values of x from all work-items in the sub-group using the specified operator, which must be one of: plus, minimum or maximum.

The value returned on work-item i is the exclusive scan of the first i work-items in the sub-group. The initial value is specified by init.

template <typename T, class BinaryOp>
T inclusive_scan(T x, BinaryOp binary_op) const

Performs an inclusive scan over the values of x from all work-items in the sub-group using the specified operator, which must be one of: plus, minimum or maximum.

The value returned on work-item i is the inclusive scan of the first i work-items in the sub-group.

template <typename T, class BinaryOp>
T inclusive_scan(T x, BinaryOp binary_op, T init) const

Performs an inclusive scan over the values of x from all work-items in the sub-group using the specified operator, which must be one of: plus, minimum or maximum.

The value returned on work-item i is the inclusive scan of the initial value init and the first i work-items in the sub-group.