ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::backend::acl_cl::CLTimer Class Reference

Class to measure CL kernels execution time. More...

#include <CLTimer.h>

Collaboration diagram for onert::backend::acl_cl::CLTimer:

Public Member Functions

void handleBegin () override
 This function replaces CL function, which enqueues a command to execute a kernel with a wrapper which remembers enqueued kernels.
 
void handleEnd () override
 Get timer result by addition executed CL kernels durations.
 
- Public Member Functions inherited from onert::util::ITimer
int getTime ()
 
virtual ~ITimer ()=default
 

Additional Inherited Members

- Protected Attributes inherited from onert::util::ITimer
int _timer_res {0}
 

Detailed Description

Class to measure CL kernels execution time.

Definition at line 33 of file CLTimer.h.

Member Function Documentation

◆ handleBegin()

void onert::backend::acl_cl::CLTimer::handleBegin ( )
inlineoverridevirtual

This function replaces CL function, which enqueues a command to execute a kernel with a wrapper which remembers enqueued kernels.

Implements onert::util::ITimer.

Definition at line 40 of file CLTimer.h.

41 {
42 _measured_events.clear();
43
44 _origin_enqueue_function = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
45
46 auto _timer_enqueue_function = [this](cl_command_queue command_queue, cl_kernel kernel,
47 cl_uint work_dim, const size_t *gwo, const size_t *gws,
48 const size_t *lws, cl_uint num_events_in_wait_list,
49 const cl_event *event_wait_list, cl_event *usr_event) {
50 cl_event event;
51 cl_int enqueue_res =
52 this->_origin_enqueue_function(command_queue, kernel, work_dim, gwo, gws, lws,
53 num_events_in_wait_list, event_wait_list, &event);
54 this->_measured_events.emplace_back(event);
55
56 // According to spec, if NULL was provided in usr_event - event shouldn't be returned
57 if (usr_event != nullptr)
58 {
59 clRetainEvent(event);
60 *usr_event = event;
61 }
62 return enqueue_res;
63 };
64 arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr = _timer_enqueue_function;
65
66 // Set CL_QUEUE_PROFILING_ENABLE flag for the CL command-queue, if it isn't already set
67 auto &cl_scheduler = arm_compute::CLScheduler::get();
68 auto props = cl_scheduler.queue().getInfo<CL_QUEUE_PROPERTIES>();
69 if ((props & CL_QUEUE_PROFILING_ENABLE) == 0)
70 {
71 cl_scheduler.set_queue(
72 cl::CommandQueue(cl_scheduler.context(), props | CL_QUEUE_PROFILING_ENABLE));
73 }
74 };

◆ handleEnd()

void onert::backend::acl_cl::CLTimer::handleEnd ( )
inlineoverridevirtual

Get timer result by addition executed CL kernels durations.

Implements onert::util::ITimer.

Definition at line 79 of file CLTimer.h.

80 {
81 _timer_res = 0;
82 for (auto const &event : _measured_events)
83 {
84 cl_ulong start;
85 cl_ulong end;
86 event.getProfilingInfo(CL_PROFILING_COMMAND_START, &start);
87 event.getProfilingInfo(CL_PROFILING_COMMAND_END, &end);
88 _timer_res += (end - start) / 1000.f; // nanoseconds -> microseconds
89 }
90
91 // Restore origin CL enqueue function
92 arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr = _origin_enqueue_function;
93 };
ShapeIterator end(const Shape &s)

References onert::util::ITimer::_timer_res.


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