Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class kernel

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

Synopsis

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

Description

See Also: command_queue, program

kernel public member functions

  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 & operator=(const kernel & other);
    Copies the kernel object from other to *this.
  6. kernel(kernel && other) noexcept;
    Move-constructs a new kernel object from other.
  7. kernel & operator=(kernel && other) noexcept;
    Move-assigns the kernel from other to *this.
  8. ~kernel();
    Destroys the kernel object.
  9. kernel clone();

    Creates a new kernel object based on a shallow copy of the undelying OpenCL kernel object.

    [Warning] Warning

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

    See the documentation for

  10. cl_kernel & get() const;
    Returns a reference to the underlying OpenCL kernel object.
  11. std::string name() const;
    Returns the function name for the kernel.
  12. size_t arity() const;
    Returns the number of arguments for the kernel.
  13. program get_program() const;
    Returns the program for the kernel.
  14. context get_context() const;
    Returns the context for the kernel.
  15. template<typename T> T get_info(cl_kernel_info info) const;

    Returns information about the kernel.

    See the documentation for

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

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

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

    This method is only available if the OpenCL version is 2.1 or later. See the documentation for

  21. 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.
  22. 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.
  23. 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.
  24. 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

  25. 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);
    

  26. 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.
  27. template<class... T> void set_args(T &&... args);
    Sets the arguments for the kernel to args.
  28. 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

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

PrevUpHomeNext