OpenCL:WorkItem
lastmod 2018-08-17created 2018-01-023 edits
Opencl execution model
Opencl-execution-model.JPG
- SIMT
- SIMT stands for SINGLE INSTRUCTION MULTIPLE THREAD, and it shows how instructions are executed on the host. As the name suggests, the same code is executed in parallel on different threads, and each thread executes the code with different data.
- Work-item
- Work-items mean the same thing as CUDA threads; they are the smallest unit of execution entity. Every time a kernel is launched, many work-items (the number is set by the programmer) are launched, and each executes the same code. Each work-item has an ID accessible in the kernel, through which work-items can distinguish which data they process.
- Work-group
- Work-groups exist so that work-items can communicate and cooperate with each other. They show how work-items are organized (as an N-dimensional grid, which can be 1, 2, or 3 dimensions). Work-groups are the same as CUDA thread blocks. Like work-items, work-groups also have a unique ID that can be referenced in the kernel.
- ND-Range
- ND-Range is the next level of organization. It defines how work-groups are organized (likewise, as an N-dimensional grid of work-groups, with 1, 2, or 3 dimensions);
Work-Item Built-In Functions
- get_work_dim(): Number of dimensions in use
- get_global_size(): Number of global work items
- get_global_id(): Global work item ID value
- get_local_size(): Number of local work items
- get_local_id(): Local work item ID
- get_num_groups(): Number of work groups
- get_group_id(): Work group ID
Kernels Indexing
| CUDA | OpenCL |
| gridDim | get_num_groups() |
| blockDim | get_local_size() |
| blockIdx | get_group_id() |
| threadIdx | get_local_id() |
| blockIdx * blockDim + threadIdx | get_global_id() |
| gridDim * blockDim | get_global_size() |