CLENQUEUENATIVEKERNE(3clc)
π CLENQUEUENATIVEKERNE π (that's clEnqueueNativeKernel, from the OpenCL Manual, section 3clc)
okay bestie sit down because this one is genuinely iconic β¨ it's a whole function that lets you yeet a native C/C++ function β like, one that was NEVER touched by the OpenCL compiler β straight into a command-queue. no shaders, no kernel language, just vibes and a raw host function. it's giving "i brought my own code to the party" π
πΈ NAME πΈ
clEnqueueNativeKernel β enqueues a command to execute a native C/C++ function not compiled using the OpenCL compiler. that's it, that's the whole job. no cap. π«Ά
β¨ SYNOPSIS β¨
cl_int clEnqueueNativeKernel(cl_command_queue command_queue,
void (*user_func)(void *), void *args,
size_t cb_args, cl_uint num_mem_objects,
const cl_mem *mem_list,
const void **args_mem_loc,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
cl_event *event);
π PARAMETERS π
command_queueβ a valid command-queue, periodt. but listen: a native user function can only run on a command-queue that was created on a device which hasCL_EXEC_NATIVE_KERNELset inCL_DEVICE_EXECUTION_CAPABILITIESβ that's specified in the table of OpenCL Device Queries forclGetDeviceInfo(3clc). check that vibe check before you commit, fr fr.user_funcβ a pointer to a host-callable user function. your function. your rules. πargsβ a pointer to the args list thatuser_funcshould be called with.cb_argsβ the size in bytes of the args list thatargspoints to.
the data pointed to by args and cb_args bytes in size will be copied, and a pointer to this copied region gets passed to user_func. why the copy, you ask? because the memory objects (cl_mem values) that args may contain need to be modified and replaced by appropriate pointers to global memory π so it's a glow-up, not a duplicate. and the best part: when clEnqueueNativeKernel returns, the memory region pointed to by args can be reused by the application. slay, no leak energy.
num_mem_objectsβ the number of buffer objects that are passed inargs.mem_listβ a list of valid buffer objects, ifnum_mem_objects > 0. the buffer object values specified inmem_listare memory object handles (cl_memvalues) returned byclCreateBuffer(3clc)orNULL.args_mem_locβ a pointer to appropriate locations thatargspoints to where memory object handles (cl_memvalues) are stored. before the user function is executed, the memory object handles are replaced by pointers to global memory. glow-up complete π«event_wait_listandnum_events_in_wait_listβ these two 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 be0. ifevent_wait_listis notNULL, the list of events pointed to byevent_wait_listmust be valid andnum_events_in_wait_listmust be greater than0. the events specified inevent_wait_listact as synchronization points. the context associated with events inevent_wait_listandcommand_queuemust be the same β same friend group only, no outsiders π the memory associated withevent_wait_listcan be reused or freed after the function returns.
π¦ NOTES π¦
the total number of read-only images specified as arguments to a kernel cannot exceed CL_DEVICE_MAX_READ_IMAGE_ARGS. each 2D image array argument to a kernel declared with the read_only qualifier counts as one image.
the total number of write-only images specified as arguments to a kernel cannot exceed CL_DEVICE_MAX_WRITE_IMAGE_ARGS. each 2D image array argument to a kernel declared with the write_only qualifier counts as one image.
π ERRORS π
returns CL_SUCCESS if the user function execution instance was successfully queued π or one of the errors below, bestie:
CL_INVALID_COMMAND_QUEUEifcommand_queueis not a valid command-queue.CL_INVALID_CONTEXTif context associated withcommand_queueand events inevent-wait_listare not the same.CL_INVALID_VALUEifuser_funcisNULL.CL_INVALID_VALUEifargsis aNULLvalue andcb_args > 0, or ifargsis aNULLvalue andnum_mem_objects > 0.CL_INVALID_VALUEifargsis notNULLandcb_argsis0.CL_INVALID_VALUEifnum_mem_objects > 0andmem_listorargs_mem_locareNULL.CL_INVALID_VALUEifnum_mem_objects = 0andmem_listorargs_mem_locare notNULL.CL_INVALID_OPERATIONif the device associated withcommand_queuecannot execute the native kernel.CL_INVALID_MEM_OBJECTif one or more memory objects specified inmem_listare not valid or are not buffer objects.CL_OUT_OF_RESOURCESif there is a failure to queue the execution instance of kernel on the command-queue because of insufficient resources needed to execute the kernel.CL_MEM_OBJECT_ALLOCATION_FAILUREif there is a failure to allocate memory for data store associated with buffer objects specified as arguments to kernel.CL_INVALID_EVENT_WAIT_LISTifevent_wait_listisNULLandnum_events_in_wait_list > 0, orevent_wait_listis notNULLandnum_events_in_wait_listis0, 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.
π SPECIFICATION π
OpenCL Specification[1]
π SEE ALSO π
clEnqueueNDRangeKernel(3clc), clEnqueueNativeKernel(3clc), clCreateCommandQueue(3clc), clCreateBuffer(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.
π§ NOTES (the footnote one, not the other one) π§
- OpenCL Specification page 174, section 5.8 - Executing Kernels (updated for 1.2 rev 14)
and that's the whole page, bestie π this one came from The Khronos Group, dated 01/14/2021, and it lives in the manual as CLENQUEUENATIVEKERNE(3clc). go enqueue something native, you absolute main character πβ¨
π¦ 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