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
25namespace itk
26{
46// Forward declaration
47class OpenCLDevice;
48
50{
51public:
52
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
159private:
160
161 cl_uint m_Dim;
162 std::size_t m_Sizes[ 3 ];
163};
164
167bool ITKOpenCL_EXPORT operator==( const OpenCLSize & lhs, const OpenCLSize & rhs );
168
171bool ITKOpenCL_EXPORT operator!=( const OpenCLSize & lhs, const OpenCLSize & rhs );
172
174template< typename charT, typename traits >
175inline
176std::basic_ostream< charT, traits > &
177operator<<( 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 */
The OpenCLDevice class represents the collection of OpenCL devices to be used by the host.
The OpenCLSize class defines the size of an item of work for an OpenCL kernel.
Definition: itkOpenCLSize.h:50
const std::vcl_size_t * GetSizes() const
OpenCLSize(const SizeType2D &size)
OpenCLSize(const std::vcl_size_t width, const std::vcl_size_t height, const std::vcl_size_t depth)
Definition: itkOpenCLSize.h:89
OpenCLSize Self
Definition: itkOpenCLSize.h:54
OpenCLSize(const SizeType1D &size)
Definition: itkOpenCLSize.h:96
static OpenCLSize GetLocalWorkSize(const OpenCLDevice &device)
Size< 1 > SizeType1D
Definition: itkOpenCLSize.h:56
static OpenCLSize GetLocalWorkSize(const OpenCLSize &maxWorkItemSize, const std::vcl_size_t maxItemsPerGroup)
OpenCLSize(const Null &)
Definition: itkOpenCLSize.h:63
static const Null null
Definition: itkOpenCLSize.h:62
OpenCLSize(const std::vcl_size_t size)
Definition: itkOpenCLSize.h:78
OpenCLSize RoundTo(const OpenCLSize &size) const
OpenCLSize & operator=(const Null &)
Definition: itkOpenCLSize.h:67
std::vcl_size_t GetDepth() const
cl_uint GetDimension() const
Size< 3 > SizeType3D
Definition: itkOpenCLSize.h:58
std::vcl_size_t & operator[](const std::vcl_size_t dim)
bool IsZero() const
OpenCLSize(const std::vcl_size_t width, const std::vcl_size_t height)
Definition: itkOpenCLSize.h:84
bool IsNull() const
Definition: itkOpenCLSize.h:68
std::vcl_size_t GetHeight() const
OpenCLSize(const SizeType3D &size)
std::vcl_size_t operator[](const std::vcl_size_t dim) const
std::vcl_size_t GetWidth() const
Size< 2 > SizeType2D
Definition: itkOpenCLSize.h:57
#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 1667476801 for elastix by doxygen 1.9.4 elastix logo