go home Home | Main Page | Topics | 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{
45
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 &
196 operator[](const std::size_t dim)
197 {
198 return this->m_Sizes[dim];
199 }
200
204 std::size_t
205 operator[](const std::size_t dim) const
206 {
207 return this->m_Sizes[dim];
208 }
209
215 static OpenCLSize
216 GetLocalWorkSize(const OpenCLSize & maxWorkItemSize, const std::size_t maxItemsPerGroup);
217
222 static OpenCLSize
224
227 RoundTo(const OpenCLSize & size) const;
228
229private:
230 cl_uint m_Dim;
231 std::size_t m_Sizes[3];
232};
233
237operator==(const OpenCLSize & lhs, const OpenCLSize & rhs);
238
242operator!=(const OpenCLSize & lhs, const OpenCLSize & rhs);
243
245template <typename charT, typename traits>
246inline std::basic_ostream<charT, traits> &
247operator<<(std::basic_ostream<charT, traits> & strm, const OpenCLSize & size)
248{
249 const cl_uint dim = size.GetDimension();
250
251 if (dim == 0)
252 {
253 strm << "OpenCLSize(null)";
254 }
255 else if (dim == 1)
256 {
257 strm << "OpenCLSize(" << size.GetWidth() << ')';
258 }
259 else if (dim == 2)
260 {
261 strm << "OpenCLSize(" << size.GetWidth() << ", " << size.GetHeight() << ')';
262 }
263 else
264 {
265 strm << "OpenCLSize(" << size.GetWidth() << ", " << size.GetHeight() << ", " << size.GetDepth() << ')';
266 }
267 return strm;
268}
269
270
271} // end namespace itk
272
273#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
std::vcl_size_t m_Sizes[3]
bool IsNull() const
std::vcl_size_t GetHeight() const
OpenCLSize Self
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 26-02-2026 for elastix by doxygen 1.16.1 (669aeeefca743c148e2d935b3d3c69535c7491e6) elastix logo