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 
25 namespace itk
26 {
35 // Forward declaration
36 class OpenCLContext;
37 
39 {
40 protected:
41 
43  OpenCLMemoryObject( OpenCLContext * context = 0 ) : m_Context( context ), m_Id( 0 ) {}
44 
48  OpenCLMemoryObject( OpenCLContext * context, const cl_mem id ) :
49  m_Context( context ), m_Id( id ) {}
50 
57 
58 public:
59 
62  typedef Size< 4 > RectangleType;
63  typedef Point< std::size_t, 2 > PointType;
64  typedef Size< 2 > SizeType;
65 
83  enum Access {
84  ReadWrite = 0x0001,
85  WriteOnly = 0x0002,
86  ReadOnly = 0x0004
87  };
88 
90  bool IsNull() const { return this->m_Id == 0; }
91 
93  cl_mem GetMemoryId() const { return this->m_Id; }
94 
96  OpenCLContext * GetContext() const { return this->m_Context; }
97 
99  cl_mem_object_type GetMemoryType() const;
100 
102  cl_mem_flags GetFlags() const;
103 
105  std::size_t GetSize() const;
106 
109  void * GetHostPointer() const;
110 
114  cl_uint GetMapCount() const;
115 
119  cl_uint GetReferenceCount() const;
120 
122  OpenCLMemoryObject::Access GetAccess() const;
123 
128  void Unmap( void * ptr, const bool wait = false );
129 
135  OpenCLEvent UnmapAsync( void * ptr, const OpenCLEventList & event_list = OpenCLEventList() );
136 
147  cl_int SetDestructorCallback(
148  void( CL_CALLBACK * pfn_notify )( cl_mem, void * ),
149  void * user_data = NULL );
150 
151 protected:
152 
154  void SetId( OpenCLContext * context, const cl_mem id );
155 
157  cl_map_flags GetMapFlags( const OpenCLMemoryObject::Access access );
158 
159 private:
160 
162  cl_mem m_Id;
163 
164  OpenCLMemoryObject( const Self & other ); // purposely not implemented
165  const Self & operator=( const Self & ); // purposely not implemented
166 
167 };
168 
172 bool ITKOpenCL_EXPORT operator==( const OpenCLMemoryObject & lhs, const OpenCLMemoryObject & rhs );
173 
177 bool ITKOpenCL_EXPORT operator!=( const OpenCLMemoryObject & lhs, const OpenCLMemoryObject & rhs );
178 
180 template< typename charT, typename traits >
181 inline
182 std::basic_ostream< charT, traits > &
183 operator<<( std::basic_ostream< charT, traits > & strm,
184  const OpenCLMemoryObject & memoryObject )
185 {
186  if( memoryObject.IsNull() )
187  {
188  strm << "OpenCLMemoryObject(null)";
189  return strm;
190  }
191 
192  const char indent = ' ';
193 
194  strm << "OpenCLMemoryObject" << std::endl
195  << indent << "Id: " << memoryObject.GetMemoryId() << std::endl
196  << indent << "Context: " << memoryObject.GetContext() << std::endl
197  << indent << "Memory type: " << memoryObject.GetMemoryType() << std::endl
198  << indent << "Flags: " << memoryObject.GetFlags() << std::endl
199  << indent << "Size: " << memoryObject.GetSize() << std::endl
200  << indent << "Map count: " << memoryObject.GetMapCount() << std::endl
201  << indent << "Reference count: " << memoryObject.GetReferenceCount() << std::endl
202  << indent << "Host pointer: " << memoryObject.GetHostPointer() << std::endl
203  << indent << "Access: ";
204 
205  switch( memoryObject.GetAccess() )
206  {
208  strm << "Read Write"; break;
210  strm << "Write Only"; break;
212  strm << "Read Only"; break;
213  default:
214  strm << "Unknown"; break;
215  }
216 
217  strm << std::endl;
218 
219  return strm;
220 }
221 
222 
223 } // end namespace itk
224 
225 #endif /* __itkOpenCLMemoryObject_h */
OpenCLEventList class represents a list of OpenCLEvent objects.
Point< std::vcl_size_t, 2 > PointType
OpenCLMemoryObject(OpenCLContext *context, const cl_mem id)
The OpenCLContext class represents an OpenCL context.
OpenCLContext * GetContext() const
bool ITKOpenCL_EXPORT operator==(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
bool ITKOpenCL_EXPORT operator!=(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
OpenCLMemoryObject(OpenCLContext *context=0)
The OpenCLMemoryObject class represents all common memory objects such as buffers and image objects...
#define ITKOpenCL_EXPORT
OpenCLEvent class represents an OpenCL event object.


Generated on 04-09-2015 for elastix by doxygen 1.8.9.1 elastix logo