Description

The functionality described in this section requires support for OpenCL C 2.0 and the cl_khr_work_group_uniform_arithmetic extension macro.

The https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#table-builtin-work-group-logical table describes the OpenCL C programming language built-in functions that perform logical arithmetic operations across work items in a work-group. These functions must be encountered by all work items in a work-group executing the kernel, otherwise the behavior is undefined. For these functions, a non-zero predicate argument or return value is logically true and a zero predicate argument or return value is logically false.

Table 1. Built-in Work-group Logical Arithmetic Functions
Function Description
int work_group_reduce_logical_and(
  int predicate);
int work_group_reduce_logical_or(
  int predicate);
int work_group_reduce_logical_xor(
  int predicate);

Returns the logical and, or, or xor of predicate for all work items in the work-group.

int work_group_scan_inclusive_logical_and(
  int predicate);
int work_group_scan_inclusive_logical_or(
  int predicate);
int work_group_scan_inclusive_logical_xor(
  int predicate);

Returns the result of an inclusive scan operation, which is the logical and, or, or xor of predicate for all work items in the work-group with a work-group linear local ID less than or equal to this work item’s work-group linear local ID.

int work_group_scan_exclusive_logical_and(
  int predicate);
int work_group_scan_exclusive_logical_or(
  int predicate);
int work_group_scan_exclusive_logical_xor(
  int predicate);

Returns the result of an exclusive scan operation, which is the logical and, or, or xor of predicate for all work items in the work-group with a work-group linear local ID less than this work item’s work-group linear local ID.

If there is no work item in the work-group with a work-group linear local ID less than this work item’s work-group linear local ID then an identity value I is returned. For and, the identity value is true (non-zero). For or and xor, the identity value is false (zero).

The https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#table-builtin-work-group-bitwise-integer table describes the OpenCL C programming language built-in functions that perform bitwise integer operations across work items in a work-group. These functions must be encountered by all work items in a work-group executing the kernel, otherwise the behavior is undefined. For the functions below, the generic type name gentype may be one of the supported built-in scalar data types int, uint, long, and ulong.

Table 2. Built-in Work-group Bitwise Integer Functions
Function Description
gentype work_group_reduce_and(
  gentype value);
gentype work_group_reduce_or(
  gentype value);
gentype work_group_reduce_xor(
  gentype value);

Returns the bitwise and, or, or xor of value for all work items in the work-group.

gentype work_group_scan_inclusive_and(
  gentype value);
gentype work_group_scan_inclusive_or(
  gentype value);
gentype work_group_scan_inclusive_xor(
  gentype value);

Returns the result of an inclusive scan operation, which is the bitwise and, or, or xor of value for all work items in the work-group with a work-group linear local ID less than or equal to this work item’s work-group linear local ID.

gentype work_group_scan_exclusive_and(
  gentype value);
gentype work_group_scan_exclusive_or(
  gentype value);
gentype work_group_scan_exclusive_xor(
  gentype value);

Returns the result of an exclusive scan operation, which is the bitwise and, or, or xor of value for all work items in the work-group with a work-group linear local ID less than this work item’s work-group linear local ID.

If there is no work item in the work-group with a work-group linear local ID less than this work item’s work-group linear local ID then an identity value I is returned. For and, the identity value is ~0 (all bits set). For or and xor, the identity value is 0.

The https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#table-builtin-work-group-multiplicative table describes the OpenCL C programming language built-in functions that perform multiplicative operations across work items in a work-group. These functions must be encountered by all work items in a work-group executing the kernel, otherwise the behavior is undefined. For the functions below, the generic type name gentype may be one of the supported built-in scalar data types int, uint, long, ulong, float, double (if double precision is supported), or half (if half precision is supported).

Table 3. Built-in Work-group Multiplicative Functions
Function Description
gentype work_group_reduce_mul(
  gentype value);

Returns the multiplication of value for all work items in the work-group.

gentype work_group_scan_inclusive_mul(
  gentype value);

Returns the result of an inclusive scan operation which is the multiplication of value for all work items in the work-group with a work-group linear local ID less than or equal to this work item’s work-group linear local ID.

gentype work_group_scan_exclusive_mul(
  gentype value);

Returns the result of an exclusive scan operation which is the multiplication of value for all work items in the work-group with a work-group linear local ID less than this work item’s work-group linear local ID.

If there is no work item in the work-group with a work-group linear local ID less than this work item’s work-group linear local ID then the identity value 1 is returned.

See Also

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-2025 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0