Loading...
Searching...
No Matches
itkOpenCLEvent.h
Go to the documentation of this file.
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkOpenCLEvent_h
#define itkOpenCLEvent_h
#include "itkOpenCL.h"
#include "itkOpenCLExtension.h"
#include <ostream>
namespace itk
{
// Forward declaration
class OpenCLUserEvent;
class ITKOpenCL_EXPORT OpenCLEvent
{
public:
using Self = OpenCLEvent;
OpenCLEvent();
OpenCLEvent(const cl_event id);
OpenCLEvent(const OpenCLEvent & other);
~OpenCLEvent();
OpenCLEvent &
operator=(const OpenCLEvent & other);
bool
IsNull() const
{
return this->m_Id == 0;
}
cl_event
GetEventId() const
{
return this->m_Id;
}
bool
IsQueued() const
{
return GetStatus() == CL_QUEUED;
}
bool
IsSubmitted() const
{
return GetStatus() == CL_SUBMITTED;
}
bool
IsRunning() const
{
return GetStatus() == CL_RUNNING;
}
bool
IsComplete() const
{
return GetStatus() == CL_COMPLETE;
}
bool
IsError() const
{
return GetStatus() < 0;
}
cl_int
GetStatus() const;
cl_command_type
GetCommandType() const;
cl_int
WaitForFinished();
cl_int
SetCallback(cl_int type, void(CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), void * user_data = nullptr);
cl_ulong
GetQueueTime() const;
cl_ulong
GetSubmitTime() const;
cl_ulong
GetRunTime() const;
cl_ulong
GetFinishTime() const;
private:
cl_event m_Id;
friend class OpenCLUserEvent;
};
bool ITKOpenCL_EXPORT
operator==(const OpenCLEvent & lhs, const OpenCLEvent & rhs);
bool ITKOpenCL_EXPORT
operator!=(const OpenCLEvent & lhs, const OpenCLEvent & rhs);
template <typename charT, typename traits>
inline std::basic_ostream<charT, traits> &
operator<<(std::basic_ostream<charT, traits> & strm, const OpenCLEvent & event)
{
const cl_event id = event.GetEventId();
if (!id)
{
strm << "OpenCLEvent()";
return strm;
}
const cl_command_type command = event.GetCommandType();
const cl_int status = event.GetStatus();
// Get command name, check for clGetEventInfo() specification
const char * commandName;
switch (command)
{
case CL_COMMAND_NDRANGE_KERNEL:
commandName = "clEnqueueNDRangeKernel";
break;
case CL_COMMAND_TASK:
commandName = "clEnqueueTask";
break;
case CL_COMMAND_NATIVE_KERNEL:
commandName = "clEnqueueNativeKernel";
break;
case CL_COMMAND_READ_BUFFER:
commandName = "clEnqueueReadBuffer";
break;
case CL_COMMAND_WRITE_BUFFER:
commandName = "clEnqueueWriteBuffer";
break;
case CL_COMMAND_COPY_BUFFER:
commandName = "clEnqueueCopyBuffer";
break;
case CL_COMMAND_READ_IMAGE:
commandName = "clEnqueueReadImage";
break;
case CL_COMMAND_WRITE_IMAGE:
commandName = "clEnqueueWriteImage";
break;
case CL_COMMAND_COPY_IMAGE:
commandName = "clEnqueueCopyImage";
break;
case CL_COMMAND_COPY_IMAGE_TO_BUFFER:
commandName = "clEnqueueCopyImageToBuffer";
break;
case CL_COMMAND_COPY_BUFFER_TO_IMAGE:
commandName = "clEnqueueCopyBufferToImage";
break;
case CL_COMMAND_MAP_BUFFER:
commandName = "clEnqueueMapBuffer";
break;
case CL_COMMAND_MAP_IMAGE:
commandName = "clEnqueueMapImage";
break;
case CL_COMMAND_UNMAP_MEM_OBJECT:
commandName = "clEnqueueUnmapMemObject";
break;
case CL_COMMAND_MARKER:
commandName = "clEnqueueMarker";
break;
case CL_COMMAND_ACQUIRE_GL_OBJECTS:
commandName = "clEnqueueAcquireGLObjects";
break;
case CL_COMMAND_RELEASE_GL_OBJECTS:
commandName = "clEnqueueReleaseGLObjects";
break;
// OpenCL 1.1 event types.
case CL_COMMAND_READ_BUFFER_RECT:
commandName = "clEnqueueReadBufferRect";
break;
case CL_COMMAND_WRITE_BUFFER_RECT:
commandName = "clEnqueueWriteBufferRect";
break;
case CL_COMMAND_COPY_BUFFER_RECT:
commandName = "clEnqueueCopyBufferRect";
break;
case CL_COMMAND_USER:
commandName = "clCreateUserEvent";
break;
// OpenCL 1.2 event types.
case CL_COMMAND_BARRIER:
commandName = "clEnqueueBarrierWithWaitList";
break;
case CL_COMMAND_MIGRATE_MEM_OBJECTS:
commandName = "clEnqueueFillImage";
break;
case CL_COMMAND_FILL_BUFFER:
commandName = "clEnqueueFillBuffer";
break;
case CL_COMMAND_FILL_IMAGE:
commandName = "clEnqueueFillImage";
break;
default:
commandName = "Unknown";
break;
}
// Get command status
const char * statusName;
switch (status)
{
case CL_COMPLETE:
statusName = "completed";
break;
case CL_RUNNING:
statusName = "running";
break;
case CL_SUBMITTED:
statusName = "submitted";
break;
case CL_QUEUED:
statusName = "queued";
break;
default:
statusName = "Unknown";
break;
}
if (status != CL_COMPLETE)
{
// Command is not complete : no profiling information available yet.
strm << "OpenCLEvent(id:" << reinterpret_cast<long>(id) << " command:" << commandName << " status:" << statusName
<< ")";
}
else
{
cl_ulong queueTime, runTime, finishTime;
if (clGetEventProfilingInfo(id, CL_PROFILING_COMMAND_QUEUED, sizeof(queueTime), &queueTime, 0) != CL_SUCCESS ||
clGetEventProfilingInfo(id, CL_PROFILING_COMMAND_START, sizeof(runTime), &runTime, 0) != CL_SUCCESS ||
clGetEventProfilingInfo(id, CL_PROFILING_COMMAND_END, sizeof(finishTime), &finishTime, 0) != CL_SUCCESS)
{
// Profiling information is not available, probably
// because it was not enabled on the command queue.
strm << "OpenCLEvent(id:" << reinterpret_cast<long>(id) << " command:" << commandName << " status:" << statusName
<< ")";
}
else
{
// Include profiling information in the debug output.
const double fullDuration = (finishTime - queueTime) / 1000000.0f;
const double runDuration = (finishTime - runTime) / 1000000.0f;
strm << "OpenCLEvent(id:" << reinterpret_cast<long>(id) << " command:" << commandName << " status:" << statusName
<< " full-time:" << fullDuration << " ms running-time:" << runDuration << "ms)";
}
}
return strm;
}
} // end namespace itk
#endif /* itkOpenCLEvent_h */
itk::OpenCLEvent
OpenCLEvent class represents an OpenCL event object.
Definition itkOpenCLEvent.h:93
itk::OpenCLEvent::OpenCLUserEvent
friend class OpenCLUserEvent
Definition itkOpenCLEvent.h:238
itk::OpenCLEvent::operator=
OpenCLEvent & operator=(const OpenCLEvent &other)
itk::OpenCLEvent::GetSubmitTime
cl_ulong GetSubmitTime() const
itk::OpenCLEvent::IsComplete
bool IsComplete() const
Definition itkOpenCLEvent.h:165
itk::OpenCLEvent::IsSubmitted
bool IsSubmitted() const
Definition itkOpenCLEvent.h:147
itk::OpenCLEvent::GetFinishTime
cl_ulong GetFinishTime() const
itk::OpenCLEvent::GetRunTime
cl_ulong GetRunTime() const
itk::OpenCLEvent::OpenCLEvent
OpenCLEvent()
itk::OpenCLEvent::GetCommandType
cl_command_type GetCommandType() const
itk::OpenCLEvent::WaitForFinished
cl_int WaitForFinished()
itk::OpenCLEvent::IsNull
bool IsNull() const
Definition itkOpenCLEvent.h:121
itk::OpenCLEvent::IsQueued
bool IsQueued() const
Definition itkOpenCLEvent.h:138
itk::OpenCLEvent::GetQueueTime
cl_ulong GetQueueTime() const
itk::OpenCLEvent::Self
OpenCLEvent Self
Definition itkOpenCLEvent.h:96
itk::OpenCLEvent::IsError
bool IsError() const
Definition itkOpenCLEvent.h:173
itk::OpenCLEvent::OpenCLEvent
OpenCLEvent(const OpenCLEvent &other)
itk::OpenCLEvent::OpenCLEvent
OpenCLEvent(const cl_event id)
itk::OpenCLEvent::m_Id
cl_event m_Id
Definition itkOpenCLEvent.h:235
itk::OpenCLEvent::SetCallback
cl_int SetCallback(cl_int type, void(CL_CALLBACK *pfn_notify)(cl_event, cl_int, void *), void *user_data=nullptr)
itk::OpenCLEvent::GetStatus
cl_int GetStatus() const
itk::OpenCLEvent::IsRunning
bool IsRunning() const
Definition itkOpenCLEvent.h:156
itk::OpenCLEvent::~OpenCLEvent
~OpenCLEvent()
itk::OpenCLEvent::GetEventId
cl_event GetEventId() const
Definition itkOpenCLEvent.h:128
itk::OpenCLUserEvent
The OpenCLUserEvent class represents OpenCL user events.
Definition itkOpenCLUserEvent.h:67
ITKOpenCL_EXPORT
#define ITKOpenCL_EXPORT
Definition itkOpenCLExport.h:33
itkOpenCLExtension.h
CL_COMMAND_FILL_IMAGE
#define CL_COMMAND_FILL_IMAGE
Definition itkOpenCLExtension.h:52
CL_COMMAND_MIGRATE_MEM_OBJECTS
#define CL_COMMAND_MIGRATE_MEM_OBJECTS
Definition itkOpenCLExtension.h:44
CL_COMMAND_BARRIER
#define CL_COMMAND_BARRIER
Definition itkOpenCLExtension.h:40
CL_COMMAND_FILL_BUFFER
#define CL_COMMAND_FILL_BUFFER
Definition itkOpenCLExtension.h:48
itkOpenCL.h
itk
Definition itkAdvancedImageToImageMetric.h:43
itk::operator==
bool ITKOpenCL_EXPORT operator==(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
itk::operator!=
bool ITKOpenCL_EXPORT operator!=(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
itk::operator<<
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &strm, const OpenCLCommandQueue &queue)
Definition itkOpenCLCommandQueue.h:135

Generated on 1768596610 for elastix by 1.15.0 |