PrevUpHomeNext

Class kernel

boost::compute::kernel — A compute kernel.

Synopsis

// 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;
};

Description

See Also:

command_queue, program

kernel public construct/copy/destruct

  1. kernel();
    Creates a null kernel object.
  2. 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.

  3. kernel(const program & program, const std::string & name);
    Creates a new kernel object with name from program.
  4. kernel(const kernel & other);
    Creates a new kernel object as a copy of other.
  5. kernel(kernel && other) noexcept;
    Move-constructs a new kernel object from other.
  6. kernel & operator=(const kernel & other);
    Copies the kernel object from other to *this.
  7. kernel & operator=(kernel && other) noexcept;
    Move-assigns the kernel from other to *this.
  8. ~kernel();
    Destroys the kernel object.

kernel public member functions

  1. cl_kernel & get() const;
    Returns a reference to the underlying OpenCL kernel object.
  2. std::string name() const;
    Returns the function name for the kernel.
  3. size_t arity() const;
    Returns the number of arguments for the kernel.
  4. program get_program() const;
    Returns the program for the kernel.
  5. context get_context() const;
    Returns the context for the kernel.
  6. template<typename T> T get_info(cl_kernel_info info) const;

    Returns information about the kernel.

    See the documentation for clGetKernelInfo() for more information.

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

  8. 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] Warning

    This method is only available if the OpenCL version is 1.2 or later.

    See the documentation for clGetKernelArgInfo() for more information.

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

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

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

  12. template<class... T> void set_args(T &&... args);
    Sets the arguments for the kernel to args.
  13. void set_exec_info(cl_kernel_exec_info info, size_t size, const void * value);

    Sets additional execution information for the kernel.

    [Warning] Warning

    This method is only available if the OpenCL version is 2.0 or later.

    See the documentation for clSetKernelExecInfo() for more information.

  14. bool operator==(const kernel & other) const;
    Returns true if the kernel is the same at other.
  15. bool operator!=(const kernel & other) const;
    Returns true if the kernel is different from other.

PrevUpHomeNext