Set the argument value for a specific argument of a kernel.
cl_int clSetKernelArg(cl_kernel kernel,
cl_uint arg_index,
size_t arg_size,
const void *arg_value)
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, wheren
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 byarg_value
is copied and thearg_value
pointer can therefore be reused by the application afterclSetKernelArg
returns. The argument value specified is the value used by all API calls that enqueuekernel
(clEnqueueNDRangeKernel
) until the argument value is changed by a call toclSetKernelArg
forkernel
.If the argument is a memory object (buffer, pipe, image or image array), the
arg_value
entry will be a pointer to the appropriate buffer, pipe, 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, thearg_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 toglobal
orconstant
memory in the kernel. If the argument is declared with thelocal
qualifier, thearg_value
entry must be NULL. If the argument is of typesampler_t
, thearg_value
entry must be a pointer to the sampler object. If the argument is of typequeue_t
, thearg_value
entry must be a pointer to the device queue 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
qualifier, the size in bytes of the memory object cannot exceedCL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
and the number of arguments declared as pointers toconstant
memory cannot exceedCL_DEVICE_MAX_CONSTANT_ARGS
.The memory object specified as argument value must be a pipe object if the argument is declared with the
pipe
qualifier.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 2D image object with image channel order =CL_DEPTH
if the argument is declared to be of typeimage2d_depth_t
. The memory object specified as argument value must be a 3D image object if argument is declared to be of typeimage3d_t
. The memory object specified as argument value must be a 1D image object if the argument is declared to be of typeimage1d_t
. The memory object specified as argument value must be a 1D image buffer object if the argument is declared to be of typeimage1d_buffer_t
. The memory object specified as argument value must be a 1D image array object if argument is declared to be of typeimage1d_array_t
. The memory object specified as argument value must be a 2D image array object if argument is declared to be of typeimage2d_array_t
. The memory object specified as argument value must be a 2D image array object with image channel order =CL_DEPTH
if argument is declared to be of typeimage2d_array_depth_t
.For all other kernel arguments, the
arg_value
entry must be a pointer to the actual data to be used as argument value.If the
cl_khr_gl_msaa_sharing
extension is supported, if the argument is a multi-sample 2D image, thearg_value
entry must be a pointer to a multisample image object. If the argument is a multi-sample 2D depth image, thearg_value
entry must be a pointer to a multisample depth image object. If the argument is a multi-sample 2D image array, thearg_value
entry must be a pointer to a multi-sample image array object. If the argument is a multi-sample 2D depth image array, thearg_value
entry must be a pointer to a multi-sample depth image array object. arg_size
-
Specifies the size of the argument value. If the argument is a memory object, the size is the size of the memory object. For arguments declared with the
local
qualifier, the size specified will be the size in bytes of the buffer that must be allocated for thelocal
argument. If the argument is of typesampler_t
, thearg_size
value must be equal tosizeof(cl_sampler)
. If the argument is of typequeue_t
, thearg_size
value must be equal tosizeof(cl_command_queue)
. For all other arguments, the size will be the size of argument type.
A kernel object does not update the reference count for objects such as memory, sampler objects specified as argument values by clSetKernelArg
.
Users may not rely on a kernel object to retain objects specified as argument values to the kernel.
Implementations shall not allow cl_kernel
objects to hold reference counts to cl_kernel
arguments, because no mechanism is provided for the user to tell the kernel to release that ownership right.
If the kernel holds ownership rights on kernel args, that would make it impossible for the user to tell with certainty when he may safely release user allocated resources associated with OpenCL objects such as the cl_mem
backing store used with CL_MEM_USE_HOST_PTR
.
clSetKernelArg
returns CL_SUCCESS
if the function is executed successfully.
Otherwise, it returns one of the following errors:
-
CL_INVALID_KERNEL
ifkernel
is not a valid kernel object. -
CL_INVALID_ARG_INDEX
ifarg_index
is not a valid argument index. -
CL_INVALID_ARG_VALUE
ifarg_value
specified is not a valid value. -
CL_INVALID_MEM_OBJECT
for an argument declared to be a memory object when the specifiedarg_value
is not a valid memory object. -
CL_INVALID_MEM_OBJECT
for an argument declared to be a multi-sample image, multisample image array, multi-sample depth image or a multi-sample depth image array and the argument value specified inarg_value
does not follow the rules described above for a depth memory object or memory array object argument. (Applies if thecl_khr_gl_msaa_sharing
extension is supported.) -
CL_INVALID_SAMPLER
for an argument declared to be of typesampler_t
when the specifiedarg_value
is not a valid sampler object. -
CL_INVALID_DEVICE_QUEUE
for an argument declared to be of typequeue_t
when the specifiedarg_value
is not a valid device queue object. -
CL_INVALID_ARG_SIZE
ifarg_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 andarg_size
!=sizeof(cl_mem)
or ifarg_size
is zero and the argument is declared with thelocal
qualifier or if the argument is a sampler andarg_size
!=sizeof(cl_sampler)
. -
CL_INVALID_ARG_VALUE
if the argument is an image declared with theread_only
qualifier andarg_value
refers to an image object created withcl_mem_flags
ofCL_MEM_WRITE
or if the image argument is declared with thewrite_only
qualifier andarg_value
refers to an image object created withcl_mem_flags
ofCL_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.
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
.