How to locate the work item in OpenCL?
- Reading Notes of OpenCL Specification version 1.0.
Global ID: A global ID is used to uniquely identify a work-item and is derived from the number
of global work-items specified when executing a kernel. The global ID is a N-dimensional value
that starts at (0, 0, 0). See also Local ID.
Local ID: A local ID specifies a unique work-item ID within a given work-group that is
executing a kernel. The local ID is a N-dimensional value that starts at (0, 0, 0). See also
Global ID.
Work-item: One of a collection of parallel executions of a kernel invoked on a device by a
command. A work-item is executed by one or more processing elements as part of a work-group
executing on a compute unit. A work-item is distinguished from other executions within the
collection by its global ID and local ID.
a single work-item can be uniquely identified by its global ID or by a combination of its local ID and work-group ID.
Each work-item is identifiable in two ways; in terms of a global index, and in terms of a work-group index plus a
local index within a work group.\
下图显示这些id的计算:
uint get_work_dim(); Returns the number of dimensions in use.
size_t get_global_size(uint dimindx);
图中是 Gx * Sx = get_global_size(0); Gy * Sy = get_global_size(1); 一行or一列的总的items数目.size_t get_gloabl_id (uint dimindx);
例如上图中gx = get_global_id(0); gy = get_global_id(1); 一行or一列中的第几个.
size_t get_local_size(uint dimindx);
图中的 Sx and Sy. 表示一个work group中一行的items数目or 一列的items数目.
size_t get_local_id (uint dimindx);
例如上图中sx = get_local_id(0); sx = get_local_id(1); 表示某一个work group中一行or一列中的第几个.
size_t get_num_groups(uint dimindx);
图中的 Gx or Gy. 表示每行or每列有多少个work group.
size_t get_group_id(uint dimindx);
图中的wx or wy. 表示一行or一列中的第几个work group.
这些build-in function是足够计算几种id的转化了.
这两个值可以通过函数取得: size_t get_global_size(uint dimindx); valid values of dimindx are 0 to get_work_dim() - 1;
local_work_size can also be a NULL value in which case the OpenCL implementation will
global_work_size: points to an array of work_dim unsigned values that describe the number of
global work-items in work_dim dimensions that will execute the kernel function. The total
number of global work-items is computed as global_work_size[0] * ... * global_work_size[work_dim - 1].
我理解在上图, work_dim 就是2指二维, global_work_size[0] = Gx, global_work_size[1] = Gy.这两个值可以通过函数取得: size_t get_global_size(uint dimindx); valid values of dimindx are 0 to get_work_dim() - 1;
local_work_size points to an array of work_dim unsigned values that describe the number of
work-items that make up a work-group (also referred to as the size of the work-group) that will
execute the kernel specified by kernel. The total number of work-items in a work-group is
computed as local_work_size[0] * ... * local_work_size[work_dim - 1].
我理解在上图, work_dim 就是2指二维, local_work_size[0] = Sx, local_work_size[1] = Sy.
这两个值可以通过函数取得: size_t get_local_size(uint dimindx); valid values of dimindx are 0 to get_work_dim() - 1;
local_work_size can also be a NULL value in which case the OpenCL implementation will
determine how to be break the global work-items into appropriate work-group instances.
If local_work_size is specified, the values specified in global_work_size[0], … global_work_size[work_dim - 1]
must be evenly divisible by the corresponding values specified in local_work_size[0], … local_work_size[work_dim – 1].
这个就很容易出错了, 例如一个image是300 * 300, 我就不能设置local size为 8 * 8.
没有评论:
发表评论