6 #include "CounterDirectory.hpp" 22 #include <boost/algorithm/string.hpp> 23 #include <boost/numeric/conversion/cast.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 GetCounterValue(uint16_t counterUid)
const override 52 using IndexValuePairsVector = std::vector<CounterValue>;
55 virtual void SendStreamMetaDataPacket() {}
58 virtual void SendCounterDirectoryPacket(
const ICounterDirectory& counterDirectory)
64 virtual void SendPeriodicCounterCapturePacket(uint64_t timestamp,
const IndexValuePairsVector& values)
66 m_timestamps.emplace_back(
Timestamp{timestamp, values});
70 virtual void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
71 const std::vector<uint16_t>& selectedCounterIds)
77 std::vector<Timestamp> GetTimestamps()
82 void ClearTimestamps()
88 std::vector<Timestamp> m_timestamps;
93 const uint32_t packetId = 0x40000;
95 uint32_t dataLength =
static_cast<uint32_t
>(4 + countervalues.size() * 2);
96 std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength);
97 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData.get());
101 for (
auto countervalue : countervalues)
107 return {packetId, dataLength, uniqueData};
142 ReadCounterVals readCounterVals;
144 MockBackendSendCounterPacket sendCounterPacket;
154 std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
156 std::unique_ptr<armnn::profiling::IBackendProfiling> gpuBackendProfilingPtr =
159 std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
160 std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
161 std::shared_ptr<armnn::profiling::IBackendProfilingContext> gpuProfilingContextPtr =
162 std::make_shared<armnn::MockBackendProfilingContext>(gpuBackendProfilingPtr);
165 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
167 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
168 backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
170 uint16_t globalId = 5;
180 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
181 backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
184 counterIdMap, backendProfilingContexts);
186 uint16_t maxArmnnCounterId = 4;
191 backendProfilingContexts,
195 periodicCounterCapture,
204 uint32_t period = 12345u;
206 std::vector<uint16_t> cpuCounters{5, 6, 7};
207 std::vector<uint16_t> gpuCounters{8, 9, 10};
210 periodicCounterSelectionCommandHandler(
PacketWriter(period, gpuCounters));
211 periodicCounterCapture.Stop();
213 std::set<armnn::BackendId> activeIds = holder.GetCaptureData().GetActiveBackends();
215 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
217 std::vector<Timestamp> recievedTimestamp = sendCounterPacket.GetTimestamps();
219 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
221 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == gpuCounters.size());
222 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
224 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == gpuCounters[i]);
225 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
227 sendCounterPacket.ClearTimestamps();
230 periodicCounterSelectionCommandHandler(
PacketWriter(period, cpuCounters));
231 periodicCounterCapture.Stop();
233 activeIds = holder.GetCaptureData().GetActiveBackends();
235 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
237 recievedTimestamp = sendCounterPacket.GetTimestamps();
239 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
241 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
242 for (
unsigned long i=0; i< cpuCounters.size(); ++i)
244 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
245 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
247 sendCounterPacket.ClearTimestamps();
251 periodicCounterSelectionCommandHandler(
PacketWriter(period, {cpuCounters[0], gpuCounters[2],
252 gpuCounters[1], cpuCounters[1], gpuCounters[0]}));
253 periodicCounterCapture.Stop();
255 activeIds = holder.GetCaptureData().GetActiveBackends();
257 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
258 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
260 recievedTimestamp = sendCounterPacket.GetTimestamps();
262 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
263 BOOST_CHECK(recievedTimestamp[1].timestamp == period);
266 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
267 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
269 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
270 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
271 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[1]);
272 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 2u);
274 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
276 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
277 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
280 sendCounterPacket.ClearTimestamps();
283 std::vector<uint16_t> counterValues;
284 counterValues.insert(counterValues.begin(), cpuCounters.begin(), cpuCounters.end());
285 counterValues.insert(counterValues.begin(), gpuCounters.begin(), gpuCounters.end());
287 periodicCounterSelectionCommandHandler(
PacketWriter(period, counterValues));
288 periodicCounterCapture.Stop();
290 activeIds = holder.GetCaptureData().GetActiveBackends();
292 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
293 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
295 recievedTimestamp = sendCounterPacket.GetTimestamps();
297 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
298 for (
unsigned long i=0; i< cpuCounters.size(); ++i)
300 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
301 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
304 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
305 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
307 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
308 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
310 sendCounterPacket.ClearTimestamps();
313 counterValues = {0, 0, 200, cpuCounters[2], gpuCounters[0],3 ,30, cpuCounters[0],cpuCounters[2], gpuCounters[1], 3,
314 90, 0, 30, gpuCounters[0], gpuCounters[0]};
316 periodicCounterSelectionCommandHandler(
PacketWriter(period, counterValues));
317 periodicCounterCapture.Stop();
319 activeIds = holder.GetCaptureData().GetActiveBackends();
321 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
322 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
324 recievedTimestamp = sendCounterPacket.GetTimestamps();
328 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
330 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
331 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
332 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[2]);
333 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 3u);
335 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == 2);
337 BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterId == gpuCounters[0]);
338 BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterValue == 1u);
339 BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterId == gpuCounters[1]);
340 BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterValue == 2u);
342 sendCounterPacket.ClearTimestamps();
345 periodicCounterSelectionCommandHandler(
PacketWriter(period, {}));
346 periodicCounterCapture.Stop();
348 activeIds = holder.GetCaptureData().GetActiveBackends();
351 recievedTimestamp = sendCounterPacket.GetTimestamps();
354 sendCounterPacket.ClearTimestamps();
357 periodicCounterSelectionCommandHandler(
PacketWriter(0, counterValues));
358 periodicCounterCapture.Stop();
360 activeIds = holder.GetCaptureData().GetActiveBackends();
363 recievedTimestamp = sendCounterPacket.GetTimestamps();
369 std::stringstream ss;
375 : m_Stream(stream), m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
379 { m_Stream.rdbuf(m_BackupBuffer); }
382 std::ostream &m_Stream;
383 std::streambuf *m_BackupBuffer;
389 ReadCounterVals readCounterVals;
392 MockBackendSendCounterPacket sendCounterPacket;
402 std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
405 std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
406 std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
409 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
411 uint16_t globalId = 5;
412 counterIdMap.RegisterMapping(globalId, 0, cpuAccId);
413 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
416 counterIdMap, backendProfilingContexts);
418 uint16_t maxArmnnCounterId = 4;
423 backendProfilingContexts,
427 periodicCounterCapture,
436 uint32_t period = 15939u;
440 periodicCounterSelectionCommandHandler(
PacketWriter(period, {5}));
441 periodicCounterCapture.Stop();
444 BOOST_CHECK(boost::contains(ss.str(),
"ActivateCounters example test error"));
468 std::unique_ptr<armnn::profiling::ISendTimelinePacket> timelinePacket =
469 backendProfilingIface->GetSendTimelinePacket();
471 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
472 timelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
473 timelinePacket->Commit();
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
virtual ProfilingDynamicGuid NextGuid()=0
Return the next random Guid in the sequence.
static IRuntimePtr Create(const CreationOptions &options)
static ProfilingService & Instance()
uint32_t GetEncodedValue()
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)
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
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 &&...)
ProfilingService & profilingService
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId) override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
Packet PacketWriter(uint32_t period, std::vector< uint16_t > countervalues)
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()
MockBackendProfilingContext * GetContext()
BOOST_AUTO_TEST_SUITE_END()
CPU Execution: NEON: ArmCompute.
void TransitionToState(ProfilingState newState)
IBackendInternal::IBackendProfilingPtr & GetBackendProfiling()
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ExternalProfilingOptions m_ProfilingOptions
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0