![]() |
Home | Libraries | People | FAQ | More |
boost::compute::kernel — A compute kernel.
// In header: <boost/compute/kernel.hpp> class kernel { public: // public member functions kernel(); explicit kernel(cl_kernel, bool = true); kernel(const program &, const std::string &); kernel(const kernel &); kernel & operator=(const kernel &); kernel(kernel &&) noexcept; kernel & operator=(kernel &&) noexcept; ~kernel(); kernel clone(); 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<int Enum> unspecified get_arg_info(size_t) const; template<typename T> T get_work_group_info(const device &, cl_kernel_work_group_info) const; template<typename T> boost::optional< T > get_sub_group_info(const device &, cl_kernel_sub_group_info, const size_t, const void *) const; template<typename T> boost::optional< T > get_sub_group_info(const device &, cl_kernel_sub_group_info) const; template<typename T> boost::optional< T > get_sub_group_info(const device &, cl_kernel_sub_group_info, const size_t) const; template<typename T> boost::optional< T > get_sub_group_info(const device &, cl_kernel_sub_group_info, const std::vector< size_t >) const; void set_arg(size_t, size_t, const void *); template<typename T> void set_arg(size_t, const T &); void set_arg(size_t, std::nullptr_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: command_queue, program
kernel
public member functionskernel();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 & operator=(const kernel & other);Copies the kernel object from
other
to *this
. kernel(kernel && other) noexcept;Move-constructs a new kernel object from
other
. kernel & operator=(kernel && other) noexcept;Move-assigns the kernel from
other
to *this
. ~kernel();Destroys the kernel object.
kernel clone();
Creates a new kernel object based on a shallow copy of the undelying OpenCL kernel object.
![]() |
Warning |
---|---|
This method is only available if the OpenCL version is 2.1 or later. |
See the documentation for
cl_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
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
template<int Enum> unspecified get_arg_info(size_t index) 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_work_group_info(const device & device, cl_kernel_work_group_info info) const;
Returns work-group information for the kernel with device
.
See the documentation for
template<typename T> boost::optional< T > get_sub_group_info(const device & device, cl_kernel_sub_group_info info, const size_t input_size, const void * input) const;
Returns sub-group information for the kernel with device
. Returns a null optional if device
is not 2.1 device, or is not 2.0 device with support for cl_khr_subgroups extension.
![]() |
Warning |
---|---|
This method is only available if the OpenCL version is 2.1 or later. See the documentation for |
template<typename T> boost::optional< T > get_sub_group_info(const device & device, cl_kernel_sub_group_info 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> boost::optional< T > get_sub_group_info(const device & device, cl_kernel_sub_group_info info, const size_t input) 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> boost::optional< T > get_sub_group_info(const device & device, cl_kernel_sub_group_info info, const std::vector< size_t > input) const;This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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
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.
For setting local memory arguments (e.g. "__local float *buf"), the local_buffer<T> class may be used:
// set argument to a local buffer with storage for 32 float's kernel.set_arg(0, local_buffer<float>(32));
For setting NULL to global and constant memory arguments (C++11):
kernel.set_arg(0, nullptr);
void set_arg(size_t index, std::nullptr_t nul);This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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
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
.