go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkOpenCLMemoryObject.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright UMC Utrecht and contributors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkOpenCLMemoryObject_h
19#define itkOpenCLMemoryObject_h
20
21#include "itkOpenCLEventList.h"
22#include "itkOpenCLSize.h"
23#include "itkPoint.h"
24
25namespace itk
26{
35// Forward declaration
36class OpenCLContext;
37
39{
40protected:
43 : m_Context(context)
44 , m_Id(0)
45 {}
46
50 OpenCLMemoryObject(OpenCLContext * context, const cl_mem id)
51 : m_Context(context)
52 , m_Id(id)
53 {}
54
61
62public:
65 using RectangleType = Size<4>;
66 using PointType = Point<std::size_t, 2>;
67 using SizeType = Size<2>;
68
86 enum Access
87 {
88 ReadWrite = 0x0001,
89 WriteOnly = 0x0002,
90 ReadOnly = 0x0004
91 };
92
94 bool
95 IsNull() const
96 {
97 return this->m_Id == 0;
98 }
99
101 cl_mem
103 {
104 return this->m_Id;
105 }
106
110 {
111 return this->m_Context;
112 }
113
115 cl_mem_object_type
117
119 cl_mem_flags
120 GetFlags() const;
121
123 std::size_t
124 GetSize() const;
125
128 void *
130
134 cl_uint
135 GetMapCount() const;
136
140 cl_uint
142
145 GetAccess() const;
146
151 void
152 Unmap(void * ptr, const bool wait = false);
153
160 UnmapAsync(void * ptr, const OpenCLEventList & event_list = OpenCLEventList());
161
172 cl_int
173 SetDestructorCallback(void(CL_CALLBACK * pfn_notify)(cl_mem, void *), void * user_data = nullptr);
174
175protected:
177 void
178 SetId(OpenCLContext * context, const cl_mem id);
179
181 cl_map_flags
183
184private:
186 cl_mem m_Id;
187
188 OpenCLMemoryObject(const Self & other) = delete;
189 const Self &
190 operator=(const Self &) = delete;
191};
192
198
204
206template <typename charT, typename traits>
207inline std::basic_ostream<charT, traits> &
208operator<<(std::basic_ostream<charT, traits> & strm, const OpenCLMemoryObject & memoryObject)
209{
210 if (memoryObject.IsNull())
211 {
212 strm << "OpenCLMemoryObject(null)";
213 return strm;
214 }
215
216 const char indent = ' ';
217
218 strm << "OpenCLMemoryObject\n"
219 << indent << "Id: " << memoryObject.GetMemoryId() << '\n'
220 << indent << "Context: " << memoryObject.GetContext() << '\n'
221 << indent << "Memory type: " << memoryObject.GetMemoryType() << '\n'
222 << indent << "Flags: " << memoryObject.GetFlags() << '\n'
223 << indent << "Size: " << memoryObject.GetSize() << '\n'
224 << indent << "Map count: " << memoryObject.GetMapCount() << '\n'
225 << indent << "Reference count: " << memoryObject.GetReferenceCount() << '\n'
226 << indent << "Host pointer: " << memoryObject.GetHostPointer() << '\n'
227 << indent << "Access: ";
228
229 switch (memoryObject.GetAccess())
230 {
232 strm << "Read Write";
233 break;
235 strm << "Write Only";
236 break;
238 strm << "Read Only";
239 break;
240 default:
241 strm << "Unknown";
242 break;
243 }
244
245 strm << std::endl;
246
247 return strm;
248}
249
250
251} // end namespace itk
252
253#endif /* itkOpenCLMemoryObject_h */
The OpenCLContext class represents an OpenCL context.
OpenCLEventList class represents a list of OpenCLEvent objects.
OpenCLEvent class represents an OpenCL event object.
The OpenCLMemoryObject class represents all common memory objects such as buffers and image objects.
cl_int SetDestructorCallback(void(CL_CALLBACK *pfn_notify)(cl_mem, void *), void *user_data=nullptr)
cl_uint GetMapCount() const
void SetId(OpenCLContext *context, const cl_mem id)
cl_map_flags GetMapFlags(const OpenCLMemoryObject::Access access)
OpenCLMemoryObject(OpenCLContext *context=0)
const Self & operator=(const Self &)=delete
OpenCLMemoryObject(const Self &other)=delete
cl_mem_object_type GetMemoryType() const
OpenCLMemoryObject(OpenCLContext *context, const cl_mem id)
cl_mem_flags GetFlags() const
cl_uint GetReferenceCount() const
Point< std::vcl_size_t, 2 > PointType
OpenCLEvent UnmapAsync(void *ptr, const OpenCLEventList &event_list=OpenCLEventList())
OpenCLContext * GetContext() const
std::vcl_size_t GetSize() const
OpenCLMemoryObject::Access GetAccess() const
void * GetHostPointer() const
void Unmap(void *ptr, const bool wait=false)
#define ITKOpenCL_EXPORT
bool ITKOpenCL_EXPORT operator==(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
bool ITKOpenCL_EXPORT operator!=(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &strm, const OpenCLCommandQueue &queue)


Generated on 2023-01-13 for elastix by doxygen 1.9.6 elastix logo