Description
The following table describes the list of built-in work-item functions that can be used to query the number of dimensions, the global and local work size specified to clEnqueueNDRangeKernel, and the global and local identifier of each work-item when this kernel is being executed on a device.
| Function | Description |
|---|---|
uint get_work_dim() |
Returns the number of dimensions in use. This is the value given to the work_dim argument specified in clEnqueueNDRangeKernel. |
size_t get_global_size(uint dimindx) |
Returns the number of global work-items specified for dimension identified by dimindx. This value is given by the global_work_size argument to clEnqueueNDRangeKernel. Valid values of dimindx are 0 to get_work_dim() - 1. For other values of dimindx, get_global_size() returns 1. |
size_t get_global_id(uint dimindx) |
Returns the unique global work-item ID value for dimension identified by dimindx. The global work-item ID specifies the work-item ID based on the number of global work-items specified to execute the kernel. Valid values of dimindx are 0 to get_work_dim() - 1. For other values of dimindx, get_global_id() returns 0. |
size_t get_local_size(uint dimindx) |
Returns the number of local work-items specified in dimension
identified by dimindx.
This value is at most the value given by the local_work_size
argument to clEnqueueNDRangeKernel if local_work_size is not
Valid values of dimindx are 0 to get_work_dim() - 1. For other values of dimindx, get_local_size() returns 1. |
size_t get_enqueued_local_size( uint dimindx) |
Returns the same value as that returned by get_local_size(dimindx) if the kernel is executed with a uniform work-group size. If the kernel is executed with a non-uniform work-group size, returns
the number of local work-items in each of the work-groups that make up
the uniform region of the global range in the dimension identified by
dimindx.
If the local_work_size argument to clEnqueueNDRangeKernel is not
Valid values of dimindx are 0 to get_work_dim() - 1. For other values of dimindx, get_enqueued_local_size() returns 1. Requires support for OpenCL 2.0 or newer. |
size_t get_local_id(uint dimindx) |
Returns the unique local work-item ID, i.e. a work-item within a specific work-group for dimension identified by dimindx. Valid values of dimindx are 0 to get_work_dim() - 1. For other values of dimindx, get_local_id() returns 0. |
size_t get_num_groups(uint dimindx) |
Returns the number of work-groups that will execute a kernel for dimension identified by dimindx. Valid values of dimindx are 0 to get_work_dim() - 1. For other values of dimindx, get_num_groups() returns 1. |
size_t get_group_id(uint dimindx) |
get_group_id returns the work-group ID which is a number from 0 .. get_num_groups(dimindx) - 1. Valid values of dimindx are 0 to get_work_dim() - 1. For other values, get_group_id() returns 0. |
size_t get_global_offset(uint dimindx) |
get_global_offset returns the offset values specified in global_work_offset argument to clEnqueueNDRangeKernel. Valid values of dimindx are 0 to get_work_dim() - 1. For other values, get_global_offset() returns 0. Requires support for OpenCL C 1.1 or newer. |
size_t get_global_linear_id() |
Returns the work-items 1-dimensional global ID. For 1D work-groups, it is computed as get_global_id(0) - get_global_offset(0). For 2D work-groups, it is computed as (get_global_id(1) - get_global_offset(1)) * get_global_size(0) + (get_global_id(0) - get_global_offset(0)). For 3D work-groups, it is computed as ((get_global_id(2) - get_global_offset(2)) * get_global_size(1) * get_global_size(0)) + ((get_global_id(1) - get_global_offset(1)) * get_global_size(0)) + (get_global_id(0) - get_global_offset(0)). Requires support for OpenCL 2.0 or newer. |
size_t get_local_linear_id() |
Returns the work-items 1-dimensional local ID. For 1D work-groups, it is the same value as get_local_id(0). For 2D work-groups, it is computed as get_local_id(1) * get_local_size(0) + get_local_id(0). For 3D work-groups, it is computed as (get_local_id(2) * get_local_size(1) * get_local_size(0)) + (get_local_id(1) * get_local_size(0)) + get_local_id(0). Requires support for OpenCL 2.0 or newer. |
The functionality described in the following table requires support for
the cl_khr_ extension macro; or for
OpenCL C 3.0 or newer and the __opencl_c_ feature.
|
The following table describes the list of built-in work-item functions that can be used to query the size of a sub-group, number of sub-groups per work-group, and identifier of the sub-group within a work-group and work-item within a sub-group when this kernel is being executed on a device.
| Function | Description |
|---|---|
uint get_sub_group_size() |
Returns the number of work-items in the sub-group. This value is no more than the maximum sub-group size and is implementation-defined based on a combination of the compiled kernel and the dispatch dimensions. This will be a constant value for the lifetime of the sub-group. |
uint get_max_sub_group_size() |
Returns the maximum size of a sub-group within the dispatch. This value will be invariant for a given set of dispatch dimensions and a kernel object compiled for a given device. |
uint get_num_sub_groups() |
Returns the number of sub-groups that the current work-group is divided into. This number will be constant for the duration of a work-group’s execution. If the kernel is executed with a non-uniform work-group size (i.e. the global_work_size values specified to clEnqueueNDRangeKernel are not evenly divisible by the local_work_size values for any dimension, calls to this built-in from some work-groups may return different values than calls to this built-in from other work-groups. |
uint get_enqueued_num_sub_groups() |
Returns the same value as that returned by get_num_sub_groups if the kernel is executed with a uniform work-group size. If the kernel is executed with a non-uniform work-group size, returns the number of sub-groups in each of the work-groups that make up the uniform region of the global range. |
uint get_sub_group_id() |
get_sub_group_id returns the sub-group ID which is a number from 0 .. get_num_sub_groups() - 1. For clEnqueueTask, this returns 0. |
uint get_sub_group_local_id() |
Returns the unique work-item ID within the current sub-group. The mapping from get_local_id(dimindx) to get_sub_group_local_id will be invariant for the lifetime of the work-group. |
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.