Voxel
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
opencl_deleter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef OPENCL_DELETER_H
4 #define OPENCL_DELETER_H
5 
6 
7 /**
8  \file
9  \brief Contains OpenCL::Deleter class.
10 */
11 
12 
13 
14 
15 #include "settings.h"
16 
17 
18 
19 
20 #if ( SETTING_OPENCL != 0 )
21 
22 
23 
24 
25 #include "opencl_exception.h"
26 
27 #include <CL/cl.h>
28 
29 
30 
31 
32 namespace OpenCL {
33 
34 
35 
36 
37 /*==============================================================================
38  Deleter class
39 ==============================================================================*/
40 
41 
42 /**
43  \brief A deleter class for OpenCL objects, for use in stl smart pointers.
44 
45  \param t_Type OpenCL pointee type.
46 
47  Specializations of this class contain a single method, <tt>operator()</tt>,
48  which passes the given <tt>t_Type*</tt> through to the appropriate OpenCL
49  function. For example, for memory objects, <tt?t_Type = _cl_mem</tt> (the
50  more familiar <tt>cl_mem</tt> is simply <tt>_cl_mem*</tt>), and
51  <tt>Deleter< _cl_mem >::operator()</tt> will call
52  <tt>clReleaseMemObject</tt>.
53 */
54 template< typename t_Type >
55 struct Deleter;
56 
57 
58 
59 
60 /*==============================================================================
61  Deleter specializations
62 ==============================================================================*/
63 
64 
65 /**
66  \brief Deleter specialization for OpenCL contexts.
67 
68  \see \ref Deleter
69 */
70 template<>
71 struct Deleter< _cl_context > {
72 
73  inline void operator()( _cl_context* const pointer ) {
74 
75  if ( pointer != NULL )
76  CHECK_OPENCL( clReleaseContext( pointer ) );
77  }
78 };
79 
80 
81 /**
82  \brief Deleter specialization for OpenCL command queues.
83 
84  \see \ref Deleter
85 */
86 template<>
87 struct Deleter< _cl_command_queue > {
88 
89  inline void operator()( _cl_command_queue* const pointer ) {
90 
91  if ( pointer != NULL )
92  CHECK_OPENCL( clReleaseCommandQueue( pointer ) );
93  }
94 };
95 
96 
97 /**
98  \brief Deleter specialization for OpenCL memory objects.
99 
100  \see \ref Deleter
101 */
102 template<>
103 struct Deleter< _cl_mem > {
104 
105  inline void operator()( _cl_mem* const pointer ) {
106 
107  if ( pointer != NULL )
108  CHECK_OPENCL( clReleaseMemObject( pointer ) );
109  }
110 };
111 
112 
113 /**
114  \brief Deleter specialization for OpenCL samplers.
115 
116  \see \ref Deleter
117 */
118 template<>
119 struct Deleter< _cl_sampler > {
120 
121  inline void operator()( _cl_sampler* const pointer ) {
122 
123  if ( pointer != NULL )
124  CHECK_OPENCL( clReleaseSampler( pointer ) );
125  }
126 };
127 
128 
129 /**
130  \brief Deleter specialization for OpenCL programs.
131 
132  \see \ref Deleter
133 */
134 template<>
135 struct Deleter< _cl_program > {
136 
137  inline void operator()( _cl_program* const pointer ) {
138 
139  if ( pointer != NULL )
140  CHECK_OPENCL( clReleaseProgram( pointer ) );
141  }
142 };
143 
144 
145 /**
146  \brief Deleter specialization for OpenCL kernels.
147 
148  \see \ref Deleter
149 */
150 template<>
151 struct Deleter< _cl_kernel > {
152 
153  inline void operator()( _cl_kernel* const pointer ) {
154 
155  if ( pointer != NULL )
156  CHECK_OPENCL( clReleaseKernel( pointer ) );
157  }
158 };
159 
160 
161 /**
162  \brief Deleter specialization for OpenCL events.
163 
164  \see \ref Deleter
165 */
166 template<>
167 struct Deleter< _cl_event > {
168 
169  inline void operator()( _cl_event* const pointer ) {
170 
171  if ( pointer != NULL )
172  CHECK_OPENCL( clReleaseEvent( pointer ) );
173  }
174 };
175 
176 
177 
178 
179 } // namespace OpenCL
180 
181 
182 
183 
184 #endif // SETTING_OPENCL
185 
186 
187 
188 
189 #endif // OPENCL_DELETER_H