go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkOpenCLEvent.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 itkOpenCLEvent_h
19#define itkOpenCLEvent_h
20
21#include "itkOpenCL.h"
22#include "itkOpenCLExtension.h"
23#include <ostream>
24
25namespace itk
26{
89// Forward declaration
90class OpenCLUserEvent;
91
93{
94public:
97
100
104 OpenCLEvent(const cl_event id);
105
108 OpenCLEvent(const OpenCLEvent & other);
109
112
117 operator=(const OpenCLEvent & other);
118
120 bool
121 IsNull() const
122 {
123 return this->m_Id == 0;
124 }
125
127 cl_event
129 {
130 return this->m_Id;
131 }
132
137 bool
138 IsQueued() const
139 {
140 return GetStatus() == CL_QUEUED;
141 }
142
146 bool
148 {
149 return GetStatus() == CL_SUBMITTED;
150 }
151
155 bool
156 IsRunning() const
157 {
158 return GetStatus() == CL_RUNNING;
159 }
160
164 bool
166 {
167 return GetStatus() == CL_COMPLETE;
168 }
169
172 bool
173 IsError() const
174 {
175 return GetStatus() < 0;
176 }
177
181 cl_int
182 GetStatus() const;
183
185 cl_command_type
187
192 cl_int
194
203 cl_int
204 SetCallback(cl_int type, void(CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), void * user_data = nullptr);
205
210 cl_ulong
212
217 cl_ulong
219
224 cl_ulong
225 GetRunTime() const;
226
231 cl_ulong
233
234private:
235 cl_event m_Id;
236
238 friend class OpenCLUserEvent;
239};
240
245 operator==(const OpenCLEvent & lhs, const OpenCLEvent & rhs);
246
251 operator!=(const OpenCLEvent & lhs, const OpenCLEvent & rhs);
252
254template <typename charT, typename traits>
255inline std::basic_ostream<charT, traits> &
256operator<<(std::basic_ostream<charT, traits> & strm, const OpenCLEvent & event)
257{
258 const cl_event id = event.GetEventId();
259
260 if (!id)
261 {
262 strm << "OpenCLEvent()";
263 return strm;
264 }
265
266 const cl_command_type command = event.GetCommandType();
267 const cl_int status = event.GetStatus();
268
269 // Get command name, check for clGetEventInfo() specification
270 const char * commandName;
271 switch (command)
272 {
273 case CL_COMMAND_NDRANGE_KERNEL:
274 commandName = "clEnqueueNDRangeKernel";
275 break;
276 case CL_COMMAND_TASK:
277 commandName = "clEnqueueTask";
278 break;
279 case CL_COMMAND_NATIVE_KERNEL:
280 commandName = "clEnqueueNativeKernel";
281 break;
282 case CL_COMMAND_READ_BUFFER:
283 commandName = "clEnqueueReadBuffer";
284 break;
285 case CL_COMMAND_WRITE_BUFFER:
286 commandName = "clEnqueueWriteBuffer";
287 break;
288 case CL_COMMAND_COPY_BUFFER:
289 commandName = "clEnqueueCopyBuffer";
290 break;
291 case CL_COMMAND_READ_IMAGE:
292 commandName = "clEnqueueReadImage";
293 break;
294 case CL_COMMAND_WRITE_IMAGE:
295 commandName = "clEnqueueWriteImage";
296 break;
297 case CL_COMMAND_COPY_IMAGE:
298 commandName = "clEnqueueCopyImage";
299 break;
300 case CL_COMMAND_COPY_IMAGE_TO_BUFFER:
301 commandName = "clEnqueueCopyImageToBuffer";
302 break;
303 case CL_COMMAND_COPY_BUFFER_TO_IMAGE:
304 commandName = "clEnqueueCopyBufferToImage";
305 break;
306 case CL_COMMAND_MAP_BUFFER:
307 commandName = "clEnqueueMapBuffer";
308 break;
309 case CL_COMMAND_MAP_IMAGE:
310 commandName = "clEnqueueMapImage";
311 break;
312 case CL_COMMAND_UNMAP_MEM_OBJECT:
313 commandName = "clEnqueueUnmapMemObject";
314 break;
315 case CL_COMMAND_MARKER:
316 commandName = "clEnqueueMarker";
317 break;
318 case CL_COMMAND_ACQUIRE_GL_OBJECTS:
319 commandName = "clEnqueueAcquireGLObjects";
320 break;
321 case CL_COMMAND_RELEASE_GL_OBJECTS:
322 commandName = "clEnqueueReleaseGLObjects";
323 break;
324 // OpenCL 1.1 event types.
325 case CL_COMMAND_READ_BUFFER_RECT:
326 commandName = "clEnqueueReadBufferRect";
327 break;
328 case CL_COMMAND_WRITE_BUFFER_RECT:
329 commandName = "clEnqueueWriteBufferRect";
330 break;
331 case CL_COMMAND_COPY_BUFFER_RECT:
332 commandName = "clEnqueueCopyBufferRect";
333 break;
334 case CL_COMMAND_USER:
335 commandName = "clCreateUserEvent";
336 break;
337 // OpenCL 1.2 event types.
339 commandName = "clEnqueueBarrierWithWaitList";
340 break;
342 commandName = "clEnqueueFillImage";
343 break;
345 commandName = "clEnqueueFillBuffer";
346 break;
348 commandName = "clEnqueueFillImage";
349 break;
350 default:
351 commandName = "Unknown";
352 break;
353 }
354
355 // Get command status
356 const char * statusName;
357 switch (status)
358 {
359 case CL_COMPLETE:
360 statusName = "completed";
361 break;
362 case CL_RUNNING:
363 statusName = "running";
364 break;
365 case CL_SUBMITTED:
366 statusName = "submitted";
367 break;
368 case CL_QUEUED:
369 statusName = "queued";
370 break;
371 default:
372 statusName = "Unknown";
373 break;
374 }
375 if (status != CL_COMPLETE)
376 {
377 // Command is not complete : no profiling information available yet.
378 strm << "OpenCLEvent(id:" << reinterpret_cast<long>(id) << " command:" << commandName << " status:" << statusName
379 << ")";
380 }
381 else
382 {
383 cl_ulong queueTime, runTime, finishTime;
384 if (clGetEventProfilingInfo(id, CL_PROFILING_COMMAND_QUEUED, sizeof(queueTime), &queueTime, 0) != CL_SUCCESS ||
385 clGetEventProfilingInfo(id, CL_PROFILING_COMMAND_START, sizeof(runTime), &runTime, 0) != CL_SUCCESS ||
386 clGetEventProfilingInfo(id, CL_PROFILING_COMMAND_END, sizeof(finishTime), &finishTime, 0) != CL_SUCCESS)
387 {
388 // Profiling information is not available, probably
389 // because it was not enabled on the command queue.
390 strm << "OpenCLEvent(id:" << reinterpret_cast<long>(id) << " command:" << commandName << " status:" << statusName
391 << ")";
392 }
393 else
394 {
395 // Include profiling information in the debug output.
396 const double fullDuration = (finishTime - queueTime) / 1000000.0f;
397 const double runDuration = (finishTime - runTime) / 1000000.0f;
398 strm << "OpenCLEvent(id:" << reinterpret_cast<long>(id) << " command:" << commandName << " status:" << statusName
399 << " full-time:" << fullDuration << " ms running-time:" << runDuration << "ms)";
400 }
401 }
402
403 return strm;
404}
405
406
407} // end namespace itk
408
409#endif /* itkOpenCLEvent_h */
OpenCLEvent class represents an OpenCL event object.
OpenCLEvent & operator=(const OpenCLEvent &other)
cl_ulong GetSubmitTime() const
bool IsComplete() const
bool IsSubmitted() const
cl_ulong GetFinishTime() const
cl_ulong GetRunTime() const
cl_command_type GetCommandType() const
cl_int WaitForFinished()
bool IsNull() const
bool IsQueued() const
cl_ulong GetQueueTime() const
bool IsError() const
OpenCLEvent(const OpenCLEvent &other)
OpenCLEvent(const cl_event id)
cl_int SetCallback(cl_int type, void(CL_CALLBACK *pfn_notify)(cl_event, cl_int, void *), void *user_data=nullptr)
cl_int GetStatus() const
bool IsRunning() const
cl_event GetEventId() const
The OpenCLUserEvent class represents OpenCL user events.
#define ITKOpenCL_EXPORT
#define CL_COMMAND_FILL_IMAGE
#define CL_COMMAND_MIGRATE_MEM_OBJECTS
#define CL_COMMAND_BARRIER
#define CL_COMMAND_FILL_BUFFER
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 2023-01-13 for elastix by doxygen 1.9.6 elastix logo