boost::compute::kernel — A compute kernel.
// In header: <boost/compute/kernel.hpp> class kernel { public: // construct/copy/destruct kernel(); explicit kernel(cl_kernel, bool = true); kernel(const program &, const std::string &); kernel(const kernel &); kernel(kernel &&) noexcept; kernel & operator=(const kernel &); kernel & operator=(kernel &&) noexcept; ~kernel(); // public member functions cl_kernel & get() const; std::string name() const; size_t arity() const; program get_program() const; context get_context() const; template<typename T> T get_info(cl_kernel_info) const; template<int Enum> unspecified get_info() const; template<typename T> T get_arg_info(size_t, cl_kernel_arg_info) const; template<typename T> T get_work_group_info(const device &, cl_kernel_work_group_info); void set_arg(size_t, size_t, const void *); template<typename T> void set_arg(size_t, const T &); template<class... T> void set_args(T &&...); void set_exec_info(cl_kernel_exec_info, size_t, const void *); bool operator==(const kernel &) const; bool operator!=(const kernel &) const; };
See Also:
kernel
public
construct/copy/destructkernel();Creates a null kernel object.
explicit kernel(cl_kernel kernel, bool retain = true);
Creates a new kernel object for kernel
. If retain
is true
, the reference count for kernel
will be incremented.
kernel(const program & program, const std::string & name);Creates a new kernel object with
name
from program
. kernel(const kernel & other);Creates a new kernel object as a copy of
other
. kernel(kernel && other) noexcept;Move-constructs a new kernel object from
other
. kernel & operator=(const kernel & other);Copies the kernel object from
other
to *this
. kernel & operator=(kernel && other) noexcept;Move-assigns the kernel from
other
to *this
. ~kernel();Destroys the kernel object.
kernel
public member functionscl_kernel & get() const;Returns a reference to the underlying OpenCL kernel object.
std::string name() const;Returns the function name for the kernel.
size_t arity() const;Returns the number of arguments for the kernel.
program get_program() const;Returns the program for the kernel.
context get_context() const;Returns the context for the kernel.
template<typename T> T get_info(cl_kernel_info info) const;
Returns information about the kernel.
See the documentation for clGetKernelInfo() for more information.
template<int Enum> unspecified get_info() const;
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename T> T get_arg_info(size_t index, cl_kernel_arg_info info) const;
Returns information about the argument at index
.
For example, to get the name of the first argument:
std::string arg = kernel.get_arg_info<std::string>(0, CL_KERNEL_ARG_NAME);
Note, this function requires that the program be compiled with the "-cl-kernel-arg-info"
flag. For example:
program.build("-cl-kernel-arg-info");
Warning | |
---|---|
This method is only available if the OpenCL version is 1.2 or later. |
See the documentation for clGetKernelArgInfo() for more information.
template<typename T> T get_work_group_info(const device & device, cl_kernel_work_group_info info);
Returns work-group information for the kernel with device
.
See the documentation for clGetKernelWorkGroupInfo() for more information.
void set_arg(size_t index, size_t size, const void * value);
Sets the argument at index
to value
with size
.
See the documentation for clSetKernelArg() for more information.
template<typename T> void set_arg(size_t index, const T & value);
Sets the argument at index
to value
.
For built-in types (e.g. float
, int4_
), this is equivalent to calling set_arg(index, sizeof(type), &value).
Additionally, this method is specialized for device memory objects such as buffer and image2d. This allows for them to be passed directly without having to extract their underlying cl_mem object.
This method is also specialized for device container types such as vector<T>
and array<T, N>. This allows for them to be passed directly as kernel arguments without having to extract their underlying buffer.
template<class... T> void set_args(T &&... args);Sets the arguments for the kernel to
args
. void set_exec_info(cl_kernel_exec_info info, size_t size, const void * value);
Sets additional execution information for the kernel.
Warning | |
---|---|
This method is only available if the OpenCL version is 2.0 or later. |
See the documentation for clSetKernelExecInfo() for more information.
bool operator==(const kernel & other) const;Returns
true
if the kernel is the same at other
. bool operator!=(const kernel & other) const;Returns
true
if the kernel is different from other
.