Enqueues a command to execute a kernel on a device.
cl_int clEnqueueNDRangeKernel(cl_command_queue command_queue,
cl_kernel kernel,
cl_uint work_dim,
const size_t *global_work_offset,
const size_t *global_work_size,
const size_t *local_work_size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
cl_event *event)command_queue-
A valid host command-queue. The kernel will be queued for execution on the device associated with
command_queue. kernel-
A valid kernel object. The OpenCL context associated with
kernelandcommand_queuemust be the same. work_dim-
The number of dimensions used to specify the global work-items and work-items in the work-group.
work_dimmust be greater than zero and less than or equal toCL_DEVICE_MAX_WORK_ITEM_DIMENSIONS. Ifglobal_work_sizeis NULL, or the value in any passed dimension is 0 then the kernel command will trivially succeed after its event dependencies are satisfied and subsequently update its completion event. The behavior in this situation is similar to that of an enqueued marker, except that unlike a marker, an enqueued kernel with no events passed toevent_wait_listmay run at any time. global_work_offset-
global_work_offsetcan be used to specify an array ofwork_dimunsigned values that describe the offset used to calculate the global ID of a work-item. Ifglobal_work_offsetis NULL, the global IDs start at offset (0, 0, … 0). global_work_size-
Points to an array of
work_dimunsigned values that describe the number of global work-items inwork_dimdimensions that will execute the kernel function. The total number of global work-items is computed asglobal_work_size[0] …global_work_size[work_dim- 1]. local_work_size-
Points to an array of
work_dimunsigned 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 bykernel. The total number of work-items in a work-group is computed aslocal_work_size[0] *… *local_work_size[work_dim- 1]. The total number of work-items in the work-group must be less than or equal to theCL_KERNEL_WORK_GROUP_SIZEvalue specified in table of OpenCL Device Queries forclGetDeviceInfoand the number of work-items specified inlocal_work_size[0],…local_work_size[work_dim- 1] must be less than or equal to the corresponding values specified byCL_DEVICE_MAX_WORK_ITEM_SIZES[0],….CL_DEVICE_MAX_WORK_ITEM_SIZES[work_dim- 1]. The explicitly specifiedlocal_work_sizewill be used to determine how to break the global work-items specified byglobal_work_sizeinto appropriate work-group instances.Enabling non-uniform work-groups requires a kernel to be compiled with the -cl-std=CL2.0 flag and without the -cl-uniform-work-group-size flag. If the program was created using clLinkProgram and any of the linked programs were compiled in a way that only supports uniform work-group sizes, the linked program only supports uniform work group sizes. If local_work_size is specified and the OpenCL kernel is compiled without non-uniform work- groups enabled, 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].
If non-uniform work-groups are enabled for the kernel, any single dimension for which the global size is not divisible by the local size will be partitioned into two regions. One region will have work-groups that have the same number of work items as was specified by the local size parameter in that dimension. The other region will have work-groups with less than the number of work items specified by the local size parameter in that dimension. The global IDs and group IDs of the work items in the first region will be numerically lower than those in the second, and the second region will be at most one work-group wide in that dimension. Work-group sizes could be non-uniform in multiple dimensions, potentially producing work-groups of up to 4 different sizes in a 2D range and 8 different sizes in a 3D range.
If
local_work_sizeis NULL and the kernel is compiled without support for non-uniform work- groups, the OpenCL runtime will implement the ND-range with uniform work-group sizes. Iflocal_work_sizeis NULL and non-uniform-work-groups are enabled, the OpenCL runtime is free to implement the ND-range using uniform or non-uniform work-group sizes, regardless of the divisibility of the global work size. If the ND-range is implemented using non-uniform work-group sizes, the work-group sizes, global IDs and group IDs will follow the same pattern as described in above paragraph.The work-group size to be used for
kernelcan also be specified in the program source or intermediate language. In this case the size of work group specified bylocal_work_sizemust match the value specified in the program source.These work-group instances are executed in parallel across multiple compute units or concurrently on the same compute unit.
Each work-item is uniquely identified by a global identifier. The global ID, which can be read inside the kernel, is computed using the value given by
global_work_sizeandglobal_work_offset. In addition, a work-item is also identified within a work-group by a unique local ID. The local ID, which can also be read by the kernel, is computed using the value given bylocal_work_size. The starting local ID is always (0, 0, … 0). event_wait_listandnum_events_in_wait_list-
Specify events that need to complete before this particular command can be executed. If
event_wait_listis NULL, then this particular command does not wait on any event to complete. Ifevent_wait_listis NULL,num_events_in_wait_listmust be 0. Ifevent_wait_listis not NULL, the list of events pointed to byevent_wait_listmust be valid andnum_events_in_wait_listmust be greater than 0. The events specified inevent_wait_listact as synchronization points. The context associated with events inevent_wait_listandcommand_queuemust be the same. The memory associated withevent_wait_listcan be reused or freed after the function returns. event-
Returns an event object that identifies this particular kernel-instance. Event objects are unique and can be used to identify a particular kernel execution instance later on. If
eventis NULL, no event will be created for this kernel execution instance and therefore it will not be possible for the application to query or queue a wait for this particular kernel execution instance. If theevent_wait_listand theeventarguments are not NULL, theeventargument should not refer to an element of theevent_wait_listarray.
Returns CL_SUCCESS if the kernel execution was successfully queued.
Otherwise, it returns one of the following errors:
-
CL_INVALID_PROGRAM_EXECUTABLEif there is no successfully built program executable available for device associated withcommand_queue. -
CL_INVALID_COMMAND_QUEUEifcommand_queueis not a valid host command-queue. -
CL_INVALID_KERNELifkernelis not a valid kernel object. -
CL_INVALID_CONTEXTif context associated withcommand_queueandkernelare not the same or if the context associated withcommand_queueand events inevent_wait_listare not the same. -
CL_INVALID_KERNEL_ARGSif the kernel argument values have not been specified or if a kernel argument declared to be a pointer to a type does not point to a named address space. -
CL_INVALID_WORK_DIMENSIONifwork_dimis not a valid value (i.e. a value between 1 and 3). -
CL_INVALID_GLOBAL_WORK_SIZEif any of the values specified inglobal_work_size[0], …global_work_size[work_dim- 1] exceed the range given by thesizeof(size_t)for the device on which the kernel execution will be enqueued. -
CL_INVALID_GLOBAL_OFFSETif the value specified inglobal_work_size+ the corresponding values inglobal_work_offsetfor any dimensions is greater than thesizeof(size_t)for the device on which the kernel execution will be enqueued. -
CL_INVALID_WORK_GROUP_SIZEiflocal_work_sizeis specified and does not match the required work-group size forkernelin the program source. -
CL_INVALID_WORK_GROUP_SIZEiflocal_work_sizeis specified and is not consistent with the required number of sub-groups forkernelin the program source. -
CL_INVALID_WORK_GROUP_SIZEiflocal_work_sizeis specified and the total number of work-items in the work-group computed aslocal_work_size[0] * …local_work_size[work_dim– 1] is greater than the value specified byCL_KERNEL_WORK_GROUP_SIZEin table 5.21. -
CL_INVALID_WORK_GROUP_SIZEif the program was compiled with–cl-uniform-work-group-sizeand the number of work-items specified byglobal_work_sizeis not evenly divisible by size of work-group given bylocal_work_sizeor by the required work- group size specified in the kernel source. -
CL_INVALID_WORK_ITEM_SIZEif the number of work-items specified in any oflocal_work_size[0], …local_work_size[work_dim- 1] is greater than the corresponding values specified byCL_DEVICE_MAX_WORK_ITEM_SIZES[0], ….CL_DEVICE_MAX_WORK_ITEM_SIZES[work_dim- 1]. -
CL_MISALIGNED_SUB_BUFFER_OFFSETif a sub-buffer object is specified as the value for an argument that is a buffer object and theoffsetspecified when the sub-buffer object is created is not aligned toCL_DEVICE_MEM_BASE_ADDR_ALIGNvalue for device associated withqueue. -
CL_INVALID_IMAGE_SIZEif an image object is specified as an argument value and the image dimensions (image width, height, specified or compute row and/or slice pitch) are not supported by device associated withqueue. -
CL_IMAGE_FORMAT_NOT_SUPPORTEDif an image object is specified as an argument value and the image format (image channel order and data type) is not supported by device associated withqueue. -
CL_OUT_OF_RESOURCESif there is a failure to queue the execution instance ofkernelon the command-queue because of insufficient resources needed to execute the kernel. For example, the explicitly specifiedlocal_work_sizecauses a failure to execute the kernel because of insufficient resources such as registers or local memory. Another example would be the number of read-only image args used inkernelexceed theCL_DEVICE_MAX_READ_IMAGE_ARGSvalue for device or the number of write-only image args used inkernelexceed theCL_DEVICE_MAX_READ_WRITE_IMAGE_ARGSvalue for device or the number of samplers used inkernelexceedCL_DEVICE_MAX_SAMPLERSfor device. -
CL_MEM_OBJECT_ALLOCATION_FAILUREif there is a failure to allocate memory for data store associated with image or buffer objects specified as arguments tokernel. -
CL_INVALID_EVENT_WAIT_LISTifevent_wait_listis NULL andnum_events_in_wait_list> 0, orevent_wait_listis not NULL andnum_events_in_wait_listis 0, or if event objects inevent_wait_listare not valid events. -
CL_INVALID_OPERATIONif SVM pointers are passed as arguments to a kernel and the device does not support SVM or if system pointers are passed as arguments to a kernel and/or stored inside SVM allocations passed as kernel arguments and the device does not support fine grain system SVM allocations. -
CL_OUT_OF_RESOURCESif there is a failure to allocate resources required by the OpenCL implementation on the device. -
CL_OUT_OF_HOST_MEMORYif there is a failure to allocate resources required by the OpenCL implementation on the host.