ArmNN  NotReleased
BackendProfilingTests.cpp File Reference
#include "CounterDirectory.hpp"
#include "CounterIdMap.hpp"
#include "Holder.hpp"
#include "MockBackend.hpp"
#include "MockBackendId.hpp"
#include "PeriodicCounterCapture.hpp"
#include "PeriodicCounterSelectionCommandHandler.hpp"
#include "ProfilingStateMachine.hpp"
#include "ProfilingUtils.hpp"
#include "RequestCounterDirectoryCommandHandler.hpp"
#include <armnn/BackendId.hpp>
#include <armnn/Logging.hpp>
#include <armnn/profiling/ISendTimelinePacket.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/test/unit_test.hpp>
#include <vector>
#include <cstdint>
#include <limits>
#include <backends/BackendProfiling.hpp>

Go to the source code of this file.

Functions

Packet PacketWriter (uint32_t period, std::vector< uint16_t > countervalues)
 
 BOOST_AUTO_TEST_CASE (BackendProfilingCounterRegisterMockBackendTest)
 
 BOOST_AUTO_TEST_CASE (TestBackendCounters)
 
 BOOST_AUTO_TEST_CASE (TestBackendCounterLogging)
 
 BOOST_AUTO_TEST_CASE (BackendProfilingContextGetSendTimelinePacket)
 
 BOOST_AUTO_TEST_CASE (GetProfilingGuidGenerator)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/5]

BOOST_AUTO_TEST_CASE ( BackendProfilingCounterRegisterMockBackendTest  )

Definition at line 111 of file BackendProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::ConfigureProfilingService(), IRuntime::Create(), ProfilingService::GetCounterMappings(), ICounterMappings::GetGlobalId(), ProfilingService::Instance(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, armnn::MockBackendId(), options, profilingService, and ProfilingService::ResetExternalProfilingOptions().

112 {
113  // Reset the profiling service to the uninitialized state
115  options.m_ProfilingOptions.m_EnableProfiling = true;
117  profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
118 
119  armnn::MockBackendInitialiser initialiser;
120  // Create a runtime
122 
123  // Check if the MockBackends 3 dummy counters {0, 1, 2-5 (four cores)} are registered
125  const armnn::profiling::ICounterMappings& counterMap = profilingService.GetCounterMappings();
126  BOOST_CHECK(counterMap.GetGlobalId(0, mockId) == 5);
127  BOOST_CHECK(counterMap.GetGlobalId(1, mockId) == 6);
128  BOOST_CHECK(counterMap.GetGlobalId(2, mockId) == 7);
129  BOOST_CHECK(counterMap.GetGlobalId(3, mockId) == 8);
130  BOOST_CHECK(counterMap.GetGlobalId(4, mockId) == 9);
131  BOOST_CHECK(counterMap.GetGlobalId(5, mockId) == 10);
132  options.m_ProfilingOptions.m_EnableProfiling = false;
133  profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
134 }
const ICounterMappings & GetCounterMappings() const override
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
constexpr const char * MockBackendId()
static ProfilingService & Instance()
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:32
ProfilingService & profilingService
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:24

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( TestBackendCounters  )

Definition at line 136 of file BackendProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), armnn::CpuAcc, Version::GetEncodedValue(), armnn::GpuAcc, ProfilingService::Instance(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, armnn::profiling::NotConnected, options, PacketWriter(), profilingService, CounterIdMap::RegisterMapping(), PacketVersionResolver::ResolvePacketVersion(), ProfilingStateMachine::TransitionToState(), and armnn::profiling::WaitingForAck.

137 {
138  Holder holder;
139  PacketVersionResolver packetVersionResolver;
140  ProfilingStateMachine stateMachine;
141  ReadCounterVals readCounterVals;
142  CounterIdMap counterIdMap;
143  MockBackendSendCounterPacket sendCounterPacket;
144 
147 
149  options.m_ProfilingOptions.m_EnableProfiling = true;
150 
152 
153  std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
154  std::make_unique<BackendProfiling>(options, profilingService, cpuAccId);
155  std::unique_ptr<armnn::profiling::IBackendProfiling> gpuBackendProfilingPtr =
156  std::make_unique<BackendProfiling>(options, profilingService, gpuAccId);
157 
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);
162 
163  std::unordered_map<armnn::BackendId,
164  std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
165 
166  backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
167  backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
168 
169  uint16_t globalId = 5;
170 
171  counterIdMap.RegisterMapping(globalId++, 0, cpuAccId);
172  counterIdMap.RegisterMapping(globalId++, 1, cpuAccId);
173  counterIdMap.RegisterMapping(globalId++, 2, cpuAccId);
174 
175  counterIdMap.RegisterMapping(globalId++, 0, gpuAccId);
176  counterIdMap.RegisterMapping(globalId++, 1, gpuAccId);
177  counterIdMap.RegisterMapping(globalId++, 2, gpuAccId);
178 
179  backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
180  backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
181 
182  PeriodicCounterCapture periodicCounterCapture(holder, sendCounterPacket, readCounterVals,
183  counterIdMap, backendProfilingContexts);
184 
185  uint16_t maxArmnnCounterId = 4;
186 
187  PeriodicCounterSelectionCommandHandler periodicCounterSelectionCommandHandler(0,
188  4,
189  packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
190  backendProfilingContexts,
191  counterIdMap,
192  holder,
193  maxArmnnCounterId,
194  periodicCounterCapture,
195  readCounterVals,
196  sendCounterPacket,
197  stateMachine);
198 
199  stateMachine.TransitionToState(ProfilingState::NotConnected);
200  stateMachine.TransitionToState(ProfilingState::WaitingForAck);
201  stateMachine.TransitionToState(ProfilingState::Active);
202 
203  uint32_t period = 12345u;
204 
205  std::vector<uint16_t> cpuCounters{5, 6, 7};
206  std::vector<uint16_t> gpuCounters{8, 9, 10};
207 
208  // Request only gpu counters
209  periodicCounterSelectionCommandHandler(PacketWriter(period, gpuCounters));
210  periodicCounterCapture.Stop();
211 
212  std::set<armnn::BackendId> activeIds = holder.GetCaptureData().GetActiveBackends();
213  BOOST_CHECK(activeIds.size() == 1);
214  BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
215 
216  std::vector<Timestamp> recievedTimestamp = sendCounterPacket.GetTimestamps();
217 
218  BOOST_CHECK(recievedTimestamp[0].timestamp == period);
219  BOOST_CHECK(recievedTimestamp.size() == 1);
220  BOOST_CHECK(recievedTimestamp[0].counterValues.size() == gpuCounters.size());
221  for (unsigned long i=0; i< gpuCounters.size(); ++i)
222  {
223  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == gpuCounters[i]);
224  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
225  }
226  sendCounterPacket.ClearTimestamps();
227 
228  // Request only cpu counters
229  periodicCounterSelectionCommandHandler(PacketWriter(period, cpuCounters));
230  periodicCounterCapture.Stop();
231 
232  activeIds = holder.GetCaptureData().GetActiveBackends();
233  BOOST_CHECK(activeIds.size() == 1);
234  BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
235 
236  recievedTimestamp = sendCounterPacket.GetTimestamps();
237 
238  BOOST_CHECK(recievedTimestamp[0].timestamp == period);
239  BOOST_CHECK(recievedTimestamp.size() == 1);
240  BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
241  for (unsigned long i=0; i< cpuCounters.size(); ++i)
242  {
243  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
244  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
245  }
246  sendCounterPacket.ClearTimestamps();
247 
248  // Request combination of cpu & gpu counters with new period
249  period = 12222u;
250  periodicCounterSelectionCommandHandler(PacketWriter(period, {cpuCounters[0], gpuCounters[2],
251  gpuCounters[1], cpuCounters[1], gpuCounters[0]}));
252  periodicCounterCapture.Stop();
253 
254  activeIds = holder.GetCaptureData().GetActiveBackends();
255  BOOST_CHECK(activeIds.size() == 2);
256  BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
257  BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
258 
259  recievedTimestamp = sendCounterPacket.GetTimestamps();
260 
261  BOOST_CHECK(recievedTimestamp[0].timestamp == period);
262  BOOST_CHECK(recievedTimestamp[1].timestamp == period);
263 
264  BOOST_CHECK(recievedTimestamp.size() == 2);
265  BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
266  BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
267 
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);
272 
273  for (unsigned long i=0; i< gpuCounters.size(); ++i)
274  {
275  BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
276  BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
277  }
278 
279  sendCounterPacket.ClearTimestamps();
280 
281  // Request all counters
282  std::vector<uint16_t> counterValues;
283  counterValues.insert(counterValues.begin(), cpuCounters.begin(), cpuCounters.end());
284  counterValues.insert(counterValues.begin(), gpuCounters.begin(), gpuCounters.end());
285 
286  periodicCounterSelectionCommandHandler(PacketWriter(period, counterValues));
287  periodicCounterCapture.Stop();
288 
289  activeIds = holder.GetCaptureData().GetActiveBackends();
290  BOOST_CHECK(activeIds.size() == 2);
291  BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
292  BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
293 
294  recievedTimestamp = sendCounterPacket.GetTimestamps();
295 
296  BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
297  for (unsigned long i=0; i< cpuCounters.size(); ++i)
298  {
299  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
300  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
301  }
302 
303  BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
304  for (unsigned long i=0; i< gpuCounters.size(); ++i)
305  {
306  BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
307  BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
308  }
309  sendCounterPacket.ClearTimestamps();
310 
311  // Request random counters with duplicates and invalid counters
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]};
314 
315  periodicCounterSelectionCommandHandler(PacketWriter(period, counterValues));
316  periodicCounterCapture.Stop();
317 
318  activeIds = holder.GetCaptureData().GetActiveBackends();
319  BOOST_CHECK(activeIds.size() == 2);
320  BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
321  BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
322 
323  recievedTimestamp = sendCounterPacket.GetTimestamps();
324 
325  BOOST_CHECK(recievedTimestamp.size() == 2);
326 
327  BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
328 
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);
333 
334  BOOST_CHECK(recievedTimestamp[1].counterValues.size() == 2);
335 
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);
340 
341  sendCounterPacket.ClearTimestamps();
342 
343  // Request no counters
344  periodicCounterSelectionCommandHandler(PacketWriter(period, {}));
345  periodicCounterCapture.Stop();
346 
347  activeIds = holder.GetCaptureData().GetActiveBackends();
348  BOOST_CHECK(activeIds.size() == 0);
349 
350  recievedTimestamp = sendCounterPacket.GetTimestamps();
351  BOOST_CHECK(recievedTimestamp.size() == 0);
352 
353  sendCounterPacket.ClearTimestamps();
354 
355  // Request period of zero
356  periodicCounterSelectionCommandHandler(PacketWriter(0, counterValues));
357  periodicCounterCapture.Stop();
358 
359  activeIds = holder.GetCaptureData().GetActiveBackends();
360  BOOST_CHECK(activeIds.size() == 0);
361 
362  recievedTimestamp = sendCounterPacket.GetTimestamps();
363  BOOST_CHECK(recievedTimestamp.size() == 0);
364 }
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
void TransitionToState(ProfilingState newState)
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId) override
Packet PacketWriter(uint32_t period, std::vector< uint16_t > countervalues)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
GPU Execution: OpenCL: ArmCompute.
static ProfilingService & Instance()
CPU Execution: NEON: ArmCompute.
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( TestBackendCounterLogging  )

Definition at line 366 of file BackendProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), armnn::CpuAcc, armnn::Fatal, Version::GetEncodedValue(), armnn::GpuAcc, ProfilingService::Instance(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, armnn::profiling::NotConnected, options, PacketWriter(), profilingService, PacketVersionResolver::ResolvePacketVersion(), armnn::SetAllLoggingSinks(), armnn::SetLogFilter(), ProfilingStateMachine::TransitionToState(), armnn::profiling::WaitingForAck, and armnn::Warning.

367 {
368  std::stringstream ss;
369 
370  struct StreamRedirector
371  {
372  public:
373  StreamRedirector(std::ostream &stream, std::streambuf *newStreamBuffer)
374  : m_Stream(stream), m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
375  {}
376 
378  { m_Stream.rdbuf(m_BackupBuffer); }
379 
380  private:
381  std::ostream &m_Stream;
382  std::streambuf *m_BackupBuffer;
383  };
384 
385  Holder holder;
386  PacketVersionResolver packetVersionResolver;
387  ProfilingStateMachine stateMachine;
388  ReadCounterVals readCounterVals;
389  StreamRedirector redirect(std::cout, ss.rdbuf());
390  CounterIdMap counterIdMap;
391  MockBackendSendCounterPacket sendCounterPacket;
392 
395 
397  options.m_ProfilingOptions.m_EnableProfiling = true;
398 
400 
401  std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
402  std::make_unique<BackendProfiling>(options, profilingService, cpuAccId);
403 
404  std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
405  std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
406 
407  std::unordered_map<armnn::BackendId,
408  std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
409 
410  uint16_t globalId = 5;
411  counterIdMap.RegisterMapping(globalId, 0, cpuAccId);
412  backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
413 
414  PeriodicCounterCapture periodicCounterCapture(holder, sendCounterPacket, readCounterVals,
415  counterIdMap, backendProfilingContexts);
416 
417  uint16_t maxArmnnCounterId = 4;
418 
419  PeriodicCounterSelectionCommandHandler periodicCounterSelectionCommandHandler(0,
420  4,
421  packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
422  backendProfilingContexts,
423  counterIdMap,
424  holder,
425  maxArmnnCounterId,
426  periodicCounterCapture,
427  readCounterVals,
428  sendCounterPacket,
429  stateMachine);
430 
431  stateMachine.TransitionToState(ProfilingState::NotConnected);
432  stateMachine.TransitionToState(ProfilingState::WaitingForAck);
433  stateMachine.TransitionToState(ProfilingState::Active);
434 
435  uint32_t period = 15939u;
436 
437  armnn::SetAllLoggingSinks(true, false, false);
439  periodicCounterSelectionCommandHandler(PacketWriter(period, {5}));
440  periodicCounterCapture.Stop();
442 
443  BOOST_CHECK(boost::contains(ss.str(), "ActivateCounters example test error"));
444 }
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
void TransitionToState(ProfilingState newState)
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
void SetLogFilter(LogSeverity level)
Definition: Logging.cpp:29
Packet PacketWriter(uint32_t period, std::vector< uint16_t > countervalues)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
GPU Execution: OpenCL: ArmCompute.
static ProfilingService & Instance()
CPU Execution: NEON: ArmCompute.
void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured)
Definition: Logging.cpp:147
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( BackendProfilingContextGetSendTimelinePacket  )

Definition at line 446 of file BackendProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::ConfigureProfilingService(), IRuntime::Create(), MockBackendProfilingContext::GetBackendProfiling(), MockBackendProfilingService::GetContext(), ProfilingService::Instance(), MockBackendProfilingService::Instance(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, options, profilingService, and ProfilingService::ResetExternalProfilingOptions().

447 {
448  // Reset the profiling service to the uninitialized state
450  options.m_ProfilingOptions.m_EnableProfiling = true;
452  profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
453 
454  armnn::MockBackendInitialiser initialiser;
455  // Create a runtime. During this the mock backend will be registered and context returned.
458  armnn::MockBackendProfilingContext *mockBackEndProfilingContext = mockProfilingService.GetContext();
459  // Check that there is a valid context set.
460  BOOST_CHECK(mockBackEndProfilingContext);
461  armnn::IBackendInternal::IBackendProfilingPtr& backendProfilingIface =
462  mockBackEndProfilingContext->GetBackendProfiling();
463  BOOST_CHECK(backendProfilingIface);
464 
465  // Now for the meat of the test. We're just going to send a random packet and make sure there
466  // are no exceptions or errors. The sending of packets is already tested in SendTimelinePacketTests.
467  std::unique_ptr<armnn::profiling::ISendTimelinePacket> timelinePacket =
468  backendProfilingIface->GetSendTimelinePacket();
469  // Send TimelineEntityClassBinaryPacket
470  const uint64_t entityBinaryPacketProfilingGuid = 123456u;
471  timelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
472  timelinePacket->Commit();
473 
474  // Reset the profiling servie after the test.
475  options.m_ProfilingOptions.m_EnableProfiling = false;
476  profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
477 }
static MockBackendProfilingService & Instance()
IBackendInternal::IBackendProfilingPtr & GetBackendProfiling()
Definition: MockBackend.hpp:39
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
MockBackendProfilingContext * GetContext()
static ProfilingService & Instance()
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:32
ProfilingService & profilingService
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:24
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr

◆ BOOST_AUTO_TEST_CASE() [5/5]

BOOST_AUTO_TEST_CASE ( GetProfilingGuidGenerator  )

Definition at line 479 of file BackendProfilingTests.cpp.

References BOOST_AUTO_TEST_SUITE_END(), BOOST_CHECK(), ProfilingService::ConfigureProfilingService(), IRuntime::Create(), MockBackendProfilingContext::GetBackendProfiling(), MockBackendProfilingService::GetContext(), ProfilingService::Instance(), MockBackendProfilingService::Instance(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, IProfilingGuidGenerator::NextGuid(), options, profilingService, and ProfilingService::ResetExternalProfilingOptions().

480 {
481  // Reset the profiling service to the uninitialized state
483  options.m_ProfilingOptions.m_EnableProfiling = true;
485  profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
486 
487  armnn::MockBackendInitialiser initialiser;
488  // Create a runtime. During this the mock backend will be registered and context returned.
491  armnn::MockBackendProfilingContext *mockBackEndProfilingContext = mockProfilingService.GetContext();
492  // Check that there is a valid context set.
493  BOOST_CHECK(mockBackEndProfilingContext);
494  armnn::IBackendInternal::IBackendProfilingPtr& backendProfilingIface =
495  mockBackEndProfilingContext->GetBackendProfiling();
496  BOOST_CHECK(backendProfilingIface);
497 
498  // Get the Guid generator and check the getting two Guid's results in the second being greater than the first.
499  armnn::profiling::IProfilingGuidGenerator& guidGenerator = backendProfilingIface->GetProfilingGuidGenerator();
500  BOOST_CHECK(backendProfilingIface);
501  const armnn::profiling::ProfilingDynamicGuid& firstGuid = guidGenerator.NextGuid();
502  BOOST_CHECK(firstGuid);
503  const armnn::profiling::ProfilingDynamicGuid& secondGuid = guidGenerator.NextGuid();
504  BOOST_CHECK(secondGuid > firstGuid);
505 
506  // Reset the profiling servie after the test.
507  options.m_ProfilingOptions.m_EnableProfiling = false;
508  profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
509 }
static MockBackendProfilingService & Instance()
virtual ProfilingDynamicGuid NextGuid()=0
Return the next random Guid in the sequence.
IBackendInternal::IBackendProfilingPtr & GetBackendProfiling()
Definition: MockBackend.hpp:39
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
MockBackendProfilingContext * GetContext()
static ProfilingService & Instance()
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:32
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:291
ProfilingService & profilingService
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:24
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr

◆ PacketWriter()

Packet PacketWriter ( uint32_t  period,
std::vector< uint16_t >  countervalues 
)

Definition at line 90 of file BackendProfilingTests.cpp.

References BOOST_AUTO_TEST_SUITE(), armnn::profiling::WriteUint16(), and armnn::profiling::WriteUint32().

Referenced by BOOST_AUTO_TEST_CASE().

91 {
92  const uint32_t packetId = 0x40000;
93  uint32_t offset = 0;
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());
97 
98  WriteUint32(data1, offset, period);
99  offset += 4;
100  for (auto countervalue : countervalues)
101  {
102  WriteUint16(data1, offset, countervalue);
103  offset += 2;
104  }
105 
106  return {packetId, dataLength, uniqueData};
107 }
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)