telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 8 | #include <Instrument.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 9 | |
Aron Virginas-Tar | 3b278e9 | 2018-10-12 13:00:55 +0100 | [diff] [blame] | 10 | #include <arm_compute/runtime/CL/CLScheduler.h> |
| 11 | #include <arm_compute/core/CL/OpenCL.h> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 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 | /// Get the name of the timer |
| 33 | /// \return Name of the timer |
| 34 | const char* GetName() const override { return "OpenClKernelTimer"; } |
| 35 | |
| 36 | /// Get the recorded measurements. This will be a list of the execution durations for all the OpenCl kernels. |
| 37 | /// \return Recorded measurements |
| 38 | std::vector<Measurement> GetMeasurements() const override; |
| 39 | |
| 40 | private: |
| 41 | using CLScheduler = arm_compute::CLScheduler; |
| 42 | using CLSymbols = arm_compute::CLSymbols; |
| 43 | using ClEvent = cl::Event; |
| 44 | using ClEnqueueFunc = decltype(CLSymbols::clEnqueueNDRangeKernel_ptr); |
| 45 | |
| 46 | /// Stores info about the OpenCl kernel |
| 47 | struct KernelInfo |
| 48 | { |
| 49 | KernelInfo(const std::string& name, cl_event& event) : m_Name(name), m_Event(event) {} |
| 50 | |
| 51 | std::string m_Name; |
| 52 | ClEvent m_Event; |
| 53 | }; |
| 54 | |
| 55 | std::list<KernelInfo> m_Kernels; ///< List of all kernels executed |
| 56 | ClEnqueueFunc m_OriginalEnqueueFunction; ///< Keep track of original OpenCl function |
| 57 | }; |
| 58 | |
| 59 | } //namespace armnn |