go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkOpenCLSize.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 __itkOpenCLWorkSize_h
19 #define __itkOpenCLWorkSize_h
20 
21 #include "itkOpenCL.h"
22 #include "itkSize.h"
23 #include <string>
24 
25 namespace itk
26 {
46 // Forward declaration
47 class OpenCLDevice;
48 
50 {
51 public:
52 
54  typedef OpenCLSize Self;
55 
56  typedef Size< 1 > SizeType1D;
57  typedef Size< 2 > SizeType2D;
58  typedef Size< 3 > SizeType3D;
59 
61  struct Null {};
62  static const Null null;
63  OpenCLSize( const Null & ) :
64  m_Dim( 0 )
65  { this->m_Sizes[ 0 ] = 0; this->m_Sizes[ 1 ] = 0; this->m_Sizes[ 2 ] = 0; }
66 
67  OpenCLSize & operator=( const Null & ) { *this = OpenCLSize( null ); return *this; }
68  bool IsNull() const { return m_Dim == 0; }
69 
73  m_Dim( 1 )
74  { this->m_Sizes[ 0 ] = 1; this->m_Sizes[ 1 ] = 1; this->m_Sizes[ 2 ] = 1; }
75 
78  OpenCLSize( const std::size_t size ) :
79  m_Dim( 1 )
80  { this->m_Sizes[ 0 ] = size; this->m_Sizes[ 1 ] = 1; this->m_Sizes[ 2 ] = 1; }
81 
84  OpenCLSize( const std::size_t width, const std::size_t height ) :
85  m_Dim( 2 )
86  { this->m_Sizes[ 0 ] = width; this->m_Sizes[ 1 ] = height; this->m_Sizes[ 2 ] = 1; }
87 
89  OpenCLSize( const std::size_t width, const std::size_t height, const std::size_t depth ) :
90  m_Dim( 3 )
91  { this->m_Sizes[ 0 ] = width; this->m_Sizes[ 1 ] = height; this->m_Sizes[ 2 ] = depth; }
92 
96  OpenCLSize( const SizeType1D & size ) :
97  m_Dim( 1 )
98  { this->m_Sizes[ 0 ] = size[ 0 ]; this->m_Sizes[ 1 ] = 1; this->m_Sizes[ 2 ] = 1; }
99 
103  OpenCLSize( const SizeType2D & size ) :
104  m_Dim( 2 )
105  { this->m_Sizes[ 0 ] = size[ 0 ]; this->m_Sizes[ 1 ] = size[ 1 ]; this->m_Sizes[ 2 ] = 1; }
106 
109  OpenCLSize( const SizeType3D & size ) :
110  m_Dim( 3 )
111  { this->m_Sizes[ 0 ] = size[ 0 ]; this->m_Sizes[ 1 ] = size[ 1 ]; this->m_Sizes[ 2 ] = size[ 2 ]; }
112 
114  cl_uint GetDimension() const { return m_Dim; }
115 
117  std::size_t GetWidth() const { return this->m_Sizes[ 0 ]; }
118 
120  std::size_t GetHeight() const { return this->m_Sizes[ 1 ]; }
121 
123  std::size_t GetDepth() const { return this->m_Sizes[ 2 ]; }
124 
126  const std::size_t * GetSizes() const { return this->m_Sizes; }
127 
129  bool IsZero() const;
130 
133  std::size_t & operator[]( const std::size_t dim )
134  { return this->m_Sizes[ dim ]; }
135 
139  std::size_t operator[]( const std::size_t dim ) const
140  { return this->m_Sizes[ dim ]; }
141 
147  static OpenCLSize GetLocalWorkSize( const OpenCLSize & maxWorkItemSize,
148  const std::size_t maxItemsPerGroup );
149 
154  static OpenCLSize GetLocalWorkSize( const OpenCLDevice & device );
155 
157  OpenCLSize RoundTo( const OpenCLSize & size ) const;
158 
159 private:
160 
161  cl_uint m_Dim;
162  std::size_t m_Sizes[ 3 ];
163 };
164 
167 bool ITKOpenCL_EXPORT operator==( const OpenCLSize & lhs, const OpenCLSize & rhs );
168 
171 bool ITKOpenCL_EXPORT operator!=( const OpenCLSize & lhs, const OpenCLSize & rhs );
172 
174 template< typename charT, typename traits >
175 inline
176 std::basic_ostream< charT, traits > &
177 operator<<( std::basic_ostream< charT, traits > & strm,
178  const OpenCLSize & size )
179 {
180  const cl_uint dim = size.GetDimension();
181 
182  if( dim == 0 )
183  {
184  strm << "OpenCLSize(null)";
185  }
186  else if( dim == 1 )
187  {
188  strm << "OpenCLSize(" << size.GetWidth() << ')';
189  }
190  else if( dim == 2 )
191  {
192  strm << "OpenCLSize(" << size.GetWidth() << ", " << size.GetHeight() << ')';
193  }
194  else
195  {
196  strm << "OpenCLSize(" << size.GetWidth() << ", " << size.GetHeight() << ", " << size.GetDepth() << ')';
197  }
198  return strm;
199 }
200 
201 
202 } // end namespace itk
203 
204 #endif /* __itkOpenCLWorkSize_h */
OpenCLSize(const std::vcl_size_t width, const std::vcl_size_t height)
Definition: itkOpenCLSize.h:84
OpenCLSize(const std::vcl_size_t width, const std::vcl_size_t height, const std::vcl_size_t depth)
Definition: itkOpenCLSize.h:89
std::vcl_size_t & operator[](const std::vcl_size_t dim)
std::vcl_size_t GetDepth() const
std::vcl_size_t operator[](const std::vcl_size_t dim) const
OpenCLSize(const SizeType1D &size)
Definition: itkOpenCLSize.h:96
const std::vcl_size_t * GetSizes() const
The OpenCLSize class defines the size of an item of work for an OpenCL kernel.
Definition: itkOpenCLSize.h:49
static const Null null
Definition: itkOpenCLSize.h:62
cl_uint GetDimension() const
std::vcl_size_t GetWidth() const
bool IsNull() const
Definition: itkOpenCLSize.h:68
bool ITKOpenCL_EXPORT operator==(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
OpenCLSize Self
Definition: itkOpenCLSize.h:54
OpenCLSize(const Null &)
Definition: itkOpenCLSize.h:63
bool ITKOpenCL_EXPORT operator!=(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
OpenCLSize(const std::vcl_size_t size)
Definition: itkOpenCLSize.h:78
Size< 2 > SizeType2D
Definition: itkOpenCLSize.h:57
The OpenCLDevice class represents the collection of OpenCL devices to be used by the host...
#define ITKOpenCL_EXPORT
std::vcl_size_t GetHeight() const
OpenCLSize & operator=(const Null &)
Definition: itkOpenCLSize.h:67
OpenCLSize(const SizeType3D &size)
Size< 1 > SizeType1D
Definition: itkOpenCLSize.h:56
OpenCLSize(const SizeType2D &size)
Size< 3 > SizeType3D
Definition: itkOpenCLSize.h:58


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