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:
54
55 using SizeType1D = Size<1>;
56 using SizeType2D = Size<2>;
57 using SizeType3D = Size<3>;
58
60 struct Null
61 {};
62 static const Null null;
64 : m_Dim(0)
65 {
66 this->m_Sizes[0] = 0;
67 this->m_Sizes[1] = 0;
68 this->m_Sizes[2] = 0;
69 }
70
72 operator=(const Null &)
73 {
74 *this = OpenCLSize(null);
75 return *this;
76 }
77 bool
78 IsNull() const
79 {
80 return m_Dim == 0;
81 }
82
86 : m_Dim(1)
87 {
88 this->m_Sizes[0] = 1;
89 this->m_Sizes[1] = 1;
90 this->m_Sizes[2] = 1;
91 }
92
95 OpenCLSize(const std::size_t size)
96 : m_Dim(1)
97 {
98 this->m_Sizes[0] = size;
99 this->m_Sizes[1] = 1;
100 this->m_Sizes[2] = 1;
101 }
102
105 OpenCLSize(const std::size_t width, const std::size_t height)
106 : m_Dim(2)
107 {
108 this->m_Sizes[0] = width;
109 this->m_Sizes[1] = height;
110 this->m_Sizes[2] = 1;
111 }
112
114 OpenCLSize(const std::size_t width, const std::size_t height, const std::size_t depth)
115 : m_Dim(3)
116 {
117 this->m_Sizes[0] = width;
118 this->m_Sizes[1] = height;
119 this->m_Sizes[2] = depth;
120 }
121
125 OpenCLSize(const SizeType1D & size)
126 : m_Dim(1)
127 {
128 this->m_Sizes[0] = size[0];
129 this->m_Sizes[1] = 1;
130 this->m_Sizes[2] = 1;
131 }
132
136 OpenCLSize(const SizeType2D & size)
137 : m_Dim(2)
138 {
139 this->m_Sizes[0] = size[0];
140 this->m_Sizes[1] = size[1];
141 this->m_Sizes[2] = 1;
142 }
143
146 OpenCLSize(const SizeType3D & size)
147 : m_Dim(3)
148 {
149 this->m_Sizes[0] = size[0];
150 this->m_Sizes[1] = size[1];
151 this->m_Sizes[2] = size[2];
152 }
153
155 cl_uint
157 {
158 return m_Dim;
159 }
160
162 std::size_t
163 GetWidth() const
164 {
165 return this->m_Sizes[0];
166 }
167
169 std::size_t
170 GetHeight() const
171 {
172 return this->m_Sizes[1];
173 }
174
176 std::size_t
177 GetDepth() const
178 {
179 return this->m_Sizes[2];
180 }
181
183 const std::size_t *
184 GetSizes() const
185 {
186 return this->m_Sizes;
187 }
188
190 bool
191 IsZero() const;
192
195 std::size_t & operator[](const std::size_t dim) { return this->m_Sizes[dim]; }
196
200 std::size_t operator[](const std::size_t dim) const { return this->m_Sizes[dim]; }
201
207 static OpenCLSize
208 GetLocalWorkSize(const OpenCLSize & maxWorkItemSize, const std::size_t maxItemsPerGroup);
209
214 static OpenCLSize
216
219 RoundTo(const OpenCLSize & size) const;
220
221private:
222 cl_uint m_Dim;
223 std::size_t m_Sizes[3];
224};
225
229 operator==(const OpenCLSize & lhs, const OpenCLSize & rhs);
230
234 operator!=(const OpenCLSize & lhs, const OpenCLSize & rhs);
235
237template <typename charT, typename traits>
238inline std::basic_ostream<charT, traits> &
239operator<<(std::basic_ostream<charT, traits> & strm, const OpenCLSize & size)
240{
241 const cl_uint dim = size.GetDimension();
242
243 if (dim == 0)
244 {
245 strm << "OpenCLSize(null)";
246 }
247 else if (dim == 1)
248 {
249 strm << "OpenCLSize(" << size.GetWidth() << ')';
250 }
251 else if (dim == 2)
252 {
253 strm << "OpenCLSize(" << size.GetWidth() << ", " << size.GetHeight() << ')';
254 }
255 else
256 {
257 strm << "OpenCLSize(" << size.GetWidth() << ", " << size.GetHeight() << ", " << size.GetDepth() << ')';
258 }
259 return strm;
260}
261
262
263} // end namespace itk
264
265#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.
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)
OpenCLSize(const SizeType1D &size)
static OpenCLSize GetLocalWorkSize(const OpenCLDevice &device)
static OpenCLSize GetLocalWorkSize(const OpenCLSize &maxWorkItemSize, const std::vcl_size_t maxItemsPerGroup)
OpenCLSize(const Null &)
static const Null null
OpenCLSize(const std::vcl_size_t size)
OpenCLSize RoundTo(const OpenCLSize &size) const
OpenCLSize & operator=(const Null &)
std::vcl_size_t GetDepth() const
cl_uint GetDimension() const
Size< 3 > SizeType3D
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)
Size< 2 > SizeType2D
bool IsNull() const
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< 1 > SizeType1D
#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 2024-07-17 for elastix by doxygen 1.11.0 (9b424b03c9833626cd435af22a444888fbbb192d) elastix logo