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;
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)
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
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)