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)
63 cl_int err = clReleaseMemObject(something);
70 struct handle_inc_dec_helper<cl_program>
72 static void inc(cl_program & something)
74 cl_int err = clRetainProgram(something);
78 static void dec(cl_program & something)
82 cl_int err = clReleaseProgram(something);
90 struct handle_inc_dec_helper<cl_kernel>
92 static void inc(cl_kernel & something)
94 cl_int err = clRetainKernel(something);
98 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)
122 cl_int err = clReleaseCommandQueue(something);
130 struct handle_inc_dec_helper<cl_context>
132 static void inc(cl_context & something)
134 cl_int err = clRetainContext(something);
138 static void dec(cl_context & something)
142 cl_int err = clReleaseContext(something);
150 template<
class OCL_TYPE>
156 handle(
const handle & other) : h_(other.h_), p_context_(other.p_context_) {
if (h_ != 0)
inc(); }
165 p_context_ = other.p_context_;
183 p_context_ = p.second;
189 operator OCL_TYPE()
const {
return h_; }
191 const OCL_TYPE &
get()
const {
return h_; }
195 assert(p_context_ != NULL &&
bool(
"Logic error: Accessing dangling context from handle."));
204 OCL_TYPE tmp = other.h_;
209 other.p_context_ = this->p_context_;
210 this->p_context_ = tmp2;
This file provides the forward declarations for the OpenCL layer of ViennaCL.
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Helper for OpenCL reference counting used by class handle.
handle(const handle &other)
viennacl::ocl::context const & context() const
#define VIENNACL_ERR_CHECK(err)
handle & operator=(std::pair< OCL_TYPE, cl_context > p)
Wraps an OpenCL handle including its associated context. Decreases the reference count if the handle ...
void context(viennacl::ocl::context const &c)
void inc()
Manually increment the OpenCL reference count. Typically called automatically, but is necessary if us...
void dec()
Manually decrement the OpenCL reference count. Typically called automatically, but might be useful wi...
handle & operator=(const OCL_TYPE &something)
Wraps an OpenCL handle. Does not change the context of this handle object! Decreases the reference co...
Error handling for the OpenCL layer of ViennaCL.
handle & swap(handle &other)
Swaps the OpenCL handle of two handle objects.
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).
viennacl::backend::mem_handle const & handle(T const &obj)
Returns the generic memory handle of an object. Const-version.
Handle class the effectively represents a smart pointer for OpenCL handles.
handle(const OCL_TYPE &something, viennacl::ocl::context const &c)