CLENQUEUENATIVEKERNE(3clc)

πŸ“¦
version 1.0~svn33624 Β· 3 versions
, in ubuntu jammy, ubuntu noble

πŸ’– 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 has CL_EXEC_NATIVE_KERNEL set in CL_DEVICE_EXECUTION_CAPABILITIES β€” that's specified in the table of OpenCL Device Queries for clGetDeviceInfo(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 that user_func should be called with.
  • cb_args β€” the size in bytes of the args list that args points 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 in args.
  • mem_list β€” a list of valid buffer objects, if num_mem_objects > 0. the buffer object values specified in mem_list are memory object handles (cl_mem values) returned by clCreateBuffer(3clc) or NULL.
  • args_mem_loc β€” a pointer to appropriate locations that args points to where memory object handles (cl_mem values) are stored. before the user function is executed, the memory object handles are replaced by pointers to global memory. glow-up complete πŸ’«
  • event_wait_list and num_events_in_wait_list β€” these two specify events that need to complete before this particular command can be executed. if event_wait_list is NULL, then this particular command does not wait on any event to complete. if event_wait_list is NULL, num_events_in_wait_list must be 0. if event_wait_list is not NULL, the list of events pointed to by event_wait_list must be valid and num_events_in_wait_list must be greater than 0. the events specified in event_wait_list act as synchronization points. the context associated with events in event_wait_list and command_queue must be the same β€” same friend group only, no outsiders πŸ™ˆ the memory associated with event_wait_list can 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_QUEUE if command_queue is not a valid command-queue.
  • CL_INVALID_CONTEXT if context associated with command_queue and events in event-wait_list are not the same.
  • CL_INVALID_VALUE if user_func is NULL.
  • CL_INVALID_VALUE if args is a NULL value and cb_args > 0, or if args is a NULL value and num_mem_objects > 0.
  • CL_INVALID_VALUE if args is not NULL and cb_args is 0.
  • CL_INVALID_VALUE if num_mem_objects > 0 and mem_list or args_mem_loc are NULL.
  • CL_INVALID_VALUE if num_mem_objects = 0 and mem_list or args_mem_loc are not NULL.
  • CL_INVALID_OPERATION if the device associated with command_queue cannot execute the native kernel.
  • CL_INVALID_MEM_OBJECT if one or more memory objects specified in mem_list are not valid or are not buffer objects.
  • CL_OUT_OF_RESOURCES if 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_FAILURE if there is a failure to allocate memory for data store associated with buffer objects specified as arguments to kernel.
  • CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0, or event_wait_list is not NULL and num_events_in_wait_list is 0, or if event objects in event_wait_list are not valid events.
  • CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device.
  • CL_OUT_OF_HOST_MEMORY if 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 Β© 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) 🧚

  1. 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