ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 37 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 44 of file CLTimer.h.

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

◆ 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 83 of file CLTimer.h.

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

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


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