logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

clSetKernelArg - Used to set the argument value for a specific argument of a kernel.

Authors

TheKhronosGroup

Errors

clSetKernelArg returns CL_SUCCESS if the function is executed successfully. Otherwise, it returns one of
       the following errors:

       •   CL_INVALID_KERNEL if kernel is not a valid kernel object.

       •   CL_INVALID_ARG_INDEX if arg_index is not a valid argument index.

       •   CL_INVALID_ARG_VALUE if arg_value specified is not a valid value.

       •   CL_INVALID_MEM_OBJECT for an argument declared to be a memory object when the specified arg_value is
           not a valid memory object.

       •   CL_INVALID_SAMPLER for an argument declared to be of type sampler_t when the specified arg_value is
           not a valid sampler object.

       •   CL_INVALID_ARG_SIZE if arg_size does not match the size of the data type for an argument that is not
           a memory object or if the argument is a memory object and arg_size != sizeof(cl_mem) or if arg_size
           is zero and the argument is declared with the local(3clc) qualifier or if the argument is a sampler
           and arg_size != sizeof(cl_sampler).

       •   CL_INVALID_ARG_VALUE if the argument is an image declared with the read_only qualifier and arg_value
           refers to an image object created with cl_mem_flags of CL_MEM_WRITE or if the image argument is
           declared with the write_only qualifier and arg_value refers to an image object created with
           cl_mem_flags of CL_MEM_READ.

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

   Example
       kernel void image_filter (int n, int m, __constant float
       *filter_weights, __read_only image2d_t src_image,
       __write_only image2d_t dst_image) { ...  }

       Argument index values for image_filter will be 0 for n, 1 for m, 2 for filter_weights, 3 for src_image
       and 4 for dst_image.

Name

       clSetKernelArg - Used to set the argument value for a specific argument of a kernel.

       cl_intclSetKernelArg(cl_kernelkernel,cl_uintarg_index,size_targ_size,constvoid*arg_value);

Notes

        1. OpenCL Specification
           page 160, section 5.7.2 - Setting Kernel Arguments

The Khronos Group                                  11/18/2024                               CLSETKERNELARG(3clc)

Parameters

kernel
           A valid kernel object.

       arg_index
           The argument index. Arguments to the kernel are referred by indices that go from 0 for the leftmost
           argument to n - 1, where n is the total number of arguments declared by a kernel.

       arg_value
           A pointer to data that should be used as the argument value for argument specified by arg_index. The
           argument data pointed to by arg_value is copied and the arg_value pointer can therefore be reused by
           the application after clSetKernelArg returns. The argument value specified is the value used by all
           API calls that enqueue kernel (clEnqueueNDRangeKernel(3clc) and clEnqueueTask(3clc)) until the
           argument value is changed by a call to clSetKernelArg for kernel.

           If the argument is a memory object (buffer, image or image array), the arg_value entry will be a
           pointer to the appropriate buffer, image or image array object. The memory object must be created
           with the context associated with the kernel object. If the argument is a buffer object, the arg_value
           pointer can be NULL or point to a NULL value in which case a NULL value will be used as the value for
           the argument declared as a pointer to global(3clc) or constant(3clc) memory in the kernel. If the
           argument is declared with the local(3clc) qualifier, the arg_value entry must be NULL. If the
           argument is of type sampler_t, the arg_value entry must be a pointer to the sampler object.

           If the argument is declared to be a pointer of a built-in scalar or vector type, or a user defined
           structure type in the global or constant address space, the memory object specified as argument value
           must be a buffer object (or NULL). If the argument is declared with the constant(3clc) qualifier, the
           size in bytes of the memory object cannot exceed CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE and the number of
           arguments declared as pointers to constant(3clc) memory cannot exceed CL_DEVICE_MAX_CONSTANT_ARGS.

           The memory object specified as argument value must be a 2D image object if the argument is declared
           to be of type image2d_t. The memory object specified as argument value must be a 3D image object if
           argument is declared to be of type image3d_t. The memory object specified as argument value must be a
           1D image object if the argument is declared to be of type image1d_t. The memory object specified as
           argument value must be a 1D image buffer object if the argument is declared to be of type
           image1d_buffer_t. The memory object specified as argument value must be a 1D image array object if
           argument is declared to be of type image1d_array_t. The memory object specified as argument value
           must be a 2D image array object if argument is declared to be of type image2d_array_t.

           For all other kernel arguments, the arg_value entry must be a pointer to the actual data to be used
           as argument value.

        arg_size
           Specifies the size of the argument value. If the argument is a memory object, the size is the size of
           the buffer or image object type. For arguments declared with the local(3clc) qualifier, the size
           specified will be the size in bytes of the buffer that must be allocated for the local(3clc)
           argument. If the argument is of type sampler_t, the arg_size value must be equal to
           sizeof(cl_sampler). For all other arguments, the size will be the size of argument type.

See Also

clCreateKernel(3clc), clCreateKernelsInProgram(3clc), clReleaseKernel(3clc), clRetainKernel(3clc),
       clGetKernelInfo(3clc), clGetKernelWorkGroupInfo(3clc)

Specification

OpenCLSpecification[1]

See Also