6 #include "CounterDirectory.hpp" 24 #include <boost/numeric/conversion/cast.hpp> 25 #include <boost/test/unit_test.hpp> 36 virtual bool IsCounterRegistered(uint16_t counterUid)
const override 38 return (counterUid > 4 && counterUid < 11);
40 virtual uint16_t GetCounterCount()
const override 44 virtual uint32_t GetAbsoluteCounterValue(uint16_t counterUid)
const override 48 virtual uint32_t GetDeltaCounterValue(uint16_t counterUid)
override 57 using IndexValuePairsVector = std::vector<CounterValue>;
60 virtual void SendStreamMetaDataPacket() {}
63 virtual void SendCounterDirectoryPacket(
const ICounterDirectory& counterDirectory)
69 virtual void SendPeriodicCounterCapturePacket(uint64_t timestamp,
const IndexValuePairsVector& values)
71 m_timestamps.emplace_back(
Timestamp{timestamp, values});
75 virtual void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
76 const std::vector<uint16_t>& selectedCounterIds)
82 std::vector<Timestamp> GetTimestamps()
87 void ClearTimestamps()
93 std::vector<Timestamp> m_timestamps;
96 Packet
PacketWriter(uint32_t period, std::vector<uint16_t> countervalues)
98 const uint32_t packetId = 0x40000;
100 uint32_t dataLength =
static_cast<uint32_t
>(4 + countervalues.size() * 2);
101 std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength);
102 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData.get());
106 for (
auto countervalue : countervalues)
112 return {packetId, dataLength, uniqueData};
145 ReadCounterVals readCounterVals;
147 MockBackendSendCounterPacket sendCounterPacket;
157 std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
159 std::unique_ptr<armnn::profiling::IBackendProfiling> gpuBackendProfilingPtr =
162 std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
163 std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
164 std::shared_ptr<armnn::profiling::IBackendProfilingContext> gpuProfilingContextPtr =
165 std::make_shared<armnn::MockBackendProfilingContext>(gpuBackendProfilingPtr);
168 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
170 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
171 backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
173 uint16_t globalId = 5;
183 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
184 backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
187 counterIdMap, backendProfilingContexts);
189 uint16_t maxArmnnCounterId = 4;
194 backendProfilingContexts,
198 periodicCounterCapture,
207 uint32_t period = 12345u;
209 std::vector<uint16_t> cpuCounters{5, 6, 7};
210 std::vector<uint16_t> gpuCounters{8, 9, 10};
213 periodicCounterSelectionCommandHandler(
PacketWriter(period, gpuCounters));
214 periodicCounterCapture.Stop();
216 std::set<armnn::BackendId> activeIds = holder.GetCaptureData().GetActiveBackends();
218 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
220 std::vector<Timestamp> recievedTimestamp = sendCounterPacket.GetTimestamps();
222 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
224 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == gpuCounters.size());
225 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
227 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == gpuCounters[i]);
228 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
230 sendCounterPacket.ClearTimestamps();
233 periodicCounterSelectionCommandHandler(
PacketWriter(period, cpuCounters));
234 periodicCounterCapture.Stop();
236 activeIds = holder.GetCaptureData().GetActiveBackends();
238 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
240 recievedTimestamp = sendCounterPacket.GetTimestamps();
242 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
244 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
245 for (
unsigned long i=0; i< cpuCounters.size(); ++i)
247 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
248 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
250 sendCounterPacket.ClearTimestamps();
254 periodicCounterSelectionCommandHandler(
PacketWriter(period, {cpuCounters[0], gpuCounters[2],
255 gpuCounters[1], cpuCounters[1], gpuCounters[0]}));
256 periodicCounterCapture.Stop();
258 activeIds = holder.GetCaptureData().GetActiveBackends();
260 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
261 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
263 recievedTimestamp = sendCounterPacket.GetTimestamps();
265 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
266 BOOST_CHECK(recievedTimestamp[1].timestamp == period);
269 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
270 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
272 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
273 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
274 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[1]);
275 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 2u);
277 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
279 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
280 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
283 sendCounterPacket.ClearTimestamps();
286 std::vector<uint16_t> counterValues;
287 counterValues.insert(counterValues.begin(), cpuCounters.begin(), cpuCounters.end());
288 counterValues.insert(counterValues.begin(), gpuCounters.begin(), gpuCounters.end());
290 periodicCounterSelectionCommandHandler(
PacketWriter(period, counterValues));
291 periodicCounterCapture.Stop();
293 activeIds = holder.GetCaptureData().GetActiveBackends();
295 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
296 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
298 recievedTimestamp = sendCounterPacket.GetTimestamps();
300 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
301 for (
unsigned long i=0; i< cpuCounters.size(); ++i)
303 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
304 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
307 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
308 for (
unsigned long i=0; i< gpuCounters.size(); ++i)
310 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
311 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
313 sendCounterPacket.ClearTimestamps();
316 counterValues = {0, 0, 200, cpuCounters[2], gpuCounters[0],3 ,30, cpuCounters[0],cpuCounters[2], gpuCounters[1], 3,
317 90, 0, 30, gpuCounters[0], gpuCounters[0]};
319 periodicCounterSelectionCommandHandler(
PacketWriter(period, counterValues));
320 periodicCounterCapture.Stop();
322 activeIds = holder.GetCaptureData().GetActiveBackends();
324 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
325 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
327 recievedTimestamp = sendCounterPacket.GetTimestamps();
331 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
333 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
334 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
335 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[2]);
336 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 3u);
338 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == 2);
340 BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterId == gpuCounters[0]);
341 BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterValue == 1u);
342 BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterId == gpuCounters[1]);
343 BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterValue == 2u);
345 sendCounterPacket.ClearTimestamps();
348 periodicCounterSelectionCommandHandler(
PacketWriter(period, {}));
349 periodicCounterCapture.Stop();
351 activeIds = holder.GetCaptureData().GetActiveBackends();
354 recievedTimestamp = sendCounterPacket.GetTimestamps();
357 sendCounterPacket.ClearTimestamps();
360 periodicCounterSelectionCommandHandler(
PacketWriter(0, counterValues));
361 periodicCounterCapture.Stop();
363 activeIds = holder.GetCaptureData().GetActiveBackends();
366 recievedTimestamp = sendCounterPacket.GetTimestamps();
372 std::stringstream ss;
378 : m_Stream(stream), m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
382 { m_Stream.rdbuf(m_BackupBuffer); }
385 std::ostream &m_Stream;
386 std::streambuf *m_BackupBuffer;
392 ReadCounterVals readCounterVals;
395 MockBackendSendCounterPacket sendCounterPacket;
405 std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
408 std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
409 std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
412 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
414 uint16_t globalId = 5;
415 counterIdMap.RegisterMapping(globalId, 0, cpuAccId);
416 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
419 counterIdMap, backendProfilingContexts);
421 uint16_t maxArmnnCounterId = 4;
426 backendProfilingContexts,
430 periodicCounterCapture,
439 uint32_t period = 15939u;
443 periodicCounterSelectionCommandHandler(
PacketWriter(period, {5}));
444 periodicCounterCapture.Stop();
447 BOOST_CHECK(ss.str().find(
"ActivateCounters example test error") != std::string::npos);
471 std::unique_ptr<armnn::profiling::ISendTimelinePacket> timelinePacket =
472 backendProfilingIface->GetSendTimelinePacket();
474 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
475 timelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
476 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)
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 &&...)
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)
profiling::ProfilingService & GetProfilingService(armnn::Runtime *runtime)
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()
armnn::profiling::ProfilingService profilingService
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