\class kernel \brief A compute kernel. \see command_queue, program
| 37 | /// |
| 38 | /// \see command_queue, program |
| 39 | class kernel |
| 40 | { |
| 41 | public: |
| 42 | /// Creates a null kernel object. |
| 43 | kernel() |
| 44 | : m_kernel(0) |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | /// Creates a new kernel object for \p kernel. If \p retain is |
| 49 | /// \c true, the reference count for \p kernel will be incremented. |
| 50 | explicit kernel(cl_kernel kernel, bool retain = true) |
| 51 | : m_kernel(kernel) |
| 52 | { |
| 53 | if(m_kernel && retain){ |
| 54 | clRetainKernel(m_kernel); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /// Creates a new kernel object with \p name from \p program. |
| 59 | kernel(const program &program, const std::string &name) |
| 60 | { |
| 61 | cl_int error = 0; |
| 62 | m_kernel = clCreateKernel(program.get(), name.c_str(), &error); |
| 63 | |
| 64 | if(!m_kernel){ |
| 65 | BOOST_THROW_EXCEPTION(opencl_error(error)); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /// Creates a new kernel object as a copy of \p other. |
| 70 | kernel(const kernel &other) |
| 71 | : m_kernel(other.m_kernel) |
| 72 | { |
| 73 | if(m_kernel){ |
| 74 | clRetainKernel(m_kernel); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /// Copies the kernel object from \p other to \c *this. |
| 79 | kernel& operator=(const kernel &other) |
| 80 | { |
| 81 | if(this != &other){ |
| 82 | if(m_kernel){ |
| 83 | clReleaseKernel(m_kernel); |
| 84 | } |
| 85 | |
| 86 | m_kernel = other.m_kernel; |
| 87 | |
| 88 | if(m_kernel){ |
| 89 | clRetainKernel(m_kernel); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return *this; |
| 94 | } |
| 95 | |
| 96 | #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES |