ArmNN
 24.02
OpenClTimer.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <Instrument.hpp>
9 
10 #include <arm_compute/runtime/CL/CLScheduler.h>
11 #include <arm_compute/core/CL/OpenCL.h>
12 
13 #include <vector>
14 #include <list>
15 
16 namespace armnn
17 {
18 
19 /// OpenClTimer instrument that times all OpenCl kernels executed between calls to Start() and Stop().
20 class OpenClTimer : public Instrument
21 {
22 public:
23  OpenClTimer();
24  ~OpenClTimer() = default;
25 
26  /// Start the OpenCl timer
27  void Start() override;
28 
29  /// Stop the OpenCl timer
30  void Stop() override;
31 
32  /// Return true if this Instrument has kernels for recording measurements
33  bool HasKernelMeasurements() const override;
34 
35  /// Get the name of the timer
36  /// \return Name of the timer
37  const char* GetName() const override { return "OpenClKernelTimer"; }
38 
39  /// Get the recorded measurements. This will be a list of the execution durations for all the OpenCl kernels.
40  /// \return Recorded measurements
41  std::vector<Measurement> GetMeasurements() const override;
42 
43 private:
44  using CLScheduler = arm_compute::CLScheduler;
45  using CLSymbols = arm_compute::CLSymbols;
46  using ClEvent = cl::Event;
47  using ClEnqueueFunc = decltype(CLSymbols::clEnqueueNDRangeKernel_ptr);
48 
49  /// Stores info about the OpenCl kernel
50  struct KernelInfo
51  {
52  KernelInfo(const std::string& name, cl_event& event) : m_Name(name), m_Event(event) {}
53 
54  std::string m_Name;
55  ClEvent m_Event;
56  };
57 
58  std::list<KernelInfo> m_Kernels; ///< List of all kernels executed
59  ClEnqueueFunc m_OriginalEnqueueFunction; ///< Keep track of original OpenCl function
60 };
61 
62 } //namespace armnn
armnn::OpenClTimer::OpenClTimer
OpenClTimer()
Definition: OpenClTimer.cpp:17
armnn::OpenClTimer::Stop
void Stop() override
Stop the OpenCl timer.
Definition: OpenClTimer.cpp:83
armnn::OpenClTimer::GetName
const char * GetName() const override
Get the name of the timer.
Definition: OpenClTimer.hpp:37
armnn::OpenClTimer
OpenClTimer instrument that times all OpenCl kernels executed between calls to Start() and Stop().
Definition: OpenClTimer.hpp:20
Instrument.hpp
armnn::OpenClTimer::GetMeasurements
std::vector< Measurement > GetMeasurements() const override
Get the recorded measurements.
Definition: OpenClTimer.cpp:93
armnn::OpenClTimer::HasKernelMeasurements
bool HasKernelMeasurements() const override
Return true if this Instrument has kernels for recording measurements.
Definition: OpenClTimer.cpp:88
armnn::Instrument
Definition: Instrument.hpp:51
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::OpenClTimer::Start
void Start() override
Start the OpenCl timer.
Definition: OpenClTimer.cpp:21
armnn::OpenClTimer::~OpenClTimer
~OpenClTimer()=default