6 #include "CounterDirectory.hpp" 24 #include <boost/test/unit_test.hpp> 35 virtual bool IsCounterRegistered(uint16_t counterUid)
const override 37 return (counterUid > 4 && counterUid < 11);
39 virtual uint16_t GetCounterCount()
const override 43 virtual uint32_t GetAbsoluteCounterValue(uint16_t counterUid)
const override 47 virtual uint32_t GetDeltaCounterValue(uint16_t counterUid)
override 56 using IndexValuePairsVector = std::vector<CounterValue>;
59 virtual void SendStreamMetaDataPacket() {}
62 virtual void SendCounterDirectoryPacket(
const ICounterDirectory& counterDirectory)
68 virtual void SendPeriodicCounterCapturePacket(uint64_t timestamp,
const IndexValuePairsVector& values)
70 m_timestamps.emplace_back(
Timestamp{timestamp, values});
74 virtual void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
75 const std::vector<uint16_t>& selectedCounterIds)
81 std::vector<Timestamp> GetTimestamps()
86 void ClearTimestamps()
92 std::vector<Timestamp> m_timestamps;
95 arm::pipe::Packet
PacketWriter(uint32_t period, std::vector<uint16_t> countervalues)
97 const uint32_t packetId = 0x40000;
99 uint32_t dataLength =
static_cast<uint32_t
>(4 + countervalues.size() * 2);
100 std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength);
101 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData.get());
105 for (
auto countervalue : countervalues)
111 return {packetId, dataLength, uniqueData};
126 unsigned int shiftedId = 0;
128 #if defined(ETHOSN_SUPPORT_ENABLED) 136 BOOST_CHECK(counterMap.
GetGlobalId(0, mockId) == 5 + shiftedId);
137 BOOST_CHECK(counterMap.
GetGlobalId(1, mockId) == 6 + shiftedId);
138 BOOST_CHECK(counterMap.
GetGlobalId(2, mockId) == 7 + shiftedId);
139 BOOST_CHECK(counterMap.
GetGlobalId(3, mockId) == 8 + shiftedId);
140 BOOST_CHECK(counterMap.
GetGlobalId(4, mockId) == 9 + shiftedId);
141 BOOST_CHECK(counterMap.
GetGlobalId(5, mockId) == 10 + shiftedId);
149 arm::pipe::PacketVersionResolver packetVersionResolver;
151 ReadCounterVals readCounterVals;
153 MockBackendSendCounterPacket sendCounterPacket;
163 std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
164 std::make_unique<BackendProfiling>(options, profilingService, cpuAccId);
165 std::unique_ptr<armnn::profiling::IBackendProfiling> gpuBackendProfilingPtr =
166 std::make_unique<BackendProfiling>(options, profilingService, gpuAccId);
168 std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
169 std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
170 std::shared_ptr<armnn::profiling::IBackendProfilingContext> gpuProfilingContextPtr =
171 std::make_shared<armnn::MockBackendProfilingContext>(gpuBackendProfilingPtr);
174 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
176 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
177 backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
179 uint16_t globalId = 5;
189 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
190 backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
193 counterIdMap, backendProfilingContexts);
195 uint16_t maxArmnnCounterId = 4;
199 packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
200 backendProfilingContexts,
204 periodicCounterCapture,
213 uint32_t period = 12345u;
215 std::vector<uint16_t> cpuCounters{5, 6, 7};
216 std::vector<uint16_t> gpuCounters{8, 9, 10};
219 periodicCounterSelectionCommandHandler(
PacketWriter(period, gpuCounters));
220 periodicCounterCapture.Stop();
222 std::set<armnn::BackendId> activeIds = holder.GetCaptureData().GetActiveBackends();
223 BOOST_CHECK(activeIds.size() == 1);
224 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
226 std::vector<Timestamp> recievedTimestamp = sendCounterPacket.GetTimestamps();
228 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
229 BOOST_CHECK(recievedTimestamp.size() == 1);
230 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == gpuCounters.size());
231 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
233 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == gpuCounters[i]);
234 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
236 sendCounterPacket.ClearTimestamps();
239 periodicCounterSelectionCommandHandler(
PacketWriter(period, cpuCounters));
240 periodicCounterCapture.Stop();
242 activeIds = holder.GetCaptureData().GetActiveBackends();
243 BOOST_CHECK(activeIds.size() == 1);
244 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
246 recievedTimestamp = sendCounterPacket.GetTimestamps();
248 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
249 BOOST_CHECK(recievedTimestamp.size() == 1);
250 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
251 for (
unsigned long i=0; i< cpuCounters.size(); ++i)
253 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
254 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
256 sendCounterPacket.ClearTimestamps();
260 periodicCounterSelectionCommandHandler(
PacketWriter(period, {cpuCounters[0], gpuCounters[2],
261 gpuCounters[1], cpuCounters[1], gpuCounters[0]}));
262 periodicCounterCapture.Stop();
264 activeIds = holder.GetCaptureData().GetActiveBackends();
265 BOOST_CHECK(activeIds.size() == 2);
266 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
267 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
269 recievedTimestamp = sendCounterPacket.GetTimestamps();
271 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
272 BOOST_CHECK(recievedTimestamp[1].timestamp == period);
274 BOOST_CHECK(recievedTimestamp.size() == 2);
275 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
276 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
278 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
279 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
280 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[1]);
281 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 2u);
283 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
285 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
286 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
289 sendCounterPacket.ClearTimestamps();
292 std::vector<uint16_t> counterValues;
293 counterValues.insert(counterValues.begin(), cpuCounters.begin(), cpuCounters.end());
294 counterValues.insert(counterValues.begin(), gpuCounters.begin(), gpuCounters.end());
296 periodicCounterSelectionCommandHandler(
PacketWriter(period, counterValues));
297 periodicCounterCapture.Stop();
299 activeIds = holder.GetCaptureData().GetActiveBackends();
300 BOOST_CHECK(activeIds.size() == 2);
301 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
302 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
304 recievedTimestamp = sendCounterPacket.GetTimestamps();
306 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
307 for (
unsigned long i=0; i< cpuCounters.size(); ++i)
309 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
310 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
313 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
314 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
316 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
317 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
319 sendCounterPacket.ClearTimestamps();
322 counterValues = {0, 0, 200, cpuCounters[2], gpuCounters[0],3 ,30, cpuCounters[0],cpuCounters[2], gpuCounters[1], 3,
323 90, 0, 30, gpuCounters[0], gpuCounters[0]};
325 periodicCounterSelectionCommandHandler(
PacketWriter(period, counterValues));
326 periodicCounterCapture.Stop();
328 activeIds = holder.GetCaptureData().GetActiveBackends();
329 BOOST_CHECK(activeIds.size() == 2);
330 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
331 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
333 recievedTimestamp = sendCounterPacket.GetTimestamps();
335 BOOST_CHECK(recievedTimestamp.size() == 2);
337 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
339 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
340 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
341 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[2]);
342 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 3u);
344 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == 2);
346 BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterId == gpuCounters[0]);
347 BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterValue == 1u);
348 BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterId == gpuCounters[1]);
349 BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterValue == 2u);
351 sendCounterPacket.ClearTimestamps();
354 periodicCounterSelectionCommandHandler(
PacketWriter(period, {}));
355 periodicCounterCapture.Stop();
357 activeIds = holder.GetCaptureData().GetActiveBackends();
358 BOOST_CHECK(activeIds.size() == 0);
360 recievedTimestamp = sendCounterPacket.GetTimestamps();
361 BOOST_CHECK(recievedTimestamp.size() == 0);
363 sendCounterPacket.ClearTimestamps();
366 periodicCounterSelectionCommandHandler(
PacketWriter(0, counterValues));
367 periodicCounterCapture.Stop();
369 activeIds = holder.GetCaptureData().GetActiveBackends();
370 BOOST_CHECK(activeIds.size() == 0);
372 recievedTimestamp = sendCounterPacket.GetTimestamps();
373 BOOST_CHECK(recievedTimestamp.size() == 0);
378 std::stringstream ss;
384 : m_Stream(stream), m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
388 { m_Stream.rdbuf(m_BackupBuffer); }
391 std::ostream &m_Stream;
392 std::streambuf *m_BackupBuffer;
396 arm::pipe::PacketVersionResolver packetVersionResolver;
398 ReadCounterVals readCounterVals;
401 MockBackendSendCounterPacket sendCounterPacket;
411 std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
412 std::make_unique<BackendProfiling>(options, profilingService, cpuAccId);
414 std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
415 std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
418 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
420 uint16_t globalId = 5;
421 counterIdMap.RegisterMapping(globalId, 0, cpuAccId);
422 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
425 counterIdMap, backendProfilingContexts);
427 uint16_t maxArmnnCounterId = 4;
431 packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
432 backendProfilingContexts,
436 periodicCounterCapture,
445 uint32_t period = 15939u;
449 periodicCounterSelectionCommandHandler(
PacketWriter(period, {5}));
450 periodicCounterCapture.Stop();
453 BOOST_CHECK(ss.str().find(
"ActivateCounters example test error") != std::string::npos);
470 BOOST_CHECK(mockBackEndProfilingContext);
473 BOOST_CHECK(backendProfilingIface);
477 std::unique_ptr<armnn::profiling::ISendTimelinePacket> timelinePacket =
478 backendProfilingIface->GetSendTimelinePacket();
480 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
481 timelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
482 timelinePacket->Commit();
501 BOOST_CHECK(mockBackEndProfilingContext);
504 BOOST_CHECK(backendProfilingIface);
510 BOOST_CHECK(secondGuid > firstGuid);
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
profiling::ProfilingService & GetProfilingService(armnn::RuntimeImpl *runtime)
virtual ProfilingDynamicGuid NextGuid()=0
Return the next random Guid in the sequence.
static IRuntimePtr Create(const CreationOptions &options)
void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured)
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
constexpr const char * MockBackendId()
void IgnoreUnused(Ts &&...)
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId) override
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr
void SetLogFilter(LogSeverity level)
const ICounterMappings & GetCounterMappings() const override
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
GPU Execution: OpenCL: ArmCompute.
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
static MockBackendProfilingService & Instance()
arm::pipe::Packet PacketWriter(uint32_t period, std::vector< uint16_t > countervalues)
MockBackendProfilingContext * GetContext()
BOOST_AUTO_TEST_SUITE_END()
CPU Execution: NEON: ArmCompute.
void TransitionToState(ProfilingState newState)
IBackendInternal::IBackendProfilingPtr & GetBackendProfiling()
ExternalProfilingOptions m_ProfilingOptions
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0