6 #include "CounterDirectory.hpp" 21 #include <boost/algorithm/string.hpp> 22 #include <boost/numeric/conversion/cast.hpp> 23 #include <boost/test/unit_test.hpp> 34 virtual bool IsCounterRegistered(uint16_t counterUid)
const override 36 return (counterUid > 4 && counterUid < 11);
38 virtual uint16_t GetCounterCount()
const override 42 virtual uint32_t GetCounterValue(uint16_t counterUid)
const override 51 using IndexValuePairsVector = std::vector<CounterValue>;
54 virtual void SendStreamMetaDataPacket() {}
57 virtual void SendCounterDirectoryPacket(
const ICounterDirectory& counterDirectory)
59 boost::ignore_unused(counterDirectory);
63 virtual void SendPeriodicCounterCapturePacket(uint64_t timestamp,
const IndexValuePairsVector& values)
65 m_timestamps.emplace_back(
Timestamp{timestamp, values});
69 virtual void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
70 const std::vector<uint16_t>& selectedCounterIds)
72 boost::ignore_unused(capturePeriod);
73 boost::ignore_unused(selectedCounterIds);
76 std::vector<Timestamp> GetTimestamps()
81 void ClearTimestamps()
87 std::vector<Timestamp> m_timestamps;
92 const uint32_t packetId = 0x40000;
94 uint32_t dataLength =
static_cast<uint32_t
>(4 + countervalues.size() * 2);
95 std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength);
96 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData.get());
100 for (
auto countervalue : countervalues)
106 return {packetId, dataLength, uniqueData};
141 ReadCounterVals readCounterVals;
143 MockBackendSendCounterPacket sendCounterPacket;
153 std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
155 std::unique_ptr<armnn::profiling::IBackendProfiling> gpuBackendProfilingPtr =
158 std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
159 std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
160 std::shared_ptr<armnn::profiling::IBackendProfilingContext> gpuProfilingContextPtr =
161 std::make_shared<armnn::MockBackendProfilingContext>(gpuBackendProfilingPtr);
164 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
166 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
167 backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
169 uint16_t globalId = 5;
179 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
180 backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
183 counterIdMap, backendProfilingContexts);
185 uint16_t maxArmnnCounterId = 4;
190 backendProfilingContexts,
194 periodicCounterCapture,
203 uint32_t period = 12345u;
205 std::vector<uint16_t> cpuCounters{5, 6, 7};
206 std::vector<uint16_t> gpuCounters{8, 9, 10};
209 periodicCounterSelectionCommandHandler(
PacketWriter(period, gpuCounters));
210 periodicCounterCapture.Stop();
212 std::set<armnn::BackendId> activeIds = holder.GetCaptureData().GetActiveBackends();
214 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
216 std::vector<Timestamp> recievedTimestamp = sendCounterPacket.GetTimestamps();
218 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
220 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == gpuCounters.size());
221 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
223 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == gpuCounters[i]);
224 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
226 sendCounterPacket.ClearTimestamps();
229 periodicCounterSelectionCommandHandler(
PacketWriter(period, cpuCounters));
230 periodicCounterCapture.Stop();
232 activeIds = holder.GetCaptureData().GetActiveBackends();
234 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
236 recievedTimestamp = sendCounterPacket.GetTimestamps();
238 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
240 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
241 for (
unsigned long i=0; i< cpuCounters.size(); ++i)
243 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
244 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
246 sendCounterPacket.ClearTimestamps();
250 periodicCounterSelectionCommandHandler(
PacketWriter(period, {cpuCounters[0], gpuCounters[2],
251 gpuCounters[1], cpuCounters[1], gpuCounters[0]}));
252 periodicCounterCapture.Stop();
254 activeIds = holder.GetCaptureData().GetActiveBackends();
256 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
257 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
259 recievedTimestamp = sendCounterPacket.GetTimestamps();
261 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
262 BOOST_CHECK(recievedTimestamp[1].timestamp == period);
265 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
266 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
268 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
269 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
270 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[1]);
271 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 2u);
273 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
275 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
276 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
279 sendCounterPacket.ClearTimestamps();
282 std::vector<uint16_t> counterValues;
283 counterValues.insert(counterValues.begin(), cpuCounters.begin(), cpuCounters.end());
284 counterValues.insert(counterValues.begin(), gpuCounters.begin(), gpuCounters.end());
286 periodicCounterSelectionCommandHandler(
PacketWriter(period, counterValues));
287 periodicCounterCapture.Stop();
289 activeIds = holder.GetCaptureData().GetActiveBackends();
291 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
292 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
294 recievedTimestamp = sendCounterPacket.GetTimestamps();
296 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
297 for (
unsigned long i=0; i< cpuCounters.size(); ++i)
299 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
300 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
303 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
304 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
306 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
307 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
309 sendCounterPacket.ClearTimestamps();
312 counterValues = {0, 0, 200, cpuCounters[2], gpuCounters[0],3 ,30, cpuCounters[0],cpuCounters[2], gpuCounters[1], 3,
313 90, 0, 30, gpuCounters[0], gpuCounters[0]};
315 periodicCounterSelectionCommandHandler(
PacketWriter(period, counterValues));
316 periodicCounterCapture.Stop();
318 activeIds = holder.GetCaptureData().GetActiveBackends();
320 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
321 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
323 recievedTimestamp = sendCounterPacket.GetTimestamps();
327 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
329 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
330 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
331 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[2]);
332 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 3u);
334 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == 2);
336 BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterId == gpuCounters[0]);
337 BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterValue == 1u);
338 BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterId == gpuCounters[1]);
339 BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterValue == 2u);
341 sendCounterPacket.ClearTimestamps();
344 periodicCounterSelectionCommandHandler(
PacketWriter(period, {}));
345 periodicCounterCapture.Stop();
347 activeIds = holder.GetCaptureData().GetActiveBackends();
350 recievedTimestamp = sendCounterPacket.GetTimestamps();
353 sendCounterPacket.ClearTimestamps();
356 periodicCounterSelectionCommandHandler(
PacketWriter(0, counterValues));
357 periodicCounterCapture.Stop();
359 activeIds = holder.GetCaptureData().GetActiveBackends();
362 recievedTimestamp = sendCounterPacket.GetTimestamps();
368 std::stringstream ss;
374 : m_Stream(stream), m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
378 { m_Stream.rdbuf(m_BackupBuffer); }
381 std::ostream &m_Stream;
382 std::streambuf *m_BackupBuffer;
388 ReadCounterVals readCounterVals;
391 MockBackendSendCounterPacket sendCounterPacket;
401 std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
404 std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
405 std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
408 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
410 uint16_t globalId = 5;
411 counterIdMap.RegisterMapping(globalId, 0, cpuAccId);
412 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
415 counterIdMap, backendProfilingContexts);
417 uint16_t maxArmnnCounterId = 4;
422 backendProfilingContexts,
426 periodicCounterCapture,
435 uint32_t period = 15939u;
439 periodicCounterSelectionCommandHandler(
PacketWriter(period, {5}));
440 periodicCounterCapture.Stop();
443 BOOST_CHECK(boost::contains(ss.str(),
"ActivateCounters example test error"));
467 std::unique_ptr<armnn::profiling::ISendTimelinePacket> timelinePacket =
468 backendProfilingIface->GetSendTimelinePacket();
470 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
471 timelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
472 timelinePacket->Commit();
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
uint32_t GetEncodedValue()
static MockBackendProfilingService & Instance()
const ICounterMappings & GetCounterMappings() const override
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
virtual ProfilingDynamicGuid NextGuid()=0
Return the next random Guid in the sequence.
void TransitionToState(ProfilingState newState)
IBackendInternal::IBackendProfilingPtr & GetBackendProfiling()
ExternalProfilingOptions m_ProfilingOptions
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId) override
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0
void SetLogFilter(LogSeverity level)
Packet PacketWriter(uint32_t period, std::vector< uint16_t > countervalues)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
GPU Execution: OpenCL: ArmCompute.
constexpr const char * MockBackendId()
MockBackendProfilingContext * GetContext()
static ProfilingService & Instance()
static IRuntimePtr Create(const CreationOptions &options)
BOOST_AUTO_TEST_SUITE_END()
CPU Execution: NEON: ArmCompute.
void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured)
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
ProfilingService & profilingService
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr