David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 1 | // |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 6 | #include "ArmNNProfilingServiceInitialiser.hpp" |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 7 | #include "MockBackendId.hpp" |
Jim Flynn | 4c9ed1d | 2022-01-23 23:57:20 +0000 | [diff] [blame] | 8 | #include "ProfilingOptionsConverter.hpp" |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 9 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 10 | #include <TestUtils.hpp> |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 11 | |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 12 | #include <armnn/BackendId.hpp> |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 13 | #include <armnn/Logging.hpp> |
Jim Flynn | c454ac9 | 2022-03-16 18:43:18 +0000 | [diff] [blame] | 14 | |
| 15 | #include <armnn/profiling/ArmNNProfiling.hpp> |
Jim Flynn | c454ac9 | 2022-03-16 18:43:18 +0000 | [diff] [blame] | 16 | |
| 17 | #include <armnn/utility/IgnoreUnused.hpp> |
| 18 | |
Cathal Corbett | 3464ba1 | 2022-03-04 11:36:39 +0000 | [diff] [blame] | 19 | #include <armnnTestUtils/MockBackend.hpp> |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 20 | |
Jim Flynn | 2776183 | 2022-03-20 21:52:17 +0000 | [diff] [blame] | 21 | #include <client/include/CounterIdMap.hpp> |
| 22 | #include <client/include/Holder.hpp> |
| 23 | #include <client/include/ISendTimelinePacket.hpp> |
| 24 | #include <client/include/ProfilingOptions.hpp> |
| 25 | |
Jim Flynn | 3e9bc19 | 2022-03-23 23:01:26 +0000 | [diff] [blame] | 26 | #include <client/src/PeriodicCounterCapture.hpp> |
| 27 | #include <client/src/PeriodicCounterSelectionCommandHandler.hpp> |
| 28 | #include <client/src/ProfilingStateMachine.hpp> |
| 29 | #include <client/src/ProfilingUtils.hpp> |
| 30 | #include <client/src/RequestCounterDirectoryCommandHandler.hpp> |
| 31 | |
| 32 | #include <client/src/backends/BackendProfiling.hpp> |
| 33 | |
Jim Flynn | c454ac9 | 2022-03-16 18:43:18 +0000 | [diff] [blame] | 34 | #include <common/include/CounterDirectory.hpp> |
Jim Flynn | 3e9bc19 | 2022-03-23 23:01:26 +0000 | [diff] [blame] | 35 | #include <common/include/PacketVersionResolver.hpp> |
Jim Flynn | c454ac9 | 2022-03-16 18:43:18 +0000 | [diff] [blame] | 36 | |
| 37 | #include <doctest/doctest.h> |
| 38 | |
| 39 | #include <vector> |
| 40 | #include <cstdint> |
| 41 | #include <limits> |
Jim Flynn | 6c9f17d | 2022-03-10 23:13:01 +0000 | [diff] [blame] | 42 | |
| 43 | namespace arm |
| 44 | { |
| 45 | |
| 46 | namespace pipe |
| 47 | { |
| 48 | |
| 49 | struct LogLevelSwapper |
| 50 | { |
| 51 | public: |
| 52 | LogLevelSwapper(arm::pipe::LogSeverity severity) |
| 53 | { |
| 54 | // Set the new log level |
| 55 | arm::pipe::ConfigureLogging(true, true, severity); |
| 56 | } |
| 57 | ~LogLevelSwapper() |
| 58 | { |
| 59 | // The default log level for unit tests is "Fatal" |
| 60 | arm::pipe::ConfigureLogging(true, true, arm::pipe::LogSeverity::Fatal); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | } // namespace pipe |
| 65 | |
| 66 | } // namespace arm |
| 67 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 68 | using namespace arm::pipe; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 69 | |
| 70 | class ReadCounterVals : public IReadCounterValues |
| 71 | { |
| 72 | virtual bool IsCounterRegistered(uint16_t counterUid) const override |
| 73 | { |
| 74 | return (counterUid > 4 && counterUid < 11); |
| 75 | } |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 76 | virtual bool IsCounterRegistered(const std::string& counterName) const override |
| 77 | { |
| 78 | armnn::IgnoreUnused(counterName); |
| 79 | return false; |
| 80 | } |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 81 | virtual uint16_t GetCounterCount() const override |
| 82 | { |
| 83 | return 1; |
| 84 | } |
Finn Williams | f3fcf32 | 2020-05-11 14:38:02 +0100 | [diff] [blame] | 85 | virtual uint32_t GetAbsoluteCounterValue(uint16_t counterUid) const override |
| 86 | { |
| 87 | return counterUid; |
| 88 | } |
| 89 | virtual uint32_t GetDeltaCounterValue(uint16_t counterUid) override |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 90 | { |
| 91 | return counterUid; |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | class MockBackendSendCounterPacket : public ISendCounterPacket |
| 96 | { |
| 97 | public: |
| 98 | using IndexValuePairsVector = std::vector<CounterValue>; |
| 99 | |
| 100 | /// Create and write a StreamMetaDataPacket in the buffer |
| 101 | virtual void SendStreamMetaDataPacket() {} |
| 102 | |
| 103 | /// Create and write a CounterDirectoryPacket from the parameters to the buffer. |
| 104 | virtual void SendCounterDirectoryPacket(const ICounterDirectory& counterDirectory) |
| 105 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 106 | armnn::IgnoreUnused(counterDirectory); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /// Create and write a PeriodicCounterCapturePacket from the parameters to the buffer. |
| 110 | virtual void SendPeriodicCounterCapturePacket(uint64_t timestamp, const IndexValuePairsVector& values) |
| 111 | { |
| 112 | m_timestamps.emplace_back(Timestamp{timestamp, values}); |
| 113 | } |
| 114 | |
| 115 | /// Create and write a PeriodicCounterSelectionPacket from the parameters to the buffer. |
| 116 | virtual void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod, |
| 117 | const std::vector<uint16_t>& selectedCounterIds) |
| 118 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 119 | armnn::IgnoreUnused(capturePeriod); |
| 120 | armnn::IgnoreUnused(selectedCounterIds); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | std::vector<Timestamp> GetTimestamps() |
| 124 | { |
| 125 | return m_timestamps; |
| 126 | } |
| 127 | |
| 128 | void ClearTimestamps() |
| 129 | { |
| 130 | m_timestamps.clear(); |
| 131 | } |
| 132 | |
| 133 | private: |
| 134 | std::vector<Timestamp> m_timestamps; |
| 135 | }; |
| 136 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 137 | arm::pipe::Packet PacketWriter(uint32_t period, std::vector<uint16_t> countervalues) |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 138 | { |
| 139 | const uint32_t packetId = 0x40000; |
| 140 | uint32_t offset = 0; |
| 141 | uint32_t dataLength = static_cast<uint32_t>(4 + countervalues.size() * 2); |
| 142 | std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength); |
| 143 | unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData.get()); |
| 144 | |
| 145 | WriteUint32(data1, offset, period); |
| 146 | offset += 4; |
| 147 | for (auto countervalue : countervalues) |
| 148 | { |
| 149 | WriteUint16(data1, offset, countervalue); |
| 150 | offset += 2; |
| 151 | } |
| 152 | |
| 153 | return {packetId, dataLength, uniqueData}; |
| 154 | } |
| 155 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 156 | TEST_SUITE("BackendProfilingTestSuite") |
| 157 | { |
| 158 | TEST_CASE("BackendProfilingCounterRegisterMockBackendTest") |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 159 | { |
Jim Flynn | 6c9f17d | 2022-03-10 23:13:01 +0000 | [diff] [blame] | 160 | arm::pipe::LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal); |
| 161 | |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 162 | // Reset the profiling service to the uninitialized state |
| 163 | armnn::IRuntime::CreationOptions options; |
Finn Williams | 45a7362 | 2020-05-15 18:41:05 +0100 | [diff] [blame] | 164 | options.m_ProfilingOptions.m_EnableProfiling = true; |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 165 | |
| 166 | armnn::MockBackendInitialiser initialiser; |
| 167 | // Create a runtime |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 168 | armnn::RuntimeImpl runtime(options); |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 169 | |
Narumol Prangnawarat | 060bad5 | 2020-11-20 16:17:48 +0000 | [diff] [blame] | 170 | unsigned int shiftedId = 0; |
| 171 | |
Nikhil Raj | 01bc02d | 2021-05-07 17:07:09 +0100 | [diff] [blame] | 172 | if (armnn::BackendRegistry().IsBackendRegistered("EthosNAcc")) |
| 173 | { |
| 174 | shiftedId = 4; |
| 175 | } |
Narumol Prangnawarat | 060bad5 | 2020-11-20 16:17:48 +0000 | [diff] [blame] | 176 | |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 177 | // Check if the MockBackends 3 dummy counters {0, 1, 2-5 (four cores)} are registered |
| 178 | armnn::BackendId mockId = armnn::MockBackendId(); |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 179 | const ICounterMappings& counterMap = GetProfilingService(&runtime).GetCounterMappings(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 180 | CHECK(counterMap.GetGlobalId(0, mockId) == 5 + shiftedId); |
| 181 | CHECK(counterMap.GetGlobalId(1, mockId) == 6 + shiftedId); |
| 182 | CHECK(counterMap.GetGlobalId(2, mockId) == 7 + shiftedId); |
| 183 | CHECK(counterMap.GetGlobalId(3, mockId) == 8 + shiftedId); |
| 184 | CHECK(counterMap.GetGlobalId(4, mockId) == 9 + shiftedId); |
| 185 | CHECK(counterMap.GetGlobalId(5, mockId) == 10 + shiftedId); |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 186 | options.m_ProfilingOptions.m_EnableProfiling = false; |
Jim Flynn | 4c9ed1d | 2022-01-23 23:57:20 +0000 | [diff] [blame] | 187 | GetProfilingService(&runtime).ResetExternalProfilingOptions( |
| 188 | ConvertExternalProfilingOptions(options.m_ProfilingOptions), true); |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 191 | TEST_CASE("TestBackendCounters") |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 192 | { |
Jim Flynn | 6c9f17d | 2022-03-10 23:13:01 +0000 | [diff] [blame] | 193 | arm::pipe::LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal); |
| 194 | |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 195 | Holder holder; |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 196 | arm::pipe::PacketVersionResolver packetVersionResolver; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 197 | ProfilingStateMachine stateMachine; |
| 198 | ReadCounterVals readCounterVals; |
| 199 | CounterIdMap counterIdMap; |
| 200 | MockBackendSendCounterPacket sendCounterPacket; |
| 201 | |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 202 | const std::string cpuAccId(GetComputeDeviceAsCString(armnn::Compute::CpuAcc)); |
| 203 | const std::string gpuAccId(GetComputeDeviceAsCString(armnn::Compute::GpuAcc)); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 204 | |
Jim Flynn | 4c9ed1d | 2022-01-23 23:57:20 +0000 | [diff] [blame] | 205 | ProfilingOptions options; |
| 206 | options.m_EnableProfiling = true; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 207 | |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 208 | armnn::ArmNNProfilingServiceInitialiser initialiser; |
| 209 | std::unique_ptr<IProfilingService> profilingService = arm::pipe::IProfilingService::CreateProfilingService( |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 210 | arm::pipe::MAX_ARMNN_COUNTER, |
| 211 | initialiser, |
| 212 | arm::pipe::ARMNN_SOFTWARE_INFO, |
| 213 | arm::pipe::ARMNN_SOFTWARE_VERSION, |
| 214 | arm::pipe::ARMNN_HARDWARE_VERSION); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 215 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 216 | std::unique_ptr<IBackendProfiling> cpuBackendProfilingPtr = |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 217 | std::make_unique<BackendProfiling>(options, *profilingService.get(), cpuAccId); |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 218 | std::unique_ptr<IBackendProfiling> gpuBackendProfilingPtr = |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 219 | std::make_unique<BackendProfiling>(options, *profilingService.get(), gpuAccId); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 220 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 221 | std::shared_ptr<IBackendProfilingContext> cpuProfilingContextPtr = |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 222 | std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr); |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 223 | std::shared_ptr<IBackendProfilingContext> gpuProfilingContextPtr = |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 224 | std::make_shared<armnn::MockBackendProfilingContext>(gpuBackendProfilingPtr); |
| 225 | |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 226 | std::unordered_map<std::string, |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 227 | std::shared_ptr<IBackendProfilingContext>> backendProfilingContexts; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 228 | |
| 229 | backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr; |
| 230 | backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr; |
| 231 | |
| 232 | uint16_t globalId = 5; |
| 233 | |
| 234 | counterIdMap.RegisterMapping(globalId++, 0, cpuAccId); |
| 235 | counterIdMap.RegisterMapping(globalId++, 1, cpuAccId); |
| 236 | counterIdMap.RegisterMapping(globalId++, 2, cpuAccId); |
| 237 | |
| 238 | counterIdMap.RegisterMapping(globalId++, 0, gpuAccId); |
| 239 | counterIdMap.RegisterMapping(globalId++, 1, gpuAccId); |
| 240 | counterIdMap.RegisterMapping(globalId++, 2, gpuAccId); |
| 241 | |
| 242 | backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr; |
| 243 | backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr; |
| 244 | |
| 245 | PeriodicCounterCapture periodicCounterCapture(holder, sendCounterPacket, readCounterVals, |
| 246 | counterIdMap, backendProfilingContexts); |
| 247 | |
| 248 | uint16_t maxArmnnCounterId = 4; |
| 249 | |
| 250 | PeriodicCounterSelectionCommandHandler periodicCounterSelectionCommandHandler(0, |
| 251 | 4, |
| 252 | packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(), |
| 253 | backendProfilingContexts, |
| 254 | counterIdMap, |
| 255 | holder, |
| 256 | maxArmnnCounterId, |
| 257 | periodicCounterCapture, |
| 258 | readCounterVals, |
| 259 | sendCounterPacket, |
| 260 | stateMachine); |
| 261 | |
| 262 | stateMachine.TransitionToState(ProfilingState::NotConnected); |
| 263 | stateMachine.TransitionToState(ProfilingState::WaitingForAck); |
| 264 | stateMachine.TransitionToState(ProfilingState::Active); |
| 265 | |
| 266 | uint32_t period = 12345u; |
| 267 | |
| 268 | std::vector<uint16_t> cpuCounters{5, 6, 7}; |
| 269 | std::vector<uint16_t> gpuCounters{8, 9, 10}; |
| 270 | |
| 271 | // Request only gpu counters |
| 272 | periodicCounterSelectionCommandHandler(PacketWriter(period, gpuCounters)); |
| 273 | periodicCounterCapture.Stop(); |
| 274 | |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 275 | std::set<std::string> activeIds = holder.GetCaptureData().GetActiveBackends(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 276 | CHECK(activeIds.size() == 1); |
| 277 | CHECK((activeIds.find(gpuAccId) != activeIds.end())); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 278 | |
| 279 | std::vector<Timestamp> recievedTimestamp = sendCounterPacket.GetTimestamps(); |
| 280 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 281 | CHECK(recievedTimestamp[0].timestamp == period); |
| 282 | CHECK(recievedTimestamp.size() == 1); |
| 283 | CHECK(recievedTimestamp[0].counterValues.size() == gpuCounters.size()); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 284 | for (unsigned long i=0; i< gpuCounters.size(); ++i) |
| 285 | { |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 286 | CHECK(recievedTimestamp[0].counterValues[i].counterId == gpuCounters[i]); |
| 287 | CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 288 | } |
| 289 | sendCounterPacket.ClearTimestamps(); |
| 290 | |
| 291 | // Request only cpu counters |
| 292 | periodicCounterSelectionCommandHandler(PacketWriter(period, cpuCounters)); |
| 293 | periodicCounterCapture.Stop(); |
| 294 | |
| 295 | activeIds = holder.GetCaptureData().GetActiveBackends(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 296 | CHECK(activeIds.size() == 1); |
| 297 | CHECK((activeIds.find(cpuAccId) != activeIds.end())); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 298 | |
| 299 | recievedTimestamp = sendCounterPacket.GetTimestamps(); |
| 300 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 301 | CHECK(recievedTimestamp[0].timestamp == period); |
| 302 | CHECK(recievedTimestamp.size() == 1); |
| 303 | CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size()); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 304 | for (unsigned long i=0; i< cpuCounters.size(); ++i) |
| 305 | { |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 306 | CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]); |
| 307 | CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 308 | } |
| 309 | sendCounterPacket.ClearTimestamps(); |
| 310 | |
| 311 | // Request combination of cpu & gpu counters with new period |
| 312 | period = 12222u; |
| 313 | periodicCounterSelectionCommandHandler(PacketWriter(period, {cpuCounters[0], gpuCounters[2], |
| 314 | gpuCounters[1], cpuCounters[1], gpuCounters[0]})); |
| 315 | periodicCounterCapture.Stop(); |
| 316 | |
| 317 | activeIds = holder.GetCaptureData().GetActiveBackends(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 318 | CHECK(activeIds.size() == 2); |
| 319 | CHECK((activeIds.find(cpuAccId) != activeIds.end())); |
| 320 | CHECK((activeIds.find(gpuAccId) != activeIds.end())); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 321 | |
| 322 | recievedTimestamp = sendCounterPacket.GetTimestamps(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 323 | // |
| 324 | CHECK(recievedTimestamp[0].timestamp == period); |
| 325 | CHECK(recievedTimestamp[1].timestamp == period); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 326 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 327 | CHECK(recievedTimestamp.size() == 2); |
| 328 | CHECK(recievedTimestamp[0].counterValues.size() == 2); |
| 329 | CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size()); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 330 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 331 | CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]); |
| 332 | CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u); |
| 333 | CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[1]); |
| 334 | CHECK(recievedTimestamp[0].counterValues[1].counterValue == 2u); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 335 | |
| 336 | for (unsigned long i=0; i< gpuCounters.size(); ++i) |
| 337 | { |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 338 | CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]); |
| 339 | CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | sendCounterPacket.ClearTimestamps(); |
| 343 | |
| 344 | // Request all counters |
| 345 | std::vector<uint16_t> counterValues; |
| 346 | counterValues.insert(counterValues.begin(), cpuCounters.begin(), cpuCounters.end()); |
| 347 | counterValues.insert(counterValues.begin(), gpuCounters.begin(), gpuCounters.end()); |
| 348 | |
| 349 | periodicCounterSelectionCommandHandler(PacketWriter(period, counterValues)); |
| 350 | periodicCounterCapture.Stop(); |
| 351 | |
| 352 | activeIds = holder.GetCaptureData().GetActiveBackends(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 353 | CHECK(activeIds.size() == 2); |
| 354 | CHECK((activeIds.find(cpuAccId) != activeIds.end())); |
| 355 | CHECK((activeIds.find(gpuAccId) != activeIds.end())); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 356 | |
| 357 | recievedTimestamp = sendCounterPacket.GetTimestamps(); |
| 358 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 359 | CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size()); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 360 | for (unsigned long i=0; i< cpuCounters.size(); ++i) |
| 361 | { |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 362 | CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]); |
| 363 | CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 366 | CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size()); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 367 | for (unsigned long i=0; i< gpuCounters.size(); ++i) |
| 368 | { |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 369 | CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]); |
| 370 | CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 371 | } |
| 372 | sendCounterPacket.ClearTimestamps(); |
| 373 | |
| 374 | // Request random counters with duplicates and invalid counters |
| 375 | counterValues = {0, 0, 200, cpuCounters[2], gpuCounters[0],3 ,30, cpuCounters[0],cpuCounters[2], gpuCounters[1], 3, |
| 376 | 90, 0, 30, gpuCounters[0], gpuCounters[0]}; |
| 377 | |
| 378 | periodicCounterSelectionCommandHandler(PacketWriter(period, counterValues)); |
| 379 | periodicCounterCapture.Stop(); |
| 380 | |
| 381 | activeIds = holder.GetCaptureData().GetActiveBackends(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 382 | CHECK(activeIds.size() == 2); |
| 383 | CHECK((activeIds.find(cpuAccId) != activeIds.end())); |
| 384 | CHECK((activeIds.find(gpuAccId) != activeIds.end())); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 385 | |
| 386 | recievedTimestamp = sendCounterPacket.GetTimestamps(); |
| 387 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 388 | CHECK(recievedTimestamp.size() == 2); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 389 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 390 | CHECK(recievedTimestamp[0].counterValues.size() == 2); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 391 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 392 | CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]); |
| 393 | CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u); |
| 394 | CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[2]); |
| 395 | CHECK(recievedTimestamp[0].counterValues[1].counterValue == 3u); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 396 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 397 | CHECK(recievedTimestamp[1].counterValues.size() == 2); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 398 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 399 | CHECK(recievedTimestamp[1].counterValues[0].counterId == gpuCounters[0]); |
| 400 | CHECK(recievedTimestamp[1].counterValues[0].counterValue == 1u); |
| 401 | CHECK(recievedTimestamp[1].counterValues[1].counterId == gpuCounters[1]); |
| 402 | CHECK(recievedTimestamp[1].counterValues[1].counterValue == 2u); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 403 | |
| 404 | sendCounterPacket.ClearTimestamps(); |
| 405 | |
| 406 | // Request no counters |
| 407 | periodicCounterSelectionCommandHandler(PacketWriter(period, {})); |
| 408 | periodicCounterCapture.Stop(); |
| 409 | |
| 410 | activeIds = holder.GetCaptureData().GetActiveBackends(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 411 | CHECK(activeIds.size() == 0); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 412 | |
| 413 | recievedTimestamp = sendCounterPacket.GetTimestamps(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 414 | CHECK(recievedTimestamp.size() == 0); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 415 | |
| 416 | sendCounterPacket.ClearTimestamps(); |
| 417 | |
| 418 | // Request period of zero |
| 419 | periodicCounterSelectionCommandHandler(PacketWriter(0, counterValues)); |
| 420 | periodicCounterCapture.Stop(); |
| 421 | |
| 422 | activeIds = holder.GetCaptureData().GetActiveBackends(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 423 | CHECK(activeIds.size() == 0); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 424 | |
| 425 | recievedTimestamp = sendCounterPacket.GetTimestamps(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 426 | CHECK(recievedTimestamp.size() == 0); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 429 | TEST_CASE("TestBackendCounterLogging") |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 430 | { |
| 431 | std::stringstream ss; |
| 432 | |
| 433 | struct StreamRedirector |
| 434 | { |
| 435 | public: |
| 436 | StreamRedirector(std::ostream &stream, std::streambuf *newStreamBuffer) |
| 437 | : m_Stream(stream), m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer)) |
| 438 | {} |
| 439 | |
| 440 | ~StreamRedirector() |
| 441 | { m_Stream.rdbuf(m_BackupBuffer); } |
| 442 | |
| 443 | private: |
| 444 | std::ostream &m_Stream; |
| 445 | std::streambuf *m_BackupBuffer; |
| 446 | }; |
| 447 | |
| 448 | Holder holder; |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 449 | arm::pipe::PacketVersionResolver packetVersionResolver; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 450 | ProfilingStateMachine stateMachine; |
| 451 | ReadCounterVals readCounterVals; |
| 452 | StreamRedirector redirect(std::cout, ss.rdbuf()); |
| 453 | CounterIdMap counterIdMap; |
| 454 | MockBackendSendCounterPacket sendCounterPacket; |
| 455 | |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 456 | const std::string cpuAccId(GetComputeDeviceAsCString(armnn::Compute::CpuAcc)); |
| 457 | const std::string gpuAccId(GetComputeDeviceAsCString(armnn::Compute::GpuAcc)); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 458 | |
Jim Flynn | 4c9ed1d | 2022-01-23 23:57:20 +0000 | [diff] [blame] | 459 | ProfilingOptions options; |
| 460 | options.m_EnableProfiling = true; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 461 | |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 462 | armnn::ArmNNProfilingServiceInitialiser initialiser; |
| 463 | std::unique_ptr<IProfilingService> profilingService = arm::pipe::IProfilingService::CreateProfilingService( |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 464 | arm::pipe::MAX_ARMNN_COUNTER, |
| 465 | initialiser, |
| 466 | arm::pipe::ARMNN_SOFTWARE_INFO, |
| 467 | arm::pipe::ARMNN_SOFTWARE_VERSION, |
| 468 | arm::pipe::ARMNN_HARDWARE_VERSION); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 469 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 470 | std::unique_ptr<IBackendProfiling> cpuBackendProfilingPtr = |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 471 | std::make_unique<BackendProfiling>(options, *profilingService.get(), cpuAccId); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 472 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 473 | std::shared_ptr<IBackendProfilingContext> cpuProfilingContextPtr = |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 474 | std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr); |
| 475 | |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 476 | std::unordered_map<std::string, |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 477 | std::shared_ptr<IBackendProfilingContext>> backendProfilingContexts; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 478 | |
| 479 | uint16_t globalId = 5; |
| 480 | counterIdMap.RegisterMapping(globalId, 0, cpuAccId); |
| 481 | backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr; |
| 482 | |
| 483 | PeriodicCounterCapture periodicCounterCapture(holder, sendCounterPacket, readCounterVals, |
| 484 | counterIdMap, backendProfilingContexts); |
| 485 | |
| 486 | uint16_t maxArmnnCounterId = 4; |
| 487 | |
| 488 | PeriodicCounterSelectionCommandHandler periodicCounterSelectionCommandHandler(0, |
| 489 | 4, |
| 490 | packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(), |
| 491 | backendProfilingContexts, |
| 492 | counterIdMap, |
| 493 | holder, |
| 494 | maxArmnnCounterId, |
| 495 | periodicCounterCapture, |
| 496 | readCounterVals, |
| 497 | sendCounterPacket, |
| 498 | stateMachine); |
| 499 | |
| 500 | stateMachine.TransitionToState(ProfilingState::NotConnected); |
| 501 | stateMachine.TransitionToState(ProfilingState::WaitingForAck); |
| 502 | stateMachine.TransitionToState(ProfilingState::Active); |
| 503 | |
| 504 | uint32_t period = 15939u; |
| 505 | |
Jim Flynn | 6c9f17d | 2022-03-10 23:13:01 +0000 | [diff] [blame] | 506 | arm::pipe::SetAllLoggingSinks(true, false, false); |
| 507 | arm::pipe::SetLogFilter(arm::pipe::LogSeverity::Warning); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 508 | periodicCounterSelectionCommandHandler(PacketWriter(period, {5})); |
| 509 | periodicCounterCapture.Stop(); |
Jim Flynn | 6c9f17d | 2022-03-10 23:13:01 +0000 | [diff] [blame] | 510 | arm::pipe::SetLogFilter(arm::pipe::LogSeverity::Fatal); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 511 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 512 | CHECK(ss.str().find("ActivateCounters example test error") != std::string::npos); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 515 | TEST_CASE("BackendProfilingContextGetSendTimelinePacket") |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 516 | { |
Jim Flynn | 6c9f17d | 2022-03-10 23:13:01 +0000 | [diff] [blame] | 517 | arm::pipe::LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal); |
| 518 | |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 519 | // Reset the profiling service to the uninitialized state |
| 520 | armnn::IRuntime::CreationOptions options; |
| 521 | options.m_ProfilingOptions.m_EnableProfiling = true; |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 522 | |
| 523 | armnn::ArmNNProfilingServiceInitialiser psInitialiser; |
| 524 | std::unique_ptr<IProfilingService> profilingService = arm::pipe::IProfilingService::CreateProfilingService( |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 525 | arm::pipe::MAX_ARMNN_COUNTER, |
| 526 | psInitialiser, |
| 527 | arm::pipe::ARMNN_SOFTWARE_INFO, |
| 528 | arm::pipe::ARMNN_SOFTWARE_VERSION, |
| 529 | arm::pipe::ARMNN_HARDWARE_VERSION); |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 530 | |
| 531 | profilingService->ConfigureProfilingService( |
Jim Flynn | 4c9ed1d | 2022-01-23 23:57:20 +0000 | [diff] [blame] | 532 | ConvertExternalProfilingOptions(options.m_ProfilingOptions), true); |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 533 | |
| 534 | armnn::MockBackendInitialiser initialiser; |
| 535 | // Create a runtime. During this the mock backend will be registered and context returned. |
| 536 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
| 537 | armnn::MockBackendProfilingService mockProfilingService = armnn::MockBackendProfilingService::Instance(); |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 538 | armnn::MockBackendProfilingContext* mockBackEndProfilingContext = mockProfilingService.GetContext(); |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 539 | // Check that there is a valid context set. |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 540 | CHECK(mockBackEndProfilingContext); |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 541 | armnn::IBackendInternal::IBackendProfilingPtr& backendProfilingIface = |
| 542 | mockBackEndProfilingContext->GetBackendProfiling(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 543 | CHECK(backendProfilingIface); |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 544 | |
| 545 | // Now for the meat of the test. We're just going to send a random packet and make sure there |
| 546 | // are no exceptions or errors. The sending of packets is already tested in SendTimelinePacketTests. |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 547 | std::unique_ptr<ISendTimelinePacket> timelinePacket = |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 548 | backendProfilingIface->GetSendTimelinePacket(); |
| 549 | // Send TimelineEntityClassBinaryPacket |
| 550 | const uint64_t entityBinaryPacketProfilingGuid = 123456u; |
| 551 | timelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid); |
| 552 | timelinePacket->Commit(); |
| 553 | |
| 554 | // Reset the profiling servie after the test. |
| 555 | options.m_ProfilingOptions.m_EnableProfiling = false; |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 556 | profilingService->ResetExternalProfilingOptions( |
Jim Flynn | 4c9ed1d | 2022-01-23 23:57:20 +0000 | [diff] [blame] | 557 | ConvertExternalProfilingOptions(options.m_ProfilingOptions), true); |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 560 | TEST_CASE("GetProfilingGuidGenerator") |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 561 | { |
Jim Flynn | 6c9f17d | 2022-03-10 23:13:01 +0000 | [diff] [blame] | 562 | arm::pipe::LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal); |
| 563 | |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 564 | // Reset the profiling service to the uninitialized state |
| 565 | armnn::IRuntime::CreationOptions options; |
| 566 | options.m_ProfilingOptions.m_EnableProfiling = true; |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 567 | |
| 568 | armnn::MockBackendInitialiser initialiser; |
| 569 | // Create a runtime. During this the mock backend will be registered and context returned. |
| 570 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
| 571 | armnn::MockBackendProfilingService mockProfilingService = armnn::MockBackendProfilingService::Instance(); |
| 572 | armnn::MockBackendProfilingContext *mockBackEndProfilingContext = mockProfilingService.GetContext(); |
| 573 | // Check that there is a valid context set. |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 574 | CHECK(mockBackEndProfilingContext); |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 575 | armnn::IBackendInternal::IBackendProfilingPtr& backendProfilingIface = |
| 576 | mockBackEndProfilingContext->GetBackendProfiling(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 577 | CHECK(backendProfilingIface); |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 578 | |
| 579 | // Get the Guid generator and check the getting two Guid's results in the second being greater than the first. |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 580 | IProfilingGuidGenerator& guidGenerator = backendProfilingIface->GetProfilingGuidGenerator(); |
| 581 | const ProfilingDynamicGuid& firstGuid = guidGenerator.NextGuid(); |
| 582 | const ProfilingDynamicGuid& secondGuid = guidGenerator.NextGuid(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 583 | CHECK(secondGuid > firstGuid); |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 584 | |
| 585 | // Reset the profiling servie after the test. |
| 586 | options.m_ProfilingOptions.m_EnableProfiling = false; |
Colm Donelan | fcb802b | 2020-02-13 20:47:08 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 589 | } |