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 | |
| 8 | #include <iostream> |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 9 | #include <memory> |
| 10 | #include <vector> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 11 | |
| 12 | namespace armnn |
| 13 | { |
| 14 | |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 15 | class ProfilerImpl; |
| 16 | class BackendId; |
| 17 | class Instrument; |
| 18 | class Event; |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 19 | struct WorkloadInfo; |
| 20 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 21 | class IProfiler |
| 22 | { |
| 23 | public: |
| 24 | /// Enables/disables profiling for this profiler. |
| 25 | /// @param [in] enableProfiling A flag that indicates whether profiling should be enabled or not. |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 26 | void EnableProfiling(bool enableProfiling); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 27 | |
| 28 | /// Checks whether profiling is enabled. |
| 29 | /// Profiling is disabled by default. |
| 30 | /// @return true if profiling is enabled, false otherwise. |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 31 | bool IsProfilingEnabled(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 32 | |
| 33 | /// Analyzes the tracked events and writes the results to the given output stream. |
| 34 | /// Please refer to the configuration variables in Profiling.cpp to customize the information written. |
| 35 | /// @param [out] outStream The stream where to write the profiling results to. |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 36 | void AnalyzeEventsAndWriteResults(std::ostream& outStream) const; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 37 | |
| 38 | /// Print stats for events in JSON Format to the given output stream. |
| 39 | /// @param [out] outStream The stream where to write the profiling results to. |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 40 | void Print(std::ostream& outStream) const; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 41 | |
Keith Davis | f487486 | 2021-08-09 16:49:18 +0100 | [diff] [blame] | 42 | /// Print out details of each layer within the network that possesses a descriptor. |
Keith Davis | 4914d0c | 2021-08-18 17:14:05 +0100 | [diff] [blame] | 43 | /// Also outputs tensor info. This will be part of the profiling json output |
| 44 | void EnableNetworkDetailsToStdOut(ProfilingDetailsMethod detailsMethod); |
Keith Davis | f487486 | 2021-08-09 16:49:18 +0100 | [diff] [blame] | 45 | |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 46 | ~IProfiler(); |
| 47 | IProfiler(); |
| 48 | |
| 49 | private: |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 50 | |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 51 | using InstrumentPtr = std::unique_ptr<Instrument>; |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 52 | |
| 53 | template<typename DescriptorType> |
| 54 | void AddLayerDetails(const std::string& name, |
| 55 | const DescriptorType& desc, |
Keith Davis | 5a64f22 | 2021-08-04 10:35:20 +0100 | [diff] [blame] | 56 | const WorkloadInfo& infos, |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 57 | const arm::pipe::ProfilingGuid guid); |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 58 | |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 59 | Event* BeginEvent(const BackendId& backendId, |
| 60 | const std::string& label, |
Keith Davis | 5a64f22 | 2021-08-04 10:35:20 +0100 | [diff] [blame] | 61 | std::vector<InstrumentPtr>&& instruments, |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 62 | const Optional<arm::pipe::ProfilingGuid>& guid); |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 63 | |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 64 | std::unique_ptr<ProfilerImpl> pProfilerImpl; |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 65 | |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 66 | friend class ScopedProfilingEvent; |
Keith Davis | 5a64f22 | 2021-08-04 10:35:20 +0100 | [diff] [blame] | 67 | |
| 68 | template<typename DescriptorType> |
| 69 | friend inline void ProfilingUpdateDescriptions(const std::string& name, |
| 70 | const DescriptorType& desc, |
| 71 | const WorkloadInfo& infos, |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 72 | const arm::pipe::ProfilingGuid guid); |
Francis Murtagh | 33199c2 | 2021-02-15 10:11:28 +0000 | [diff] [blame] | 73 | |
| 74 | // Friend functions for unit testing, see ProfilerTests.cpp. |
| 75 | friend size_t GetProfilerEventSequenceSize(armnn::IProfiler* profiler); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace armnn |