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