ArmNN  NotReleased
OpenClTimer Class Reference

OpenClTimer instrument that times all OpenCl kernels executed between calls to Start() and Stop(). More...

#include <OpenClTimer.hpp>

Inheritance diagram for OpenClTimer:
Instrument

Public Member Functions

 OpenClTimer ()
 
 ~OpenClTimer ()=default
 
void Start () override
 Start the OpenCl timer. More...
 
void Stop () override
 Stop the OpenCl timer. More...
 
const char * GetName () const override
 
std::vector< MeasurementGetMeasurements () const override
 
- Public Member Functions inherited from Instrument
virtual ~Instrument ()
 

Detailed Description

OpenClTimer instrument that times all OpenCl kernels executed between calls to Start() and Stop().

Definition at line 20 of file OpenClTimer.hpp.

Constructor & Destructor Documentation

◆ OpenClTimer()

Definition at line 16 of file OpenClTimer.cpp.

17 {
18 }

◆ ~OpenClTimer()

~OpenClTimer ( )
default

Member Function Documentation

◆ GetMeasurements()

std::vector< Measurement > GetMeasurements ( ) const
overridevirtual

Get the recorded measurements. This will be a list of the execution durations for all the OpenCl kernels.

Returns
Recorded measurements

Implements Instrument.

Definition at line 80 of file OpenClTimer.cpp.

References OpenClTimer::GetName().

Referenced by OpenClTimer::GetName().

81 {
82  std::vector<Measurement> measurements;
83 
84  cl_command_queue_properties clQueueProperties = CLScheduler::get().queue().getInfo<CL_QUEUE_PROPERTIES>();
85 
86  int idx = 0;
87  for (auto& kernel : m_Kernels)
88  {
89  std::string name = std::string(this->GetName()) + "/" + std::to_string(idx++) + ": " + kernel.m_Name;
90 
91  double timeUs = 0.0;
92  if((clQueueProperties & CL_QUEUE_PROFILING_ENABLE) != 0)
93  {
94  // Wait for the event to finish before accessing profile results.
95  kernel.m_Event.wait();
96 
97  cl_ulong start = kernel.m_Event.getProfilingInfo<CL_PROFILING_COMMAND_START>();
98  cl_ulong end = kernel.m_Event.getProfilingInfo<CL_PROFILING_COMMAND_END>();
99  timeUs = static_cast<double>(end - start) / 1000.0;
100  }
101 
102  measurements.emplace_back(name, timeUs, Measurement::Unit::TIME_US);
103  }
104 
105  return measurements;
106 }
const char * GetName() const override
Definition: OpenClTimer.hpp:34

◆ GetName()

const char* GetName ( ) const
inlineoverridevirtual

Get the name of the timer

Returns
Name of the timer

Implements Instrument.

Definition at line 34 of file OpenClTimer.hpp.

References armnn::Event, and OpenClTimer::GetMeasurements().

Referenced by OpenClTimer::GetMeasurements().

34 { return "OpenClKernelTimer"; }

◆ Start()

void Start ( )
overridevirtual

Start the OpenCl timer.

Implements Instrument.

Definition at line 20 of file OpenClTimer.cpp.

21 {
22  m_Kernels.clear();
23 
24  auto interceptor = [this]( cl_command_queue command_queue,
25  cl_kernel kernel,
26  cl_uint work_dim,
27  const size_t *gwo,
28  const size_t *gws,
29  const size_t *lws,
30  cl_uint num_events_in_wait_list,
31  const cl_event * event_wait_list,
32  cl_event * event)
33  {
34  boost::ignore_unused(event);
35  cl_int retVal = 0;
36 
37  // Get the name of the kernel
38  cl::Kernel retainedKernel(kernel, true);
39  std::stringstream ss;
40  ss << retainedKernel.getInfo<CL_KERNEL_FUNCTION_NAME>();
41 
42  // Embed workgroup sizes into the name
43  if(gws != nullptr)
44  {
45  ss << " GWS[" << gws[0] << "," << gws[1] << "," << gws[2] << "]";
46  }
47  if(lws != nullptr)
48  {
49  ss << " LWS[" << lws[0] << "," << lws[1] << "," << lws[2] << "]";
50  }
51 
52  cl_event customEvent;
53 
54  // Forward to original OpenCl function
55  retVal = m_OriginalEnqueueFunction( command_queue,
56  kernel,
57  work_dim,
58  gwo,
59  gws,
60  lws,
61  num_events_in_wait_list,
62  event_wait_list,
63  &customEvent);
64 
65  // Store the Kernel info for later GetMeasurements() call
66  m_Kernels.emplace_back(ss.str(), customEvent);
67 
68  return retVal;
69  };
70 
71  m_OriginalEnqueueFunction = CLSymbols::get().clEnqueueNDRangeKernel_ptr;
72  CLSymbols::get().clEnqueueNDRangeKernel_ptr = interceptor;
73 }

◆ Stop()

void Stop ( )
overridevirtual

Stop the OpenCl timer.

Implements Instrument.

Definition at line 75 of file OpenClTimer.cpp.

76 {
77  CLSymbols::get().clEnqueueNDRangeKernel_ptr = m_OriginalEnqueueFunction;
78 }

The documentation for this class was generated from the following files: