1 #ifndef VIENNACL_OCL_HANDLE_HPP_
2 #define VIENNACL_OCL_HANDLE_HPP_
26 #include <OpenCL/cl.h>
44 template<
class OCL_TYPE>
47 typedef typename OCL_TYPE::ERROR_TEMPLATE_ARGUMENT_FOR_CLASS_INVALID ErrorType;
55 static void inc(cl_mem & something)
57 cl_int err = clRetainMemObject(something);
61 static void dec(cl_mem & something)
64 cl_int err = clReleaseMemObject(something);
72 struct handle_inc_dec_helper<cl_program>
74 static void inc(cl_program & something)
76 cl_int err = clRetainProgram(something);
80 static void dec(cl_program & something)
83 cl_int err = clReleaseProgram(something);
91 struct handle_inc_dec_helper<cl_kernel>
93 static void inc(cl_kernel & something)
95 cl_int err = clRetainKernel(something);
99 static void dec(cl_kernel & something)
102 cl_int err = clReleaseKernel(something);
110 struct handle_inc_dec_helper<cl_command_queue>
112 static void inc(cl_command_queue & something)
114 cl_int err = clRetainCommandQueue(something);
118 static void dec(cl_command_queue & something)
121 cl_int err = clReleaseCommandQueue(something);
129 struct handle_inc_dec_helper<cl_context>
131 static void inc(cl_context & something)
133 cl_int err = clRetainContext(something);
137 static void dec(cl_context & something)
140 cl_int err = clReleaseContext(something);
148 template<
class OCL_TYPE>
154 handle(
const handle & other) : h_(other.h_), p_context_(other.p_context_) {
if (h_ != 0)
inc(); }
163 p_context_ = other.p_context_;
181 p_context_ = p.second;
187 operator OCL_TYPE()
const {
return h_; }
189 const OCL_TYPE &
get()
const {
return h_; }
193 assert(p_context_ != NULL &&
bool(
"Logic error: Accessing dangling context from handle."));
202 OCL_TYPE tmp = other.h_;
207 other.p_context_ = this->p_context_;
208 this->p_context_ = tmp2;
handle & operator=(const handle &other)
Copies the OpenCL handle from the provided handle. Does not take ownership like e.g. std::auto_ptr<>, so both handle objects are valid (more like shared_ptr).
Definition: handle.hpp:158
void context(viennacl::ocl::context const &c)
Definition: handle.hpp:196
This file provides the forward declarations for the OpenCL layer of ViennaCL.
void inc()
Manually increment the OpenCL reference count. Typically called automatically, but is necessary if us...
Definition: handle.hpp:214
handle & operator=(std::pair< OCL_TYPE, cl_context > p)
Wraps an OpenCL handle including its associated context. Decreases the reference count if the handle ...
Definition: handle.hpp:177
void dec()
Manually decrement the OpenCL reference count. Typically called automatically, but might be useful wi...
Definition: handle.hpp:216
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:51
Helper for OpenCL reference counting used by class handle.
Definition: handle.hpp:45
handle()
Definition: handle.hpp:152
handle(const handle &other)
Definition: handle.hpp:154
#define VIENNACL_ERR_CHECK(err)
Definition: error.hpp:655
handle & swap(handle &other)
Swaps the OpenCL handle of two handle objects.
Definition: handle.hpp:200
handle(const OCL_TYPE &something, viennacl::ocl::context const &c)
Definition: handle.hpp:153
Error handling for the OpenCL layer of ViennaCL.
viennacl::ocl::context const & context() const
Definition: handle.hpp:191
~handle()
Definition: handle.hpp:155
handle & operator=(const OCL_TYPE &something)
Wraps an OpenCL handle. Does not change the context of this handle object! Decreases the reference co...
Definition: handle.hpp:169
viennacl::backend::mem_handle const & handle(T const &obj)
Returns the generic memory handle of an object. Const-version.
Definition: handle.hpp:48
Handle class the effectively represents a smart pointer for OpenCL handles.
Definition: forwards.h:51