CLENQUEUENDRANGEKERN(3clc)
π NAME π
clEnqueueNDRangeKernel β bestie, this one literally enqueues a command to execute a kernel on a device. That's it, that's the vibe β¨
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);
okay real talk, this is the function that actually sends your kernel to the GPU (or CPU, or whatever device you're on). it's giving main character energy in every OpenCL app ever π«Ά
πΈ PARAMETERS πΈ
command_queueβ a valid command-queue, no cap. the kernel gets queued for execution on the device that's associated withcommand_queue. πkernelβ a valid kernel object. heads up: the OpenCL context associated withkernelandcommand_queuemust be the same. if they're not matching, that's a whole situation (seeCL_INVALID_CONTEXTbelow, iykyk π).work_dimβ the number of dimensions used to specify the global work-items and the work-items in the work-group.work_dimmust be greater than zero and less than or equal toCL_DEVICE_MAX_WORK_ITEM_DIMENSIONS. so like, 1D, 2D, or 3D only bestie, don't get creative πglobal_work_offsetβ this one can 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_offsetisNULL, the global IDs start at offset(0, 0, ... 0). so no offset = start at zero, easy β¨global_work_sizeβ points to an array ofwork_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 as:
global_work_size[0] *...* global_work_size[work_dim - 1]
π¦ this is how many work-items you're throwing at the kernel, periodt.
local_work_sizeβ points to an array ofwork_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 as:
local_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 the CL_DEVICE_MAX_WORK_GROUP_SIZE value specified in the table of OpenCL Device Queries for clGetDeviceInfo(3clc) π€ and the number of work-items specified in local_work_size[0],... local_work_size[work_dim - 1] must be less than or equal to the corresponding values specified by CL_DEVICE_MAX_WORK_ITEM_SIZES[0],.... CL_DEVICE_MAX_WORK_ITEM_SIZES[work_dim - 1]. the explicitly specified local_work_size will be used to determine how to break the global work-items specified by global_work_size 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]. π
local_work_size can also be a NULL value, in which case the OpenCL implementation will determine how to break the global work-items into appropriate work-group instances. so like, let the driver decide, she's got it π
event_wait_listandnum_events_in_wait_listβ specify events that need to complete before this particular command can be executed. ifevent_wait_listisNULL, then this particular command does not wait on any event to complete. ifevent_wait_listisNULL,num_events_in_wait_listmust be 0. ifevent_wait_listis notNULL, 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. (yes, freed. you don't have to keep it alive, bestie, we love that for us π)eventβ returns an event object that identifies this particular kernel execution instance. event objects are unique and can be used to identify a particular kernel execution instance later on. ifeventisNULL, 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. so if you passNULLhere, don't come crying later that you can't wait on it, okay? ππ
β¨ NOTES β¨
the work-group size to be used for kernel can also be specified in the program source using the attribute(3clc) ((reqd_work_group_size(X, Y, Z))) qualifier. in this case the size of work group specified by local_work_size must match the value specified by the reqd_work_group_size attribute(3clc) qualifier. matching outfits only, no mismatched energy allowed π
these work-group instances are executed in parallel across multiple compute units or concurrently on the same compute unit. parallel besties, doing their own thing at the same time π₯
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_size and global_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 by local_work_size. the starting local ID is always (0, 0, ... 0). π
π ERRORS π
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. (no built program? no kernel run, sorry babe π)CL_INVALID_COMMAND_QUEUEifcommand_queueis not a valid command-queue.CL_INVALID_KERNELifkernelis not a valid kernel object.CL_INVALID_CONTEXTif context associated withcommand_queueandkernelis 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. (you forgot to set your args, bestie, it happens π)CL_INVALID_WORK_DIMENSIONifwork_dimis not a valid value (i.e. a value between 1 and 3).CL_INVALID_GLOBAL_WORK_SIZEifglobal_work_sizeisNULL, or if any of the values specified inglobal_work_size[0], ...global_work_size[work_dim - 1]are 0 or 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 number of work-items specified byglobal_work_sizeis not evenly divisable by size of work-group given bylocal_work_sizeor does not match the work-group size specified forkernelusing thefunctionQualifiers(3clc)((reqd_work_group_size(X, Y, Z)))qualifier in 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_DEVICE_MAX_WORK_GROUP_SIZEin the table of OpenCL Device Queries forclGetDeviceInfo(3clc).CL_INVALID_WORK_GROUP_SIZEiflocal_work_sizeisNULLand thefunctionQualifiers(3clc)((reqd_work_group_size(X, Y, Z)))qualifier is used to declare the work-group size forkernelin the program 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 the offset specified when the sub-buffer object is created is not aligned toCL_DEVICE_MEM_BASE_ADDR_ALIGNvalue for device associated with queue.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 with queue.CL_INVALID_IMAGE_FORMATif 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 with queue.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_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_listisNULLandnum_events_in_wait_list> 0, orevent_wait_listis notNULLandnum_events_in_wait_listis 0, or if event objects inevent_wait_listare not valid events.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.
lowkey the error list is long but every single one of these is a real "why is my kernel not running" moment, so read them, bestie π
π SPECIFICATION π
OpenCL Specification[1]
π¦ SEE ALSO π¦
clCreateCommandQueue(3clc), clGetDeviceInfo(3clc), clEnqueueNativeKernel(3clc), clEnqueueTask(3clc), workItemFunctions(3clc)
π AUTHORS π
The Khronos Group
π COPYRIGHT π
Copyright Β© 2007-2011 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.
- The OpenCL Specification β bestie, it's literally on page 169, section 5.8 - Executing Kernels (updated for 1.2 rev 14). That's the receipts, that's the source of truth, go read it π
and that's a wrap on CLENQUEUENDRANGEKERN(3clc), fr fr π this lil masterpiece was brought to you by The Khronos Group, dated 01/14/2021 β¨ go execute some kernels, you absolute icon ππ
π¦ where this page comes from
- ubuntu jammy: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- ubuntu noble: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms