Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "ProfilingUtils.hpp" |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 9 | #include "Runtime.hpp" |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 10 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 11 | #include <BufferManager.hpp> |
| 12 | #include <ProfilingService.hpp> |
| 13 | |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame^] | 14 | #include <armnn/profiling/ArmNNProfiling.hpp> |
| 15 | |
Jim Flynn | decd08b | 2022-03-13 22:35:46 +0000 | [diff] [blame] | 16 | #include <common/include/Optional.hpp> |
Nikhil Raj | 77fe76b | 2021-06-09 14:55:32 +0100 | [diff] [blame] | 17 | #include <common/include/ProfilingGuid.hpp> |
| 18 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 19 | using namespace armnn; |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 20 | using namespace arm::pipe; |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 21 | |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 22 | const static uint32_t bodyHeaderSize = 6; |
| 23 | |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 24 | uint32_t GetStreamMetaDataPacketSize(); |
| 25 | |
Jan Eilers | f78c767 | 2020-07-01 18:09:39 +0100 | [diff] [blame] | 26 | /// Returns a vector of CpuRef, CpuAcc or GpuAcc backends if they where registered |
| 27 | std::vector<BackendId> GetSuitableBackendRegistered(); |
| 28 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 29 | inline unsigned int OffsetToNextWord(unsigned int numberOfBytes); |
| 30 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 31 | void VerifyTimelineHeaderBinary(const unsigned char* readableData, |
| 32 | unsigned int& offset, |
| 33 | uint32_t packetDataLength); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 34 | |
Jim Flynn | decd08b | 2022-03-13 22:35:46 +0000 | [diff] [blame] | 35 | ProfilingGuid VerifyTimelineLabelBinaryPacketData(arm::pipe::Optional<ProfilingGuid> guid, |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 36 | const std::string& label, |
| 37 | const unsigned char* readableData, |
| 38 | unsigned int& offset); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 39 | |
| 40 | void VerifyTimelineEventClassBinaryPacketData(ProfilingGuid guid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 41 | ProfilingGuid nameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 42 | const unsigned char* readableData, |
| 43 | unsigned int& offset); |
| 44 | |
| 45 | void VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType relationshipType, |
Jim Flynn | decd08b | 2022-03-13 22:35:46 +0000 | [diff] [blame] | 46 | arm::pipe::Optional<ProfilingGuid> relationshipGuid, |
| 47 | arm::pipe::Optional<ProfilingGuid> headGuid, |
| 48 | arm::pipe::Optional<ProfilingGuid> tailGuid, |
| 49 | arm::pipe::Optional<ProfilingGuid> attributeGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 50 | const unsigned char* readableData, |
| 51 | unsigned int& offset); |
| 52 | |
Jim Flynn | decd08b | 2022-03-13 22:35:46 +0000 | [diff] [blame] | 53 | ProfilingGuid VerifyTimelineEntityBinaryPacketData(arm::pipe::Optional<ProfilingGuid> guid, |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 54 | const unsigned char* readableData, |
| 55 | unsigned int& offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 56 | |
Jim Flynn | decd08b | 2022-03-13 22:35:46 +0000 | [diff] [blame] | 57 | ProfilingGuid VerifyTimelineEventBinaryPacket(arm::pipe::Optional<uint64_t> timestamp, |
| 58 | arm::pipe::Optional<int> threadId, |
| 59 | arm::pipe::Optional<ProfilingGuid> eventGuid, |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 60 | const unsigned char* readableData, |
| 61 | unsigned int& offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 62 | |
| 63 | void VerifyPostOptimisationStructureTestImpl(armnn::BackendId backendId); |
| 64 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 65 | bool CompareOutput(std::vector<std::string> output, std::vector<std::string> expectedOutput); |
| 66 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 67 | namespace arm |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 68 | { |
| 69 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 70 | namespace pipe |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 71 | { |
| 72 | |
| 73 | class ProfilingServiceRuntimeHelper : public ProfilingService |
| 74 | { |
| 75 | public: |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 76 | ProfilingServiceRuntimeHelper(uint16_t maxGlobalCounterId, |
| 77 | IInitialiseProfilingService& initialiser, |
| 78 | arm::pipe::IProfilingService& profilingService) |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame^] | 79 | : ProfilingService(maxGlobalCounterId, |
| 80 | initialiser, |
| 81 | arm::pipe::ARMNN_SOFTWARE_INFO, |
| 82 | arm::pipe::ARMNN_SOFTWARE_VERSION, |
| 83 | arm::pipe::ARMNN_HARDWARE_VERSION), |
| 84 | m_ProfilingService(profilingService) {} |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 85 | ~ProfilingServiceRuntimeHelper() = default; |
| 86 | |
| 87 | BufferManager& GetProfilingBufferManager() |
| 88 | { |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 89 | return GetBufferManager(static_cast<arm::pipe::ProfilingService&>(m_ProfilingService)); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 90 | } |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 91 | arm::pipe::IProfilingService& m_ProfilingService; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 92 | |
| 93 | void ForceTransitionToState(ProfilingState newState) |
| 94 | { |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 95 | TransitionToState(static_cast<arm::pipe::ProfilingService&>(m_ProfilingService), newState); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 96 | } |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Jim Flynn | 6c9f17d | 2022-03-10 23:13:01 +0000 | [diff] [blame] | 99 | struct LogLevelSwapper |
| 100 | { |
| 101 | public: |
| 102 | LogLevelSwapper(arm::pipe::LogSeverity severity) |
| 103 | { |
| 104 | // Set the new log level |
| 105 | arm::pipe::ConfigureLogging(true, true, severity); |
| 106 | } |
| 107 | ~LogLevelSwapper() |
| 108 | { |
| 109 | // The default log level for unit tests is "Fatal" |
| 110 | arm::pipe::ConfigureLogging(true, true, arm::pipe::LogSeverity::Fatal); |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | struct StreamRedirector |
| 115 | { |
| 116 | public: |
| 117 | StreamRedirector(std::ostream& stream, std::streambuf* newStreamBuffer) |
| 118 | : m_Stream(stream) |
| 119 | , m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer)) |
| 120 | {} |
| 121 | |
| 122 | ~StreamRedirector() { CancelRedirect(); } |
| 123 | |
| 124 | void CancelRedirect() |
| 125 | { |
| 126 | // Only cancel the redirect once. |
| 127 | if (m_BackupBuffer != nullptr ) |
| 128 | { |
| 129 | m_Stream.rdbuf(m_BackupBuffer); |
| 130 | m_BackupBuffer = nullptr; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | private: |
| 135 | std::ostream& m_Stream; |
| 136 | std::streambuf* m_BackupBuffer; |
| 137 | }; |
| 138 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 139 | } // namespace pipe |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 140 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 141 | } // namespace arm |