'\" t .\" Title: clSetKernelArg .\" Author: The Khronos Group .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 01/14/2021 .\" Manual: OpenCL Manual .\" Source: The Khronos Group .\" Language: English .\" .TH "CLSETKERNELARG" "3clc" "01/14/2021" "The Khronos Group" "OpenCL Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" clSetKernelArg \- Used to set the argument value for a specific argument of a kernel\&. .SH "" .HP \w'cl_int\ clSetKernelArg('u .BI "cl_int clSetKernelArg(cl_kernel\ " "kernel" ", cl_uint\ " "arg_index" ", size_t\ " "arg_size" ", const\ void\ *" "arg_value" ");" .SH "PARAMETERS" .PP \fIkernel\fR .RS 4 A valid kernel object\&. .RE .PP \fIarg_index\fR .RS 4 The argument index\&. Arguments to the kernel are referred by indices that go from 0 for the leftmost argument to \fIn\fR \- 1, where \fIn\fR is the total number of arguments declared by a kernel\&. .RE .PP \fIarg_value\fR .RS 4 A pointer to data that should be used as the argument value for argument specified by \fIarg_index\fR\&. The argument data pointed to by \fIarg_value\fR is copied and the \fIarg_value\fR pointer can therefore be reused by the application after \fBclSetKernelArg\fR returns\&. The argument value specified is the value used by all API calls that enqueue \fIkernel\fR (\fBclEnqueueNDRangeKernel\fR(3clc) and \fBclEnqueueTask\fR(3clc)) until the argument value is changed by a call to \fBclSetKernelArg\fR for \fIkernel\fR\&. .sp If the argument is a memory object (buffer, image or image array), the \fIarg_value\fR 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 \fIarg_value\fR 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 \fBglobal\fR(3clc) or \fBconstant\fR(3clc) memory in the kernel\&. If the argument is declared with the \fBlocal\fR(3clc) qualifier, the \fIarg_value\fR entry must be NULL\&. If the argument is of type sampler_t, the \fIarg_value\fR entry must be a pointer to the sampler object\&. .sp 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 \fBconstant\fR(3clc) qualifier, the size in bytes of the memory object cannot exceed \fBCL_DEVICE_MAX_CONSTANT_BUFFER_SIZE\fR and the number of arguments declared as pointers to \fBconstant\fR(3clc) memory cannot exceed \fBCL_DEVICE_MAX_CONSTANT_ARGS\fR\&. .sp 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\&. .sp For all other kernel arguments, the \fIarg_value\fR entry must be a pointer to the actual data to be used as argument value\&. .RE .PP \fI arg_size \fR .RS 4 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 \fBlocal\fR(3clc) qualifier, the size specified will be the size in bytes of the buffer that must be allocated for the \fBlocal\fR(3clc) argument\&. If the argument is of type \fBsampler_t\fR, the \fIarg_size\fR value must be equal to sizeof(cl_sampler)\&. For all other arguments, the size will be the size of argument type\&. .RE .SH "NOTES" .PP A kernel object does not update the reference count for objects such as memory, sampler objects specified as argument values by \fBclSetKernelArg\fR\&. Users may not rely on a kernel object to retain objects specified as argument values to the kernel\&. .PP 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 \fBCL_MEM_USE_HOST_PTR\fR\&. .PP An OpenCL API call is considered to be \fIthread\-safe\fR if the internal state as managed by OpenCL remains consistent when called simultaneously by multiple \fIhost\fR threads\&. OpenCL API calls that are \fIthread\-safe\fR allow an application to call these functions in multiple \fIhost\fR threads without having to implement mutual exclusion across these \fIhost\fR threads i\&.e\&. they are also re\-entrant\-safe\&. .PP All OpenCL API calls are thread\-safe except \fBclSetKernelArg\fR\&. \fBclSetKernelArg\fR is safe to call from any host thread, and is safe to call re\-entrantly so long as concurrent calls operate on different cl_kernel objects\&. However, the behavior of the cl_kernel object is undefined if \fBclSetKernelArg\fR is called from multiple host threads on the same cl_kernel object at the same time\&. Please note that there are additional limitations as to which OpenCL APIs may be called from OpenCL callback functions \-\- please see section 5\&.9\&. .PP There is an inherent race condition in the design of OpenCL that occurs between setting a kernel argument and using the kernel with \fBclEnqueueNDRangeKernel\fR(3clc) or \fBclEnqueueTask\fR(3clc)\&. Another host thread might change the kernel arguments between when a host thread sets the kernel arguments and then enqueues the kernel, causing the wrong kernel arguments to be enqueued\&. Rather than attempt to share cl_kernel objects among multiple host threads, applications are strongly encouraged to make additional cl_kernel objects for kernel functions for each host thread\&. .SH "ERRORS" .PP \fBclSetKernelArg\fR returns CL_SUCCESS if the function is executed successfully\&. Otherwise, it returns one of the following errors: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_KERNEL if \fIkernel\fR is not a valid kernel object\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_ARG_INDEX if \fIarg_index\fR is not a valid argument index\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_ARG_VALUE if \fIarg_value\fR specified is not a valid value\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_MEM_OBJECT for an argument declared to be a memory object when the specified \fIarg_value\fR is not a valid memory object\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_SAMPLER for an argument declared to be of type \fIsampler_t\fR when the specified \fIarg_value\fR is not a valid sampler object\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_ARG_SIZE if \fIarg_size\fR 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 \fIarg_size\fR != \fBsizeof(cl_mem)\fR or if \fIarg_size\fR is zero and the argument is declared with the \fBlocal\fR(3clc) qualifier or if the argument is a sampler and \fIarg_size\fR != \fBsizeof(cl_sampler)\fR\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_ARG_VALUE if the argument is an image declared with the \fBread_only\fR qualifier and \fIarg_value\fR refers to an image object created with \fIcl_mem_flags\fR of \fBCL_MEM_WRITE\fR or if the image argument is declared with the \fBwrite_only\fR qualifier and \fIarg_value\fR refers to an image object created with \fIcl_mem_flags\fR of \fBCL_MEM_READ\fR\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host\&. .RE .SS "Example" .TS tab(:); l. T{ kernel void image_filter (int n, int m, __constant float *filter_weights, __read_only image2d_t src_image, __write_only image2d_t dst_image) { \&.\&.\&. } T} .TE .sp 1 .PP Argument index values for \fBimage_filter\fR will be 0 for \fBn\fR, 1 for \fBm\fR, 2 for \fBfilter_weights\fR, 3 for \fBsrc_image\fR and 4 for \fBdst_image\fR\&. .SH "SPECIFICATION" .PP \m[blue]\fBOpenCL Specification\fR\m[]\&\s-2\u[1]\d\s+2 .SH "SEE ALSO" .PP \fBclCreateKernel\fR(3clc), \fBclCreateKernelsInProgram\fR(3clc), \fBclReleaseKernel\fR(3clc), \fBclRetainKernel\fR(3clc), \fBclGetKernelInfo\fR(3clc), \fBclGetKernelWorkGroupInfo\fR(3clc) .SH "AUTHORS" .PP \fBThe Khronos Group\fR .SH "COPYRIGHT" .br Copyright \(co 2007-2011 The Khronos Group Inc. .br 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. .sp .SH "NOTES" .IP " 1." 4 OpenCL Specification .RS 4 \%page 160, section 5.7.2 - Setting Kernel Arguments .RE