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:
95
98
101
105 OpenCLEvent( const cl_event id );
106
109 OpenCLEvent( const OpenCLEvent & other );
110
113
118
120 bool IsNull() const { return this->m_Id == 0; }
121
123 cl_event GetEventId() const { return this->m_Id; }
124
129 bool IsQueued() const { return GetStatus() == CL_QUEUED; }
130
134 bool IsSubmitted() const { return GetStatus() == CL_SUBMITTED; }
135
139 bool IsRunning() const { return GetStatus() == CL_RUNNING; }
140
144 bool IsComplete() const { return GetStatus() == CL_COMPLETE; }
145
148 bool IsError() const { return GetStatus() < 0; }
149
153 cl_int GetStatus() const;
154
156 cl_command_type GetCommandType() const;
157
163
172 cl_int SetCallback( cl_int type,
173 void ( CL_CALLBACK * pfn_notify )( cl_event, cl_int, void * ),
174 void * user_data = nullptr );
175
180 cl_ulong GetQueueTime() const;
181
186 cl_ulong GetSubmitTime() const;
187
192 cl_ulong GetRunTime() const;
193
198 cl_ulong GetFinishTime() const;
199
200private:
201
202 cl_event m_Id;
203
205 friend class OpenCLUserEvent;
206};
207
211bool ITKOpenCL_EXPORT operator==( const OpenCLEvent & lhs, const OpenCLEvent & rhs );
212
216bool ITKOpenCL_EXPORT operator!=( const OpenCLEvent & lhs, const OpenCLEvent & rhs );
217
219template< typename charT, typename traits >
220inline
221std::basic_ostream< charT, traits > &
222operator<<( std::basic_ostream< charT, traits > & strm,
223 const OpenCLEvent & event )
224{
225 const cl_event id = event.GetEventId();
226
227 if( !id )
228 {
229 strm << "OpenCLEvent()";
230 return strm;
231 }
232
233 const cl_command_type command = event.GetCommandType();
234 const cl_int status = event.GetStatus();
235
236 // Get command name, check for clGetEventInfo() specification
237 const char * commandName;
238 switch( command )
239 {
240 case CL_COMMAND_NDRANGE_KERNEL:
241 commandName = "clEnqueueNDRangeKernel"; break;
242 case CL_COMMAND_TASK:
243 commandName = "clEnqueueTask"; break;
244 case CL_COMMAND_NATIVE_KERNEL:
245 commandName = "clEnqueueNativeKernel"; break;
246 case CL_COMMAND_READ_BUFFER:
247 commandName = "clEnqueueReadBuffer"; break;
248 case CL_COMMAND_WRITE_BUFFER:
249 commandName = "clEnqueueWriteBuffer"; break;
250 case CL_COMMAND_COPY_BUFFER:
251 commandName = "clEnqueueCopyBuffer"; break;
252 case CL_COMMAND_READ_IMAGE:
253 commandName = "clEnqueueReadImage"; break;
254 case CL_COMMAND_WRITE_IMAGE:
255 commandName = "clEnqueueWriteImage"; break;
256 case CL_COMMAND_COPY_IMAGE:
257 commandName = "clEnqueueCopyImage"; break;
258 case CL_COMMAND_COPY_IMAGE_TO_BUFFER:
259 commandName = "clEnqueueCopyImageToBuffer"; break;
260 case CL_COMMAND_COPY_BUFFER_TO_IMAGE:
261 commandName = "clEnqueueCopyBufferToImage"; break;
262 case CL_COMMAND_MAP_BUFFER:
263 commandName = "clEnqueueMapBuffer"; break;
264 case CL_COMMAND_MAP_IMAGE:
265 commandName = "clEnqueueMapImage"; break;
266 case CL_COMMAND_UNMAP_MEM_OBJECT:
267 commandName = "clEnqueueUnmapMemObject"; break;
268 case CL_COMMAND_MARKER:
269 commandName = "clEnqueueMarker"; break;
270 case CL_COMMAND_ACQUIRE_GL_OBJECTS:
271 commandName = "clEnqueueAcquireGLObjects"; break;
272 case CL_COMMAND_RELEASE_GL_OBJECTS:
273 commandName = "clEnqueueReleaseGLObjects"; break;
274 // OpenCL 1.1 event types.
275 case CL_COMMAND_READ_BUFFER_RECT:
276 commandName = "clEnqueueReadBufferRect"; break;
277 case CL_COMMAND_WRITE_BUFFER_RECT:
278 commandName = "clEnqueueWriteBufferRect"; break;
279 case CL_COMMAND_COPY_BUFFER_RECT:
280 commandName = "clEnqueueCopyBufferRect"; break;
281 case CL_COMMAND_USER:
282 commandName = "clCreateUserEvent"; break;
283 // OpenCL 1.2 event types.
285 commandName = "clEnqueueBarrierWithWaitList"; break;
287 commandName = "clEnqueueFillImage"; break;
289 commandName = "clEnqueueFillBuffer"; break;
291 commandName = "clEnqueueFillImage"; break;
292 default:
293 commandName = "Unknown"; break;
294 }
295
296 // Get command status
297 const char * statusName;
298 switch( status )
299 {
300 case CL_COMPLETE:
301 statusName = "completed"; break;
302 case CL_RUNNING:
303 statusName = "running"; break;
304 case CL_SUBMITTED:
305 statusName = "submitted"; break;
306 case CL_QUEUED:
307 statusName = "queued"; break;
308 default:
309 statusName = "Unknown"; break;
310 }
311 if( status != CL_COMPLETE )
312 {
313 // Command is not complete : no profiling information available yet.
314 strm << "OpenCLEvent(id:" << reinterpret_cast< long >( id )
315 << " command:" << commandName
316 << " status:" << statusName
317 << ")";
318 }
319 else
320 {
321 cl_ulong queueTime, runTime, finishTime;
322 if( clGetEventProfilingInfo
323 ( id, CL_PROFILING_COMMAND_QUEUED,
324 sizeof( queueTime ), &queueTime, 0 ) != CL_SUCCESS
325 || clGetEventProfilingInfo
326 ( id, CL_PROFILING_COMMAND_START,
327 sizeof( runTime ), &runTime, 0 ) != CL_SUCCESS
328 || clGetEventProfilingInfo
329 ( id, CL_PROFILING_COMMAND_END,
330 sizeof( finishTime ), &finishTime, 0 ) != CL_SUCCESS )
331 {
332 // Profiling information is not available, probably
333 // because it was not enabled on the command queue.
334 strm << "OpenCLEvent(id:" << reinterpret_cast< long >( id )
335 << " command:" << commandName
336 << " status:" << statusName
337 << ")";
338 }
339 else
340 {
341 // Include profiling information in the debug output.
342 const double fullDuration = ( finishTime - queueTime ) / 1000000.0f;
343 const double runDuration = ( finishTime - runTime ) / 1000000.0f;
344 strm << "OpenCLEvent(id:" << reinterpret_cast< long >( id )
345 << " command:" << commandName
346 << " status:" << statusName
347 << " full-time:" << fullDuration
348 << " ms running-time:" << runDuration
349 << "ms)";
350 }
351 }
352
353 return strm;
354}
355
356
357} // end namespace itk
358
359#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 Self
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 1667476801 for elastix by doxygen 1.9.4 elastix logo