C Specification

To enqueue a command to execute a native C/C++ function not compiled using the OpenCL compiler, call the function

cl_int clEnqueueNativeKernel(
    cl_command_queue command_queue,
    void (CL_CALLBACK* 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 is a valid host command-queue. A native user function can only be executed on a command-queue created on a device that has CL_​EXEC_​NATIVE_​KERNEL capability set in CL_​DEVICE_​EXECUTION_​CAPABILITIES as specified in the Device Queries table.

  • user_func is a pointer to a host-callable user function.

  • args is a pointer to the args list that user_func should be called with.

  • cb_args is the size in bytes of the args list that args points to.

  • num_mem_objects is the number of buffer objects that are passed in args.

  • mem_list is 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 or NULL.

  • args_mem_loc is 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.

  • event_wait_list, num_events_in_wait_list and event are as described in clEnqueueNDRangeKernel.

Description

The data pointed to by args and cb_args bytes in size will be copied and a pointer to this copied region will be passed to user_func. The copy needs to be done because the memory objects (cl_mem values) that args may contain need to be modified and replaced by appropriate pointers to global memory. When clEnqueueNativeKernel returns, the memory region pointed to by args can be reused by the application.

clEnqueueNativeKernel returns CL_​SUCCESS if the user function execution instance was successfully queued. Otherwise, it returns one of the following errors:

  • CL_​INVALID_​COMMAND_​QUEUE if command_queue is not a valid host 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_​INVALID_​OPERATION if 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_​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.

The total number of read-only images specified as arguments to a kernel cannot exceed CL_​DEVICE_​MAX_​READ_​IMAGE_​ARGS. Each 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 image array argument to a kernel declared with the write_only qualifier counts as one image.

The total number of read-write images specified as arguments to a kernel cannot exceed CL_​DEVICE_​MAX_​READ_​WRITE_​IMAGE_​ARGS. Each image array argument to a kernel declared with the read_write qualifier counts as one image.

See Also

Document Notes

For more information, see the OpenCL Specification

This page is extracted from the OpenCL Specification. Fixes and changes should be made to the Specification, not directly.

Copyright (c) 2014-2020 Khronos Group. This work is licensed under a Creative Commons Attribution 4.0 International License.